Starting initial refactoring of current code base.

Made changes to test suite to allow running test without headers already sent errors.
Moved Component::initialize(), Controller::beforeFilter(); and Component::startup(); from Dipatcher::start() to Controller::constructClasses();
Removed Dispatcher::start();
Fixing model instances not being created
Adding additional test to CookieComponent to increase coverage to 95%
Optimizing Set::diff();
Fixing SessionComponent test and RequestHandlerComponent test
Fixing CakeSession tests, removed deprecated code from CakeSession

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7162 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-06-10 22:38:05 +00:00
parent 70aa290f5b
commit 6807d4c333
19 changed files with 850 additions and 623 deletions

View file

@ -153,4 +153,6 @@ if (isset($_GET['group'])) {
CakePHPTestGroupTestList();
}
CakePHPTestSuiteFooter();
$output = ob_get_clean();
echo $output;
?>

View file

@ -153,4 +153,6 @@ if (isset($_GET['group'])) {
CakePHPTestGroupTestList();
}
CakePHPTestSuiteFooter();
$output = ob_get_clean();
echo $output;
?>

View file

@ -86,11 +86,11 @@ class Dispatcher extends Object {
* Constructor.
*/
function __construct($url = null, $base = false) {
parent::__construct();
if ($base !== false) {
Configure::write('App.base', $base);
}
$this->base = Configure::read('App.base');
if ($url !== null) {
return $this->dispatch($url);
}
@ -109,6 +109,7 @@ class Dispatcher extends Object {
*/
function dispatch($url = null, $additionalParams = array()) {
$parse = true;
if ($this->base === false) {
$this->base = $this->baseUrl();
}
@ -143,9 +144,7 @@ class Dispatcher extends Object {
'className' => Inflector::camelize($this->params['controller']) . 'Controller',
'webroot' => $this->webroot,
'url' => $url,
'base' => $this->base
)
));
'base' => $this->base)));
}
$missingAction = $missingView = $privateAction = false;
@ -162,7 +161,6 @@ class Dispatcher extends Object {
$privateAction = in_array($prefix, $prefixes);
}
}
$protected = array_map('strtolower', get_class_methods('controller'));
$classMethods = array_map('strtolower', get_class_methods($controller));
@ -177,7 +175,6 @@ class Dispatcher extends Object {
if (in_array('return', array_keys($this->params)) && $this->params['return'] == 1) {
$controller->autoRender = false;
}
$controller->base = $this->base;
$controller->here = $this->here;
$controller->webroot = $this->webroot;
@ -214,9 +211,8 @@ class Dispatcher extends Object {
$controller->{$var} = array_merge($controller->{$var}, $diff);
}
}
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)));
$this->start($controller);
$controller->constructClasses();
if ($privateAction) {
return $this->cakeError('privateAction', array(
@ -225,11 +221,8 @@ class Dispatcher extends Object {
'action' => $this->params['action'],
'webroot' => $this->webroot,
'url' => $url,
'base' => $this->base
)
));
'base' => $this->base)));
}
return $this->_invoke($controller, $this->params, $missingAction);
}
/**
@ -254,9 +247,7 @@ class Dispatcher extends Object {
'action' => $params['action'],
'webroot' => $this->webroot,
'url' => $this->here,
'base' => $this->base
)
));
'base' => $this->base)));
} else {
$output = $controller->dispatchMethod($params['action'], $params['pass']);
}
@ -266,45 +257,13 @@ class Dispatcher extends Object {
} elseif (empty($controller->output)) {
$controller->output = $output;
}
$controller->Component->shutdown($controller);
$controller->afterFilter();
if (isset($params['return'])) {
return $controller->output;
}
e($controller->output);
}
/**
* Starts up a controller (by calling its beforeFilter methods and
* starting its components)
*
* @param object $controller Controller to start
* @access public
*/
function start(&$controller) {
$controller->constructClasses();
$controller->Component->initialize($controller);
if (!empty($controller->beforeFilter)) {
trigger_error(sprintf(__('Dispatcher::start - Controller::$beforeFilter property usage is deprecated and will no longer be supported. Use Controller::beforeFilter().', true)), E_USER_WARNING);
if (is_array($controller->beforeFilter)) {
foreach ($controller->beforeFilter as $filter) {
if (is_callable(array($controller,$filter)) && $filter != 'beforeFilter') {
$controller->$filter();
}
}
} else {
if (is_callable(array($controller, $controller->beforeFilter)) && $controller->beforeFilter != 'beforeFilter') {
$controller->{$controller->beforeFilter}();
}
}
}
$controller->beforeFilter();
$controller->Component->startup($controller);
echo($controller->output);
}
/**
* Sets the params when $url is passed as an array to Object::requestAction();
@ -349,7 +308,6 @@ class Dispatcher extends Object {
unset($params['form']['_method']);
}
}
extract(Router::getNamedExpressions());
include CONFIGS . 'routes.php';
$params = array_merge(Router::parse($fromUrl), $params);
@ -400,7 +358,6 @@ class Dispatcher extends Object {
* @access public
*/
function baseUrl() {
$dir = $webroot = null;
$config = Configure::read('App');
extract($config);
@ -431,11 +388,12 @@ class Dispatcher extends Object {
$this->webroot = $base .'/';
return $base;
}
$file = null;
if ($baseUrl) {
$file = '/' . basename($baseUrl);
$base = dirname($baseUrl);
if (in_array($base, array(DS, '.'))) {
$base = '';
}
@ -570,11 +528,13 @@ class Dispatcher extends Object {
if (Configure::read('App.server') == 'IIS') {
$uri = preg_replace('/^(?:\/)?(?:\/)?(?:\?)?(?:url=)?/', '', $uri);
}
if (!empty($uri)) {
if (key($_GET) && strpos(key($_GET), '?') !== false) {
unset($_GET[key($_GET)]);
}
$uri = preg_split('/\?/', $uri, 2);
if (isset($uri[1])) {
parse_str($uri[1], $_GET);
}
@ -582,9 +542,11 @@ class Dispatcher extends Object {
} elseif (empty($uri) && is_string(env('QUERY_STRING'))) {
$uri = env('QUERY_STRING');
}
if (strpos($uri, 'index.php') !== false) {
list(, $uri) = explode('index.php', $uri, 2);
}
if (empty($uri) || $uri == '/' || $uri == '//') {
return '';
}
@ -603,6 +565,7 @@ class Dispatcher extends Object {
if ($uri == null) {
$uri = $this->uri();
}
if ($base == null) {
$base = $this->base;
}
@ -620,12 +583,14 @@ class Dispatcher extends Object {
} else {
$elements = array();
}
if (!empty($elements[1])) {
$_GET['url'] = $elements[1];
$url = $elements[1];
} else {
$url = $_GET['url'] = '/';
}
if (strpos($url, '/') === 0 && $url != '/') {
$url = $_GET['url'] = substr($url, 1);
}
@ -633,6 +598,7 @@ class Dispatcher extends Object {
} else {
$url = $_GET['url'];
}
if ($url{0} == '/') {
$url = substr($url, 1);
}
@ -652,9 +618,9 @@ class Dispatcher extends Object {
include WWW_ROOT . DS . Configure::read('Asset.filter.js');
$this->_stop();
}
$assets = array('js' => 'text/javascript', 'css' => 'text/css');
$isAsset = false;
foreach ($assets as $type => $contentType) {
$pos = strpos($url, $type . '/');
if ($pos !== false) {
@ -670,9 +636,9 @@ class Dispatcher extends Object {
ob_start();
ob_start('ob_gzhandler');
}
$assetFile = null;
$paths = array();
if ($pos > 0) {
$plugin = substr($url, 0, $pos - 1);
$url = str_replace($plugin . '/', '', $url);
@ -682,7 +648,6 @@ class Dispatcher extends Object {
$paths[] = $pluginPaths[$i] . $plugin . DS . 'vendors' . DS;
}
}
$paths = array_merge($paths, Configure::read('vendorPaths'));
foreach ($paths as $path) {
@ -711,9 +676,11 @@ class Dispatcher extends Object {
if (Configure::read('Cache.check') === true) {
$filename = CACHE . 'views' . DS . Inflector::slug($this->here) . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views' . DS . Inflector::slug($this->here) . '_index.php';
}
if (file_exists($filename)) {
if (!class_exists('View')) {
App::import('Core', 'View');

View file

@ -159,30 +159,9 @@ class CookieComponent extends Object {
*
* @param object $controller A reference to the instantiating controller object
* @access public
* @deprecated use Controller::beforeFilter() to set the properties of the CookieComponent
*/
function initialize(&$controller) {
$this->key = Configure::read('Security.salt');
if (is_object($controller)) {
if (isset($controller->cookieName)) {
$this->name = $controller->cookieName;
}
if (isset($controller->cookieTime)) {
$this->time = $controller->cookieTime;
}
if (isset($controller->cookieKey)) {
$this->key = $controller->cookieKey;
}
if (isset($controller->cookiePath)) {
$this->path = $controller->cookiePath;
}
if (isset($controller->cookieDomain)) {
$this->domain = $controller->cookieDomain;
}
if (isset($controller->cookieSecure)) {
$this->secure = $controller->cookieSecure;
}
}
}
/**
* Start CookieComponent for use in the controller

View file

@ -384,24 +384,26 @@ class Controller extends Object {
$this->__mergeVars();
$this->Component->init($this);
if ($this->uses === null || ($this->uses === array())) {
return false;
}
if (empty($this->passedArgs) || !isset($this->passedArgs['0'])) {
$id = false;
} else {
$id = $this->passedArgs['0'];
}
if ($this->uses !== null || ($this->uses !== array())) {
if (empty($this->passedArgs) || !isset($this->passedArgs['0'])) {
$id = false;
} else {
$id = $this->passedArgs['0'];
}
if ($this->uses === false) {
$this->loadModel($this->modelClass, $id);
} elseif ($this->uses) {
$uses = is_array($this->uses) ? $this->uses : array($this->uses);
$this->modelClass = $uses[0];
foreach ($uses as $modelClass) {
$this->loadModel($modelClass);
if ($this->uses === false) {
$this->loadModel($this->modelClass, $id);
} elseif ($this->uses) {
$uses = is_array($this->uses) ? $this->uses : array($this->uses);
$this->modelClass = $uses[0];
foreach ($uses as $modelClass) {
$this->loadModel($modelClass);
}
}
}
$this->Component->initialize($this);
$this->beforeFilter();
$this->Component->startup($this);
return true;
}
/**

View file

@ -401,5 +401,4 @@ class ContainableBehavior extends ModelBehavior {
return $map;
}
}
?>

View file

@ -33,7 +33,7 @@
* Database name for cake sessions.
*
*/
uses('set');
App::import('Core', 'Set');
/**
* Session class for Cake.
*
@ -123,7 +123,7 @@ class CakeSession extends Object {
*/
function __construct($base = null, $start = true) {
if (Configure::read('Session.save') === 'database' && !class_exists('ConnectionManager')) {
uses('model' . DS . 'connection_manager');
App::import('Core', 'ConnectionManager');
}
if (Configure::read('Session.checkAgent') === true || Configure::read('Session.checkAgent') === null) {
@ -147,7 +147,7 @@ class CakeSession extends Object {
}
if (!class_exists('Security')) {
uses('security');
App::import('Core', 'Security');
}
$this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout'));
@ -212,29 +212,6 @@ class CakeSession extends Object {
return $this->id;
}
}
/**
* Temp method until we are able to remove the last eval().
* Builds an expression to fetch a session variable with specified name.
*
* @param string $name Name of variable (in dot notation)
* @access private
*/
function __sessionVarNames($name) {
if (is_string($name) && preg_match("/^[ 0-9a-zA-Z._-]*$/", $name)) {
if (strpos($name, ".")) {
$names = explode(".", $name);
} else {
$names = array($name);
}
$expression = "\$_SESSION";
foreach ($names as $item) {
$expression .= is_numeric($item) ? "[$item]" : "['$item']";
}
return $expression;
}
$this->__setError(3, "$name is not a string");
return false;
}
/**
* Removes a variable from session.
*

View file

@ -752,26 +752,28 @@ class Set extends Object {
* @access public
*/
function diff($val1, $val2 = null) {
if ($val2 == null && (is_a($this, 'set') || is_a($this, 'Set'))) {
if ($val2 == null && is_a($this, 'set')) {
$val2 = $val1;
$val1 = $this->get();
}
if (is_object($val2) && (is_a($val2, 'set') || is_a($val2, 'Set'))) {
if (is_a($val2, 'set')) {
$val2 = $val2->get();
}
$out = array();
if (empty($val1)) {
return (array)$val2;
} elseif (empty($val2)) {
return (array)$val1;
}
$out = array();
foreach ($val1 as $key => $val) {
if (array_key_exists($key, $val2) && $val2[$key] != $val) {
$exists = array_key_exists($key, $val2);
if ($exists && $val2[$key] != $val) {
$out[$key] = $val;
} elseif (!array_key_exists($key, $val2)) {
} elseif (!$exists) {
$out[$key] = $val;
}
unset($val2[$key]);

View file

@ -1198,7 +1198,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* testAutomaticPluginControllerMissingActionDispatch method
*
*
* @access public
* @return void
*/
@ -1218,7 +1218,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* testPrefixProtection method
*
*
* @access public
* @return void
*/
@ -1240,7 +1240,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* testChangingParamsFromBeforeFilter method
*
*
* @access public
* @return void
*/
@ -1260,7 +1260,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* testStaticAssets method
*
*
* @access public
* @return void
*/
@ -1293,7 +1293,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* testFullPageCachingDispatch method
*
*
* @access public
* @return void
*/
@ -1388,7 +1388,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* testHttpMethodOverrides method
*
*
* @access public
* @return void
*/
@ -1441,7 +1441,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* testEnvironmentDetection method
*
*
* @access public
* @return void
*/
@ -1546,7 +1546,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* backupEnvironment method
*
*
* @access private
* @return void
*/
@ -1560,7 +1560,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* reloadEnvironment method
*
*
* @access private
* @return void
*/
@ -1578,8 +1578,8 @@ class DispatcherTest extends UnitTestCase {
}
/**
* loadEnvironment method
*
* @param mixed $env
*
* @param mixed $env
* @access private
* @return void
*/
@ -1612,7 +1612,7 @@ class DispatcherTest extends UnitTestCase {
}
/**
* tearDown method
*
*
* @access public
* @return void
*/
@ -1620,4 +1620,4 @@ class DispatcherTest extends UnitTestCase {
$_GET = $this->_get;
}
}
?>
?>

View file

@ -32,8 +32,8 @@ if (!class_exists('AppController')) {
/**
* AppController class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller
* @package cake
* @subpackage cake.tests.cases.libs.controller
*/
class AppController extends Controller {
/**
@ -69,7 +69,6 @@ if (!class_exists('AppController')) {
} else {
define('AppControllerExists', true);
}
/**
* ParamTestComponent
*
@ -83,14 +82,14 @@ class ParamTestComponent extends Object {
* @access public
*/
var $name = 'ParamTest';
/**
/**
* components property
*
* @var array
* @access public
*/
var $components = array('Banana' => array('config' => 'value'));
/**
/**
* initialize method
*
* @param mixed $controller
@ -107,14 +106,12 @@ class ParamTestComponent extends Object {
}
}
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller
*/
class ComponentTestController extends AppController {
/**
@ -135,8 +132,8 @@ class ComponentTestController extends AppController {
/**
* AppleComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller
* @package cake
* @subpackage cake.tests.cases.libs.controller
*/
class AppleComponent extends Object {
/**
@ -163,13 +160,12 @@ class AppleComponent extends Object {
function startup(&$controller) {
$this->testName = $controller->name;
}
}
/**
* OrangeComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller
* @package cake
* @subpackage cake.tests.cases.libs.controller
*/
class OrangeComponent extends Object {
/**
@ -194,8 +190,8 @@ class OrangeComponent extends Object {
/**
* BananaComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller
* @package cake
* @subpackage cake.tests.cases.libs.controller
*/
class BananaComponent extends Object {
/**
@ -205,9 +201,7 @@ class BananaComponent extends Object {
* @access public
*/
var $testField = 'BananaField';
}
/**
* MutuallyReferencingOneComponent class
*
@ -217,7 +211,6 @@ class BananaComponent extends Object {
class MutuallyReferencingOneComponent extends Object {
var $components = array('MutuallyReferencingTwo');
}
/**
* MutuallyReferencingTwoComponent class
*
@ -227,15 +220,11 @@ class MutuallyReferencingOneComponent extends Object {
class MutuallyReferencingTwoComponent extends Object {
var $components = array('MutuallyReferencingOne');
}
/**
* ComponentTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller
* @package cake
* @subpackage cake.tests.cases.libs.controller
*/
class ComponentTest extends CakeTestCase {
/**
@ -319,10 +308,6 @@ class ComponentTest extends CakeTestCase {
$Controller->constructClasses();
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
$this->assertEqual($Controller->Apple->testName, null);
$Controller->Component->startup($Controller);
$this->assertEqual($Controller->Apple->testName, 'ComponentTest');
}
/**
@ -335,8 +320,6 @@ class ComponentTest extends CakeTestCase {
$Controller->components = array('Orange', 'Banana');
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertEqual($Controller->Banana->testField, 'OrangeField');
$this->assertEqual($Controller->Orange->Banana->testField, 'OrangeField');
}
@ -353,7 +336,6 @@ class ComponentTest extends CakeTestCase {
$Controller->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple');
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertTrue(is_a($Controller->ParamTest, 'ParamTestComponent'));
$this->assertTrue(is_a($Controller->ParamTest->Banana, 'BananaComponent'));
@ -367,7 +349,6 @@ class ComponentTest extends CakeTestCase {
$Controller =& new ComponentTestController();
$Controller->components = array('ParamTest' => array('test' => 'value'), 'Orange' => array('ripeness' => 'perfect'));
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertEqual($Controller->Orange->settings, array('colour' => 'blood orange', 'ripeness' => 'perfect'));
$this->assertEqual($Controller->ParamTest->test, 'value');
@ -386,7 +367,6 @@ class ComponentTest extends CakeTestCase {
$this->assertTrue(is_a($Controller->MutuallyReferencingOne, 'MutuallyReferencingOneComponent'));
$this->assertTrue(is_a($Controller->MutuallyReferencingOne->MutuallyReferencingTwo, 'MutuallyReferencingTwoComponent'));
$this->assertTrue(is_a($Controller->MutuallyReferencingOne->MutuallyReferencingTwo->MutuallyReferencingOne, 'MutuallyReferencingOneComponent'));
}
}
?>

View file

@ -33,21 +33,21 @@ App::import(array('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl'));
/**
* AclNodeTwoTestBase class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class AclNodeTwoTestBase extends AclNode {
/**
* useDbConfig property
*
*
* @var string 'test_suite'
* @access public
*/
var $useDbConfig = 'test_suite';
/**
* cacheSources property
*
*
* @var bool false
* @access public
*/
@ -55,28 +55,28 @@ class AclNodeTwoTestBase extends AclNode {
}
/**
* AroTwoTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class AroTwoTest extends AclNodeTwoTestBase {
/**
* name property
*
*
* @var string 'AroTwoTest'
* @access public
*/
var $name = 'AroTwoTest';
/**
* useTable property
*
*
* @var string 'aro_twos'
* @access public
*/
var $useTable = 'aro_twos';
/**
* hasAndBelongsToMany property
*
*
* @var array
* @access public
*/
@ -84,28 +84,28 @@ class AroTwoTest extends AclNodeTwoTestBase {
}
/**
* AcoTwoTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class AcoTwoTest extends AclNodeTwoTestBase {
/**
* name property
*
*
* @var string 'AcoTwoTest'
* @access public
*/
var $name = 'AcoTwoTest';
/**
* useTable property
*
*
* @var string 'aco_twos'
* @access public
*/
var $useTable = 'aco_twos';
/**
* hasAndBelongsToMany property
*
*
* @var array
* @access public
*/
@ -113,42 +113,42 @@ class AcoTwoTest extends AclNodeTwoTestBase {
}
/**
* PermissionTwoTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class PermissionTwoTest extends CakeTestModel {
/**
* name property
*
*
* @var string 'PermissionTwoTest'
* @access public
*/
var $name = 'PermissionTwoTest';
/**
* useTable property
*
*
* @var string 'aros_aco_twos'
* @access public
*/
var $useTable = 'aros_aco_twos';
/**
* cacheQueries property
*
*
* @var bool false
* @access public
*/
var $cacheQueries = false;
/**
* belongsTo property
*
*
* @var array
* @access public
*/
var $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id'));
/**
* actsAs property
*
*
* @var mixed null
* @access public
*/
@ -156,14 +156,14 @@ class PermissionTwoTest extends CakeTestModel {
}
/**
* DbAclTwoTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class DbAclTwoTest extends DbAcl {
/**
* construct method
*
*
* @access private
* @return void
*/
@ -176,9 +176,9 @@ class DbAclTwoTest extends DbAcl {
}
/**
* IniAclTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class IniAclTest extends IniAcl {
@ -187,20 +187,20 @@ class IniAclTest extends IniAcl {
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
class AclComponentTest extends CakeTestCase {
/**
* fixtures property
*
*
* @var array
* @access public
*/
var $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
/**
* startTest method
*
*
* @access public
* @return void
*/
@ -209,8 +209,8 @@ class AclComponentTest extends CakeTestCase {
}
/**
* before method
*
* @param mixed $method
*
* @param mixed $method
* @access public
* @return void
*/
@ -221,7 +221,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testAclCreate method
*
*
* @access public
* @return void
*/
@ -248,7 +248,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testAclCreateWithParent method
*
*
* @access public
* @return void
*/
@ -267,7 +267,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbAclAllow method
*
*
* @access public
* @return void
*/
@ -282,23 +282,21 @@ class AclComponentTest extends CakeTestCase {
$this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->allow('Micheal', 'printers', 'create'));
$this->assertTrue($this->Acl->allow('Micheal', 'printers', 'create'));
// Michael no longer has his delete permission for tpsReports!
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view'));
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
$this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
$this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update'));
// Samir should still have his tpsReports/view permissions, but does not
// Samir should still have his tpsReports/view permissions, but does not
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
$this->expectError('DbAcl::allow() - Invalid node');
@ -309,11 +307,11 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbAclCheck method
*
*
* @access public
* @return void
*/
function testDbAclCheck() {
function testDbAclCheck() {
$this->assertTrue($this->Acl->check('Samir', 'print', 'read'));
$this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read'));
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
@ -356,7 +354,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbAclDeny method
*
*
* @access public
* @return void
*/
@ -385,7 +383,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testAclNodeLookup method
*
*
* @access public
* @return void
*/
@ -409,7 +407,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbInherit method
*
*
* @access public
* @return void
*/
@ -426,7 +424,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbGrant method
*
*
* @access public
* @return void
*/
@ -447,7 +445,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbRevoke method
*
*
* @access public
* @return void
*/
@ -467,7 +465,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testStartup method
*
*
* @access public
* @return void
*/
@ -479,7 +477,7 @@ class AclComponentTest extends CakeTestCase {
/* The following tests and AclComponent methods are not fully implemented yet
/**
* testDbSetAro method
*
*
* @access public
* @return void
*/
@ -490,7 +488,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbSetAco method
*
*
* @access public
* @return void
*/
@ -501,7 +499,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbGetAro method
*
*
* @access public
* @return void
*/
@ -512,7 +510,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testDbGetAco method
*
*
* @access public
* @return void
*/
@ -566,7 +564,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* testIniCheck method
*
*
* @access public
* @return void
*/
@ -591,7 +589,7 @@ class AclComponentTest extends CakeTestCase {
}
/**
* tearDown method
*
*
* @access public
* @return void
*/

View file

@ -27,7 +27,6 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import(array('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl'));
App::import(array('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl'));
Configure::write('Security.salt', 'JfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
/**
@ -39,14 +38,14 @@ Configure::write('Security.salt', 'JfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0Fga
class TestAuthComponent extends AuthComponent {
/**
* testStop property
*
*
* @var bool false
* @access public
*/
var $testStop = false;
/**
* stop method
*
*
* @access public
* @return void
*/
@ -54,7 +53,6 @@ class TestAuthComponent extends AuthComponent {
$this->testStop = true;
}
}
/**
* Short description for class.
*
@ -64,21 +62,21 @@ class TestAuthComponent extends AuthComponent {
class AuthUser extends CakeTestModel {
/**
* name property
*
*
* @var string 'AuthUser'
* @access public
*/
var $name = 'AuthUser';
/**
* useDbConfig property
*
*
* @var string 'test_suite'
* @access public
*/
var $useDbConfig = 'test_suite';
/**
* parentNode method
*
*
* @access public
* @return void
*/
@ -87,8 +85,8 @@ class AuthUser extends CakeTestModel {
}
/**
* bindNode method
*
* @param mixed $object
*
* @param mixed $object
* @access public
* @return void
*/
@ -97,10 +95,10 @@ class AuthUser extends CakeTestModel {
}
/**
* isAuthorized method
*
* @param mixed $user
* @param mixed $controller
* @param mixed $action
*
* @param mixed $user
* @param mixed $controller
* @param mixed $action
* @access public
* @return void
*/
@ -120,35 +118,35 @@ class AuthUser extends CakeTestModel {
class AuthTestController extends Controller {
/**
* name property
*
*
* @var string 'AuthTest'
* @access public
*/
var $name = 'AuthTest';
/**
* uses property
*
*
* @var array
* @access public
*/
var $uses = array('AuthUser');
/**
* components property
*
*
* @var array
* @access public
*/
var $components = array('Auth', 'Acl');
/**
* testUrl property
*
*
* @var mixed null
* @access public
*/
var $testUrl = null;
/**
* construct method
*
*
* @access private
* @return void
*/
@ -159,7 +157,7 @@ class AuthTestController extends Controller {
}
/**
* beforeFilter method
*
*
* @access public
* @return void
*/
@ -167,7 +165,7 @@ class AuthTestController extends Controller {
}
/**
* login method
*
*
* @access public
* @return void
*/
@ -175,7 +173,7 @@ class AuthTestController extends Controller {
}
/**
* admin_login method
*
*
* @access public
* @return void
*/
@ -183,7 +181,7 @@ class AuthTestController extends Controller {
}
/**
* logout method
*
*
* @access public
* @return void
*/
@ -192,7 +190,7 @@ class AuthTestController extends Controller {
}
/**
* add method
*
*
* @access public
* @return void
*/
@ -201,10 +199,10 @@ class AuthTestController extends Controller {
}
/**
* redirect method
*
* @param mixed $url
* @param mixed $status
* @param mixed $exit
*
* @param mixed $url
* @param mixed $status
* @param mixed $exit
* @access public
* @return void
*/
@ -214,7 +212,7 @@ class AuthTestController extends Controller {
}
/**
* isAuthorized method
*
*
* @access public
* @return void
*/
@ -227,42 +225,42 @@ class AuthTestController extends Controller {
}
/**
* AjaxAuthController class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class AjaxAuthController extends Controller {
/**
* name property
*
*
* @var string 'AjaxAuth'
* @access public
*/
var $name = 'AjaxAuth';
/**
* components property
*
*
* @var array
* @access public
*/
var $components = array('TestAuth');
/**
* uses property
*
*
* @var array
* @access public
*/
var $uses = array();
/**
* testUrl property
*
*
* @var mixed null
* @access public
*/
var $testUrl = null;
/**
* beforeFilter method
*
*
* @access public
* @return void
*/
@ -272,7 +270,7 @@ class AjaxAuthController extends Controller {
}
/**
* add method
*
*
* @access public
* @return void
*/
@ -283,10 +281,10 @@ class AjaxAuthController extends Controller {
}
/**
* redirect method
*
* @param mixed $url
* @param mixed $status
* @param mixed $exit
*
* @param mixed $url
* @param mixed $status
* @param mixed $exit
* @access public
* @return void
*/
@ -304,28 +302,28 @@ class AjaxAuthController extends Controller {
class AuthTest extends CakeTestCase {
/**
* name property
*
*
* @var string 'Auth'
* @access public
*/
var $name = 'Auth';
/**
* fixtures property
*
*
* @var array
* @access public
*/
var $fixtures = array('core.auth_user', 'core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action');
/**
* initialized property
*
*
* @var bool false
* @access public
*/
var $initialized = false;
/**
* startTest method
*
*
* @access public
* @return void
*/
@ -336,7 +334,6 @@ class AuthTest extends CakeTestCase {
if (isset($this->fixtures) && (!is_array($this->fixtures) || empty($this->fixtures))) {
unset($this->fixtures);
}
// Create records
if (isset($this->_fixtures) && isset($this->db)) {
foreach ($this->_fixtures as $fixture) {
@ -344,10 +341,9 @@ class AuthTest extends CakeTestCase {
}
}
}
$this->Controller =& new AuthTestController();
$this->Controller->Component->init($this->Controller);
ClassRegistry::addObject('view', new View($this->Controller));
$this->Controller->Session->del('Auth');
$this->Controller->Session->del('Message.auth');
@ -355,7 +351,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testNoAuth method
*
*
* @access public
* @return void
*/
@ -364,7 +360,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testLogin method
*
*
* @access public
* @return void
*/
@ -425,7 +421,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testAuthorizeFalse method
*
*
* @access public
* @return void
*/
@ -444,7 +440,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testAuthorizeController method
*
*
* @access public
* @return void
*/
@ -466,7 +462,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testAuthorizeModel method
*
*
* @access public
* @return void
*/
@ -492,7 +488,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testAuthorizeCrud method
*
*
* @access public
* @return void
*/
@ -553,7 +549,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testLoginRedirect method
*
*
* @access public
* @return void
*/
@ -635,7 +631,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testEmptyUsernameOrPassword method
*
*
* @access public
* @return void
*/
@ -666,7 +662,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testInjection method
*
*
* @access public
* @return void
*/
@ -709,7 +705,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testCustomRoute method
*
*
* @access public
* @return void
*/
@ -738,7 +734,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testAdminRoute method
*
*
* @access public
* @return void
*/
@ -772,7 +768,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testAjaxLogin method
*
*
* @access public
* @return void
*/
@ -794,7 +790,7 @@ class AuthTest extends CakeTestCase {
}
/**
* testLoginActionRedirect method
*
*
* @access public
* @return void
*/
@ -830,7 +826,7 @@ class AuthTest extends CakeTestCase {
}
/**
* tearDown method
*
*
* @access public
* @return void
*/

View file

@ -26,7 +26,19 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
uses('controller' . DS . 'components' . DS .'cookie');
App::import('Core', array('Component', 'Controller', 'Cookie'));
class CookieComponentTestController extends Controller {
var $components = array('Cookie');
function beforeFilter() {
$this->Cookie->name = 'CakeTestCookie';
$this->Cookie->time = 10;
$this->Cookie->path = '/';
$this->Cookie->domain = '';
$this->Cookie->secure = false;
$this->Cookie->key = 'somerandomhaskey';
}
}
/**
* Short description for class.
*
@ -34,14 +46,261 @@ uses('controller' . DS . 'components' . DS .'cookie');
* @subpackage cake.tests.cases.libs.controller.components
*/
class CookieComponentTest extends CakeTestCase {
/**
* skip method
*
* @access public
* @return void
*/
function skip() {
$this->skipif (true, 'CookieComponentTest not implemented');
var $Controller;
function start() {
$this->Controller = new CookieComponentTestController();
$this->Controller->constructClasses();
$this->Controller->Cookie->destroy();
}
function testCookieName() {
$this->assertEqual($this->Controller->Cookie->name, 'CakeTestCookie');
}
function testSettingEncryptedCookieData() {
$this->Controller->Cookie->write('Encrytped_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'));
$this->Controller->Cookie->write('Encrytped_multi_cookies.name', 'CakePHP');
$this->Controller->Cookie->write('Encrytped_multi_cookies.version', '1.2.0.x');
$this->Controller->Cookie->write('Encrytped_multi_cookies.tag', 'CakePHP Rocks!');
}
function testReadEncryptedCookieData() {
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
}
function testSettingPlainCookieData() {
$this->Controller->Cookie->write('Plain_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'), false);
$this->Controller->Cookie->write('Plain_multi_cookies.name', 'CakePHP', false);
$this->Controller->Cookie->write('Plain_multi_cookies.version', '1.2.0.x', false);
$this->Controller->Cookie->write('Plain_multi_cookies.tag', 'CakePHP Rocks!', false);
}
function testReadPlainCookieData() {
$data = $this->Controller->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
}
function testReadingCookieValue() {
$data = $this->Controller->Cookie->read();
$expected = array(
'Encrytped_array' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'),
'Encrytped_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'),
'Plain_array' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'),
'Plain_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'));
$this->assertEqual($data, $expected);
}
function testDeleteCookieValue() {
$this->Controller->Cookie->del('Encrytped_multi_cookies.name');
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->Controller->Cookie->del('Encrytped_array');
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array();
$this->assertEqual($data, $expected);
$this->Controller->Cookie->del('Plain_multi_cookies.name');
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->Controller->Cookie->del('Plain_array');
$data = $this->Controller->Cookie->read('Plain_array');
$expected = array();
$this->assertEqual($data, $expected);
}
function testSettingCookiesWithArray() {
$this->Controller->Cookie->destroy();
$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
}
function testReadingCookieArray() {
$data = $this->Controller->Cookie->read('Encrytped_array.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_array.version');
$expected = '1.2.0.x';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_array.tag');
$expected = 'CakePHP Rocks!';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.version');
$expected = '1.2.0.x';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.tag');
$expected = 'CakePHP Rocks!';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_array.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_array.version');
$expected = '1.2.0.x';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_array.tag');
$expected = 'CakePHP Rocks!';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_multi_cookies.name');
$expected = 'CakePHP';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_multi_cookies.version');
$expected = '1.2.0.x';
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_multi_cookies.tag');
$expected = 'CakePHP Rocks!';
$this->assertEqual($data, $expected);
}
function testReadingCookieDataOnStartup() {
$this->Controller->Cookie->destroy();
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array();
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array();
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_array');
$expected = array();
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
$expected = array();
$this->assertEqual($data, $expected);
$_COOKIE['CakeTestCookie'] = array(
'Encrytped_array' => 'Q2FrZQ==.y5J8fefUM83X0rdlMjuYFca8ZMYASU/8hM75rHuvjVNHO2WQ+6wK9nkVxm4abxI=',
'Encrytped_multi_cookies' => array(
'name' => 'Q2FrZQ==.5pJ6fcvfAg==',
'version' => 'Q2FrZQ==.lN0jNqu5Kg==',
'tag' => 'Q2FrZQ==.5pJ6fcvfAobg7ZxebWw='),
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
'Plain_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'));
$this->Controller->Cookie->startup();
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->Controller->Cookie->destroy();
unset($_COOKIE['CakeTestCookie']);
}
function testReadingCookieDataWithoutStartup() {
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array();
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array();
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_array');
$expected = array();
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
$expected = array();
$this->assertEqual($data, $expected);
$_COOKIE['CakeTestCookie'] = array(
'Encrytped_array' => 'Q2FrZQ==.y5J8fefUM83X0rdlMjuYFca8ZMYASU/8hM75rHuvjVNHO2WQ+6wK9nkVxm4abxI=',
'Encrytped_multi_cookies' => array(
'name' => 'Q2FrZQ==.5pJ6fcvfAg==',
'version' => 'Q2FrZQ==.lN0jNqu5Kg==',
'tag' => 'Q2FrZQ==.5pJ6fcvfAobg7ZxebWw='),
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
'Plain_multi_cookies' => array(
'name' => 'CakePHP',
'version' => '1.2.0.x',
'tag' => 'CakePHP Rocks!'));
$data = $this->Controller->Cookie->read('Encrytped_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_array');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
$this->assertEqual($data, $expected);
$this->Controller->Cookie->destroy();
unset($_COOKIE['CakeTestCookie']);
}
function end() {
$this->Controller->Cookie->destroy();
}
}
?>
?>

View file

@ -30,22 +30,22 @@ App::import('Core', array('Controller'));
App::import('Component', array('RequestHandler'));
/**
* RequestHandlerTestController class
*
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class RequestHandlerTestController extends Controller {
/**
* uses property
*
*
* @var mixed null
* @access public
*/
var $uses = null;
/**
* construct method
*
* @param array $params
*
* @param array $params
* @access private
* @return void
*/
@ -56,7 +56,38 @@ class RequestHandlerTestController extends Controller {
parent::__construct();
}
}
/**
* RequestHandlerTestDisabledController class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class RequestHandlerTestDisabledController extends Controller {
/**
* uses property
*
* @var mixed null
* @access public
*/
var $uses = null;
/**
* construct method
*
* @param array $params
* @access private
* @return void
*/
function __construct($params = array()) {
foreach ($params as $key => $val) {
$this->{$key} = $val;
}
parent::__construct();
}
function beforeFilter() {
$this->RequestHandler->enabled = false;
}
}
/**
* Short description for class.
*
@ -66,7 +97,7 @@ class RequestHandlerTestController extends Controller {
class RequestHandlerComponentTest extends CakeTestCase {
/**
* setUp method
*
*
* @access public
* @return void
*/
@ -75,7 +106,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* init method
*
*
* @access protected
* @return void
*/
@ -86,7 +117,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testInitializeCallback method
*
*
* @access public
* @return void
*/
@ -100,26 +131,22 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testDisabling method
*
*
* @access public
* @return void
*/
function testDisabling() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->assertEqual($this->Controller->params, array());
$this->RequestHandler->startup($this->Controller);
$this->_init();
$this->assertEqual($this->Controller->params, array('isAjax' => true));
$this->_init();
$this->assertEqual($this->Controller->params, array());
$this->RequestHandler->enabled = false;
$this->RequestHandler->startup($this->Controller);
$this->Controller = new RequestHandlerTestDisabledController(array('components' => array('RequestHandler')));
$this->assertEqual($this->Controller->params, array());
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
}
/**
* testAutoResponseType method
*
*
* @access public
* @return void
*/
@ -132,7 +159,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testStartupCallback method
*
*
* @access public
* @return void
*/
@ -145,7 +172,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testNonAjaxRedirect method
*
*
* @access public
* @return void
*/
@ -156,7 +183,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testRenderAs method
*
*
* @access public
* @return void
*/
@ -167,7 +194,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testRequestClientTypes method
*
*
* @access public
* @return void
*/
@ -189,7 +216,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testRequestContentTypes method
*
*
* @access public
* @return void
*/
@ -232,7 +259,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testResponseContentType method
*
*
* @access public
* @return void
*/
@ -243,7 +270,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testMobileDeviceDetection method
*
*
* @access public
* @return void
*/
@ -254,7 +281,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testRequestProperties method
*
*
* @access public
* @return void
*/
@ -273,7 +300,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testRequestMethod method
*
*
* @access public
* @return void
*/
@ -304,7 +331,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testClientContentPreference method
*
*
* @access public
* @return void
*/
@ -328,7 +355,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testCustomContent method
*
*
* @access public
* @return void
*/
@ -346,7 +373,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* testClientProperties method
*
*
* @access public
* @return void
*/
@ -373,7 +400,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
}
/**
* tearDown method
*
*
* @access public
* @return void
*/

View file

@ -26,10 +26,11 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
uses('controller' . DS . 'controller', 'controller' . DS . 'components' . DS .'session');
App::import('Core', 'Controller');
App::import('Component', 'Session');
/**
* SessionTestController class
*
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
@ -43,7 +44,7 @@ class SessionTestController extends Controller {}
class SessionComponentTest extends CakeTestCase {
/**
* testSessionAutoStart method
*
*
* @access public
* @return void
*/
@ -53,259 +54,239 @@ class SessionComponentTest extends CakeTestCase {
$this->assertFalse($Session->__active);
$this->assertFalse($Session->__started);
$Session->startup(new SessionTestController());
// $this->assertFalse(isset($_SESSION));
unset($_SESSION);
Configure::write('Session.start', true);
$Session =& new SessionComponent();
$this->assertTrue($Session->__active);
$this->assertFalse($Session->__started);
$Session->startup(new SessionTestController());
$this->assertTrue(isset($_SESSION));
unset($_SESSION);
}
/**
/**
* testSessionInitialize method
*
*
* @access public
* @return void
*/
function testSessionInitialize() {
$Session =& new SessionComponent();
$this->assertEqual($Session->__bare, 0);
$Session->initialize(new SessionTestController());
$this->assertEqual($Session->__bare, 0);
$sessionController =& new SessionTestController();
$sessionController->params['bare'] = 1;
$Session->initialize($sessionController);
$this->assertEqual($Session->__bare, 1);
unset($_SESSION);
}
/**
/**
* testSessionActivate method
*
*
* @access public
* @return void
*/
function testSessionActivate() {
$Session =& new SessionComponent();
$this->assertTrue($Session->__active);
$this->assertNull($Session->activate());
$this->assertTrue($Session->__active);
unset($_SESSION);
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$this->assertFalse($Session->__active);
$this->assertNull($Session->activate());
$this->assertTrue($Session->__active);
Configure::write('Session.start', true);
unset($_SESSION);
$Session->destroy();
}
/**
/**
* testSessionValid method
*
*
* @access public
* @return void
*/
function testSessionValid() {
$Session =& new SessionComponent();
$this->assertTrue($Session->valid());
$Session->_userAgent = 'rweerw';
$this->assertFalse($Session->valid());
unset($_SESSION);
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$this->assertFalse($Session->__active);
$this->assertFalse($Session->valid());
Configure::write('Session.start', true);
unset($_SESSION);
}
/**
/**
* testSessionError method
*
*
* @access public
* @return void
*/
function testSessionError() {
$Session =& new SessionComponent();
$this->assertFalse($Session->error());
unset($_SESSION);
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$this->assertFalse($Session->__active);
$this->assertFalse($Session->error());
Configure::write('Session.start', true);
unset($_SESSION);
}
/**
/**
* testSessionReadWrite method
*
*
* @access public
* @return void
*/
function testSessionReadWrite() {
$Session =& new SessionComponent();
$this->assertFalse($Session->read());
$this->assertFalse($Session->read('Test'));
$this->assertTrue($Session->write('Test', 'some value'));
$this->assertEqual($Session->read('Test'), 'some value');
$this->assertFalse($Session->write('Test.key', 'some value'));
$Session->del('Test');
$this->assertTrue($Session->write('Test.key.path', 'some value'));
$this->assertEqual($Session->read('Test.key.path'), 'some value');
$this->assertEqual($Session->read('Test.key'), array('path' => 'some value'));
$this->assertTrue($Session->write('Test.key.path2', 'another value'));
$this->assertEqual($Session->read('Test.key'), array('path' => 'some value', 'path2' => 'another value'));
$Session->del('Test');
$array = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3');
$this->assertTrue($Session->write('Test', $array));
$this->assertEqual($Session->read('Test'), $array);
$Session->del('Test');
$this->assertFalse($Session->write(array('Test'), 'some value'));
$this->assertTrue($Session->write(array('Test' => 'some value')));
$this->assertEqual($Session->read('Test'), 'some value');
$Session->del('Test');
unset($_SESSION);
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$this->assertFalse($Session->write('Test', 'some value'));
$Session->write('Test', 'some value');
$this->assertFalse($Session->read('Test'));
Configure::write('Session.start', true);
unset($_SESSION);
}
/**
/**
* testSessionDel method
*
*
* @access public
* @return void
*/
function testSessionDel() {
$Session =& new SessionComponent();
$this->assertFalse($Session->del('Test'));
$Session->write('Test', 'some value');
$this->assertTrue($Session->del('Test'));
unset($_SESSION);
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$Session->write('Test', 'some value');
$this->assertFalse($Session->del('Test'));
Configure::write('Session.start', true);
unset($_SESSION);
}
/**
/**
* testSessionDelete method
*
*
* @access public
* @return void
*/
function testSessionDelete() {
$Session =& new SessionComponent();
$this->assertFalse($Session->delete('Test'));
$Session->write('Test', 'some value');
$this->assertTrue($Session->delete('Test'));
unset($_SESSION);
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$Session->write('Test', 'some value');
$this->assertFalse($Session->delete('Test'));
Configure::write('Session.start', true);
unset($_SESSION);
}
/**
* testSessionId method
*
* @access public
* @return void
*/
function testSessionId() {
$Session =& new SessionComponent();
$this->assertNull($Session->id());
unset($_SESSION);
}
/**
/**
* testSessionCheck method
*
*
* @access public
* @return void
*/
function testSessionCheck() {
$Session =& new SessionComponent();
$this->assertFalse($Session->check('Test'));
$Session->write('Test', 'some value');
$this->assertTrue($Session->check('Test'));
$Session->delete('Test');
unset($_SESSION);
Configure::write('Session.start', false);
$Session =& new SessionComponent();
$Session->write('Test', 'some value');
$this->assertFalse($Session->check('Test'));
Configure::write('Session.start', true);
unset($_SESSION);
}
/**
/**
* testSessionFlash method
*
*
* @access public
* @return void
*/
function testSessionFlash() {
$Session =& new SessionComponent();
$this->assertNull($Session->read('Message.flash'));
$Session->setFlash('This is a test message');
$this->assertEqual($Session->read('Message.flash'), array('message' => 'This is a test message', 'layout' => 'default', 'params' => array()));
$Session->setFlash('This is a test message', 'test', array('name' => 'Joel Moss'));
$this->assertEqual($Session->read('Message.flash'), array('message' => 'This is a test message', 'layout' => 'test', 'params' => array('name' => 'Joel Moss')));
$Session->setFlash('This is a test message', 'default', array(), 'myFlash');
$this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'layout' => 'default', 'params' => array()));
$Session->setFlash('This is a test message', 'non_existing_layout');
$this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'layout' => 'default', 'params' => array()));
}
/**
/**
* testSessionId method
*
* @access public
* @return void
*/
function testSessionId() {
unset($_SESSION);
$Session =& new SessionComponent();
$this->assertNull($Session->id());
}
/**
* testSessionDestroy method
*
*
* @access public
* @return void
*/
function testSessionDestroy() {
$Session =& new SessionComponent();
$Session->write('Test', 'some value');
$this->assertEqual($Session->read('Test'), 'some value');
$Session->destroy('Test');
$this->assertNull($Session->read('Test'));
}
}
?>
?>

View file

@ -34,7 +34,7 @@ App::import('Core', 'Session');
* @subpackage cake.tests.cases.libs
*/
class SessionTest extends CakeTestCase {
var $fixtures = array('core.session');//using fixtures really messes things up. but should eventually be used.
var $fixtures = array('core.session');
/**
* setUp method
*
@ -42,13 +42,9 @@ class SessionTest extends CakeTestCase {
* @return void
*/
function setUp() {
restore_error_handler();
@$this->Session =& new CakeSession();
$this->Session =& new CakeSession();
$this->Session->start();
$this->Session->_checkValid();
set_error_handler('simpleTestErrorHandler');
}
/**
* testCheck method
@ -270,11 +266,12 @@ class SessionTest extends CakeTestCase {
* @access public
* @return void
*/
function testReadAndWriteWithDatabaseStorage() {
Configure::write('Session.table', 'sessions');
Configure::write('Session.database', 'default');
Configure::write('Session.save', 'database');
$this->Session->renew();
function testReadAndWriteWithCakeStorage() {
unset($_SESSION);
session_destroy();
ini_set('session.save_handler', 'files');
Configure::write('Session.save', 'cake');
$this->setUp();
$this->Session->write('SessionTestCase', 0);
$this->assertEqual($this->Session->read('SessionTestCase'), 0);
@ -291,17 +288,82 @@ class SessionTest extends CakeTestCase {
$this->Session->write('SessionTestCase', 'This is a Test');
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
$this->Session->write('SessionTestCase', 'This is a Test');
$this->Session->write('SessionTestCase', 'This was updated');
$this->assertEqual($this->Session->read('SessionTestCase'), 'This was updated');
$this->Session->destroy();
$this->assertFalse($this->Session->read('SessionTestCase'));
}
/**
* tearDown method
*
* testReadAndWriteWithDatabaseStorage method
*
* @access public
* @return void
*/
function tearDown() {
$this->Session->del('SessionTestCase');
unset($this->Session);
function testReadAndWriteWithCacheStorage() {
unset($_SESSION);
session_destroy();
ini_set('session.save_handler', 'files');
Configure::write('Session.save', 'cache');
$this->setUp();
$this->Session->write('SessionTestCase', 0);
$this->assertEqual($this->Session->read('SessionTestCase'), 0);
$this->Session->write('SessionTestCase', '0');
$this->assertEqual($this->Session->read('SessionTestCase'), '0');
$this->assertFalse($this->Session->read('SessionTestCase') === 0);
$this->Session->write('SessionTestCase', false);
$this->assertFalse($this->Session->read('SessionTestCase'));
$this->Session->write('SessionTestCase', null);
$this->assertEqual($this->Session->read('SessionTestCase'), null);
$this->Session->write('SessionTestCase', 'This is a Test');
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
$this->Session->write('SessionTestCase', 'This is a Test');
$this->Session->write('SessionTestCase', 'This was updated');
$this->assertEqual($this->Session->read('SessionTestCase'), 'This was updated');
$this->Session->destroy();
$this->assertFalse($this->Session->read('SessionTestCase'));
}
/**
* testReadAndWriteWithDatabaseStorage method
*
* @access public
* @return void
*/
function testReadAndWriteWithDatabaseStorage() {
unset($_SESSION);
session_destroy();
Configure::write('Session.table', 'sessions');
Configure::write('Session.database', 'test');
Configure::write('Session.save', 'database');
$this->setUp();
$this->Session->write('SessionTestCase', 0);
$this->assertEqual($this->Session->read('SessionTestCase'), 0);
$this->Session->write('SessionTestCase', '0');
$this->assertEqual($this->Session->read('SessionTestCase'), '0');
$this->assertFalse($this->Session->read('SessionTestCase') === 0);
$this->Session->write('SessionTestCase', false);
$this->assertFalse($this->Session->read('SessionTestCase'));
$this->Session->write('SessionTestCase', null);
$this->assertEqual($this->Session->read('SessionTestCase'), null);
$this->Session->write('SessionTestCase', 'This is a Test');
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
$this->Session->destroy();
$this->assertFalse($this->Session->read('SessionTestCase'));
}
}
?>
?>

View file

@ -33,183 +33,177 @@
* @subpackage cake.cake.tests.lib
*/
class CakeHtmlReporter extends SimpleReporter {
var $_character_set;
var $_character_set;
var $_show_passes = false;
/**
* Does nothing yet. The first output will
* be sent on the first test start. For use
* by a web browser.
* @access public
*/
function CakeHtmlReporter($character_set = 'ISO-8859-1') {
/**
* Does nothing yet. The first output will
* be sent on the first test start. For use
* by a web browser.
* @access public
*/
function CakeHtmlReporter($character_set = 'ISO-8859-1') {
if (isset($_GET['show_passes']) && $_GET['show_passes']) {
$this->_show_passes = true;
}
$this->SimpleReporter();
$this->_character_set = $character_set;
}
/**
* Paints the top of the web page setting the
* title to the name of the starting test.
* @param string $test_name Name class of test.
* @access public
*/
$this->SimpleReporter();
$this->_character_set = $character_set;
}
/**
* Paints the top of the web page setting the
* title to the name of the starting test.
* @param string $test_name Name class of test.
* @access public
*/
function paintHeader($testName) {
$this->sendNoCacheHeaders();
$baseUrl = BASE;
print "<h2>$testName</h2>\n";
print "<ul class='tests'>\n";
flush();
ob_start();
echo "<h2>$testName</h2>\n";
echo "<ul class='tests'>\n";
}
/**
* Send the headers necessary to ensure the page is
* reloaded on every request. Otherwise you could be
* scratching your head over out of date test data.
* @access public
* @static
*/
function sendNoCacheHeaders() {
if (! headers_sent()) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
}
/**
* Paints the end of the test with a summary of
* the passes and failures.
* @param string $test_name Name class of test.
* @access public
*/
function paintFooter($test_name) {
$colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
print "</ul>\n";
print "<div style=\"";
print "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
print "\">";
print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
print " test cases complete:\n";
print "<strong>" . $this->getPassCount() . "</strong> passes, ";
print "<strong>" . $this->getFailCount() . "</strong> fails and ";
print "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
print "</div>\n";
print "</body>\n</html>\n";
}
/**
* Paints the test failure with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
* @param string $message Failure message displayed in
* the context of the other tests.
* @access public
*/
function paintFail($message) {
parent::paintFail($message);
print "<li class='fail'>\n";
print "<span>Failed</span>";
print "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
/**
* Send the headers necessary to ensure the page is
* reloaded on every request. Otherwise you could be
* scratching your head over out of date test data.
* @access public
* @static
*/
function sendNoCacheHeaders() {
if (!headers_sent()) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
}
/**
* Paints the end of the test with a summary of
* the passes and failures.
* @param string $test_name Name class of test.
* @access public
*/
function paintFooter($test_name) {
$colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
ob_start();
echo "</ul>\n";
echo "<div style=\"";
echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
echo "\">";
echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
echo " test cases complete:\n";
echo "<strong>" . $this->getPassCount() . "</strong> passes, ";
echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
echo "</div>\n";
echo "</body>\n</html>\n";
}
/**
* Paints the test failure with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
* @param string $message Failure message displayed in
* the context of the other tests.
* @access public
*/
function paintFail($message) {
ob_start();
parent::paintFail($message);
echo "<li class='fail'>\n";
echo "<span>Failed</span>";
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
print "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
print "</li>\n";
}
echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
echo "</li>\n";
}
/**
* Paints the test pass with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
* @param string $message Pass message displayed in
* the context of the other tests.
* @access public
*/
function paintPass($message) {
ob_start();
parent::paintPass($message);
/**
* Paints the test pass with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
* @param string $message Pass message displayed in
* the context of the other tests.
* @access public
*/
function paintPass($message) {
parent::paintPass($message);
if ($this->_show_passes) {
print "<li class='pass'>\n";
print "<span>Passed</span> ";
echo "<li class='pass'>\n";
echo "<span>Passed</span> ";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
print implode(" -&gt; ", $breadcrumb);
print "<br />" . $this->_htmlEntities($message) . "\n";
print "</li>\n";
echo implode(" -&gt; ", $breadcrumb);
echo "<br />" . $this->_htmlEntities($message) . "\n";
echo "</li>\n";
}
}
/**
* Paints a PHP error.
* @param string $message Message is ignored.
* @access public
*/
function paintError($message) {
parent::paintError($message);
print "<li class='fail'>\n";
print "<span>Error</span>";
print "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
print "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
print "</li>\n";
}
/**
* Paints a PHP exception.
* @param Exception $exception Exception to display.
* @access public
*/
function paintException($exception) {
parent::paintException($exception);
print "<li class='fail'>\n";
print "<span>Exception</span>";
$message = 'Unexpected exception of type [' . get_class($exception) .
'] with message ['. $exception->getMessage() .
'] in ['. $exception->getFile() .
' line ' . $exception->getLine() . ']';
print "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
print "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
print "</li>\n";
}
/**
* Prints the message for skipping tests.
* @param string $message Text of skip condition.
* @access public
*/
function paintSkip($message) {
parent::paintSkip($message);
print "<li class='skipped'>\n";
print "<span>Skipped</span> ";
print $this->_htmlEntities($message);
print "</li>\n";
}
/**
* Paints formatted text such as dumped variables.
* @param string $message Text to show.
* @access public
*/
function paintFormattedMessage($message) {
print '<pre>' . $this->_htmlEntities($message) . '</pre>';
}
/**
* Character set adjusted entity conversion.
* @param string $message Plain text or Unicode message.
* @return string Browser readable message.
* @access protected
*/
function _htmlEntities($message) {
return htmlentities($message, ENT_COMPAT, $this->_character_set);
}
/**
* Paints a PHP error.
* @param string $message Message is ignored.
* @access public
*/
function paintError($message) {
ob_start();
parent::paintError($message);
echo "<li class='fail'>\n";
echo "<span>Error</span>";
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
echo "</li>\n";
}
/**
* Paints a PHP exception.
* @param Exception $exception Exception to display.
* @access public
*/
function paintException($exception) {
ob_start();
parent::paintException($exception);
echo "<li class='fail'>\n";
echo "<span>Exception</span>";
$message = 'Unexpected exception of type [' . get_class($exception) .
'] with message ['. $exception->getMessage() .
'] in ['. $exception->getFile() .
' line ' . $exception->getLine() . ']';
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
echo "</li>\n";
}
/**
* Prints the message for skipping tests.
* @param string $message Text of skip condition.
* @access public
*/
function paintSkip($message) {
ob_start();
parent::paintSkip($message);
echo "<li class='skipped'>\n";
echo "<span>Skipped</span> ";
echo $this->_htmlEntities($message);
echo "</li>\n";
}
/**
* Paints formatted text such as dumped variables.
* @param string $message Text to show.
* @access public
*/
function paintFormattedMessage($message) {
ob_start();
echo '<pre>' . $this->_htmlEntities($message) . '</pre>';
}
/**
* Character set adjusted entity conversion.
* @param string $message Plain text or Unicode message.
* @return string Browser readable message.
* @access protected
*/
function _htmlEntities($message) {
return htmlentities($message, ENT_COMPAT, $this->_character_set);
}
}
?>

View file

@ -128,7 +128,6 @@ class CakeTestCase extends UnitTestCase {
*/
function endTest($method) {
}
/**
* Overrides SimpleTestCase::assert to enable calling of skipIf() from within tests
*/
@ -138,7 +137,6 @@ class CakeTestCase extends UnitTestCase {
}
return parent::assert($expectation, $compare, $message);
}
/**
* Overrides SimpleTestCase::skipIf to provide a boolean return value
*/
@ -146,7 +144,6 @@ class CakeTestCase extends UnitTestCase {
parent::skipIf($shouldSkip, $message);
return $shouldSkip;
}
/**
* Callback issued when a controller's action is about to be invoked through testAction().
*
@ -158,7 +155,6 @@ class CakeTestCase extends UnitTestCase {
if (!isset($this->db)) {
$this->_initDb();
}
$classRegistry =& ClassRegistry::getInstance();
$models = array();
@ -168,8 +164,7 @@ class CakeTestCase extends UnitTestCase {
$models[$object->alias] = array (
'table' => $object->table,
'model' => $object->alias,
'key' => Inflector::camelize($key)
);
'key' => Inflector::camelize($key));
}
}
@ -177,8 +172,7 @@ class CakeTestCase extends UnitTestCase {
$this->_queries = array(
'create' => array(),
'insert' => array(),
'drop' => array()
);
'drop' => array());
foreach ($models as $model) {
$fixture =& new CakeTestFixture($this->db);

View file

@ -33,8 +33,8 @@ define ('APP_TEST_GROUPS', APP . 'tests' .DS. 'groups');
/**
* Short description for class.
*
* @package cake
* @subpackage cake.cake.tests.lib
* @package cake
* @subpackage cake.cake.tests.lib
*/
class TestManager {
var $_testExtension = '.test.php';
@ -119,7 +119,7 @@ class TestManager {
function addTestFile(&$groupTest, $file) {
$manager =& new TestManager();
if (file_exists($file.'.test.php')) {
$file .= '.test.php';
} elseif (file_exists($file.'.group.php')) {
@ -243,8 +243,8 @@ class TestManager {
/**
* Short description for class.
*
* @package cake
* @subpackage cake.cake.tests.lib
* @package cake
* @subpackage cake.cake.tests.lib
*/
class CliTestManager extends TestManager {
@ -273,8 +273,8 @@ class CliTestManager extends TestManager {
/**
* Short description for class.
*
* @package cake
* @subpackage cake.cake.tests.lib
* @package cake
* @subpackage cake.cake.tests.lib
*/
class TextTestManager extends TestManager {
var $_url;
@ -302,7 +302,7 @@ class TextTestManager extends TestManager {
$urlExtra = '&plugin=' . $manager->pluginTest;
}
$buffer .= "All tests\n" . $_SERVER['SERVER_NAME'] . $manager->getBaseURL() . "?group=all&output=txt{$urlExtra}\n";
$buffer .= "All tests\n" . $_SERVER['SERVER_NAME'] . $manager->getBaseURL() . "?group=all&output=txt{$urlExtra}\n";
foreach ((array)$groupTests as $groupTest) {
$buffer .= $_SERVER['SERVER_NAME']. $manager->getBaseURL()."?group=" . $groupTest . "&output=txt{$urlExtra}"."\n";
@ -341,8 +341,8 @@ class TextTestManager extends TestManager {
/**
* Short description for class.
*
* @package cake
* @subpackage cake.cake.tests.lib
* @package cake
* @subpackage cake.cake.tests.lib
*/
class HtmlTestManager extends TestManager {
var $_url;
@ -376,7 +376,7 @@ class HtmlTestManager extends TestManager {
foreach ((array)$groupTests as $groupTest) {
$buffer .= "<li><a href='" . $manager->getBaseURL() . "?group={$groupTest}" . "{$urlExtra}'>" . $groupTest . "</a></li>\n";
}
$buffer .= "</ul>\n";
$buffer .= "</ul>\n";
return $buffer;
}
@ -407,7 +407,7 @@ class HtmlTestManager extends TestManager {
$buffer .= "<li><a href='" . $manager->getBaseURL() . "?case=" . urlencode($testCase) . $urlExtra ."'>" . $title . "</a></li>\n";
}
$buffer .= "</ul>\n";
$buffer .= "</ul>\n";
return $buffer;
}
}
@ -465,6 +465,7 @@ if (function_exists('caketestsgetreporter')) {
$query .= '&amp;plugin=' . $_GET['plugin'];
}
}
ob_start();
echo "<p><a href='" . RUN_TEST_LINK . $show . "'>Run more tests</a> | <a href='" . RUN_TEST_LINK . $query . "&show_passes=1'>Show Passes</a> | \n";
break;
}
@ -489,6 +490,7 @@ if (function_exists('caketestsgetreporter')) {
}
}
$query .= '&amp;code_coverage=true';
ob_start();
echo " <a href='" . RUN_TEST_LINK . $query . "'>Analyze Code Coverage</a></p>\n";
break;
}
@ -497,6 +499,7 @@ if (function_exists('caketestsgetreporter')) {
function CakePHPTestCaseList() {
switch (CAKE_TEST_OUTPUT) {
case CAKE_TEST_OUTPUT_HTML:
ob_start();
echo HtmlTestManager::getTestCaseList();
break;
case CAKE_TEST_OUTPUT_TEXT:
@ -521,6 +524,7 @@ if (function_exists('caketestsgetreporter')) {
function CakePHPTestHeader() {
switch (CAKE_TEST_OUTPUT) {
case CAKE_TEST_OUTPUT_HTML:
ob_start();
$dispatch =& new Dispatcher();
$dispatch->baseUrl();
define('BASE', $dispatch->webroot);
@ -538,6 +542,7 @@ if (function_exists('caketestsgetreporter')) {
function CakePHPTestSuiteHeader() {
switch (CAKE_TEST_OUTPUT) {
case CAKE_TEST_OUTPUT_HTML:
ob_start();
$groups = $_SERVER['PHP_SELF'].'?show=groups';
$cases = $_SERVER['PHP_SELF'].'?show=cases';
$plugins = Configure::listObjects('plugin');
@ -549,6 +554,7 @@ if (function_exists('caketestsgetreporter')) {
function CakePHPTestSuiteFooter() {
switch ( CAKE_TEST_OUTPUT) {
case CAKE_TEST_OUTPUT_HTML:
ob_start();
$baseUrl = BASE;
include CAKE_TESTS_LIB . 'footer.php';
break;