Skip to content

Commit

Permalink
Merge pull request #94 from codingmusica/bug/cascorder0
Browse files Browse the repository at this point in the history
Changed the order of arguments in array_merge_recursive() to prioritize ...
  • Loading branch information
lsmith77 committed Apr 15, 2014
2 parents 20bd342 + 3783969 commit 76ceada
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Locator/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(KernelInterface $kernel, ActiveTheme $activeTheme, $
),
);

$this->pathPatterns = array_merge_recursive($defaultPathPatterns, array_filter($pathPatterns));
$this->pathPatterns = array_merge_recursive(array_filter($pathPatterns), $defaultPathPatterns);

$this->setCurrentTheme($this->activeTheme->getName());
}
Expand Down
Empty file.
Empty file.
33 changes: 24 additions & 9 deletions Tests/Locator/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,39 @@ public function testConstructorFallbackPathMerge()
array(),
array(
'app_resource' => array(
'%app_path%/themes/fallback/%template%'
'%app_path%/views/themes/%current_theme%/%template',
'%app_path%/views/themes/fallback/%template%',
),
'bundle_resource' => array(
'%bundle_path%/Resources/themes/fallback/%template%'
'%bundle_path%/Resources/views/themes/%current_theme%/%template%',
'%bundle_path%/Resources/views/themes/fallback/%template%',

),
'bundle_resource_dir' => array(
'%dir%/themes/fallback/%bundle_name%/%template%'
'%dir%/views/themes/%current_theme%/%bundle_name%/%template%',
'%dir%/views/themes/fallback/%bundle_name%/%template%',
)
)
);

$this->assertEquals(
array(
'app_resource' => array(
'%app_path%/views/themes/%current_theme%/%template',
'%app_path%/views/themes/fallback/%template%',
'%app_path%/themes/%current_theme%/%template%',
'%app_path%/views/%template%',
'%app_path%/themes/fallback/%template%'
),
'bundle_resource' => array(
'%bundle_path%/Resources/views/themes/%current_theme%/%template%',
'%bundle_path%/Resources/views/themes/fallback/%template%',
'%bundle_path%/Resources/themes/%current_theme%/%template%',
'%bundle_path%/Resources/themes/fallback/%template%'
),
'bundle_resource_dir' => array(
'%dir%/views/themes/%current_theme%/%bundle_name%/%template%',
'%dir%/views/themes/fallback/%bundle_name%/%template%',
'%dir%/themes/%current_theme%/%bundle_name%/%template%',
'%dir%/%bundle_name%/%override_path%',
'%dir%/themes/fallback/%bundle_name%/%template%'
),
),
$property->getValue($fileLocator)
Expand All @@ -153,21 +160,29 @@ public function testLocate()
* @covers Liip\ThemeBundle\Locator\FileLocator::locate
* @covers Liip\ThemeBundle\Locator\FileLocator::locateBundleResource
*/
public function testLocateWithOverridenPathPattern()
public function testLocateWithOverriddenPathPattern()
{
$kernel = $this->getKernelMock();
$activeTheme = new ActiveTheme('foo', array('foo', 'bar', 'foobar'));

$pathPatterns = array(
'bundle_resource' => array(
'%bundle_path%/Resources/themes2/%current_theme%/%template%',
'%bundle_path%/Resources/views/themes/%current_theme%/%template%',
'%bundle_path%/Resources/views/themes/fallback/%template%',
)
);
$fileLocator = new FileLocator($kernel, $activeTheme, $this->getFixturePath() . '/rootdir/Resources', array(), $pathPatterns);

$file = $fileLocator->locate('@ThemeBundle/Resources/views/template', $this->getFixturePath(), true);
$this->assertEquals($this->getFixturePath().'/Resources/views/themes/foo/template', $file);

// Fall through user-configured cascade order - /Resources/views/themes/bar will not be found.
$activeTheme = new ActiveTheme('bar', array('foo', 'bar', 'foobar'));

$fileLocator = new FileLocator($kernel, $activeTheme, $this->getFixturePath() . '/rootdir/Resources', array(), $pathPatterns);

$file = $fileLocator->locate('@ThemeBundle/Resources/views/template', $this->getFixturePath(), true);
$this->assertEquals($this->getFixturePath().'/Resources/themes/foo/template', $file);
$this->assertEquals($this->getFixturePath().'/Resources/views/themes/fallback/template', $file);
}

/**
Expand Down

0 comments on commit 76ceada

Please sign in to comment.