Skip to content

Commit

Permalink
Replace public property View::$ext with protected View::$_ext.
Browse files Browse the repository at this point in the history
The view file extension can longer be changed through controller.
  • Loading branch information
ADmad committed Mar 8, 2014
1 parent 0953c3d commit 6feb079
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 60 deletions.
16 changes: 8 additions & 8 deletions src/View/View.php
Expand Up @@ -148,7 +148,7 @@ class View extends Object {
* *
* @var string * @var string
*/ */
public $ext = '.ctp'; protected $_ext = '.ctp';


/** /**
* Sub-directory for this view file. This is often used for extension based routing. * Sub-directory for this view file. This is often used for extension based routing.
Expand Down Expand Up @@ -235,7 +235,7 @@ class View extends Object {
* @var array * @var array
*/ */
protected $_passedVars = array( protected $_passedVars = array(
'viewVars', 'autoLayout', 'ext', 'helpers', 'view', 'layout', 'name', 'theme', 'viewVars', 'autoLayout', 'helpers', 'view', 'layout', 'name', 'theme',
'layoutPath', 'viewPath', 'request', 'plugin', 'passedArgs', 'cacheAction' 'layoutPath', 'viewPath', 'request', 'plugin', 'passedArgs', 'cacheAction'
); );


Expand Down Expand Up @@ -411,7 +411,7 @@ public function element($name, $data = array(), $options = array()) {
if (empty($options['ignoreMissing'])) { if (empty($options['ignoreMissing'])) {
list ($plugin, $name) = pluginSplit($name, true); list ($plugin, $name) = pluginSplit($name, true);
$name = str_replace('/', DS, $name); $name = str_replace('/', DS, $name);
$file = $plugin . 'Element' . DS . $name . $this->ext; $file = $plugin . 'Element' . DS . $name . $this->_ext;
trigger_error(sprintf('Element Not Found: %s', $file), E_USER_NOTICE); trigger_error(sprintf('Element Not Found: %s', $file), E_USER_NOTICE);
} }
} }
Expand Down Expand Up @@ -706,7 +706,7 @@ public function extend($name) {
$defaultPath = $paths[0] . 'Element' . DS; $defaultPath = $paths[0] . 'Element' . DS;
throw new \LogicException(sprintf( throw new \LogicException(sprintf(
'You cannot extend an element which does not exist (%s).', 'You cannot extend an element which does not exist (%s).',
$defaultPath . $name . $this->ext $defaultPath . $name . $this->_ext
)); ));
} }
break; break;
Expand Down Expand Up @@ -949,7 +949,7 @@ protected function _getViewFileName($name = null) {
} }
} }
} }
throw new Error\MissingViewException(array('file' => $defaultPath . $name . $this->ext)); throw new Error\MissingViewException(array('file' => $defaultPath . $name . $this->_ext));
} }


/** /**
Expand Down Expand Up @@ -1002,7 +1002,7 @@ protected function _getLayoutFileName($name = null) {
} }
} }
} }
throw new Error\MissingLayoutException(array('file' => $paths[0] . $file . $this->ext)); throw new Error\MissingLayoutException(array('file' => $paths[0] . $file . $this->_ext));
} }


/** /**
Expand All @@ -1011,8 +1011,8 @@ protected function _getLayoutFileName($name = null) {
* @return array Array of extensions view files use. * @return array Array of extensions view files use.
*/ */
protected function _getExtensions() { protected function _getExtensions() {
$exts = array($this->ext); $exts = array($this->_ext);
if ($this->ext !== '.ctp') { if ($this->_ext !== '.ctp') {
$exts[] = '.ctp'; $exts[] = '.ctp';
} }
return $exts; return $exts;
Expand Down
52 changes: 0 additions & 52 deletions tests/TestCase/View/ViewTest.php
Expand Up @@ -793,21 +793,6 @@ public function testMagicGet() {
$this->assertInstanceOf('Cake\View\Helper\HtmlHelper', $View->Html); $this->assertInstanceOf('Cake\View\Helper\HtmlHelper', $View->Html);
} }


/**
* Test that ctp is used as a fallback file extension for elements
*
* @return void
*/
public function testElementCtpFallback() {
$View = new TestView($this->PostsController);
$View->ext = '.missing';
$element = 'test_element';
$expected = 'this is the test element';
$result = $View->element($element);

$this->assertEquals($expected, $result);
}

/** /**
* Test loadHelpers method * Test loadHelpers method
* *
Expand Down Expand Up @@ -1164,43 +1149,6 @@ public function testRenderStrippingNoCacheTagsOnlyCacheCheck() {
$this->assertNotRegExp('/cake:nocache/', $result); $this->assertNotRegExp('/cake:nocache/', $result);
} }


/**
* testBadExt method
*
* @expectedException \Cake\Error\MissingViewException
* @return void
*/
public function testBadExt() {
$this->PostsController->action = 'something';
$this->PostsController->ext = '.whatever';

$View = new TestView($this->PostsController);
$View->render('this_is_missing');
}

/**
* testAltExt method
*
* @return void
*/
public function testAltExt() {
$this->PostsController->ext = '.alt';
$View = new TestView($this->PostsController);
$result = $View->render('alt_ext', false);
$this->assertEquals('alt ext', $result);
}

/**
* testAltBadExt method
*
* @expectedException \Cake\Error\MissingViewException
* @return void
*/
public function testAltBadExt() {
$View = new TestView($this->PostsController);
$View->render('alt_ext');
}

/** /**
* Test creating a block with capturing output. * Test creating a block with capturing output.
* *
Expand Down

0 comments on commit 6feb079

Please sign in to comment.