From 0f4c90588d6e4b43c41ee2ce883303fe32ff14b1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Jan 2011 20:43:41 -0500 Subject: [PATCH] Fixing issue where elements did not get .ctp as a fallback extension unlike view and layout files. Adding a protected method to get extensions, as it would be in 3 places now. Added tests. Fixes #1438 --- cake/libs/view/view.php | 39 +++++++++++++++--------- cake/tests/cases/libs/view/view.test.php | 15 +++++++++ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index dbf7b5f9b..0224ce4c9 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -372,11 +372,13 @@ class View extends Object { } } $paths = $this->_paths($plugin); - - foreach ($paths as $path) { - if (file_exists($path . 'elements' . DS . $name . $this->ext)) { - $file = $path . 'elements' . DS . $name . $this->ext; - break; + $exts = $this->_getExtensions(); + foreach ($exts as $ext) { + foreach ($paths as $path) { + if (file_exists($path . 'elements' . DS . $name . $ext)) { + $file = $path . 'elements' . DS . $name . $ext; + break; + } } } @@ -862,10 +864,7 @@ class View extends Object { } $paths = $this->_paths(Inflector::underscore($this->plugin)); - $exts = array($this->ext); - if ($this->ext !== '.ctp') { - array_push($exts, '.ctp'); - } + $exts = $this->_getExtensions(); foreach ($exts as $ext) { foreach ($paths as $path) { if (file_exists($path . $name . $ext)) { @@ -905,11 +904,8 @@ class View extends Object { } $paths = $this->_paths(Inflector::underscore($this->plugin)); $file = 'layouts' . DS . $subDir . $name; - - $exts = array($this->ext); - if ($this->ext !== '.ctp') { - array_push($exts, '.ctp'); - } + + $exts = $this->_getExtensions(); foreach ($exts as $ext) { foreach ($paths as $path) { if (file_exists($path . $file . $ext)) { @@ -920,6 +916,21 @@ class View extends Object { return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout'); } + +/** + * Get the extensions that view files can use. + * + * @return array Array of extensions view files use. + * @access protected + */ + function _getExtensions() { + $exts = array($this->ext); + if ($this->ext !== '.ctp') { + array_push($exts, '.ctp'); + } + return $exts; + } + /** * Return a misssing view error message * diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 8ffb0837a..938b1aac4 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -573,6 +573,21 @@ class ViewTest extends CakeTestCase { } +/** + * test that ctp is used as a fallback file extension for elements + * + * @return void + */ + function testElementCtpFallback() { + $View = new TestView($this->PostsController); + $View->ext = '.missing'; + $element = 'test_element'; + $expected = 'this is the test element'; + $result = $View->element($element); + + $this->assertEqual($expected, $result); + } + /** * testLoadHelpers method *