From 30cb38eb93b416f53abd946b5a48e2794cf61b70 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Thu, 28 Jan 2010 11:11:19 -0500 Subject: [PATCH] Refactoring extensions in ScaffoldView to reflect removal of magic .thtml extension. Adding test for interaction of Themed views and Scaffolded views. Fixes #255 --- cake/libs/controller/scaffold.php | 12 +++++++----- .../cases/libs/controller/scaffold.test.php | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index e0bf3bef0..1abd00c2c 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -584,11 +584,13 @@ class ScaffoldView extends ThemeView { $names[] = 'scaffolds' . DS . $subDir . $name; $paths = $this->_paths($this->plugin); - - $exts = array($this->ext, '.ctp', '.thtml'); - foreach ($paths as $path) { - foreach ($names as $name) { - foreach ($exts as $ext) { + $exts = array($this->ext); + if ($this->ext !== '.ctp') { + array_push($exts, '.ctp'); + } + foreach ($exts as $ext) { + foreach ($paths as $path) { + foreach ($names as $name) { if (file_exists($path . $name . $ext)) { return $path . $name . $ext; } diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 6ddd3c150..63ebba91e 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -380,6 +380,23 @@ class ScaffoldViewTest extends CakeTestCase { Configure::write('Routing.prefixes', $_admin); } +/** + * test getting the view file name for themed scaffolds. + * + * @return void + */ + function testGetViewFileNameWithTheme() { + $this->Controller->action = 'index'; + $this->Controller->viewPath = 'posts'; + $this->Controller->theme = 'test_theme'; + $ScaffoldView =& new TestScaffoldView($this->Controller); + + $result = $ScaffoldView->testGetFilename('index'); + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS + . 'themed' . DS . 'test_theme' . DS . 'posts' . DS . 'scaffold.index.ctp'; + $this->assertEqual($result, $expected); + } + /** * test default index scaffold generation *