Skip to content
Permalink
Browse files

Raise a cell specific error when views are missing.

The standard MissingView error page references controllers. By using
a more specific error message we can avoid referencing the controller
and only mention that the cell view is missing.
  • Loading branch information...
markstory committed Jul 23, 2014
1 parent e64e01a commit ad401ec86eae8e07b0c88b0b28916a98a28599fd
Showing with 45 additions and 2 deletions.
  1. +8 −1 src/View/Cell.php
  2. +25 −0 src/View/Error/MissingCellViewException.php
  3. +12 −1 tests/TestCase/View/CellTest.php
@@ -20,6 +20,8 @@
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Utility\Inflector;
use Cake\View\Error\MissingCellViewException;
use Cake\View\Error\MissingViewException;
use Cake\View\ViewVarsTrait;
/**
@@ -132,6 +134,7 @@ public function __construct(Request $request = null, Response $response = null,
* @param string $template Custom template name to render. If not provided (null), the last
* value will be used. This value is automatically set by `CellTrait::cell()`.
* @return void
* @throws \Cake\Error\MissingCellViewException When a MissingViewException is raised during rendering.
*/
public function render($template = null) {
if ($template !== null && strpos($template, '/') === false) {
@@ -148,7 +151,11 @@ public function render($template = null) {
$className = array_pop($className);
$this->View->subDir = 'Cell' . DS . substr($className, 0, strpos($className, 'Cell'));
return $this->View->render($template);
try {
return $this->View->render($template);
} catch (MissingViewException $e) {
throw new MissingCellViewException(['file' => $template]);
}
}
/**
@@ -0,0 +1,25 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\View\Error;
use Cake\Error\Exception;
/**
* Used when a view file for a cell cannot be found.
*/
class MissingCellViewException extends Exception {
protected $_messageTemplate = 'Cell view file "%s" is missing.';
}
@@ -81,7 +81,7 @@ public function testCellImplictRenderWithError() {
$capture = function ($errno, $msg) {
restore_error_handler();
$this->assertEquals(E_USER_WARNING, $errno);
$this->assertContains('Could not render cell - View file', $msg);
$this->assertContains('Could not render cell - Cell view file', $msg);
};
set_error_handler($capture);
@@ -133,6 +133,17 @@ public function testCellManualRender() {
$this->assertContains('<h2>Lorem ipsum</h2>', $cell->render('teaser_list'));
}
/**
* Tests manual render() invocation with error
*
* @expectedException \Cake\View\Error\MissingCellViewException
* @return void
*/
public function testCellManualRenderError() {
$cell = $this->View->cell('Articles');
$cell->render('derp');
}
/**
* Test rendering a cell with a theme.
*

0 comments on commit ad401ec

Please sign in to comment.
You can’t perform that action at this time.