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(); CakePHPTestGroupTestList();
} }
CakePHPTestSuiteFooter(); CakePHPTestSuiteFooter();
$output = ob_get_clean();
echo $output;
?> ?>

View file

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

View file

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

View file

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

View file

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

View file

@ -33,7 +33,7 @@
* Database name for cake sessions. * Database name for cake sessions.
* *
*/ */
uses('set'); App::import('Core', 'Set');
/** /**
* Session class for Cake. * Session class for Cake.
* *
@ -123,7 +123,7 @@ class CakeSession extends Object {
*/ */
function __construct($base = null, $start = true) { function __construct($base = null, $start = true) {
if (Configure::read('Session.save') === 'database' && !class_exists('ConnectionManager')) { 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) { if (Configure::read('Session.checkAgent') === true || Configure::read('Session.checkAgent') === null) {
@ -147,7 +147,7 @@ class CakeSession extends Object {
} }
if (!class_exists('Security')) { if (!class_exists('Security')) {
uses('security'); App::import('Core', 'Security');
} }
$this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout')); $this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout'));
@ -212,29 +212,6 @@ class CakeSession extends Object {
return $this->id; 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. * Removes a variable from session.
* *

View file

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

View file

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

View file

@ -32,8 +32,8 @@ if (!class_exists('AppController')) {
/** /**
* AppController class * AppController class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller * @subpackage cake.tests.cases.libs.controller
*/ */
class AppController extends Controller { class AppController extends Controller {
/** /**
@ -69,7 +69,6 @@ if (!class_exists('AppController')) {
} else { } else {
define('AppControllerExists', true); define('AppControllerExists', true);
} }
/** /**
* ParamTestComponent * ParamTestComponent
* *
@ -83,14 +82,14 @@ class ParamTestComponent extends Object {
* @access public * @access public
*/ */
var $name = 'ParamTest'; var $name = 'ParamTest';
/** /**
* components property * components property
* *
* @var array * @var array
* @access public * @access public
*/ */
var $components = array('Banana' => array('config' => 'value')); var $components = array('Banana' => array('config' => 'value'));
/** /**
* initialize method * initialize method
* *
* @param mixed $controller * @param mixed $controller
@ -107,14 +106,12 @@ class ParamTestComponent extends Object {
} }
} }
} }
} }
/** /**
* Short description for class. * Short description for class.
* *
* @package cake.tests * @package cake.tests
* @subpackage cake.tests.cases.libs.controller * @subpackage cake.tests.cases.libs.controller
*/ */
class ComponentTestController extends AppController { class ComponentTestController extends AppController {
/** /**
@ -135,8 +132,8 @@ class ComponentTestController extends AppController {
/** /**
* AppleComponent class * AppleComponent class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller * @subpackage cake.tests.cases.libs.controller
*/ */
class AppleComponent extends Object { class AppleComponent extends Object {
/** /**
@ -163,13 +160,12 @@ class AppleComponent extends Object {
function startup(&$controller) { function startup(&$controller) {
$this->testName = $controller->name; $this->testName = $controller->name;
} }
} }
/** /**
* OrangeComponent class * OrangeComponent class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller * @subpackage cake.tests.cases.libs.controller
*/ */
class OrangeComponent extends Object { class OrangeComponent extends Object {
/** /**
@ -194,8 +190,8 @@ class OrangeComponent extends Object {
/** /**
* BananaComponent class * BananaComponent class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller * @subpackage cake.tests.cases.libs.controller
*/ */
class BananaComponent extends Object { class BananaComponent extends Object {
/** /**
@ -205,9 +201,7 @@ class BananaComponent extends Object {
* @access public * @access public
*/ */
var $testField = 'BananaField'; var $testField = 'BananaField';
} }
/** /**
* MutuallyReferencingOneComponent class * MutuallyReferencingOneComponent class
* *
@ -217,7 +211,6 @@ class BananaComponent extends Object {
class MutuallyReferencingOneComponent extends Object { class MutuallyReferencingOneComponent extends Object {
var $components = array('MutuallyReferencingTwo'); var $components = array('MutuallyReferencingTwo');
} }
/** /**
* MutuallyReferencingTwoComponent class * MutuallyReferencingTwoComponent class
* *
@ -227,15 +220,11 @@ class MutuallyReferencingOneComponent extends Object {
class MutuallyReferencingTwoComponent extends Object { class MutuallyReferencingTwoComponent extends Object {
var $components = array('MutuallyReferencingOne'); var $components = array('MutuallyReferencingOne');
} }
/** /**
* ComponentTest class * ComponentTest class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller * @subpackage cake.tests.cases.libs.controller
*/ */
class ComponentTest extends CakeTestCase { class ComponentTest extends CakeTestCase {
/** /**
@ -319,10 +308,6 @@ class ComponentTest extends CakeTestCase {
$Controller->constructClasses(); $Controller->constructClasses();
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent')); $this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
$this->assertEqual($Controller->Apple->testName, null);
$Controller->Component->startup($Controller);
$this->assertEqual($Controller->Apple->testName, 'ComponentTest'); $this->assertEqual($Controller->Apple->testName, 'ComponentTest');
} }
/** /**
@ -335,8 +320,6 @@ class ComponentTest extends CakeTestCase {
$Controller->components = array('Orange', 'Banana'); $Controller->components = array('Orange', 'Banana');
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertEqual($Controller->Banana->testField, 'OrangeField'); $this->assertEqual($Controller->Banana->testField, 'OrangeField');
$this->assertEqual($Controller->Orange->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->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple');
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertTrue(is_a($Controller->ParamTest, 'ParamTestComponent')); $this->assertTrue(is_a($Controller->ParamTest, 'ParamTestComponent'));
$this->assertTrue(is_a($Controller->ParamTest->Banana, 'BananaComponent')); $this->assertTrue(is_a($Controller->ParamTest->Banana, 'BananaComponent'));
@ -367,7 +349,6 @@ class ComponentTest extends CakeTestCase {
$Controller =& new ComponentTestController(); $Controller =& new ComponentTestController();
$Controller->components = array('ParamTest' => array('test' => 'value'), 'Orange' => array('ripeness' => 'perfect')); $Controller->components = array('ParamTest' => array('test' => 'value'), 'Orange' => array('ripeness' => 'perfect'));
$Controller->constructClasses(); $Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertEqual($Controller->Orange->settings, array('colour' => 'blood orange', 'ripeness' => 'perfect')); $this->assertEqual($Controller->Orange->settings, array('colour' => 'blood orange', 'ripeness' => 'perfect'));
$this->assertEqual($Controller->ParamTest->test, 'value'); $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, 'MutuallyReferencingOneComponent'));
$this->assertTrue(is_a($Controller->MutuallyReferencingOne->MutuallyReferencingTwo, 'MutuallyReferencingTwoComponent')); $this->assertTrue(is_a($Controller->MutuallyReferencingOne->MutuallyReferencingTwo, 'MutuallyReferencingTwoComponent'));
$this->assertTrue(is_a($Controller->MutuallyReferencingOne->MutuallyReferencingTwo->MutuallyReferencingOne, 'MutuallyReferencingOneComponent')); $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 * AclNodeTwoTestBase class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class AclNodeTwoTestBase extends AclNode { class AclNodeTwoTestBase extends AclNode {
/** /**
* useDbConfig property * useDbConfig property
* *
* @var string 'test_suite' * @var string 'test_suite'
* @access public * @access public
*/ */
var $useDbConfig = 'test_suite'; var $useDbConfig = 'test_suite';
/** /**
* cacheSources property * cacheSources property
* *
* @var bool false * @var bool false
* @access public * @access public
*/ */
@ -55,28 +55,28 @@ class AclNodeTwoTestBase extends AclNode {
} }
/** /**
* AroTwoTest class * AroTwoTest class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class AroTwoTest extends AclNodeTwoTestBase { class AroTwoTest extends AclNodeTwoTestBase {
/** /**
* name property * name property
* *
* @var string 'AroTwoTest' * @var string 'AroTwoTest'
* @access public * @access public
*/ */
var $name = 'AroTwoTest'; var $name = 'AroTwoTest';
/** /**
* useTable property * useTable property
* *
* @var string 'aro_twos' * @var string 'aro_twos'
* @access public * @access public
*/ */
var $useTable = 'aro_twos'; var $useTable = 'aro_twos';
/** /**
* hasAndBelongsToMany property * hasAndBelongsToMany property
* *
* @var array * @var array
* @access public * @access public
*/ */
@ -84,28 +84,28 @@ class AroTwoTest extends AclNodeTwoTestBase {
} }
/** /**
* AcoTwoTest class * AcoTwoTest class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class AcoTwoTest extends AclNodeTwoTestBase { class AcoTwoTest extends AclNodeTwoTestBase {
/** /**
* name property * name property
* *
* @var string 'AcoTwoTest' * @var string 'AcoTwoTest'
* @access public * @access public
*/ */
var $name = 'AcoTwoTest'; var $name = 'AcoTwoTest';
/** /**
* useTable property * useTable property
* *
* @var string 'aco_twos' * @var string 'aco_twos'
* @access public * @access public
*/ */
var $useTable = 'aco_twos'; var $useTable = 'aco_twos';
/** /**
* hasAndBelongsToMany property * hasAndBelongsToMany property
* *
* @var array * @var array
* @access public * @access public
*/ */
@ -113,42 +113,42 @@ class AcoTwoTest extends AclNodeTwoTestBase {
} }
/** /**
* PermissionTwoTest class * PermissionTwoTest class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class PermissionTwoTest extends CakeTestModel { class PermissionTwoTest extends CakeTestModel {
/** /**
* name property * name property
* *
* @var string 'PermissionTwoTest' * @var string 'PermissionTwoTest'
* @access public * @access public
*/ */
var $name = 'PermissionTwoTest'; var $name = 'PermissionTwoTest';
/** /**
* useTable property * useTable property
* *
* @var string 'aros_aco_twos' * @var string 'aros_aco_twos'
* @access public * @access public
*/ */
var $useTable = 'aros_aco_twos'; var $useTable = 'aros_aco_twos';
/** /**
* cacheQueries property * cacheQueries property
* *
* @var bool false * @var bool false
* @access public * @access public
*/ */
var $cacheQueries = false; var $cacheQueries = false;
/** /**
* belongsTo property * belongsTo property
* *
* @var array * @var array
* @access public * @access public
*/ */
var $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id')); var $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id'));
/** /**
* actsAs property * actsAs property
* *
* @var mixed null * @var mixed null
* @access public * @access public
*/ */
@ -156,14 +156,14 @@ class PermissionTwoTest extends CakeTestModel {
} }
/** /**
* DbAclTwoTest class * DbAclTwoTest class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class DbAclTwoTest extends DbAcl { class DbAclTwoTest extends DbAcl {
/** /**
* construct method * construct method
* *
* @access private * @access private
* @return void * @return void
*/ */
@ -176,9 +176,9 @@ class DbAclTwoTest extends DbAcl {
} }
/** /**
* IniAclTest class * IniAclTest class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class IniAclTest extends IniAcl { class IniAclTest extends IniAcl {
@ -187,20 +187,20 @@ class IniAclTest extends IniAcl {
/** /**
* Short description for class. * Short description for class.
* *
* @package cake.tests * @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class AclComponentTest extends CakeTestCase { class AclComponentTest extends CakeTestCase {
/** /**
* fixtures property * fixtures property
* *
* @var array * @var array
* @access public * @access public
*/ */
var $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two'); var $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
/** /**
* startTest method * startTest method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -209,8 +209,8 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* before method * before method
* *
* @param mixed $method * @param mixed $method
* @access public * @access public
* @return void * @return void
*/ */
@ -221,7 +221,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testAclCreate method * testAclCreate method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -248,7 +248,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testAclCreateWithParent method * testAclCreateWithParent method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -267,7 +267,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbAclAllow method * testDbAclAllow method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -282,23 +282,21 @@ class AclComponentTest extends CakeTestCase {
$this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create')); $this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create')); $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create'));
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete')); $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! // Michael no longer has his delete permission for tpsReports!
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete')); $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
$this->assertTrue($this->Acl->check('Micheal', 'printers', 'create')); $this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view')); $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->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
$this->assertTrue($this->Acl->check('Samir', 'view', 'read')); $this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update')); $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->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
$this->assertTrue($this->Acl->check('Samir', 'update', 'read')); $this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update')); $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->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
$this->expectError('DbAcl::allow() - Invalid node'); $this->expectError('DbAcl::allow() - Invalid node');
@ -309,11 +307,11 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbAclCheck method * testDbAclCheck method
* *
* @access public * @access public
* @return void * @return void
*/ */
function testDbAclCheck() { function testDbAclCheck() {
$this->assertTrue($this->Acl->check('Samir', 'print', 'read')); $this->assertTrue($this->Acl->check('Samir', 'print', 'read'));
$this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read')); $this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read'));
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read')); $this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
@ -356,7 +354,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbAclDeny method * testDbAclDeny method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -385,7 +383,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testAclNodeLookup method * testAclNodeLookup method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -409,7 +407,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbInherit method * testDbInherit method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -426,7 +424,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbGrant method * testDbGrant method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -447,7 +445,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbRevoke method * testDbRevoke method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -467,7 +465,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testStartup method * testStartup method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -479,7 +477,7 @@ class AclComponentTest extends CakeTestCase {
/* The following tests and AclComponent methods are not fully implemented yet /* The following tests and AclComponent methods are not fully implemented yet
/** /**
* testDbSetAro method * testDbSetAro method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -490,7 +488,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbSetAco method * testDbSetAco method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -501,7 +499,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbGetAro method * testDbGetAro method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -512,7 +510,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testDbGetAco method * testDbGetAco method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -566,7 +564,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* testIniCheck method * testIniCheck method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -591,7 +589,7 @@ class AclComponentTest extends CakeTestCase {
} }
/** /**
* tearDown method * tearDown method
* *
* @access public * @access public
* @return void * @return void
*/ */

View file

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

View file

@ -26,7 +26,19 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License * @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. * Short description for class.
* *
@ -34,14 +46,261 @@ uses('controller' . DS . 'components' . DS .'cookie');
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class CookieComponentTest extends CakeTestCase { class CookieComponentTest extends CakeTestCase {
/** var $Controller;
* skip method
* function start() {
* @access public $this->Controller = new CookieComponentTestController();
* @return void $this->Controller->constructClasses();
*/ $this->Controller->Cookie->destroy();
function skip() { }
$this->skipif (true, 'CookieComponentTest not implemented');
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')); App::import('Component', array('RequestHandler'));
/** /**
* RequestHandlerTestController class * RequestHandlerTestController class
* *
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.controller.components * @subpackage cake.tests.cases.libs.controller.components
*/ */
class RequestHandlerTestController extends Controller { class RequestHandlerTestController extends Controller {
/** /**
* uses property * uses property
* *
* @var mixed null * @var mixed null
* @access public * @access public
*/ */
var $uses = null; var $uses = null;
/** /**
* construct method * construct method
* *
* @param array $params * @param array $params
* @access private * @access private
* @return void * @return void
*/ */
@ -56,7 +56,38 @@ class RequestHandlerTestController extends Controller {
parent::__construct(); 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. * Short description for class.
* *
@ -66,7 +97,7 @@ class RequestHandlerTestController extends Controller {
class RequestHandlerComponentTest extends CakeTestCase { class RequestHandlerComponentTest extends CakeTestCase {
/** /**
* setUp method * setUp method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -75,7 +106,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* init method * init method
* *
* @access protected * @access protected
* @return void * @return void
*/ */
@ -86,7 +117,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testInitializeCallback method * testInitializeCallback method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -100,26 +131,22 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testDisabling method * testDisabling method
* *
* @access public * @access public
* @return void * @return void
*/ */
function testDisabling() { function testDisabling() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->assertEqual($this->Controller->params, array()); $this->_init();
$this->RequestHandler->startup($this->Controller);
$this->assertEqual($this->Controller->params, array('isAjax' => true)); $this->assertEqual($this->Controller->params, array('isAjax' => true));
$this->_init(); $this->Controller = new RequestHandlerTestDisabledController(array('components' => array('RequestHandler')));
$this->assertEqual($this->Controller->params, array());
$this->RequestHandler->enabled = false;
$this->RequestHandler->startup($this->Controller);
$this->assertEqual($this->Controller->params, array()); $this->assertEqual($this->Controller->params, array());
unset($_SERVER['HTTP_X_REQUESTED_WITH']); unset($_SERVER['HTTP_X_REQUESTED_WITH']);
} }
/** /**
* testAutoResponseType method * testAutoResponseType method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -132,7 +159,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testStartupCallback method * testStartupCallback method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -145,7 +172,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testNonAjaxRedirect method * testNonAjaxRedirect method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -156,7 +183,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testRenderAs method * testRenderAs method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -167,7 +194,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testRequestClientTypes method * testRequestClientTypes method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -189,7 +216,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testRequestContentTypes method * testRequestContentTypes method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -232,7 +259,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testResponseContentType method * testResponseContentType method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -243,7 +270,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testMobileDeviceDetection method * testMobileDeviceDetection method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -254,7 +281,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testRequestProperties method * testRequestProperties method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -273,7 +300,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testRequestMethod method * testRequestMethod method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -304,7 +331,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testClientContentPreference method * testClientContentPreference method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -328,7 +355,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testCustomContent method * testCustomContent method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -346,7 +373,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* testClientProperties method * testClientProperties method
* *
* @access public * @access public
* @return void * @return void
*/ */
@ -373,7 +400,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
} }
/** /**
* tearDown method * tearDown method
* *
* @access public * @access public
* @return void * @return void
*/ */

View file

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

View file

@ -34,7 +34,7 @@ App::import('Core', 'Session');
* @subpackage cake.tests.cases.libs * @subpackage cake.tests.cases.libs
*/ */
class SessionTest extends CakeTestCase { 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 * setUp method
* *
@ -42,13 +42,9 @@ class SessionTest extends CakeTestCase {
* @return void * @return void
*/ */
function setUp() { function setUp() {
restore_error_handler(); $this->Session =& new CakeSession();
@$this->Session =& new CakeSession();
$this->Session->start(); $this->Session->start();
$this->Session->_checkValid(); $this->Session->_checkValid();
set_error_handler('simpleTestErrorHandler');
} }
/** /**
* testCheck method * testCheck method
@ -270,11 +266,12 @@ class SessionTest extends CakeTestCase {
* @access public * @access public
* @return void * @return void
*/ */
function testReadAndWriteWithDatabaseStorage() { function testReadAndWriteWithCakeStorage() {
Configure::write('Session.table', 'sessions'); unset($_SESSION);
Configure::write('Session.database', 'default'); session_destroy();
Configure::write('Session.save', 'database'); ini_set('session.save_handler', 'files');
$this->Session->renew(); Configure::write('Session.save', 'cake');
$this->setUp();
$this->Session->write('SessionTestCase', 0); $this->Session->write('SessionTestCase', 0);
$this->assertEqual($this->Session->read('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->Session->write('SessionTestCase', 'This is a Test');
$this->assertEqual($this->Session->read('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 * @access public
* @return void * @return void
*/ */
function tearDown() { function testReadAndWriteWithCacheStorage() {
$this->Session->del('SessionTestCase'); unset($_SESSION);
unset($this->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 * @subpackage cake.cake.tests.lib
*/ */
class CakeHtmlReporter extends SimpleReporter { class CakeHtmlReporter extends SimpleReporter {
var $_character_set; var $_character_set;
var $_show_passes = false; var $_show_passes = false;
/**
/** * Does nothing yet. The first output will
* Does nothing yet. The first output will * be sent on the first test start. For use
* be sent on the first test start. For use * by a web browser.
* by a web browser. * @access public
* @access public */
*/ function CakeHtmlReporter($character_set = 'ISO-8859-1') {
function CakeHtmlReporter($character_set = 'ISO-8859-1') {
if (isset($_GET['show_passes']) && $_GET['show_passes']) { if (isset($_GET['show_passes']) && $_GET['show_passes']) {
$this->_show_passes = true; $this->_show_passes = true;
} }
$this->SimpleReporter(); $this->SimpleReporter();
$this->_character_set = $character_set; $this->_character_set = $character_set;
} }
/**
/** * Paints the top of the web page setting the
* Paints the top of the web page setting the * title to the name of the starting test.
* title to the name of the starting test. * @param string $test_name Name class of test.
* @param string $test_name Name class of test. * @access public
* @access public */
*/
function paintHeader($testName) { function paintHeader($testName) {
$this->sendNoCacheHeaders(); $this->sendNoCacheHeaders();
$baseUrl = BASE; ob_start();
print "<h2>$testName</h2>\n"; echo "<h2>$testName</h2>\n";
print "<ul class='tests'>\n"; echo "<ul class='tests'>\n";
flush();
} }
/**
/** * Send the headers necessary to ensure the page is
* Send the headers necessary to ensure the page is * reloaded on every request. Otherwise you could be
* reloaded on every request. Otherwise you could be * scratching your head over out of date test data.
* scratching your head over out of date test data. * @access public
* @access public * @static
* @static */
*/ function sendNoCacheHeaders() {
function sendNoCacheHeaders() { if (!headers_sent()) {
if (! headers_sent()) { header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " 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: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false);
header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache");
header("Pragma: no-cache"); }
} }
} /**
* Paints the end of the test with a summary of
/** * the passes and failures.
* Paints the end of the test with a summary of * @param string $test_name Name class of test.
* the passes and failures. * @access public
* @param string $test_name Name class of test. */
* @access public function paintFooter($test_name) {
*/ $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
function paintFooter($test_name) { ob_start();
$colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green"); echo "</ul>\n";
print "</ul>\n"; echo "<div style=\"";
print "<div style=\""; echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
print "padding: 8px; margin: 1em 0; background-color: $colour; color: white;"; echo "\">";
print "\">"; echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount(); echo " test cases complete:\n";
print " test cases complete:\n"; echo "<strong>" . $this->getPassCount() . "</strong> passes, ";
print "<strong>" . $this->getPassCount() . "</strong> passes, "; echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
print "<strong>" . $this->getFailCount() . "</strong> fails and "; echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
print "<strong>" . $this->getExceptionCount() . "</strong> exceptions."; echo "</div>\n";
print "</div>\n"; echo "</body>\n</html>\n";
print "</body>\n</html>\n"; }
} /**
* Paints the test failure with a breadcrumbs
/** * trail of the nesting test suites below the
* Paints the test failure with a breadcrumbs * top level test.
* trail of the nesting test suites below the * @param string $message Failure message displayed in
* top level test. * the context of the other tests.
* @param string $message Failure message displayed in * @access public
* the context of the other tests. */
* @access public function paintFail($message) {
*/ ob_start();
function paintFail($message) { parent::paintFail($message);
parent::paintFail($message); echo "<li class='fail'>\n";
print "<li class='fail'>\n"; echo "<span>Failed</span>";
print "<span>Failed</span>"; echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
print "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList()); $breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb); array_shift($breadcrumb);
print "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n"; echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
print "</li>\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) { if ($this->_show_passes) {
print "<li class='pass'>\n"; echo "<li class='pass'>\n";
print "<span>Passed</span> "; echo "<span>Passed</span> ";
$breadcrumb = Set::filter($this->getTestList()); $breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb); array_shift($breadcrumb);
print implode(" -&gt; ", $breadcrumb); echo implode(" -&gt; ", $breadcrumb);
print "<br />" . $this->_htmlEntities($message) . "\n"; echo "<br />" . $this->_htmlEntities($message) . "\n";
print "</li>\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 a PHP error.
* Paints formatted text such as dumped variables. * @param string $message Message is ignored.
* @param string $message Text to show. * @access public
* @access public */
*/ function paintError($message) {
function paintFormattedMessage($message) { ob_start();
print '<pre>' . $this->_htmlEntities($message) . '</pre>'; parent::paintError($message);
} echo "<li class='fail'>\n";
echo "<span>Error</span>";
/** echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
* Character set adjusted entity conversion. $breadcrumb = Set::filter($this->getTestList());
* @param string $message Plain text or Unicode message. array_shift($breadcrumb);
* @return string Browser readable message. echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
* @access protected echo "</li>\n";
*/ }
function _htmlEntities($message) { /**
return htmlentities($message, ENT_COMPAT, $this->_character_set); * 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) { function endTest($method) {
} }
/** /**
* Overrides SimpleTestCase::assert to enable calling of skipIf() from within tests * 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); return parent::assert($expectation, $compare, $message);
} }
/** /**
* Overrides SimpleTestCase::skipIf to provide a boolean return value * Overrides SimpleTestCase::skipIf to provide a boolean return value
*/ */
@ -146,7 +144,6 @@ class CakeTestCase extends UnitTestCase {
parent::skipIf($shouldSkip, $message); parent::skipIf($shouldSkip, $message);
return $shouldSkip; return $shouldSkip;
} }
/** /**
* Callback issued when a controller's action is about to be invoked through testAction(). * 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)) { if (!isset($this->db)) {
$this->_initDb(); $this->_initDb();
} }
$classRegistry =& ClassRegistry::getInstance(); $classRegistry =& ClassRegistry::getInstance();
$models = array(); $models = array();
@ -168,8 +164,7 @@ class CakeTestCase extends UnitTestCase {
$models[$object->alias] = array ( $models[$object->alias] = array (
'table' => $object->table, 'table' => $object->table,
'model' => $object->alias, 'model' => $object->alias,
'key' => Inflector::camelize($key) 'key' => Inflector::camelize($key));
);
} }
} }
@ -177,8 +172,7 @@ class CakeTestCase extends UnitTestCase {
$this->_queries = array( $this->_queries = array(
'create' => array(), 'create' => array(),
'insert' => array(), 'insert' => array(),
'drop' => array() 'drop' => array());
);
foreach ($models as $model) { foreach ($models as $model) {
$fixture =& new CakeTestFixture($this->db); $fixture =& new CakeTestFixture($this->db);

View file

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