mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Making MissingView and MissingLayout cake errors into exceptions.
This commit is contained in:
parent
a23207791a
commit
1d983e1cd4
2 changed files with 11 additions and 45 deletions
|
@ -747,6 +747,7 @@ class View extends Object {
|
|||
*
|
||||
* @param string $name Controller action to find template filename for
|
||||
* @return string Template filename
|
||||
* @throws MissingViewException when a view file could not be found.
|
||||
*/
|
||||
protected function _getViewFileName($name = null) {
|
||||
$subDir = null;
|
||||
|
@ -798,7 +799,7 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
return $this->_missingView($defaultPath . $name . $this->ext, 'missingView');
|
||||
throw new MissingViewException($defaultPath . $name . $this->ext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -806,6 +807,7 @@ class View extends Object {
|
|||
*
|
||||
* @param string $name The name of the layout to find.
|
||||
* @return string Filename for layout file (.ctp).
|
||||
* @throws MissingLayoutException when a layout cannot be located
|
||||
*/
|
||||
protected function _getLayoutFileName($name = null) {
|
||||
if ($name === null) {
|
||||
|
@ -830,32 +832,7 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a misssing view error message
|
||||
*
|
||||
* @param string $viewFileName the filename that should exist
|
||||
* @return false
|
||||
*/
|
||||
protected function _missingView($file, $error = 'missingView') {
|
||||
if ($error === 'missingView') {
|
||||
$this->cakeError('missingView', array(
|
||||
'className' => $this->name,
|
||||
'action' => $this->action,
|
||||
'file' => $file,
|
||||
'base' => $this->base
|
||||
));
|
||||
return false;
|
||||
} elseif ($error === 'missingLayout') {
|
||||
$this->cakeError('missingLayout', array(
|
||||
'layout' => $this->layout,
|
||||
'file' => $file,
|
||||
'base' => $this->base
|
||||
));
|
||||
return false;
|
||||
}
|
||||
throw new MissingLayoutException($paths[0] . $file . $this->ext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -886,3 +863,6 @@ class View extends Object {
|
|||
return $this->__paths;
|
||||
}
|
||||
}
|
||||
|
||||
class MissingViewException extends RuntimeException { }
|
||||
class MissingLayoutException extends RuntimeException { }
|
||||
|
|
|
@ -375,6 +375,7 @@ class ViewTest extends CakeTestCase {
|
|||
/**
|
||||
* testMissingView method
|
||||
*
|
||||
* @expectedException MissingViewException
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -388,15 +389,12 @@ class ViewTest extends CakeTestCase {
|
|||
$View = new TestView($this->Controller);
|
||||
ob_start();
|
||||
$result = $View->getViewFileName('does_not_exist');
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
|
||||
$this->assertPattern("/PagesController::/", $expected);
|
||||
$this->assertPattern("/pages(\/|\\\)does_not_exist.ctp/", $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testMissingLayout method
|
||||
*
|
||||
* @expectedException MissingLayoutException
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -410,9 +408,6 @@ class ViewTest extends CakeTestCase {
|
|||
ob_start();
|
||||
$result = $View->getLayoutFileName();
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
|
||||
$this->assertPattern("/Missing Layout/", $expected);
|
||||
$this->assertPattern("/layouts(\/|\\\)whatever.ctp/", $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -895,25 +890,16 @@ class ViewTest extends CakeTestCase {
|
|||
/**
|
||||
* testBadExt method
|
||||
*
|
||||
* @expectedException MissingViewException
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testBadExt() {
|
||||
$this->PostsController->action = 'something';
|
||||
$this->PostsController->ext = '.whatever';
|
||||
ob_start();
|
||||
|
||||
$View = new TestView($this->PostsController);
|
||||
$View->render('this_is_missing');
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
|
||||
$this->assertPattern("/<em>PostsController::<\/em><em>something\(\)<\/em>/", $result);
|
||||
$this->assertPattern("/posts(\/|\\\)this_is_missing.whatever/", $result);
|
||||
|
||||
$this->PostsController->ext = ".bad";
|
||||
$View = new TestView($this->PostsController);
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", $View->render('index'));
|
||||
|
||||
$this->assertPattern("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>/", $result);
|
||||
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue