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
This commit is contained in:
mark_story 2011-01-12 20:43:41 -05:00
parent f893e3b63b
commit 0f4c90588d
2 changed files with 40 additions and 14 deletions

View file

@ -372,11 +372,13 @@ class View extends Object {
} }
} }
$paths = $this->_paths($plugin); $paths = $this->_paths($plugin);
$exts = $this->_getExtensions();
foreach ($paths as $path) { foreach ($exts as $ext) {
if (file_exists($path . 'elements' . DS . $name . $this->ext)) { foreach ($paths as $path) {
$file = $path . 'elements' . DS . $name . $this->ext; if (file_exists($path . 'elements' . DS . $name . $ext)) {
break; $file = $path . 'elements' . DS . $name . $ext;
break;
}
} }
} }
@ -862,10 +864,7 @@ class View extends Object {
} }
$paths = $this->_paths(Inflector::underscore($this->plugin)); $paths = $this->_paths(Inflector::underscore($this->plugin));
$exts = array($this->ext); $exts = $this->_getExtensions();
if ($this->ext !== '.ctp') {
array_push($exts, '.ctp');
}
foreach ($exts as $ext) { foreach ($exts as $ext) {
foreach ($paths as $path) { foreach ($paths as $path) {
if (file_exists($path . $name . $ext)) { if (file_exists($path . $name . $ext)) {
@ -905,11 +904,8 @@ class View extends Object {
} }
$paths = $this->_paths(Inflector::underscore($this->plugin)); $paths = $this->_paths(Inflector::underscore($this->plugin));
$file = 'layouts' . DS . $subDir . $name; $file = 'layouts' . DS . $subDir . $name;
$exts = array($this->ext); $exts = $this->_getExtensions();
if ($this->ext !== '.ctp') {
array_push($exts, '.ctp');
}
foreach ($exts as $ext) { foreach ($exts as $ext) {
foreach ($paths as $path) { foreach ($paths as $path) {
if (file_exists($path . $file . $ext)) { if (file_exists($path . $file . $ext)) {
@ -920,6 +916,21 @@ class View extends Object {
return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout'); 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 * Return a misssing view error message
* *

View file

@ -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 * testLoadHelpers method
* *