diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 953e5c216..721d08b5f 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -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 { } diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 91502287f..fe1a85d69 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -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("/PostsController::<\/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("//", $result); - $this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result); } }