mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
updating error handling, error.test, view.test, theme.test, change socket.test to use App::import()
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6479 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
3316731dd9
commit
d3e2d51cbc
6 changed files with 101 additions and 146 deletions
|
@ -102,7 +102,7 @@ class Component extends Object {
|
|||
'file' => Inflector::underscore($component) . '.php',
|
||||
'base' => $this->controller->base
|
||||
)));
|
||||
exit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ class Component extends Object {
|
|||
'file' => Inflector::underscore($component) . '.php',
|
||||
'base' => $this->controller->base
|
||||
)));
|
||||
exit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$base = null;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
/**
|
||||
* Included libraries.
|
||||
*/
|
||||
App::import('Core', array('view' . DS . 'helper', 'ClassRegistry'));
|
||||
App::import('Core', array('Helper', 'ClassRegistry'));
|
||||
|
||||
/**
|
||||
* View, the V in the MVC triad.
|
||||
|
@ -330,8 +330,7 @@ class View extends Object {
|
|||
$action = $file;
|
||||
}
|
||||
|
||||
if ($action !== false) {
|
||||
$viewFileName = $this->_getViewFileName($action);
|
||||
if ($action !== false && $viewFileName = $this->_getViewFileName($action)) {
|
||||
if (substr($viewFileName, -3) === 'ctp' || substr($viewFileName, -5) === 'thtml') {
|
||||
$out = View::_render($viewFileName, $this->viewVars);
|
||||
} else {
|
||||
|
@ -722,7 +721,7 @@ class View extends Object {
|
|||
'file' => Inflector::underscore($helper) . '.php',
|
||||
'base' => $this->base
|
||||
)));
|
||||
exit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!class_exists($helperCn)) {
|
||||
|
@ -731,7 +730,7 @@ class View extends Object {
|
|||
'file' => Inflector::underscore($helper) . '.php',
|
||||
'base' => $this->base
|
||||
)));
|
||||
exit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$loaded[$helper] =& new $helperCn($options);
|
||||
|
@ -766,7 +765,6 @@ class View extends Object {
|
|||
*/
|
||||
function _getViewFileName($name = null) {
|
||||
$subDir = null;
|
||||
|
||||
if (!is_null($this->subDir)) {
|
||||
$subDir = $this->subDir . DS;
|
||||
}
|
||||
|
@ -801,6 +799,8 @@ class View extends Object {
|
|||
foreach ($paths as $path) {
|
||||
if (file_exists($path . $name . $this->ext)) {
|
||||
return $path . $name . $this->ext;
|
||||
} elseif (file_exists($path . $name . '.ctp')) {
|
||||
return $path . $name . '.ctp';
|
||||
} elseif (file_exists($path . $name . '.thtml')) {
|
||||
return $path . $name . '.thtml';
|
||||
}
|
||||
|
@ -831,6 +831,8 @@ class View extends Object {
|
|||
foreach ($paths as $path) {
|
||||
if (file_exists($path . $file . $this->ext)) {
|
||||
return $path . $file . $this->ext;
|
||||
} elseif (file_exists($path . $name . '.ctp')) {
|
||||
return $path . $file . '.ctp';
|
||||
} elseif (file_exists($path . $file . '.thtml')) {
|
||||
return $path . $file . '.thtml';
|
||||
}
|
||||
|
@ -845,43 +847,24 @@ class View extends Object {
|
|||
* @return cakeError
|
||||
*/
|
||||
function _missingView($file, $error = 'missingView') {
|
||||
if (Configure::read() == 0) {
|
||||
$this->cakeError('error404');
|
||||
exit();
|
||||
}
|
||||
$paths = $this->_paths($this->plugin);
|
||||
$name = 'errors' . DS . Inflector::underscore($error);
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path . $name . $this->ext)) {
|
||||
$name = $path . $name . $this->ext;
|
||||
break;
|
||||
} elseif (file_exists($path . $name . '.ctp')) {
|
||||
$name = $path . $name . '.ctp';
|
||||
$this->ext = '.ctp';
|
||||
break;
|
||||
} elseif (file_exists($path . $name . '.thtml')) {
|
||||
$name = $path . $name . '.thtml';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($error === 'missingView') {
|
||||
$this->set(array(
|
||||
'controller' => $this->name,
|
||||
$this->cakeError('missingView', array(
|
||||
'className' => $this->name,
|
||||
'action' => $this->action,
|
||||
'file' => $file,
|
||||
'base' => $this->base
|
||||
));
|
||||
return false;
|
||||
} elseif ($error === 'missingLayout') {
|
||||
$this->set(array(
|
||||
$this->cakeError('missingLayout', array(
|
||||
'layout' => $this->layout,
|
||||
'file' => $file,
|
||||
'base' => $this->base
|
||||
));
|
||||
return false;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
/**
|
||||
* Return all possible paths to find view files in order
|
||||
|
|
|
@ -26,10 +26,12 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Core', array('Error', 'Controller'));
|
||||
|
||||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
||||
}
|
||||
uses('error', 'controller' . DS .'controller');
|
||||
|
||||
if (!class_exists('TestAppController')) {
|
||||
class TestAppController extends Controller {
|
||||
function beforeFilter() {
|
||||
|
@ -105,10 +107,33 @@ class ErrorHandlerTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
function testMissingView() {
|
||||
restore_error_handler();
|
||||
ob_start();
|
||||
$ErrorHandler = new ErrorHandler('missingView', array(
|
||||
'className' => 'Pages',
|
||||
'action' => 'display',
|
||||
'file' => 'pages/about.ctp',
|
||||
'base' => ''
|
||||
));
|
||||
$expected = ob_get_clean();
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
$this->assertPattern("/PagesController::/", $expected);
|
||||
$this->assertPattern("/pages\/about.ctp/", $expected);
|
||||
|
||||
}
|
||||
|
||||
function testMissingLayout() {
|
||||
restore_error_handler();
|
||||
ob_start();
|
||||
$ErrorHandler = new ErrorHandler('missingLayout', array(
|
||||
'layout' => 'my_layout',
|
||||
'file' => 'layouts/my_layout.ctp',
|
||||
'base' => ''
|
||||
));
|
||||
$expected = ob_get_clean();
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
$this->assertPattern("/Missing Layout/", $expected);
|
||||
$this->assertPattern("/layouts\/my_layout.ctp/", $expected);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
uses('socket');
|
||||
App::import('Core', 'Socket');
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
|
|
@ -26,7 +26,11 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
uses('controller' . DS . 'controller', 'view'.DS.'theme');
|
||||
App::import('Core', array('Theme', 'Controller'));
|
||||
|
||||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
||||
}
|
||||
|
||||
class ThemePostsController extends Controller {
|
||||
var $name = 'ThemePosts';
|
||||
|
@ -50,10 +54,6 @@ class TestThemeView extends ThemeView {
|
|||
function getLayoutFileName($name = null) {
|
||||
return $this->_getLayoutFileName($name);
|
||||
}
|
||||
|
||||
function cakeError($name, $params) {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,14 +134,18 @@ class ThemeViewTest extends UnitTestCase {
|
|||
$this->Controller->name = 'Pages';
|
||||
$this->Controller->viewPath = 'pages';
|
||||
$this->Controller->action = 'display';
|
||||
$this->Controller->theme = 'my_theme';
|
||||
|
||||
$this->Controller->params['pass'] = array('home');
|
||||
|
||||
$ThemeView = new TestThemeView($this->Controller);
|
||||
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'errors' . DS . 'missing_view.ctp';
|
||||
$result = $ThemeView->getViewFileName('does_not_exist');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
restore_error_handler();
|
||||
$View = new TestThemeView($this->Controller);
|
||||
ob_start();
|
||||
$result = $View->getViewFileName('does_not_exist');
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
$this->assertPattern("/PagesController::/", $expected);
|
||||
$this->assertPattern("/views\/themed\/my_theme\/pages\/does_not_exist.ctp/", $expected);
|
||||
}
|
||||
|
||||
function testMissingLayout() {
|
||||
|
@ -149,11 +153,16 @@ class ThemeViewTest extends UnitTestCase {
|
|||
$this->Controller->name = 'Posts';
|
||||
$this->Controller->viewPath = 'posts';
|
||||
$this->Controller->layout = 'whatever';
|
||||
$this->Controller->theme = 'my_theme';
|
||||
|
||||
$ThemeView = new TestThemeView($this->Controller);
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'errors' . DS . 'missing_layout.ctp';
|
||||
$result = $ThemeView->getLayoutFileName();
|
||||
$this->assertEqual($result, $expected);
|
||||
restore_error_handler();
|
||||
$View = new TestThemeView($this->Controller);
|
||||
ob_start();
|
||||
$result = $View->getLayoutFileName();
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
$this->assertPattern("/Missing Layout/", $expected);
|
||||
$this->assertPattern("/views\/themed\/my_theme\/layouts\/whatever.ctp/", $expected);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
|
|
|
@ -26,7 +26,11 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
uses('controller' . DS . 'controller', 'view'.DS.'view');
|
||||
App::import('Core', array('View', 'Controller'));
|
||||
|
||||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
||||
}
|
||||
|
||||
class ViewPostsController extends Controller {
|
||||
var $name = 'Posts';
|
||||
|
@ -55,7 +59,6 @@ class TestView extends View {
|
|||
return $this->_loadHelpers($loaded, $helpers, $parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
@ -133,11 +136,14 @@ class ViewTest extends UnitTestCase {
|
|||
$this->Controller->action = 'display';
|
||||
$this->Controller->params['pass'] = array('home');
|
||||
|
||||
restore_error_handler();
|
||||
$View = new TestView($this->Controller);
|
||||
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'errors' . DS . 'missing_view.ctp';
|
||||
ob_start();
|
||||
$result = $View->getViewFileName('does_not_exist');
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
$this->assertPattern("/PagesController::/", $expected);
|
||||
$this->assertPattern("/pages\/does_not_exist.ctp/", $expected);
|
||||
}
|
||||
|
||||
function testMissingLayout() {
|
||||
|
@ -146,10 +152,15 @@ class ViewTest extends UnitTestCase {
|
|||
$this->Controller->viewPath = 'posts';
|
||||
$this->Controller->layout = 'whatever';
|
||||
|
||||
restore_error_handler();
|
||||
$View = new TestView($this->Controller);
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'errors' . DS . 'missing_layout.ctp';
|
||||
ob_start();
|
||||
$result = $View->getLayoutFileName();
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
$this->assertPattern("/Missing Layout/", $expected);
|
||||
$this->assertPattern("/layouts\/whatever.ctp/", $expected);
|
||||
|
||||
}
|
||||
|
||||
function testViewVars() {
|
||||
|
@ -259,117 +270,44 @@ class ViewTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
function testRender() {
|
||||
restore_error_handler();
|
||||
$View = new TestView($this->PostsController);
|
||||
ob_start();
|
||||
$View->render('index');
|
||||
$result = ob_get_clean();
|
||||
$expected = '
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>
|
||||
CakePHP: the rapid development php framework: Posts </title>
|
||||
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" type="text/css" href="css/cake.generic.css" /> </head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="header">
|
||||
<h1><a href="http://cakephp.org">CakePHP: the rapid development php framework</a></h1>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
||||
posts index
|
||||
</div>
|
||||
<div id="footer">
|
||||
<a href="http://www.cakephp.org/" target="_new"><img src="img/cake.power.gif" alt="CakePHP: the rapid development php framework" border="0" /></a> </div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
';
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
$this->assertPattern("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>/", $result);
|
||||
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
|
||||
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
|
||||
|
||||
$this->PostsController->set('url', 'flash');
|
||||
$this->PostsController->set('message', 'yo what up');
|
||||
$this->PostsController->set('pause', 3);
|
||||
$this->PostsController->set('page_title', 'yo what up');
|
||||
|
||||
restore_error_handler();
|
||||
$View = new TestView($this->PostsController);
|
||||
|
||||
ob_start();
|
||||
$View->render(false, 'flash');
|
||||
$result = ob_get_clean();
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
|
||||
$expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>yo what up</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style><!--
|
||||
P { text-align:center; font:bold 1.1em sans-serif }
|
||||
A { color:#444; text-decoration:none }
|
||||
A:HOVER { text-decoration: underline; color:#44E }
|
||||
--></style>
|
||||
</head>
|
||||
<body>
|
||||
<p><a href="flash">yo what up</a></p>
|
||||
</body>
|
||||
</html>';
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertPattern("/<title>yo what up<\/title>/", $result);
|
||||
$this->assertPattern("/<p><a href=\"flash\">yo what up<\/a><\/p>/", $result);
|
||||
}
|
||||
|
||||
function testBadExt() {
|
||||
$this->PostsController->action = 'something';
|
||||
$this->PostsController->ext = '.whatever';
|
||||
$View = new TestView($this->PostsController);
|
||||
restore_error_handler();
|
||||
ob_start();
|
||||
$View = new TestView($this->PostsController);
|
||||
$View->render('this_is_missing');
|
||||
$result = ob_get_clean();
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
|
||||
$expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>
|
||||
CakePHP: the rapid development php framework: Posts </title>
|
||||
|
||||
<link rel="icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" type="text/css" href="css/cake.generic.css" /> </head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="header">
|
||||
<h1><a href="http://cakephp.org">CakePHP: the rapid development php framework</a></h1>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
||||
<h2>Missing View</h2>
|
||||
<p class="error">
|
||||
<strong>Error: </strong>
|
||||
The view for <em>PostsController::</em><em>something()</em> was not found.</p>
|
||||
<p class="error">
|
||||
<strong>Error: </strong>
|
||||
Confirm you have created the file: '.TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'posts'. DS . 'this_is_missing.whatever</p>
|
||||
<p class="notice">
|
||||
<strong>Notice: </strong>
|
||||
If you want to customize this error message, create '.APP_DIR.'/views/errors/missing_view.ctp</p>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<a href="http://www.cakephp.org/" target="_new"><img src="img/cake.power.gif" alt="CakePHP: the rapid development php framework" border="0" /></a> </div>
|
||||
</div>
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
|
||||
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertPattern("/<em>PostsController::<\/em><em>something\(\)<\/em>/", $result);
|
||||
$this->assertPattern("/posts\/this_is_missing.whatever/", $result);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
|
|
Loading…
Add table
Reference in a new issue