mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
70aa290f5b
commit
6807d4c333
19 changed files with 850 additions and 623 deletions
|
@ -153,4 +153,6 @@ if (isset($_GET['group'])) {
|
|||
CakePHPTestGroupTestList();
|
||||
}
|
||||
CakePHPTestSuiteFooter();
|
||||
$output = ob_get_clean();
|
||||
echo $output;
|
||||
?>
|
|
@ -153,4 +153,6 @@ if (isset($_GET['group'])) {
|
|||
CakePHPTestGroupTestList();
|
||||
}
|
||||
CakePHPTestSuiteFooter();
|
||||
$output = ob_get_clean();
|
||||
echo $output;
|
||||
?>
|
|
@ -86,11 +86,11 @@ class Dispatcher extends Object {
|
|||
* Constructor.
|
||||
*/
|
||||
function __construct($url = null, $base = false) {
|
||||
parent::__construct();
|
||||
if ($base !== false) {
|
||||
Configure::write('App.base', $base);
|
||||
}
|
||||
$this->base = Configure::read('App.base');
|
||||
|
||||
if ($url !== null) {
|
||||
return $this->dispatch($url);
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ class Dispatcher extends Object {
|
|||
*/
|
||||
function dispatch($url = null, $additionalParams = array()) {
|
||||
$parse = true;
|
||||
|
||||
if ($this->base === false) {
|
||||
$this->base = $this->baseUrl();
|
||||
}
|
||||
|
@ -143,9 +144,7 @@ class Dispatcher extends Object {
|
|||
'className' => Inflector::camelize($this->params['controller']) . 'Controller',
|
||||
'webroot' => $this->webroot,
|
||||
'url' => $url,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
'base' => $this->base)));
|
||||
}
|
||||
$missingAction = $missingView = $privateAction = false;
|
||||
|
||||
|
@ -162,7 +161,6 @@ class Dispatcher extends Object {
|
|||
$privateAction = in_array($prefix, $prefixes);
|
||||
}
|
||||
}
|
||||
|
||||
$protected = array_map('strtolower', get_class_methods('controller'));
|
||||
$classMethods = array_map('strtolower', get_class_methods($controller));
|
||||
|
||||
|
@ -177,7 +175,6 @@ class Dispatcher extends Object {
|
|||
if (in_array('return', array_keys($this->params)) && $this->params['return'] == 1) {
|
||||
$controller->autoRender = false;
|
||||
}
|
||||
|
||||
$controller->base = $this->base;
|
||||
$controller->here = $this->here;
|
||||
$controller->webroot = $this->webroot;
|
||||
|
@ -214,9 +211,8 @@ class Dispatcher extends Object {
|
|||
$controller->{$var} = array_merge($controller->{$var}, $diff);
|
||||
}
|
||||
}
|
||||
|
||||
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)));
|
||||
$this->start($controller);
|
||||
$controller->constructClasses();
|
||||
|
||||
if ($privateAction) {
|
||||
return $this->cakeError('privateAction', array(
|
||||
|
@ -225,11 +221,8 @@ class Dispatcher extends Object {
|
|||
'action' => $this->params['action'],
|
||||
'webroot' => $this->webroot,
|
||||
'url' => $url,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
'base' => $this->base)));
|
||||
}
|
||||
|
||||
return $this->_invoke($controller, $this->params, $missingAction);
|
||||
}
|
||||
/**
|
||||
|
@ -254,9 +247,7 @@ class Dispatcher extends Object {
|
|||
'action' => $params['action'],
|
||||
'webroot' => $this->webroot,
|
||||
'url' => $this->here,
|
||||
'base' => $this->base
|
||||
)
|
||||
));
|
||||
'base' => $this->base)));
|
||||
} else {
|
||||
$output = $controller->dispatchMethod($params['action'], $params['pass']);
|
||||
}
|
||||
|
@ -266,45 +257,13 @@ class Dispatcher extends Object {
|
|||
} elseif (empty($controller->output)) {
|
||||
$controller->output = $output;
|
||||
}
|
||||
|
||||
$controller->Component->shutdown($controller);
|
||||
|
||||
$controller->afterFilter();
|
||||
|
||||
if (isset($params['return'])) {
|
||||
return $controller->output;
|
||||
}
|
||||
e($controller->output);
|
||||
}
|
||||
/**
|
||||
* Starts up a controller (by calling its beforeFilter methods and
|
||||
* starting its components)
|
||||
*
|
||||
* @param object $controller Controller to start
|
||||
* @access public
|
||||
*/
|
||||
function start(&$controller) {
|
||||
$controller->constructClasses();
|
||||
|
||||
$controller->Component->initialize($controller);
|
||||
|
||||
if (!empty($controller->beforeFilter)) {
|
||||
trigger_error(sprintf(__('Dispatcher::start - Controller::$beforeFilter property usage is deprecated and will no longer be supported. Use Controller::beforeFilter().', true)), E_USER_WARNING);
|
||||
|
||||
if (is_array($controller->beforeFilter)) {
|
||||
foreach ($controller->beforeFilter as $filter) {
|
||||
if (is_callable(array($controller,$filter)) && $filter != 'beforeFilter') {
|
||||
$controller->$filter();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (is_callable(array($controller, $controller->beforeFilter)) && $controller->beforeFilter != 'beforeFilter') {
|
||||
$controller->{$controller->beforeFilter}();
|
||||
}
|
||||
}
|
||||
}
|
||||
$controller->beforeFilter();
|
||||
|
||||
$controller->Component->startup($controller);
|
||||
echo($controller->output);
|
||||
}
|
||||
/**
|
||||
* Sets the params when $url is passed as an array to Object::requestAction();
|
||||
|
@ -349,7 +308,6 @@ class Dispatcher extends Object {
|
|||
unset($params['form']['_method']);
|
||||
}
|
||||
}
|
||||
|
||||
extract(Router::getNamedExpressions());
|
||||
include CONFIGS . 'routes.php';
|
||||
$params = array_merge(Router::parse($fromUrl), $params);
|
||||
|
@ -400,7 +358,6 @@ class Dispatcher extends Object {
|
|||
* @access public
|
||||
*/
|
||||
function baseUrl() {
|
||||
|
||||
$dir = $webroot = null;
|
||||
$config = Configure::read('App');
|
||||
extract($config);
|
||||
|
@ -431,11 +388,12 @@ class Dispatcher extends Object {
|
|||
$this->webroot = $base .'/';
|
||||
return $base;
|
||||
}
|
||||
|
||||
$file = null;
|
||||
|
||||
if ($baseUrl) {
|
||||
$file = '/' . basename($baseUrl);
|
||||
$base = dirname($baseUrl);
|
||||
|
||||
if (in_array($base, array(DS, '.'))) {
|
||||
$base = '';
|
||||
}
|
||||
|
@ -570,11 +528,13 @@ class Dispatcher extends Object {
|
|||
if (Configure::read('App.server') == 'IIS') {
|
||||
$uri = preg_replace('/^(?:\/)?(?:\/)?(?:\?)?(?:url=)?/', '', $uri);
|
||||
}
|
||||
|
||||
if (!empty($uri)) {
|
||||
if (key($_GET) && strpos(key($_GET), '?') !== false) {
|
||||
unset($_GET[key($_GET)]);
|
||||
}
|
||||
$uri = preg_split('/\?/', $uri, 2);
|
||||
|
||||
if (isset($uri[1])) {
|
||||
parse_str($uri[1], $_GET);
|
||||
}
|
||||
|
@ -582,9 +542,11 @@ class Dispatcher extends Object {
|
|||
} elseif (empty($uri) && is_string(env('QUERY_STRING'))) {
|
||||
$uri = env('QUERY_STRING');
|
||||
}
|
||||
|
||||
if (strpos($uri, 'index.php') !== false) {
|
||||
list(, $uri) = explode('index.php', $uri, 2);
|
||||
}
|
||||
|
||||
if (empty($uri) || $uri == '/' || $uri == '//') {
|
||||
return '';
|
||||
}
|
||||
|
@ -603,6 +565,7 @@ class Dispatcher extends Object {
|
|||
if ($uri == null) {
|
||||
$uri = $this->uri();
|
||||
}
|
||||
|
||||
if ($base == null) {
|
||||
$base = $this->base;
|
||||
}
|
||||
|
@ -620,12 +583,14 @@ class Dispatcher extends Object {
|
|||
} else {
|
||||
$elements = array();
|
||||
}
|
||||
|
||||
if (!empty($elements[1])) {
|
||||
$_GET['url'] = $elements[1];
|
||||
$url = $elements[1];
|
||||
} else {
|
||||
$url = $_GET['url'] = '/';
|
||||
}
|
||||
|
||||
if (strpos($url, '/') === 0 && $url != '/') {
|
||||
$url = $_GET['url'] = substr($url, 1);
|
||||
}
|
||||
|
@ -633,6 +598,7 @@ class Dispatcher extends Object {
|
|||
} else {
|
||||
$url = $_GET['url'];
|
||||
}
|
||||
|
||||
if ($url{0} == '/') {
|
||||
$url = substr($url, 1);
|
||||
}
|
||||
|
@ -652,9 +618,9 @@ class Dispatcher extends Object {
|
|||
include WWW_ROOT . DS . Configure::read('Asset.filter.js');
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$assets = array('js' => 'text/javascript', 'css' => 'text/css');
|
||||
$isAsset = false;
|
||||
|
||||
foreach ($assets as $type => $contentType) {
|
||||
$pos = strpos($url, $type . '/');
|
||||
if ($pos !== false) {
|
||||
|
@ -670,9 +636,9 @@ class Dispatcher extends Object {
|
|||
ob_start();
|
||||
ob_start('ob_gzhandler');
|
||||
}
|
||||
|
||||
$assetFile = null;
|
||||
$paths = array();
|
||||
|
||||
if ($pos > 0) {
|
||||
$plugin = substr($url, 0, $pos - 1);
|
||||
$url = str_replace($plugin . '/', '', $url);
|
||||
|
@ -682,7 +648,6 @@ class Dispatcher extends Object {
|
|||
$paths[] = $pluginPaths[$i] . $plugin . DS . 'vendors' . DS;
|
||||
}
|
||||
}
|
||||
|
||||
$paths = array_merge($paths, Configure::read('vendorPaths'));
|
||||
|
||||
foreach ($paths as $path) {
|
||||
|
@ -711,9 +676,11 @@ class Dispatcher extends Object {
|
|||
|
||||
if (Configure::read('Cache.check') === true) {
|
||||
$filename = CACHE . 'views' . DS . Inflector::slug($this->here) . '.php';
|
||||
|
||||
if (!file_exists($filename)) {
|
||||
$filename = CACHE . 'views' . DS . Inflector::slug($this->here) . '_index.php';
|
||||
}
|
||||
|
||||
if (file_exists($filename)) {
|
||||
if (!class_exists('View')) {
|
||||
App::import('Core', 'View');
|
||||
|
|
|
@ -159,30 +159,9 @@ class CookieComponent extends Object {
|
|||
*
|
||||
* @param object $controller A reference to the instantiating controller object
|
||||
* @access public
|
||||
* @deprecated use Controller::beforeFilter() to set the properties of the CookieComponent
|
||||
*/
|
||||
function initialize(&$controller) {
|
||||
$this->key = Configure::read('Security.salt');
|
||||
if (is_object($controller)) {
|
||||
if (isset($controller->cookieName)) {
|
||||
$this->name = $controller->cookieName;
|
||||
}
|
||||
if (isset($controller->cookieTime)) {
|
||||
$this->time = $controller->cookieTime;
|
||||
}
|
||||
if (isset($controller->cookieKey)) {
|
||||
$this->key = $controller->cookieKey;
|
||||
}
|
||||
if (isset($controller->cookiePath)) {
|
||||
$this->path = $controller->cookiePath;
|
||||
}
|
||||
if (isset($controller->cookieDomain)) {
|
||||
$this->domain = $controller->cookieDomain;
|
||||
}
|
||||
if (isset($controller->cookieSecure)) {
|
||||
$this->secure = $controller->cookieSecure;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Start CookieComponent for use in the controller
|
||||
|
|
|
@ -384,9 +384,7 @@ class Controller extends Object {
|
|||
$this->__mergeVars();
|
||||
$this->Component->init($this);
|
||||
|
||||
if ($this->uses === null || ($this->uses === array())) {
|
||||
return false;
|
||||
}
|
||||
if ($this->uses !== null || ($this->uses !== array())) {
|
||||
if (empty($this->passedArgs) || !isset($this->passedArgs['0'])) {
|
||||
$id = false;
|
||||
} else {
|
||||
|
@ -402,6 +400,10 @@ class Controller extends Object {
|
|||
$this->loadModel($modelClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->Component->initialize($this);
|
||||
$this->beforeFilter();
|
||||
$this->Component->startup($this);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -401,5 +401,4 @@ class ContainableBehavior extends ModelBehavior {
|
|||
return $map;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -33,7 +33,7 @@
|
|||
* Database name for cake sessions.
|
||||
*
|
||||
*/
|
||||
uses('set');
|
||||
App::import('Core', 'Set');
|
||||
/**
|
||||
* Session class for Cake.
|
||||
*
|
||||
|
@ -123,7 +123,7 @@ class CakeSession extends Object {
|
|||
*/
|
||||
function __construct($base = null, $start = true) {
|
||||
if (Configure::read('Session.save') === 'database' && !class_exists('ConnectionManager')) {
|
||||
uses('model' . DS . 'connection_manager');
|
||||
App::import('Core', 'ConnectionManager');
|
||||
}
|
||||
|
||||
if (Configure::read('Session.checkAgent') === true || Configure::read('Session.checkAgent') === null) {
|
||||
|
@ -147,7 +147,7 @@ class CakeSession extends Object {
|
|||
}
|
||||
|
||||
if (!class_exists('Security')) {
|
||||
uses('security');
|
||||
App::import('Core', 'Security');
|
||||
}
|
||||
|
||||
$this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout'));
|
||||
|
@ -212,29 +212,6 @@ class CakeSession extends Object {
|
|||
return $this->id;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Temp method until we are able to remove the last eval().
|
||||
* Builds an expression to fetch a session variable with specified name.
|
||||
*
|
||||
* @param string $name Name of variable (in dot notation)
|
||||
* @access private
|
||||
*/
|
||||
function __sessionVarNames($name) {
|
||||
if (is_string($name) && preg_match("/^[ 0-9a-zA-Z._-]*$/", $name)) {
|
||||
if (strpos($name, ".")) {
|
||||
$names = explode(".", $name);
|
||||
} else {
|
||||
$names = array($name);
|
||||
}
|
||||
$expression = "\$_SESSION";
|
||||
foreach ($names as $item) {
|
||||
$expression .= is_numeric($item) ? "[$item]" : "['$item']";
|
||||
}
|
||||
return $expression;
|
||||
}
|
||||
$this->__setError(3, "$name is not a string");
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Removes a variable from session.
|
||||
*
|
||||
|
|
|
@ -752,26 +752,28 @@ class Set extends Object {
|
|||
* @access public
|
||||
*/
|
||||
function diff($val1, $val2 = null) {
|
||||
if ($val2 == null && (is_a($this, 'set') || is_a($this, 'Set'))) {
|
||||
if ($val2 == null && is_a($this, 'set')) {
|
||||
$val2 = $val1;
|
||||
$val1 = $this->get();
|
||||
}
|
||||
|
||||
if (is_object($val2) && (is_a($val2, 'set') || is_a($val2, 'Set'))) {
|
||||
if (is_a($val2, 'set')) {
|
||||
$val2 = $val2->get();
|
||||
}
|
||||
$out = array();
|
||||
|
||||
if (empty($val1)) {
|
||||
return (array)$val2;
|
||||
} elseif (empty($val2)) {
|
||||
return (array)$val1;
|
||||
}
|
||||
$out = array();
|
||||
|
||||
foreach ($val1 as $key => $val) {
|
||||
if (array_key_exists($key, $val2) && $val2[$key] != $val) {
|
||||
$exists = array_key_exists($key, $val2);
|
||||
|
||||
if ($exists && $val2[$key] != $val) {
|
||||
$out[$key] = $val;
|
||||
} elseif (!array_key_exists($key, $val2)) {
|
||||
} elseif (!$exists) {
|
||||
$out[$key] = $val;
|
||||
}
|
||||
unset($val2[$key]);
|
||||
|
|
|
@ -69,7 +69,6 @@ if (!class_exists('AppController')) {
|
|||
} else {
|
||||
define('AppControllerExists', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* ParamTestComponent
|
||||
*
|
||||
|
@ -83,14 +82,14 @@ class ParamTestComponent extends Object {
|
|||
* @access public
|
||||
*/
|
||||
var $name = 'ParamTest';
|
||||
/**
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $components = array('Banana' => array('config' => 'value'));
|
||||
/**
|
||||
/**
|
||||
* initialize method
|
||||
*
|
||||
* @param mixed $controller
|
||||
|
@ -107,9 +106,7 @@ class ParamTestComponent extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
@ -163,7 +160,6 @@ class AppleComponent extends Object {
|
|||
function startup(&$controller) {
|
||||
$this->testName = $controller->name;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* OrangeComponent class
|
||||
|
@ -205,9 +201,7 @@ class BananaComponent extends Object {
|
|||
* @access public
|
||||
*/
|
||||
var $testField = 'BananaField';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* MutuallyReferencingOneComponent class
|
||||
*
|
||||
|
@ -217,7 +211,6 @@ class BananaComponent extends Object {
|
|||
class MutuallyReferencingOneComponent extends Object {
|
||||
var $components = array('MutuallyReferencingTwo');
|
||||
}
|
||||
|
||||
/**
|
||||
* MutuallyReferencingTwoComponent class
|
||||
*
|
||||
|
@ -227,10 +220,6 @@ class MutuallyReferencingOneComponent extends Object {
|
|||
class MutuallyReferencingTwoComponent extends Object {
|
||||
var $components = array('MutuallyReferencingOne');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ComponentTest class
|
||||
*
|
||||
|
@ -319,10 +308,6 @@ class ComponentTest extends CakeTestCase {
|
|||
$Controller->constructClasses();
|
||||
|
||||
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
|
||||
$this->assertEqual($Controller->Apple->testName, null);
|
||||
|
||||
$Controller->Component->startup($Controller);
|
||||
|
||||
$this->assertEqual($Controller->Apple->testName, 'ComponentTest');
|
||||
}
|
||||
/**
|
||||
|
@ -335,8 +320,6 @@ class ComponentTest extends CakeTestCase {
|
|||
$Controller->components = array('Orange', 'Banana');
|
||||
$Controller->constructClasses();
|
||||
|
||||
$Controller->Component->initialize($Controller);
|
||||
|
||||
$this->assertEqual($Controller->Banana->testField, 'OrangeField');
|
||||
$this->assertEqual($Controller->Orange->Banana->testField, 'OrangeField');
|
||||
}
|
||||
|
@ -353,7 +336,6 @@ class ComponentTest extends CakeTestCase {
|
|||
$Controller->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple');
|
||||
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
|
||||
$this->assertTrue(is_a($Controller->ParamTest, 'ParamTestComponent'));
|
||||
$this->assertTrue(is_a($Controller->ParamTest->Banana, 'BananaComponent'));
|
||||
|
@ -367,7 +349,6 @@ class ComponentTest extends CakeTestCase {
|
|||
$Controller =& new ComponentTestController();
|
||||
$Controller->components = array('ParamTest' => array('test' => 'value'), 'Orange' => array('ripeness' => 'perfect'));
|
||||
$Controller->constructClasses();
|
||||
$Controller->Component->initialize($Controller);
|
||||
|
||||
$this->assertEqual($Controller->Orange->settings, array('colour' => 'blood orange', 'ripeness' => 'perfect'));
|
||||
$this->assertEqual($Controller->ParamTest->test, 'value');
|
||||
|
@ -386,7 +367,6 @@ class ComponentTest extends CakeTestCase {
|
|||
$this->assertTrue(is_a($Controller->MutuallyReferencingOne, 'MutuallyReferencingOneComponent'));
|
||||
$this->assertTrue(is_a($Controller->MutuallyReferencingOne->MutuallyReferencingTwo, 'MutuallyReferencingTwoComponent'));
|
||||
$this->assertTrue(is_a($Controller->MutuallyReferencingOne->MutuallyReferencingTwo->MutuallyReferencingOne, 'MutuallyReferencingOneComponent'));
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -287,13 +287,11 @@ class AclComponentTest extends CakeTestCase {
|
|||
$this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
|
||||
$this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
|
||||
|
||||
|
||||
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view'));
|
||||
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
|
||||
$this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
|
||||
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
|
||||
|
||||
|
||||
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
|
||||
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
|
||||
$this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import(array('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl'));
|
||||
|
||||
App::import(array('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl'));
|
||||
Configure::write('Security.salt', 'JfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
|
||||
/**
|
||||
|
@ -54,7 +53,6 @@ class TestAuthComponent extends AuthComponent {
|
|||
$this->testStop = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
@ -336,7 +334,6 @@ class AuthTest extends CakeTestCase {
|
|||
if (isset($this->fixtures) && (!is_array($this->fixtures) || empty($this->fixtures))) {
|
||||
unset($this->fixtures);
|
||||
}
|
||||
|
||||
// Create records
|
||||
if (isset($this->_fixtures) && isset($this->db)) {
|
||||
foreach ($this->_fixtures as $fixture) {
|
||||
|
@ -344,10 +341,9 @@ class AuthTest extends CakeTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->Controller =& new AuthTestController();
|
||||
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
|
||||
ClassRegistry::addObject('view', new View($this->Controller));
|
||||
$this->Controller->Session->del('Auth');
|
||||
$this->Controller->Session->del('Message.auth');
|
||||
|
|
|
@ -26,7 +26,19 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
uses('controller' . DS . 'components' . DS .'cookie');
|
||||
App::import('Core', array('Component', 'Controller', 'Cookie'));
|
||||
class CookieComponentTestController extends Controller {
|
||||
var $components = array('Cookie');
|
||||
|
||||
function beforeFilter() {
|
||||
$this->Cookie->name = 'CakeTestCookie';
|
||||
$this->Cookie->time = 10;
|
||||
$this->Cookie->path = '/';
|
||||
$this->Cookie->domain = '';
|
||||
$this->Cookie->secure = false;
|
||||
$this->Cookie->key = 'somerandomhaskey';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
@ -34,14 +46,261 @@ uses('controller' . DS . 'components' . DS .'cookie');
|
|||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class CookieComponentTest extends CakeTestCase {
|
||||
/**
|
||||
* skip method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function skip() {
|
||||
$this->skipif (true, 'CookieComponentTest not implemented');
|
||||
var $Controller;
|
||||
|
||||
function start() {
|
||||
$this->Controller = new CookieComponentTestController();
|
||||
$this->Controller->constructClasses();
|
||||
$this->Controller->Cookie->destroy();
|
||||
}
|
||||
|
||||
function testCookieName() {
|
||||
$this->assertEqual($this->Controller->Cookie->name, 'CakeTestCookie');
|
||||
}
|
||||
|
||||
function testSettingEncryptedCookieData() {
|
||||
$this->Controller->Cookie->write('Encrytped_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'));
|
||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.name', 'CakePHP');
|
||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.version', '1.2.0.x');
|
||||
$this->Controller->Cookie->write('Encrytped_multi_cookies.tag', 'CakePHP Rocks!');
|
||||
}
|
||||
|
||||
function testReadEncryptedCookieData() {
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
function testSettingPlainCookieData() {
|
||||
$this->Controller->Cookie->write('Plain_array', array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!'), false);
|
||||
$this->Controller->Cookie->write('Plain_multi_cookies.name', 'CakePHP', false);
|
||||
$this->Controller->Cookie->write('Plain_multi_cookies.version', '1.2.0.x', false);
|
||||
$this->Controller->Cookie->write('Plain_multi_cookies.tag', 'CakePHP Rocks!', false);
|
||||
}
|
||||
|
||||
function testReadPlainCookieData() {
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
function testReadingCookieValue() {
|
||||
$data = $this->Controller->Cookie->read();
|
||||
$expected = array(
|
||||
'Encrytped_array' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'),
|
||||
'Encrytped_multi_cookies' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'),
|
||||
'Plain_array' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'),
|
||||
'Plain_multi_cookies' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'));
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
function testDeleteCookieValue() {
|
||||
$this->Controller->Cookie->del('Encrytped_multi_cookies.name');
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$this->Controller->Cookie->del('Encrytped_array');
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$this->Controller->Cookie->del('Plain_multi_cookies.name');
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array('version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$this->Controller->Cookie->del('Plain_array');
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
function testSettingCookiesWithArray() {
|
||||
$this->Controller->Cookie->destroy();
|
||||
|
||||
$this->Controller->Cookie->write(array('Encrytped_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')));
|
||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.name' => 'CakePHP'));
|
||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.version' => '1.2.0.x'));
|
||||
$this->Controller->Cookie->write(array('Encrytped_multi_cookies.tag' => 'CakePHP Rocks!'));
|
||||
|
||||
$this->Controller->Cookie->write(array('Plain_array' => array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!')), null, false);
|
||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.name' => 'CakePHP'), null, false);
|
||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.version' => '1.2.0.x'), null, false);
|
||||
$this->Controller->Cookie->write(array('Plain_multi_cookies.tag' => 'CakePHP Rocks!'), null, false);
|
||||
}
|
||||
|
||||
function testReadingCookieArray() {
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array.name');
|
||||
$expected = 'CakePHP';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array.version');
|
||||
$expected = '1.2.0.x';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array.tag');
|
||||
$expected = 'CakePHP Rocks!';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.name');
|
||||
$expected = 'CakePHP';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.version');
|
||||
$expected = '1.2.0.x';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies.tag');
|
||||
$expected = 'CakePHP Rocks!';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array.name');
|
||||
$expected = 'CakePHP';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array.version');
|
||||
$expected = '1.2.0.x';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array.tag');
|
||||
$expected = 'CakePHP Rocks!';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies.name');
|
||||
$expected = 'CakePHP';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies.version');
|
||||
$expected = '1.2.0.x';
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies.tag');
|
||||
$expected = 'CakePHP Rocks!';
|
||||
$this->assertEqual($data, $expected);
|
||||
}
|
||||
|
||||
function testReadingCookieDataOnStartup() {
|
||||
$this->Controller->Cookie->destroy();
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$_COOKIE['CakeTestCookie'] = array(
|
||||
'Encrytped_array' => 'Q2FrZQ==.y5J8fefUM83X0rdlMjuYFca8ZMYASU/8hM75rHuvjVNHO2WQ+6wK9nkVxm4abxI=',
|
||||
'Encrytped_multi_cookies' => array(
|
||||
'name' => 'Q2FrZQ==.5pJ6fcvfAg==',
|
||||
'version' => 'Q2FrZQ==.lN0jNqu5Kg==',
|
||||
'tag' => 'Q2FrZQ==.5pJ6fcvfAobg7ZxebWw='),
|
||||
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
|
||||
'Plain_multi_cookies' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'));
|
||||
$this->Controller->Cookie->startup();
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
$this->Controller->Cookie->destroy();
|
||||
unset($_COOKIE['CakeTestCookie']);
|
||||
}
|
||||
|
||||
function testReadingCookieDataWithoutStartup() {
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array();
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$_COOKIE['CakeTestCookie'] = array(
|
||||
'Encrytped_array' => 'Q2FrZQ==.y5J8fefUM83X0rdlMjuYFca8ZMYASU/8hM75rHuvjVNHO2WQ+6wK9nkVxm4abxI=',
|
||||
'Encrytped_multi_cookies' => array(
|
||||
'name' => 'Q2FrZQ==.5pJ6fcvfAg==',
|
||||
'version' => 'Q2FrZQ==.lN0jNqu5Kg==',
|
||||
'tag' => 'Q2FrZQ==.5pJ6fcvfAobg7ZxebWw='),
|
||||
'Plain_array' => 'name|CakePHP,version|1.2.0.x,tag|CakePHP Rocks!',
|
||||
'Plain_multi_cookies' => array(
|
||||
'name' => 'CakePHP',
|
||||
'version' => '1.2.0.x',
|
||||
'tag' => 'CakePHP Rocks!'));
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Encrytped_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_array');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
|
||||
$data = $this->Controller->Cookie->read('Plain_multi_cookies');
|
||||
$expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' =>'CakePHP Rocks!');
|
||||
$this->assertEqual($data, $expected);
|
||||
$this->Controller->Cookie->destroy();
|
||||
unset($_COOKIE['CakeTestCookie']);
|
||||
}
|
||||
|
||||
function end() {
|
||||
$this->Controller->Cookie->destroy();
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -56,7 +56,38 @@ class RequestHandlerTestController extends Controller {
|
|||
parent::__construct();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* RequestHandlerTestDisabledController class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.controller.components
|
||||
*/
|
||||
class RequestHandlerTestDisabledController extends Controller {
|
||||
/**
|
||||
* uses property
|
||||
*
|
||||
* @var mixed null
|
||||
* @access public
|
||||
*/
|
||||
var $uses = null;
|
||||
/**
|
||||
* construct method
|
||||
*
|
||||
* @param array $params
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function __construct($params = array()) {
|
||||
foreach ($params as $key => $val) {
|
||||
$this->{$key} = $val;
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function beforeFilter() {
|
||||
$this->RequestHandler->enabled = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
@ -106,14 +137,10 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
|||
*/
|
||||
function testDisabling() {
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
$this->assertEqual($this->Controller->params, array());
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->_init();
|
||||
$this->assertEqual($this->Controller->params, array('isAjax' => true));
|
||||
|
||||
$this->_init();
|
||||
$this->assertEqual($this->Controller->params, array());
|
||||
$this->RequestHandler->enabled = false;
|
||||
$this->RequestHandler->startup($this->Controller);
|
||||
$this->Controller = new RequestHandlerTestDisabledController(array('components' => array('RequestHandler')));
|
||||
$this->assertEqual($this->Controller->params, array());
|
||||
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
uses('controller' . DS . 'controller', 'controller' . DS . 'components' . DS .'session');
|
||||
App::import('Core', 'Controller');
|
||||
App::import('Component', 'Session');
|
||||
/**
|
||||
* SessionTestController class
|
||||
*
|
||||
|
@ -53,8 +54,6 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$this->assertFalse($Session->__active);
|
||||
$this->assertFalse($Session->__started);
|
||||
$Session->startup(new SessionTestController());
|
||||
// $this->assertFalse(isset($_SESSION));
|
||||
unset($_SESSION);
|
||||
|
||||
Configure::write('Session.start', true);
|
||||
$Session =& new SessionComponent();
|
||||
|
@ -62,9 +61,8 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$this->assertFalse($Session->__started);
|
||||
$Session->startup(new SessionTestController());
|
||||
$this->assertTrue(isset($_SESSION));
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionInitialize method
|
||||
*
|
||||
* @access public
|
||||
|
@ -82,10 +80,8 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$sessionController->params['bare'] = 1;
|
||||
$Session->initialize($sessionController);
|
||||
$this->assertEqual($Session->__bare, 1);
|
||||
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionActivate method
|
||||
*
|
||||
* @access public
|
||||
|
@ -97,7 +93,6 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$this->assertTrue($Session->__active);
|
||||
$this->assertNull($Session->activate());
|
||||
$this->assertTrue($Session->__active);
|
||||
unset($_SESSION);
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
|
@ -105,9 +100,9 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$this->assertNull($Session->activate());
|
||||
$this->assertTrue($Session->__active);
|
||||
Configure::write('Session.start', true);
|
||||
unset($_SESSION);
|
||||
$Session->destroy();
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionValid method
|
||||
*
|
||||
* @access public
|
||||
|
@ -116,17 +111,18 @@ class SessionComponentTest extends CakeTestCase {
|
|||
function testSessionValid() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertTrue($Session->valid());
|
||||
|
||||
$Session->_userAgent = 'rweerw';
|
||||
$this->assertFalse($Session->valid());
|
||||
unset($_SESSION);
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertFalse($Session->__active);
|
||||
$this->assertFalse($Session->valid());
|
||||
Configure::write('Session.start', true);
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionError method
|
||||
*
|
||||
* @access public
|
||||
|
@ -136,16 +132,14 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertFalse($Session->error());
|
||||
unset($_SESSION);
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertFalse($Session->__active);
|
||||
$this->assertFalse($Session->error());
|
||||
Configure::write('Session.start', true);
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionReadWrite method
|
||||
*
|
||||
* @access public
|
||||
|
@ -154,7 +148,6 @@ class SessionComponentTest extends CakeTestCase {
|
|||
function testSessionReadWrite() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertFalse($Session->read());
|
||||
$this->assertFalse($Session->read('Test'));
|
||||
|
||||
$this->assertTrue($Session->write('Test', 'some value'));
|
||||
|
@ -179,17 +172,14 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$this->assertEqual($Session->read('Test'), 'some value');
|
||||
$Session->del('Test');
|
||||
|
||||
unset($_SESSION);
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertFalse($Session->write('Test', 'some value'));
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertFalse($Session->read('Test'));
|
||||
Configure::write('Session.start', true);
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionDel method
|
||||
*
|
||||
* @access public
|
||||
|
@ -202,16 +192,14 @@ class SessionComponentTest extends CakeTestCase {
|
|||
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertTrue($Session->del('Test'));
|
||||
unset($_SESSION);
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertFalse($Session->del('Test'));
|
||||
Configure::write('Session.start', true);
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionDelete method
|
||||
*
|
||||
* @access public
|
||||
|
@ -224,28 +212,14 @@ class SessionComponentTest extends CakeTestCase {
|
|||
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertTrue($Session->delete('Test'));
|
||||
unset($_SESSION);
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertFalse($Session->delete('Test'));
|
||||
Configure::write('Session.start', true);
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
* testSessionId method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionId() {
|
||||
$Session =& new SessionComponent();
|
||||
|
||||
$this->assertNull($Session->id());
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionCheck method
|
||||
*
|
||||
* @access public
|
||||
|
@ -259,16 +233,14 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$Session->write('Test', 'some value');
|
||||
$this->assertTrue($Session->check('Test'));
|
||||
$Session->delete('Test');
|
||||
unset($_SESSION);
|
||||
|
||||
Configure::write('Session.start', false);
|
||||
$Session =& new SessionComponent();
|
||||
$Session->write('Test', 'some value');
|
||||
$this->assertFalse($Session->check('Test'));
|
||||
Configure::write('Session.start', true);
|
||||
unset($_SESSION);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionFlash method
|
||||
*
|
||||
* @access public
|
||||
|
@ -291,7 +263,18 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$Session->setFlash('This is a test message', 'non_existing_layout');
|
||||
$this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'layout' => 'default', 'params' => array()));
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* testSessionId method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSessionId() {
|
||||
unset($_SESSION);
|
||||
$Session =& new SessionComponent();
|
||||
$this->assertNull($Session->id());
|
||||
}
|
||||
/**
|
||||
* testSessionDestroy method
|
||||
*
|
||||
* @access public
|
||||
|
@ -305,7 +288,5 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$Session->destroy('Test');
|
||||
$this->assertNull($Session->read('Test'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -34,7 +34,7 @@ App::import('Core', 'Session');
|
|||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class SessionTest extends CakeTestCase {
|
||||
var $fixtures = array('core.session');//using fixtures really messes things up. but should eventually be used.
|
||||
var $fixtures = array('core.session');
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
|
@ -42,13 +42,9 @@ class SessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function setUp() {
|
||||
restore_error_handler();
|
||||
|
||||
@$this->Session =& new CakeSession();
|
||||
$this->Session =& new CakeSession();
|
||||
$this->Session->start();
|
||||
$this->Session->_checkValid();
|
||||
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
}
|
||||
/**
|
||||
* testCheck method
|
||||
|
@ -270,11 +266,12 @@ class SessionTest extends CakeTestCase {
|
|||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testReadAndWriteWithDatabaseStorage() {
|
||||
Configure::write('Session.table', 'sessions');
|
||||
Configure::write('Session.database', 'default');
|
||||
Configure::write('Session.save', 'database');
|
||||
$this->Session->renew();
|
||||
function testReadAndWriteWithCakeStorage() {
|
||||
unset($_SESSION);
|
||||
session_destroy();
|
||||
ini_set('session.save_handler', 'files');
|
||||
Configure::write('Session.save', 'cake');
|
||||
$this->setUp();
|
||||
|
||||
$this->Session->write('SessionTestCase', 0);
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 0);
|
||||
|
@ -291,17 +288,82 @@ class SessionTest extends CakeTestCase {
|
|||
|
||||
$this->Session->write('SessionTestCase', 'This is a Test');
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
|
||||
|
||||
$this->Session->write('SessionTestCase', 'This is a Test');
|
||||
$this->Session->write('SessionTestCase', 'This was updated');
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'This was updated');
|
||||
|
||||
$this->Session->destroy();
|
||||
$this->assertFalse($this->Session->read('SessionTestCase'));
|
||||
}
|
||||
/**
|
||||
* tearDown method
|
||||
* testReadAndWriteWithDatabaseStorage method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
$this->Session->del('SessionTestCase');
|
||||
unset($this->Session);
|
||||
function testReadAndWriteWithCacheStorage() {
|
||||
unset($_SESSION);
|
||||
session_destroy();
|
||||
ini_set('session.save_handler', 'files');
|
||||
Configure::write('Session.save', 'cache');
|
||||
$this->setUp();
|
||||
|
||||
$this->Session->write('SessionTestCase', 0);
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 0);
|
||||
|
||||
$this->Session->write('SessionTestCase', '0');
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), '0');
|
||||
$this->assertFalse($this->Session->read('SessionTestCase') === 0);
|
||||
|
||||
$this->Session->write('SessionTestCase', false);
|
||||
$this->assertFalse($this->Session->read('SessionTestCase'));
|
||||
|
||||
$this->Session->write('SessionTestCase', null);
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), null);
|
||||
|
||||
$this->Session->write('SessionTestCase', 'This is a Test');
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
|
||||
|
||||
$this->Session->write('SessionTestCase', 'This is a Test');
|
||||
$this->Session->write('SessionTestCase', 'This was updated');
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'This was updated');
|
||||
|
||||
$this->Session->destroy();
|
||||
$this->assertFalse($this->Session->read('SessionTestCase'));
|
||||
}
|
||||
/**
|
||||
* testReadAndWriteWithDatabaseStorage method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testReadAndWriteWithDatabaseStorage() {
|
||||
unset($_SESSION);
|
||||
session_destroy();
|
||||
Configure::write('Session.table', 'sessions');
|
||||
Configure::write('Session.database', 'test');
|
||||
Configure::write('Session.save', 'database');
|
||||
$this->setUp();
|
||||
|
||||
$this->Session->write('SessionTestCase', 0);
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 0);
|
||||
|
||||
$this->Session->write('SessionTestCase', '0');
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), '0');
|
||||
$this->assertFalse($this->Session->read('SessionTestCase') === 0);
|
||||
|
||||
$this->Session->write('SessionTestCase', false);
|
||||
$this->assertFalse($this->Session->read('SessionTestCase'));
|
||||
|
||||
$this->Session->write('SessionTestCase', null);
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), null);
|
||||
|
||||
$this->Session->write('SessionTestCase', 'This is a Test');
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
|
||||
|
||||
$this->Session->destroy();
|
||||
$this->assertFalse($this->Session->read('SessionTestCase'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -35,8 +35,7 @@
|
|||
class CakeHtmlReporter extends SimpleReporter {
|
||||
var $_character_set;
|
||||
var $_show_passes = false;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Does nothing yet. The first output will
|
||||
* be sent on the first test start. For use
|
||||
* by a web browser.
|
||||
|
@ -49,8 +48,7 @@ class CakeHtmlReporter extends SimpleReporter {
|
|||
$this->SimpleReporter();
|
||||
$this->_character_set = $character_set;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Paints the top of the web page setting the
|
||||
* title to the name of the starting test.
|
||||
* @param string $test_name Name class of test.
|
||||
|
@ -58,13 +56,11 @@ class CakeHtmlReporter extends SimpleReporter {
|
|||
*/
|
||||
function paintHeader($testName) {
|
||||
$this->sendNoCacheHeaders();
|
||||
$baseUrl = BASE;
|
||||
print "<h2>$testName</h2>\n";
|
||||
print "<ul class='tests'>\n";
|
||||
flush();
|
||||
ob_start();
|
||||
echo "<h2>$testName</h2>\n";
|
||||
echo "<ul class='tests'>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Send the headers necessary to ensure the page is
|
||||
* reloaded on every request. Otherwise you could be
|
||||
* scratching your head over out of date test data.
|
||||
|
@ -72,7 +68,7 @@ class CakeHtmlReporter extends SimpleReporter {
|
|||
* @static
|
||||
*/
|
||||
function sendNoCacheHeaders() {
|
||||
if (! headers_sent()) {
|
||||
if (!headers_sent()) {
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
|
@ -80,8 +76,7 @@ class CakeHtmlReporter extends SimpleReporter {
|
|||
header("Pragma: no-cache");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Paints the end of the test with a summary of
|
||||
* the passes and failures.
|
||||
* @param string $test_name Name class of test.
|
||||
|
@ -89,20 +84,20 @@ class CakeHtmlReporter extends SimpleReporter {
|
|||
*/
|
||||
function paintFooter($test_name) {
|
||||
$colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
|
||||
print "</ul>\n";
|
||||
print "<div style=\"";
|
||||
print "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
|
||||
print "\">";
|
||||
print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
|
||||
print " test cases complete:\n";
|
||||
print "<strong>" . $this->getPassCount() . "</strong> passes, ";
|
||||
print "<strong>" . $this->getFailCount() . "</strong> fails and ";
|
||||
print "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
|
||||
print "</div>\n";
|
||||
print "</body>\n</html>\n";
|
||||
ob_start();
|
||||
echo "</ul>\n";
|
||||
echo "<div style=\"";
|
||||
echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
|
||||
echo "\">";
|
||||
echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
|
||||
echo " test cases complete:\n";
|
||||
echo "<strong>" . $this->getPassCount() . "</strong> passes, ";
|
||||
echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
|
||||
echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
|
||||
echo "</div>\n";
|
||||
echo "</body>\n</html>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Paints the test failure with a breadcrumbs
|
||||
* trail of the nesting test suites below the
|
||||
* top level test.
|
||||
|
@ -111,17 +106,17 @@ class CakeHtmlReporter extends SimpleReporter {
|
|||
* @access public
|
||||
*/
|
||||
function paintFail($message) {
|
||||
ob_start();
|
||||
parent::paintFail($message);
|
||||
print "<li class='fail'>\n";
|
||||
print "<span>Failed</span>";
|
||||
print "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
|
||||
echo "<li class='fail'>\n";
|
||||
echo "<span>Failed</span>";
|
||||
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
|
||||
$breadcrumb = Set::filter($this->getTestList());
|
||||
array_shift($breadcrumb);
|
||||
print "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
||||
print "</li>\n";
|
||||
echo "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
||||
echo "</li>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Paints the test pass with a breadcrumbs
|
||||
* trail of the nesting test suites below the
|
||||
* top level test.
|
||||
|
@ -130,77 +125,78 @@ class CakeHtmlReporter extends SimpleReporter {
|
|||
* @access public
|
||||
*/
|
||||
function paintPass($message) {
|
||||
ob_start();
|
||||
parent::paintPass($message);
|
||||
|
||||
if ($this->_show_passes) {
|
||||
print "<li class='pass'>\n";
|
||||
print "<span>Passed</span> ";
|
||||
echo "<li class='pass'>\n";
|
||||
echo "<span>Passed</span> ";
|
||||
$breadcrumb = Set::filter($this->getTestList());
|
||||
array_shift($breadcrumb);
|
||||
print implode(" -> ", $breadcrumb);
|
||||
print "<br />" . $this->_htmlEntities($message) . "\n";
|
||||
print "</li>\n";
|
||||
echo implode(" -> ", $breadcrumb);
|
||||
echo "<br />" . $this->_htmlEntities($message) . "\n";
|
||||
echo "</li>\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Paints a PHP error.
|
||||
* @param string $message Message is ignored.
|
||||
* @access public
|
||||
*/
|
||||
function paintError($message) {
|
||||
ob_start();
|
||||
parent::paintError($message);
|
||||
print "<li class='fail'>\n";
|
||||
print "<span>Error</span>";
|
||||
print "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
|
||||
echo "<li class='fail'>\n";
|
||||
echo "<span>Error</span>";
|
||||
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
|
||||
$breadcrumb = Set::filter($this->getTestList());
|
||||
array_shift($breadcrumb);
|
||||
print "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
||||
print "</li>\n";
|
||||
echo "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
||||
echo "</li>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Paints a PHP exception.
|
||||
* @param Exception $exception Exception to display.
|
||||
* @access public
|
||||
*/
|
||||
function paintException($exception) {
|
||||
ob_start();
|
||||
parent::paintException($exception);
|
||||
print "<li class='fail'>\n";
|
||||
print "<span>Exception</span>";
|
||||
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() . ']';
|
||||
print "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
|
||||
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
|
||||
$breadcrumb = Set::filter($this->getTestList());
|
||||
array_shift($breadcrumb);
|
||||
print "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
||||
print "</li>\n";
|
||||
echo "<div>" . implode(" -> ", $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);
|
||||
print "<li class='skipped'>\n";
|
||||
print "<span>Skipped</span> ";
|
||||
print $this->_htmlEntities($message);
|
||||
print "</li>\n";
|
||||
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) {
|
||||
print '<pre>' . $this->_htmlEntities($message) . '</pre>';
|
||||
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.
|
||||
|
@ -209,7 +205,5 @@ class CakeHtmlReporter extends SimpleReporter {
|
|||
function _htmlEntities($message) {
|
||||
return htmlentities($message, ENT_COMPAT, $this->_character_set);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -128,7 +128,6 @@ class CakeTestCase extends UnitTestCase {
|
|||
*/
|
||||
function endTest($method) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides SimpleTestCase::assert to enable calling of skipIf() from within tests
|
||||
*/
|
||||
|
@ -138,7 +137,6 @@ class CakeTestCase extends UnitTestCase {
|
|||
}
|
||||
return parent::assert($expectation, $compare, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides SimpleTestCase::skipIf to provide a boolean return value
|
||||
*/
|
||||
|
@ -146,7 +144,6 @@ class CakeTestCase extends UnitTestCase {
|
|||
parent::skipIf($shouldSkip, $message);
|
||||
return $shouldSkip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback issued when a controller's action is about to be invoked through testAction().
|
||||
*
|
||||
|
@ -158,7 +155,6 @@ class CakeTestCase extends UnitTestCase {
|
|||
if (!isset($this->db)) {
|
||||
$this->_initDb();
|
||||
}
|
||||
|
||||
$classRegistry =& ClassRegistry::getInstance();
|
||||
$models = array();
|
||||
|
||||
|
@ -168,8 +164,7 @@ class CakeTestCase extends UnitTestCase {
|
|||
$models[$object->alias] = array (
|
||||
'table' => $object->table,
|
||||
'model' => $object->alias,
|
||||
'key' => Inflector::camelize($key)
|
||||
);
|
||||
'key' => Inflector::camelize($key));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,8 +172,7 @@ class CakeTestCase extends UnitTestCase {
|
|||
$this->_queries = array(
|
||||
'create' => array(),
|
||||
'insert' => array(),
|
||||
'drop' => array()
|
||||
);
|
||||
'drop' => array());
|
||||
|
||||
foreach ($models as $model) {
|
||||
$fixture =& new CakeTestFixture($this->db);
|
||||
|
|
|
@ -465,6 +465,7 @@ if (function_exists('caketestsgetreporter')) {
|
|||
$query .= '&plugin=' . $_GET['plugin'];
|
||||
}
|
||||
}
|
||||
ob_start();
|
||||
echo "<p><a href='" . RUN_TEST_LINK . $show . "'>Run more tests</a> | <a href='" . RUN_TEST_LINK . $query . "&show_passes=1'>Show Passes</a> | \n";
|
||||
break;
|
||||
}
|
||||
|
@ -489,6 +490,7 @@ if (function_exists('caketestsgetreporter')) {
|
|||
}
|
||||
}
|
||||
$query .= '&code_coverage=true';
|
||||
ob_start();
|
||||
echo " <a href='" . RUN_TEST_LINK . $query . "'>Analyze Code Coverage</a></p>\n";
|
||||
break;
|
||||
}
|
||||
|
@ -497,6 +499,7 @@ if (function_exists('caketestsgetreporter')) {
|
|||
function CakePHPTestCaseList() {
|
||||
switch (CAKE_TEST_OUTPUT) {
|
||||
case CAKE_TEST_OUTPUT_HTML:
|
||||
ob_start();
|
||||
echo HtmlTestManager::getTestCaseList();
|
||||
break;
|
||||
case CAKE_TEST_OUTPUT_TEXT:
|
||||
|
@ -521,6 +524,7 @@ if (function_exists('caketestsgetreporter')) {
|
|||
function CakePHPTestHeader() {
|
||||
switch (CAKE_TEST_OUTPUT) {
|
||||
case CAKE_TEST_OUTPUT_HTML:
|
||||
ob_start();
|
||||
$dispatch =& new Dispatcher();
|
||||
$dispatch->baseUrl();
|
||||
define('BASE', $dispatch->webroot);
|
||||
|
@ -538,6 +542,7 @@ if (function_exists('caketestsgetreporter')) {
|
|||
function CakePHPTestSuiteHeader() {
|
||||
switch (CAKE_TEST_OUTPUT) {
|
||||
case CAKE_TEST_OUTPUT_HTML:
|
||||
ob_start();
|
||||
$groups = $_SERVER['PHP_SELF'].'?show=groups';
|
||||
$cases = $_SERVER['PHP_SELF'].'?show=cases';
|
||||
$plugins = Configure::listObjects('plugin');
|
||||
|
@ -549,6 +554,7 @@ if (function_exists('caketestsgetreporter')) {
|
|||
function CakePHPTestSuiteFooter() {
|
||||
switch ( CAKE_TEST_OUTPUT) {
|
||||
case CAKE_TEST_OUTPUT_HTML:
|
||||
ob_start();
|
||||
$baseUrl = BASE;
|
||||
include CAKE_TESTS_LIB . 'footer.php';
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue