Skip to content

Commit

Permalink
Consistently inflect theme names.
Browse files Browse the repository at this point in the history
Themes should be consistently converted into CamelCase, this
makes the camelization consitent with the treatment in App::themePath().

Fixes #3508
  • Loading branch information
markstory committed Jan 4, 2013
1 parent 75f654b commit 6d74397
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
13 changes: 3 additions & 10 deletions lib/Cake/Test/Case/View/ViewTest.php
Expand Up @@ -300,7 +300,7 @@ public function testGetTemplate() {
$this->Controller->params['pass'] = array('home'); $this->Controller->params['pass'] = array('home');


$ThemeView = new TestThemeView($this->Controller); $ThemeView = new TestThemeView($this->Controller);
$ThemeView->theme = 'TestTheme'; $ThemeView->theme = 'test_theme';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages' . DS . 'home.ctp'; $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages' . DS . 'home.ctp';
$result = $ThemeView->getViewFileName('home'); $result = $ThemeView->getViewFileName('home');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
Expand All @@ -309,6 +309,7 @@ public function testGetTemplate() {
$result = $ThemeView->getViewFileName('/Posts/index'); $result = $ThemeView->getViewFileName('/Posts/index');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);


$ThemeView->theme = 'TestTheme';
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS . 'default.ctp'; $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS . 'default.ctp';
$result = $ThemeView->getLayoutFileName(); $result = $ThemeView->getLayoutFileName();
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
Expand Down Expand Up @@ -546,11 +547,7 @@ public function testMissingView() {
$this->ThemeController->params['pass'] = array('home'); $this->ThemeController->params['pass'] = array('home');


$View = new TestThemeView($this->ThemeController); $View = new TestThemeView($this->ThemeController);
ob_start(); $View->getViewFileName('does_not_exist');
$result = $View->getViewFileName('does_not_exist');
$expected = ob_get_clean();
$this->assertRegExp("/PagesController::/", $expected);
$this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)pages(\/|\\\)does_not_exist.ctp/", $expected);
} }


/** /**
Expand All @@ -577,11 +574,7 @@ public function testMissingLayout() {
$this->ThemeController->theme = 'my_theme'; $this->ThemeController->theme = 'my_theme';


$View = new TestThemeView($this->ThemeController); $View = new TestThemeView($this->ThemeController);
ob_start();
$result = $View->getLayoutFileName(); $result = $View->getLayoutFileName();
$expected = ob_get_clean();
$this->assertRegExp("/Missing Layout/", $expected);
$this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)layouts(\/|\\\)whatever.ctp/", $expected);
} }


/** /**
Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/View/View.php
Expand Up @@ -1111,13 +1111,14 @@ protected function _paths($plugin = null, $cached = true) {


$paths = array_unique(array_merge($paths, $viewPaths)); $paths = array_unique(array_merge($paths, $viewPaths));
if (!empty($this->theme)) { if (!empty($this->theme)) {
$theme = Inflector::camelize($this->theme);
$themePaths = array(); $themePaths = array();
foreach ($paths as $path) { foreach ($paths as $path) {
if (strpos($path, DS . 'Plugin' . DS) === false) { if (strpos($path, DS . 'Plugin' . DS) === false) {
if ($plugin) { if ($plugin) {
$themePaths[] = $path . 'Themed' . DS . $this->theme . DS . 'Plugin' . DS . $plugin . DS; $themePaths[] = $path . 'Themed' . DS . $theme . DS . 'Plugin' . DS . $plugin . DS;
} }
$themePaths[] = $path . 'Themed' . DS . $this->theme . DS; $themePaths[] = $path . 'Themed' . DS . $theme . DS;
} }
} }
$paths = array_merge($themePaths, $paths); $paths = array_merge($themePaths, $paths);
Expand Down

0 comments on commit 6d74397

Please sign in to comment.