code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
function testResponseContentType() { $this->assertNull($this->RequestHandler->responseType()); $this->assertTrue($this->RequestHandler->respondAs('atom')); $this->assertEqual($this->RequestHandler->responseType(), 'atom'); }
testResponseContentType method @access public @return void
testResponseContentType
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testMobileDeviceDetection() { $this->assertFalse($this->RequestHandler->isMobile()); $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3'; $this->assertTrue($this->RequestHandler->isMobile()); $_SERVER['HTTP_USER_AGENT'] = 'Some imaginary UA'; $this->RequestHandler->mobileUA []= 'imaginary'; $this->assertTrue($this->RequestHandler->isMobile()); array_pop($this->RequestHandler->mobileUA); }
testMobileDeviceDetection method @access public @return void
testMobileDeviceDetection
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testRequestProperties() { $_SERVER['HTTPS'] = 'on'; $this->assertTrue($this->RequestHandler->isSSL()); unset($_SERVER['HTTPS']); $this->assertFalse($this->RequestHandler->isSSL()); $_ENV['SCRIPT_URI'] = 'https://localhost/'; $s = $_SERVER; $_SERVER = array(); $this->assertTrue($this->RequestHandler->isSSL()); $_SERVER = $s; }
testRequestProperties method @access public @return void
testRequestProperties
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testRequestMethod() { $_SERVER['REQUEST_METHOD'] = 'GET'; $this->assertTrue($this->RequestHandler->isGet()); $this->assertFalse($this->RequestHandler->isPost()); $this->assertFalse($this->RequestHandler->isPut()); $this->assertFalse($this->RequestHandler->isDelete()); $_SERVER['REQUEST_METHOD'] = 'POST'; $this->assertFalse($this->RequestHandler->isGet()); $this->assertTrue($this->RequestHandler->isPost()); $this->assertFalse($this->RequestHandler->isPut()); $this->assertFalse($this->RequestHandler->isDelete()); $_SERVER['REQUEST_METHOD'] = 'PUT'; $this->assertFalse($this->RequestHandler->isGet()); $this->assertFalse($this->RequestHandler->isPost()); $this->assertTrue($this->RequestHandler->isPut()); $this->assertFalse($this->RequestHandler->isDelete()); $_SERVER['REQUEST_METHOD'] = 'DELETE'; $this->assertFalse($this->RequestHandler->isGet()); $this->assertFalse($this->RequestHandler->isPost()); $this->assertFalse($this->RequestHandler->isPut()); $this->assertTrue($this->RequestHandler->isDelete()); }
testRequestMethod method @access public @return void
testRequestMethod
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testClientContentPreference() { $_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*'; $this->_init(); $this->assertNotEqual($this->RequestHandler->prefers(), 'rss'); $this->RequestHandler->ext = 'rss'; $this->assertEqual($this->RequestHandler->prefers(), 'rss'); $this->assertFalse($this->RequestHandler->prefers('xml')); $this->assertEqual($this->RequestHandler->prefers(array('js', 'xml', 'xhtml')), 'xml'); $this->assertTrue($this->RequestHandler->accepts('xml')); $_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'; $this->_init(); $this->assertEqual($this->RequestHandler->prefers(), 'xml'); $this->assertEqual($this->RequestHandler->accepts(array('js', 'xml', 'html')), 'xml'); $this->assertFalse($this->RequestHandler->accepts(array('gif', 'jpeg', 'foo'))); $_SERVER['HTTP_ACCEPT'] = '*/*;q=0.5'; $this->_init(); $this->assertEqual($this->RequestHandler->prefers(), 'html'); $this->assertFalse($this->RequestHandler->prefers('rss')); $this->assertFalse($this->RequestHandler->accepts('rss')); }
testClientContentPreference method @access public @return void
testClientContentPreference
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testCustomContent() { $_SERVER['HTTP_ACCEPT'] = 'text/x-mobile,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5'; $this->_init(); $this->RequestHandler->setContent('mobile', 'text/x-mobile'); $this->RequestHandler->startup($this->Controller); $this->assertEqual($this->RequestHandler->prefers(), 'mobile'); $this->_init(); $this->RequestHandler->setContent(array('mobile' => 'text/x-mobile')); $this->RequestHandler->startup($this->Controller); $this->assertEqual($this->RequestHandler->prefers(), 'mobile'); }
testCustomContent method @access public @return void
testCustomContent
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testClientProperties() { $_SERVER['HTTP_HOST'] = 'localhost:80'; $this->assertEqual($this->RequestHandler->getReferer(), 'localhost'); $_SERVER['HTTP_HOST'] = null; $_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org'; $this->assertEqual($this->RequestHandler->getReferer(), 'cakephp.org'); $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.1.5, 10.0.1.1, proxy.com'; $_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2'; $_SERVER['REMOTE_ADDR'] = '192.168.1.3'; $this->assertEqual($this->RequestHandler->getClientIP(false), '192.168.1.5'); $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2'); unset($_SERVER['HTTP_X_FORWARDED_FOR']); $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.2'); unset($_SERVER['HTTP_CLIENT_IP']); $this->assertEqual($this->RequestHandler->getClientIP(), '192.168.1.3'); $_SERVER['HTTP_CLIENTADDRESS'] = '10.0.1.2, 10.0.1.1'; $this->assertEqual($this->RequestHandler->getClientIP(), '10.0.1.2'); }
testClientProperties method @access public @return void
testClientProperties
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testAjaxRedirectAsRequestAction() { $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->_init(); App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) ), true); $this->Controller->RequestHandler = new NoStopRequestHandler($this); $this->Controller->RequestHandler->expectOnce('_stop'); ob_start(); $this->Controller->RequestHandler->beforeRedirect( $this->Controller, array('controller' => 'request_handler_test', 'action' => 'destination') ); $result = ob_get_clean(); $this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.'); unset($_SERVER['HTTP_X_REQUESTED_WITH']); App::build(); }
test that ajax requests involving redirects trigger requestAction instead. @return void
testAjaxRedirectAsRequestAction
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testAjaxRedirectAsRequestActionStillRenderingLayout() { $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->_init(); App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) ), true); $this->Controller->RequestHandler = new NoStopRequestHandler($this); $this->Controller->RequestHandler->expectOnce('_stop'); ob_start(); $this->Controller->RequestHandler->beforeRedirect( $this->Controller, array('controller' => 'request_handler_test', 'action' => 'ajax2_layout') ); $result = ob_get_clean(); $this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.'); $this->assertPattern('/Ajax!/', $result, 'Layout was not rendered.'); unset($_SERVER['HTTP_X_REQUESTED_WITH']); App::build(); }
test that ajax requests involving redirects don't force no layout this would cause the ajax layout to not be rendered. @return void
testAjaxRedirectAsRequestActionStillRenderingLayout
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testBeforeRedirectCallbackWithArrayUrl() { $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')), array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/') )); $RequestHandler =& new NoStopRequestHandler(); ob_start(); $RequestHandler->beforeRedirect( $this->Controller, array('controller' => 'request_handler_test', 'action' => 'param_method', 'first', 'second') ); $result = ob_get_clean(); $this->assertEqual($result, 'one: first two: second'); }
test that the beforeRedirect callback properly converts array urls into their correct string ones, and adds base => false so the correct urls are generated. @link http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276 @return void
testBeforeRedirectCallbackWithArrayUrl
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function testBeforeRedirectCallingHeader() { $controller =& new RequestHandlerMockController(); $RequestHandler =& new NoStopRequestHandler(); $controller->expectOnce('header', array('HTTP/1.1 403 Forbidden')); ob_start(); $RequestHandler->beforeRedirect($controller, 'request_handler_test/param_method/first/second', 403); $result = ob_get_clean(); }
assure that beforeRedirect with a status code will correctly set the status header @return void
testBeforeRedirectCallingHeader
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/request_handler.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/request_handler.test.php
MIT
function validatePost(&$controller) { return $this->_validatePost($controller); }
validatePost method @param Controller $controller @return unknown
validatePost
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function fail() { $this->failed = true; }
fail method @access public @return void
fail
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function redirect($option, $code, $exit) { return $code; }
redirect method @param mixed $option @param mixed $code @param mixed $exit @access public @return void
redirect
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function header($status) { $this->testHeaders[] = $status; }
Conveinence method for header() @param string $status @return void @access public
header
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function startTest() { $this->Controller =& new SecurityTestController(); $this->Controller->Component->init($this->Controller); $this->Controller->Security =& $this->Controller->TestSecurity; $this->Controller->Security->blackHoleCallback = 'fail'; $this->oldSalt = Configure::read('Security.salt'); Configure::write('Security.salt', 'foo!'); }
setUp method @access public @return void
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function endTest() { Configure::write('Security.salt', $this->oldSalt); $this->Controller->Session->delete('_Token'); unset($this->Controller->Security); unset($this->Controller->Component); unset($this->Controller); }
Tear-down method. Resets environment state. @access public @return void
endTest
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testInitialize() { $settings = array( 'requirePost' => array('edit', 'update'), 'requireSecure' => array('update_account'), 'requireGet' => array('index'), 'validatePost' => false, 'loginUsers' => array( 'mark' => 'password' ), 'requireLogin' => array('login'), ); $this->Controller->Security->initialize($this->Controller, $settings); $this->assertEqual($this->Controller->Security->requirePost, $settings['requirePost']); $this->assertEqual($this->Controller->Security->requireSecure, $settings['requireSecure']); $this->assertEqual($this->Controller->Security->requireGet, $settings['requireGet']); $this->assertEqual($this->Controller->Security->validatePost, $settings['validatePost']); $this->assertEqual($this->Controller->Security->loginUsers, $settings['loginUsers']); $this->assertEqual($this->Controller->Security->requireLogin, $settings['requireLogin']); }
test that initalize can set properties. @return void
testInitialize
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testStartup() { $this->Controller->Security->startup($this->Controller); $result = $this->Controller->params['_Token']['key']; $this->assertNotNull($result); $this->assertTrue($this->Controller->Session->check('_Token')); }
testStartup method @access public @return void
testStartup
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequirePostFail() { $_SERVER['REQUEST_METHOD'] = 'GET'; $this->Controller->action = 'posted'; $this->Controller->Security->requirePost(array('posted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); }
testRequirePostFail method @access public @return void
testRequirePostFail
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequirePostSucceed() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'posted'; $this->Controller->Security->requirePost('posted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequirePostSucceed method @access public @return void
testRequirePostSucceed
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireSecureFail() { $_SERVER['HTTPS'] = 'off'; $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'posted'; $this->Controller->Security->requireSecure(array('posted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); }
testRequireSecureFail method @access public @return void
testRequireSecureFail
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireSecureSucceed() { $_SERVER['REQUEST_METHOD'] = 'Secure'; $this->Controller->action = 'posted'; $_SERVER['HTTPS'] = 'on'; $this->Controller->Security->requireSecure('posted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequireSecureSucceed method @access public @return void
testRequireSecureSucceed
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireAuthFail() { $_SERVER['REQUEST_METHOD'] = 'AUTH'; $this->Controller->action = 'posted'; $this->Controller->data = array('username' => 'willy', 'password' => 'somePass'); $this->Controller->Security->requireAuth(array('posted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); $this->Controller->Session->write('_Token', serialize(array('allowedControllers' => array()))); $this->Controller->data = array('username' => 'willy', 'password' => 'somePass'); $this->Controller->action = 'posted'; $this->Controller->Security->requireAuth('posted'); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); $this->Controller->Session->write('_Token', serialize(array( 'allowedControllers' => array('SecurityTest'), 'allowedActions' => array('posted2') ))); $this->Controller->data = array('username' => 'willy', 'password' => 'somePass'); $this->Controller->action = 'posted'; $this->Controller->Security->requireAuth('posted'); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); }
testRequireAuthFail method @access public @return void
testRequireAuthFail
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireAuthSucceed() { $_SERVER['REQUEST_METHOD'] = 'AUTH'; $this->Controller->action = 'posted'; $this->Controller->Security->requireAuth('posted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); $this->Controller->Security->Session->write('_Token', serialize(array( 'allowedControllers' => array('SecurityTest'), 'allowedActions' => array('posted') ))); $this->Controller->params['controller'] = 'SecurityTest'; $this->Controller->params['action'] = 'posted'; $this->Controller->data = array( 'username' => 'willy', 'password' => 'somePass', '_Token' => '' ); $this->Controller->action = 'posted'; $this->Controller->Security->requireAuth('posted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequireAuthSucceed method @access public @return void
testRequireAuthSucceed
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequirePostSucceedWrongMethod() { $_SERVER['REQUEST_METHOD'] = 'GET'; $this->Controller->action = 'getted'; $this->Controller->Security->requirePost('posted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequirePostSucceedWrongMethod method @access public @return void
testRequirePostSucceedWrongMethod
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireGetFail() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'getted'; $this->Controller->Security->requireGet(array('getted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); }
testRequireGetFail method @access public @return void
testRequireGetFail
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireGetSucceed() { $_SERVER['REQUEST_METHOD'] = 'GET'; $this->Controller->action = 'getted'; $this->Controller->Security->requireGet('getted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequireGetSucceed method @access public @return void
testRequireGetSucceed
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireLogin() { $this->Controller->action = 'posted'; $this->Controller->Security->requireLogin( 'posted', array('type' => 'basic', 'users' => array('admin' => 'password')) ); $_SERVER['PHP_AUTH_USER'] = 'admin'; $_SERVER['PHP_AUTH_PW'] = 'password'; $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); $this->Controller->action = 'posted'; $this->Controller->Security->requireLogin( array('posted'), array('type' => 'basic', 'users' => array('admin' => 'password')) ); $_SERVER['PHP_AUTH_USER'] = 'admin2'; $_SERVER['PHP_AUTH_PW'] = 'password'; $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); $this->Controller->action = 'posted'; $this->Controller->Security->requireLogin( 'posted', array('type' => 'basic', 'users' => array('admin' => 'password')) ); $_SERVER['PHP_AUTH_USER'] = 'admin'; $_SERVER['PHP_AUTH_PW'] = 'password2'; $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); }
testRequireLogin method @access public @return void
testRequireLogin
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testDigestAuth() { $skip = $this->skipIf((version_compare(PHP_VERSION, '5.1') == -1) XOR (!function_exists('apache_request_headers')), "%s Cannot run Digest Auth test for PHP versions < 5.1" ); if ($skip) { return; } $this->Controller->action = 'posted'; $_SERVER['PHP_AUTH_DIGEST'] = $digest = <<<DIGEST Digest username="Mufasa", realm="[email protected]", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="460d0d3c6867c2f1ab85b1ada1aece48", opaque="5ccc069c403ebaf9f0171e9517f40e41" DIGEST; $this->Controller->Security->requireLogin('posted', array( 'type' => 'digest', 'users' => array('Mufasa' => 'password'), 'realm' => '[email protected]' )); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testDigestAuth method @access public @return void
testDigestAuth
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireGetSucceedWrongMethod() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'posted'; $this->Controller->Security->requireGet('getted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequireGetSucceedWrongMethod method @access public @return void
testRequireGetSucceedWrongMethod
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequirePutFail() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'putted'; $this->Controller->Security->requirePut(array('putted')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); }
testRequirePutFail method @access public @return void
testRequirePutFail
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequirePutSucceed() { $_SERVER['REQUEST_METHOD'] = 'PUT'; $this->Controller->action = 'putted'; $this->Controller->Security->requirePut('putted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequirePutSucceed method @access public @return void
testRequirePutSucceed
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequirePutSucceedWrongMethod() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'posted'; $this->Controller->Security->requirePut('putted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequirePutSucceedWrongMethod method @access public @return void
testRequirePutSucceedWrongMethod
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireDeleteFail() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'deleted'; $this->Controller->Security->requireDelete(array('deleted', 'other_method')); $this->Controller->Security->startup($this->Controller); $this->assertTrue($this->Controller->failed); }
testRequireDeleteFail method @access public @return void
testRequireDeleteFail
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireDeleteSucceed() { $_SERVER['REQUEST_METHOD'] = 'DELETE'; $this->Controller->action = 'deleted'; $this->Controller->Security->requireDelete('deleted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequireDeleteSucceed method @access public @return void
testRequireDeleteSucceed
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireDeleteSucceedWrongMethod() { $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'posted'; $this->Controller->Security->requireDelete('deleted'); $this->Controller->Security->startup($this->Controller); $this->assertFalse($this->Controller->failed); }
testRequireDeleteSucceedWrongMethod method @access public @return void
testRequireDeleteSucceedWrongMethod
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireLoginSettings() { $this->Controller->Security->requireLogin( 'add', 'edit', array('type' => 'basic', 'users' => array('admin' => 'password')) ); $this->assertEqual($this->Controller->Security->requireLogin, array('add', 'edit')); $this->assertEqual($this->Controller->Security->loginUsers, array('admin' => 'password')); }
testRequireLoginSettings method @access public @return void
testRequireLoginSettings
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRequireLoginAllActions() { $this->Controller->Security->requireLogin( array('type' => 'basic', 'users' => array('admin' => 'password')) ); $this->assertEqual($this->Controller->Security->requireLogin, array('*')); $this->assertEqual($this->Controller->Security->loginUsers, array('admin' => 'password')); }
testRequireLoginAllActions method @access public @return void
testRequireLoginAllActions
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePost() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid'; $this->Controller->data = array( 'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'), '_Token' => compact('key', 'fields') ); $this->assertTrue($this->Controller->Security->validatePost($this->Controller)); }
Simple hash validation test @access public @return void
testValidatePost
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostNoSession() { $this->Controller->Security->startup($this->Controller); $this->Controller->Session->delete('_Token'); $key = $this->Controller->params['_Token']['key']; $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid'; $this->Controller->data = array( 'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'), '_Token' => compact('key', 'fields') ); $this->assertFalse($this->Controller->Security->validatePost($this->Controller)); }
Test that validatePost fails if you are missing the session information. @return void
testValidatePostNoSession
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostFormHacking() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid'; $this->Controller->data = array( 'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'), '_Token' => compact('key') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertFalse($result, 'validatePost passed when fields were missing. %s'); $this->Controller->data = array( 'Model' => array('username' => 'nate', 'password' => 'foo', 'valid' => '0'), '_Token' => compact('fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertFalse($result, 'validatePost passed when key was missing. %s'); }
test that validatePost fails if any of its required fields are missing. @return void
testValidatePostFormHacking
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostObjectDeserialize() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877'; // a corrupted serialized object, so we can see if it ever gets to deserialize $attack = 'O:3:"App":1:{s:5:"__map";a:1:{s:3:"foo";s:7:"Hacked!";s:1:"fail"}}'; $fields .= urlencode(':' . str_rot13($attack)); $this->Controller->data = array( 'Model' => array('username' => 'mark', 'password' => 'foo', 'valid' => '0'), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertFalse($result, 'validatePost passed when key was missing. %s'); }
Test that objects can't be passed into the serialized string. This was a vector for RFI and LFI attacks. Thanks to Felix Wilhelm @return void
testValidatePostObjectDeserialize
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostArray() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A'; $this->Controller->data = array( 'Model' => array('multi_field' => array('1', '3')), '_Token' => compact('key', 'fields') ); $this->assertTrue($this->Controller->Security->validatePost($this->Controller)); }
Tests validation of checkbox arrays @access public @return void
testValidatePostArray
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostNoModel() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '540ac9c60d323c22bafe997b72c0790f39a8bdef%3A'; $this->Controller->data = array( 'anything' => 'some_data', '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testValidatePostNoModel method @access public @return void
testValidatePostNoModel
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostSimple() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '69f493434187b867ea14b901fdf58b55d27c935d%3A'; $this->Controller->data = $data = array( 'Model' => array('username' => '', 'password' => ''), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testValidatePostSimple method @access public @return void
testValidatePostSimple
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostComplex() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id'; $this->Controller->data = array( 'Addresses' => array( '0' => array( 'id' => '123456', 'title' => '', 'first_name' => '', 'last_name' => '', 'address' => '', 'city' => '', 'phone' => '', 'primary' => '' ), '1' => array( 'id' => '654321', 'title' => '', 'first_name' => '', 'last_name' => '', 'address' => '', 'city' => '', 'phone' => '', 'primary' => '' ) ), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
Tests hash validation for multiple records, including locked fields @access public @return void
testValidatePostComplex
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostMultipleSelect() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '422cde416475abc171568be690a98cad20e66079%3A'; $this->Controller->data = array( 'Tag' => array('Tag' => array(1, 2)), '_Token' => compact('key', 'fields'), ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); $this->Controller->data = array( 'Tag' => array('Tag' => array(1, 2, 3)), '_Token' => compact('key', 'fields'), ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); $this->Controller->data = array( 'Tag' => array('Tag' => array(1, 2, 3, 4)), '_Token' => compact('key', 'fields'), ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); $fields = '19464422eafe977ee729c59222af07f983010c5f%3A'; $this->Controller->data = array( 'User.password' => 'bar', 'User.name' => 'foo', 'User.is_valid' => '1', 'Tag' => array('Tag' => array(1)), '_Token' => compact('key', 'fields'), ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
test ValidatePost with multiple select elements. @return void
testValidatePostMultipleSelect
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostCheckbox() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid'; $this->Controller->data = array( 'Model' => array('username' => '', 'password' => '', 'valid' => '0'), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); $fields = '874439ca69f89b4c4a5f50fb9c36ff56a28f5d42%3A'; $this->Controller->data = array( 'Model' => array('username' => '', 'password' => '', 'valid' => '0'), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); $this->Controller->data = array(); $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $this->Controller->data = $data = array( 'Model' => array('username' => '', 'password' => '', 'valid' => '0'), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testValidatePostCheckbox method First block tests un-checked checkbox Second block tests checked checkbox @access public @return void
testValidatePostCheckbox
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostHidden() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '51ccd8cb0997c7b3d4523ecde5a109318405ef8c%3AModel.hidden%7CModel.other_hidden'; $fields .= ''; $this->Controller->data = array( 'Model' => array( 'username' => '', 'password' => '', 'hidden' => '0', 'other_hidden' => 'some hidden value' ), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testValidatePostHidden method @access public @return void
testValidatePostHidden
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidatePostWithDisabledFields() { $this->Controller->Security->disabledFields = array('Model.username', 'Model.password'); $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = 'ef1082968c449397bcd849f963636864383278b1%3AModel.hidden'; $this->Controller->data = array( 'Model' => array( 'username' => '', 'password' => '', 'hidden' => '0' ), '_Token' => compact('fields', 'key') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testValidatePostWithDisabledFields method @access public @return void
testValidatePostWithDisabledFields
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidateHiddenMultipleModel() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = 'a2d01072dc4660eea9d15007025f35a7a5b58e18%3AModel.valid%7CModel2.valid%7CModel3.valid'; $this->Controller->data = array( 'Model' => array('username' => '', 'password' => '', 'valid' => '0'), 'Model2' => array('valid' => '0'), 'Model3' => array('valid' => '0'), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testValidateHiddenMultipleModel method @access public @return void
testValidateHiddenMultipleModel
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidateHasManyModel() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid'; $fields .= '%7CModel.1.hidden%7CModel.1.valid'; $this->Controller->data = array( 'Model' => array( array( 'username' => 'username', 'password' => 'password', 'hidden' => 'value', 'valid' => '0' ), array( 'username' => 'username', 'password' => 'password', 'hidden' => 'value', 'valid' => '0' ) ), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testValidateHasManyModel method @access public @return void
testValidateHasManyModel
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidateHasManyRecordsPass() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3AAddress.0.id%7CAddress.0.primary%7C'; $fields .= 'Address.1.id%7CAddress.1.primary'; $this->Controller->data = array( 'Address' => array( 0 => array( 'id' => '123', 'title' => 'home', 'first_name' => 'Bilbo', 'last_name' => 'Baggins', 'address' => '23 Bag end way', 'city' => 'the shire', 'phone' => 'N/A', 'primary' => '1', ), 1 => array( 'id' => '124', 'title' => 'home', 'first_name' => 'Frodo', 'last_name' => 'Baggins', 'address' => '50 Bag end way', 'city' => 'the shire', 'phone' => 'N/A', 'primary' => '1' ) ), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testValidateHasManyRecordsPass method @access public @return void
testValidateHasManyRecordsPass
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testValidateHasManyRecordsFail() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '7a203edb3d345bbf38fe0dccae960da8842e11d7%3AAddress.0.id%7CAddress.0.primary%7C'; $fields .= 'Address.1.id%7CAddress.1.primary'; $this->Controller->data = array( 'Address' => array( 0 => array( 'id' => '123', 'title' => 'home', 'first_name' => 'Bilbo', 'last_name' => 'Baggins', 'address' => '23 Bag end way', 'city' => 'the shire', 'phone' => 'N/A', 'primary' => '5', ), 1 => array( 'id' => '124', 'title' => 'home', 'first_name' => 'Frodo', 'last_name' => 'Baggins', 'address' => '50 Bag end way', 'city' => 'the shire', 'phone' => 'N/A', 'primary' => '1' ) ), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertFalse($result); }
testValidateHasManyRecords method validatePost should fail, hidden fields have been changed. @access public @return void
testValidateHasManyRecordsFail
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testLoginRequest() { $this->Controller->Security->startup($this->Controller); $realm = 'cakephp.org'; $options = array('realm' => $realm, 'type' => 'basic'); $result = $this->Controller->Security->loginRequest($options); $expected = 'WWW-Authenticate: Basic realm="'.$realm.'"'; $this->assertEqual($result, $expected); $this->Controller->Security->startup($this->Controller); $options = array('realm' => $realm, 'type' => 'digest'); $result = $this->Controller->Security->loginRequest($options); $this->assertPattern('/realm="'.$realm.'"/', $result); $this->assertPattern('/qop="auth"/', $result); }
testLoginRequest method @access public @return void
testLoginRequest
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testGenerateDigestResponseHash() { $this->Controller->Security->startup($this->Controller); $realm = 'cakephp.org'; $loginData = array('realm' => $realm, 'users' => array('Willy Smith' => 'password')); $this->Controller->Security->requireLogin($loginData); $data = array( 'username' => 'Willy Smith', 'password' => 'password', 'nonce' => String::uuid(), 'nc' => 1, 'cnonce' => 1, 'realm' => $realm, 'uri' => 'path_to_identifier', 'qop' => 'testme' ); $_SERVER['REQUEST_METHOD'] = 'POST'; $result = $this->Controller->Security->generateDigestResponseHash($data); $expected = md5( md5($data['username'] . ':' . $loginData['realm'] . ':' . $data['password']) . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . md5(env('REQUEST_METHOD') . ':' . $data['uri']) ); $this->assertIdentical($result, $expected); }
testGenerateDigestResponseHash method @access public @return void
testGenerateDigestResponseHash
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testLoginCredentials() { $this->Controller->Security->startup($this->Controller); $_SERVER['PHP_AUTH_USER'] = $user = 'Willy Test'; $_SERVER['PHP_AUTH_PW'] = $pw = 'some password for the nice test'; $result = $this->Controller->Security->loginCredentials('basic'); $expected = array('username' => $user, 'password' => $pw); $this->assertIdentical($result, $expected); if (version_compare(PHP_VERSION, '5.1') != -1) { $_SERVER['PHP_AUTH_DIGEST'] = $digest = <<<DIGEST Digest username="Mufasa", realm="[email protected]", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="6629fae49393a05397450978507c4ef1", opaque="5ccc069c403ebaf9f0171e9517f40e41" DIGEST; $expected = array( 'username' => 'Mufasa', 'realm' => '[email protected]', 'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093', 'uri' => '/dir/index.html', 'qop' => 'auth', 'nc' => '00000001', 'cnonce' => '0a4f113b', 'response' => '6629fae49393a05397450978507c4ef1', 'opaque' => '5ccc069c403ebaf9f0171e9517f40e41' ); $result = $this->Controller->Security->loginCredentials('digest'); $this->assertIdentical($result, $expected); } }
testLoginCredentials method @access public @return void
testLoginCredentials
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testParseDigestAuthData() { $this->Controller->Security->startup($this->Controller); $digest = <<<DIGEST Digest username="Mufasa", realm="[email protected]", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="6629fae49393a05397450978507c4ef1", opaque="5ccc069c403ebaf9f0171e9517f40e41" DIGEST; $expected = array( 'username' => 'Mufasa', 'realm' => '[email protected]', 'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093', 'uri' => '/dir/index.html', 'qop' => 'auth', 'nc' => '00000001', 'cnonce' => '0a4f113b', 'response' => '6629fae49393a05397450978507c4ef1', 'opaque' => '5ccc069c403ebaf9f0171e9517f40e41' ); $result = $this->Controller->Security->parseDigestAuthData($digest); $this->assertIdentical($result, $expected); $result = $this->Controller->Security->parseDigestAuthData(''); $this->assertNull($result); }
testParseDigestAuthData method @access public @return void
testParseDigestAuthData
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testParseDigestAuthEmailAddress() { $this->Controller->Security->startup($this->Controller); $digest = <<<DIGEST Digest username="[email protected]", realm="[email protected]", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="6629fae49393a05397450978507c4ef1", opaque="5ccc069c403ebaf9f0171e9517f40e41" DIGEST; $expected = array( 'username' => '[email protected]', 'realm' => '[email protected]', 'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093', 'uri' => '/dir/index.html', 'qop' => 'auth', 'nc' => '00000001', 'cnonce' => '0a4f113b', 'response' => '6629fae49393a05397450978507c4ef1', 'opaque' => '5ccc069c403ebaf9f0171e9517f40e41' ); $result = $this->Controller->Security->parseDigestAuthData($digest); $this->assertIdentical($result, $expected); }
test parsing digest information with email addresses @return void
testParseDigestAuthEmailAddress
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testFormDisabledFields() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '11842060341b9d0fc3808b90ba29fdea7054d6ad%3An%3A0%3A%7B%7D'; $this->Controller->data = array( 'MyModel' => array('name' => 'some data'), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertFalse($result); $this->Controller->Security->startup($this->Controller); $this->Controller->Security->disabledFields = array('MyModel.name'); $key = $this->Controller->params['_Token']['key']; $this->Controller->data = array( 'MyModel' => array('name' => 'some data'), '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testFormDisabledFields method @access public @return void
testFormDisabledFields
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testRadio() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $fields = '575ef54ca4fc8cab468d6d898e9acd3a9671c17e%3An%3A0%3A%7B%7D'; $this->Controller->data = array( '_Token' => compact('key', 'fields') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertFalse($result); $this->Controller->data = array( '_Token' => compact('key', 'fields'), 'Test' => array('test' => '') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); $this->Controller->data = array( '_Token' => compact('key', 'fields'), 'Test' => array('test' => '1') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); $this->Controller->data = array( '_Token' => compact('key', 'fields'), 'Test' => array('test' => '2') ); $result = $this->Controller->Security->validatePost($this->Controller); $this->assertTrue($result); }
testRadio method @access public @return void
testRadio
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testInvalidAuthHeaders() { $this->Controller->Security->blackHoleCallback = null; $_SERVER['PHP_AUTH_USER'] = 'admin'; $_SERVER['PHP_AUTH_PW'] = 'password'; $realm = 'cakephp.org'; $loginData = array('type' => 'basic', 'realm' => $realm); $this->Controller->Security->requireLogin($loginData); $this->Controller->Security->startup($this->Controller); $expected = 'WWW-Authenticate: Basic realm="'.$realm.'"'; $this->assertEqual(count($this->Controller->testHeaders), 1); $this->assertEqual(current($this->Controller->testHeaders), $expected); }
testInvalidAuthHeaders method @access public @return void
testInvalidAuthHeaders
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testSettingTokenForRequestAction() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; $this->Controller->params['requested'] = 1; unset($this->Controller->params['_Token']); $this->Controller->Security->startup($this->Controller); $this->assertEqual($this->Controller->params['_Token']['key'], $key); }
test that a requestAction's controller will have the _Token appended to the params. @return void @see http://cakephp.lighthouseapp.com/projects/42648/tickets/68
testSettingTokenForRequestAction
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function testBlackHoleNotDeletingSessionInformation() { $this->Controller->Security->startup($this->Controller); $this->Controller->Security->blackHole($this->Controller, 'auth'); $this->assertTrue($this->Controller->Security->Session->check('_Token'), '_Token was deleted by blackHole %s'); }
test that blackhole doesn't delete the _Token session key so repeat data submissions stay blackholed. @link http://cakephp.lighthouseapp.com/projects/42648/tickets/214 @return void
testBlackHoleNotDeletingSessionInformation
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/security.test.php
MIT
function setUp() { $this->_session = Configure::read('Session'); }
setUp method @access public @return void
setUp
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function tearDown() { Configure::write('Session', $this->_session); }
tearDown method @access public @return void
tearDown
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionAutoStart() { Configure::write('Session.start', false); $Session =& new SessionComponent(); $this->assertFalse($Session->__active); $this->assertFalse($Session->started()); $Session->startup(new SessionTestController()); Configure::write('Session.start', true); $Session =& new SessionComponent(); $this->assertTrue($Session->__active); $this->assertFalse($Session->started()); $Session->startup(new SessionTestController()); $this->assertTrue(isset($_SESSION)); $Object = new Object(); $Session =& new SessionComponent(); $Session->start(); $expected = $Session->id(); $result = $Object->requestAction('/session_test/session_id'); $this->assertEqual($result, $expected); $result = $Object->requestAction('/orange_session_test/session_id'); $this->assertEqual($result, $expected); }
testSessionAutoStart method @access public @return void
testSessionAutoStart
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionActivate() { $Session =& new SessionComponent(); $this->assertTrue($Session->__active); $this->assertNull($Session->activate()); $this->assertTrue($Session->__active); Configure::write('Session.start', false); $Session =& new SessionComponent(); $this->assertFalse($Session->__active); $this->assertNull($Session->activate()); $this->assertTrue($Session->__active); Configure::write('Session.start', true); $Session->destroy(); }
testSessionActivate method @access public @return void
testSessionActivate
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionValid() { $Session =& new SessionComponent(); $this->assertTrue($Session->valid()); $Session->_userAgent = 'rweerw'; $this->assertFalse($Session->valid()); Configure::write('Session.start', false); $Session =& new SessionComponent(); $this->assertFalse($Session->__active); $this->assertFalse($Session->valid()); Configure::write('Session.start', true); $Session =& new SessionComponent(); $Session->time = $Session->read('Config.time') + 1; $this->assertFalse($Session->valid()); Configure::write('Session.checkAgent', false); $Session =& new SessionComponent(); $Session->time = $Session->read('Config.time') + 1; $this->assertFalse($Session->valid()); Configure::write('Session.checkAgent', true); }
testSessionValid method @access public @return void
testSessionValid
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionError() { $Session =& new SessionComponent(); $this->assertFalse($Session->error()); Configure::write('Session.start', false); $Session =& new SessionComponent(); $this->assertFalse($Session->__active); $this->assertFalse($Session->error()); Configure::write('Session.start', true); }
testSessionError method @access public @return void
testSessionError
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionReadWrite() { $Session =& new SessionComponent(); $this->assertFalse($Session->read('Test')); $this->assertTrue($Session->write('Test', 'some value')); $this->assertEqual($Session->read('Test'), 'some value'); $this->assertFalse($Session->write('Test.key', 'some value')); $Session->delete('Test'); $this->assertTrue($Session->write('Test.key.path', 'some value')); $this->assertEqual($Session->read('Test.key.path'), 'some value'); $this->assertEqual($Session->read('Test.key'), array('path' => 'some value')); $this->assertTrue($Session->write('Test.key.path2', 'another value')); $this->assertEqual($Session->read('Test.key'), array('path' => 'some value', 'path2' => 'another value')); $Session->delete('Test'); $array = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'); $this->assertTrue($Session->write('Test', $array)); $this->assertEqual($Session->read('Test'), $array); $Session->delete('Test'); $this->assertFalse($Session->write(array('Test'), 'some value')); $this->assertTrue($Session->write(array('Test' => 'some value'))); $this->assertEqual($Session->read('Test'), 'some value'); $Session->delete('Test'); 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); }
testSessionReadWrite method @access public @return void
testSessionReadWrite
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionDelete() { $Session =& new SessionComponent(); $this->assertFalse($Session->delete('Test')); $Session->write('Test', 'some value'); $this->assertTrue($Session->delete('Test')); Configure::write('Session.start', false); $Session =& new SessionComponent(); $Session->write('Test', 'some value'); $this->assertFalse($Session->delete('Test')); Configure::write('Session.start', true); }
testSessionDelete method @access public @return void
testSessionDelete
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionCheck() { $Session =& new SessionComponent(); $this->assertFalse($Session->check('Test')); $Session->write('Test', 'some value'); $this->assertTrue($Session->check('Test')); $Session->delete('Test'); Configure::write('Session.start', false); $Session =& new SessionComponent(); $Session->write('Test', 'some value'); $this->assertFalse($Session->check('Test')); Configure::write('Session.start', true); }
testSessionCheck method @access public @return void
testSessionCheck
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionFlash() { $Session =& new SessionComponent(); $this->assertNull($Session->read('Message.flash')); $Session->setFlash('This is a test message'); $this->assertEqual($Session->read('Message.flash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array())); $Session->setFlash('This is a test message', 'test', array('name' => 'Joel Moss')); $this->assertEqual($Session->read('Message.flash'), array('message' => 'This is a test message', 'element' => 'test', 'params' => array('name' => 'Joel Moss'))); $Session->setFlash('This is a test message', 'default', array(), 'myFlash'); $this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array())); $Session->setFlash('This is a test message', 'non_existing_layout'); $this->assertEqual($Session->read('Message.myFlash'), array('message' => 'This is a test message', 'element' => 'default', 'params' => array())); $Session->delete('Message'); }
testSessionFlash method @access public @return void
testSessionFlash
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionId() { unset($_SESSION); $Session =& new SessionComponent(); $this->assertNull($Session->id()); }
testSessionId method @access public @return void
testSessionId
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionDestroy() { $Session =& new SessionComponent(); $Session->write('Test', 'some value'); $this->assertEqual($Session->read('Test'), 'some value'); $Session->destroy('Test'); $this->assertNull($Session->read('Test')); }
testSessionDestroy method @access public @return void
testSessionDestroy
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testSessionTimeout() { Configure::write('debug', 2); Configure::write('Security.level', 'low'); session_destroy(); $Session =& new SessionComponent(); $Session->destroy(); $Session->write('Test', 'some value'); $this->assertEqual($Session->sessionTime, time() + (300 * Configure::read('Session.timeout'))); $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); $this->assertEqual($Session->time, time()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (300 * Configure::read('Session.timeout'))); Configure::write('Security.level', 'medium'); $Session =& new SessionComponent(); $Session->destroy(); $Session->write('Test', 'some value'); $this->assertEqual($Session->sessionTime, mktime() + (100 * Configure::read('Session.timeout'))); $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); $this->assertEqual($Session->time, time()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); Configure::write('Security.level', 'high'); $Session =& new SessionComponent(); $Session->destroy(); $Session->write('Test', 'some value'); $this->assertEqual($Session->sessionTime, time() + (10 * Configure::read('Session.timeout'))); $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); $this->assertEqual($Session->time, time()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); }
testSessionTimeout method @access public @return void
testSessionTimeout
php
Datawalke/Coordino
cake/tests/cases/libs/controller/components/session.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/controller/components/session.test.php
MIT
function testLogFileWriting() { @unlink(LOGS . 'error.log'); $log =& new FileLog(); $log->write('warning', 'Test warning'); $this->assertTrue(file_exists(LOGS . 'error.log')); $result = file_get_contents(LOGS . 'error.log'); $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning/', $result); unlink(LOGS . 'error.log'); @unlink(LOGS . 'debug.log'); $log->write('debug', 'Test warning'); $this->assertTrue(file_exists(LOGS . 'debug.log')); $result = file_get_contents(LOGS . 'debug.log'); $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: Test warning/', $result); unlink(LOGS . 'debug.log'); @unlink(LOGS . 'random.log'); $log->write('random', 'Test warning'); $this->assertTrue(file_exists(LOGS . 'random.log')); $result = file_get_contents(LOGS . 'random.log'); $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Random: Test warning/', $result); unlink(LOGS . 'random.log'); }
testLogFileWriting method @access public @return void
testLogFileWriting
php
Datawalke/Coordino
cake/tests/cases/libs/log/file_log.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/log/file_log.test.php
MIT
function testPathSetting() { $path = TMP . 'tests' . DS; @unlink($path . 'error.log'); $log =& new FileLog(compact('path')); $log->write('warning', 'Test warning'); $this->assertTrue(file_exists($path . 'error.log')); unlink($path . 'error.log'); }
test using the path setting to write logs in other places. @return void
testPathSetting
php
Datawalke/Coordino
cake/tests/cases/libs/log/file_log.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/log/file_log.test.php
MIT
function startTest() { $this->Schema = new TestAppSchema(); }
setUp method @access public @return void
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function tearDown() { @unlink(TMP . 'tests' . DS .'schema.php'); unset($this->Schema); ClassRegistry::flush(); }
tearDown method @access public @return void
tearDown
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaName() { $Schema = new CakeSchema(); $this->assertEqual(strtolower($Schema->name), strtolower(APP_DIR)); Configure::write('App.dir', 'Some.name.with.dots'); $Schema = new CakeSchema(); $this->assertEqual($Schema->name, 'SomeNameWithDots'); Configure::write('App.dir', 'app'); }
testSchemaName method @access public @return void
testSchemaName
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaRead() { $read = $this->Schema->read(array( 'connection' => 'test_suite', 'name' => 'TestApp', 'models' => array('SchemaPost', 'SchemaComment', 'SchemaTag', 'SchemaDatatype') )); unset($read['tables']['missing']); $expected = array('comments', 'datatypes', 'posts', 'posts_tags', 'tags'); $this->assertEqual(array_keys($read['tables']), $expected); foreach ($read['tables'] as $table => $fields) { $this->assertEqual(array_keys($fields), array_keys($this->Schema->tables[$table])); } $this->assertEqual( $read['tables']['datatypes']['float_field'], $this->Schema->tables['datatypes']['float_field'] ); $SchemaPost =& ClassRegistry::init('SchemaPost'); $SchemaPost->table = 'sts'; $SchemaPost->tablePrefix = 'po'; $read = $this->Schema->read(array( 'connection' => 'test_suite', 'name' => 'TestApp', 'models' => array('SchemaPost') )); $this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix %s'); $read = $this->Schema->read(array( 'connection' => 'test_suite', 'name' => 'TestApp', 'models' => array('SchemaComment', 'SchemaTag', 'SchemaPost') )); $this->assertFalse(isset($read['tables']['missing']['posts_tags']), 'Join table marked as missing %s'); }
testSchemaRead method @access public @return void
testSchemaRead
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaReadWithTablePrefix() { $model =& new SchemaPrefixAuthUser(); $Schema =& new CakeSchema(); $read = $Schema->read(array( 'connection' => 'test_suite', 'name' => 'TestApp', 'models' => array('SchemaPrefixAuthUser') )); unset($read['tables']['missing']); $this->assertTrue(isset($read['tables']['auth_users']), 'auth_users key missing %s'); }
test read() with tablePrefix properties. @return void
testSchemaReadWithTablePrefix
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaReadWithConfigPrefix() { $db =& ConnectionManager::getDataSource('test_suite'); $config = $db->config; $config['prefix'] = 'schema_test_prefix_'; ConnectionManager::create('schema_prefix', $config); $read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false)); $this->assertTrue(empty($read['tables'])); $config['prefix'] = 'prefix_'; ConnectionManager::create('schema_prefix2', $config); $read = $this->Schema->read(array( 'connection' => 'schema_prefix2', 'name' => 'TestApp', 'models' => false)); $this->assertTrue(isset($read['tables']['prefix_tests'])); }
test reading schema with config prefix. @return void
testSchemaReadWithConfigPrefix
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaReadWithPlugins() { App::objects('model', null, false); App::build(array( 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) )); $Schema =& new CakeSchema(); $Schema->plugin = 'TestPlugin'; $read = $Schema->read(array( 'connection' => 'test_suite', 'name' => 'TestApp', 'models' => true )); unset($read['tables']['missing']); $this->assertTrue(isset($read['tables']['auth_users'])); $this->assertTrue(isset($read['tables']['authors'])); $this->assertTrue(isset($read['tables']['test_plugin_comments'])); $this->assertTrue(isset($read['tables']['posts'])); $this->assertEqual(count($read['tables']), 4); App::build(); }
test reading schema from plugins. @return void
testSchemaReadWithPlugins
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaReadWithCrossDatabase() { $config = new DATABASE_CONFIG(); $skip = $this->skipIf( !isset($config->test) || !isset($config->test2), '%s Primary and secondary test databases not configured, skipping cross-database ' .'join tests.' .' To run these tests, you must define $test and $test2 in your database configuration.' ); if ($skip) { return; } $db2 =& ConnectionManager::getDataSource('test2'); $fixture = new SchemaCrossDatabaseFixture(); $fixture->create($db2); $fixture->insert($db2); $read = $this->Schema->read(array( 'connection' => 'test_suite', 'name' => 'TestApp', 'models' => array('SchemaCrossDatabase', 'SchemaPost') )); $this->assertTrue(isset($read['tables']['posts'])); $this->assertFalse(isset($read['tables']['cross_database']), 'Cross database should not appear'); $this->assertFalse(isset($read['tables']['missing']['cross_database']), 'Cross database should not appear'); $read = $this->Schema->read(array( 'connection' => 'test2', 'name' => 'TestApp', 'models' => array('SchemaCrossDatabase', 'SchemaPost') )); $this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear'); $this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear'); $this->assertTrue(isset($read['tables']['cross_database'])); $fixture->drop($db2); }
test reading schema with tables from another database. @return void
testSchemaReadWithCrossDatabase
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testGenerateTable() { $fields = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), 'author_id' => array('type' => 'integer', 'null' => false), 'title' => array('type' => 'string', 'null' => false), 'body' => array('type' => 'text', 'null' => true, 'default' => null), 'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)), ); $result = $this->Schema->generateTable('posts', $fields); $this->assertPattern('/var \$posts/', $result); eval(substr($result, 4)); $this->assertEqual($posts, $fields); }
test that tables are generated correctly @return void
testGenerateTable
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaWrite() { $write = $this->Schema->write(array('name' => 'MyOtherApp', 'tables' => $this->Schema->tables, 'path' => TMP . 'tests')); $file = file_get_contents(TMP . 'tests' . DS .'schema.php'); $this->assertEqual($write, $file); require_once( TMP . 'tests' . DS .'schema.php'); $OtherSchema = new MyOtherAppSchema(); $this->assertEqual($this->Schema->tables, $OtherSchema->tables); }
testSchemaWrite method @access public @return void
testSchemaWrite
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaComparison() { $New = new MyAppSchema(); $compare = $New->compare($this->Schema); $expected = array( 'comments' => array( 'add' => array( 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'after' => 'id'), 'title' => array('type' => 'string', 'null' => false, 'length' => 100, 'after' => 'user_id'), ), 'drop' => array( 'article_id' => array('type' => 'integer', 'null' => false), 'tableParameters' => array(), ), 'change' => array( 'comment' => array('type' => 'text', 'null' => false, 'default' => null), ) ), 'posts' => array( 'add' => array( 'summary' => array('type' => 'text', 'null' => 1, 'after' => 'body'), ), 'drop' => array( 'tableParameters' => array(), ), 'change' => array( 'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''), 'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'), 'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => '1') ) ), ); $this->assertEqual($expected, $compare); $tables = array( 'missing' => array( 'categories' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), 'name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 100), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), 'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM') ) ), 'ratings' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL), 'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL), 'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL), 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), 'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM') ) ); $compare = $New->compare($this->Schema, $tables); $expected = array( 'ratings' => array( 'add' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'after' => 'id'), 'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL, 'after' => 'foreign_key'), 'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL, 'after' => 'model'), 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL, 'after' => 'value'), 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL, 'after' => 'created'), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), 'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM') ) ) ); $this->assertEqual($expected, $compare); }
testSchemaComparison method @access public @return void
testSchemaComparison
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testCompareEmptyStringAndNull() { $One =& new CakeSchema(array( 'posts' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => false, 'default' => '') ) )); $Two =& new CakeSchema(array( 'posts' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => false, 'default' => null) ) )); $compare = $One->compare($Two); $expected = array( 'posts' => array( 'change' => array( 'name' => array('type' => 'string', 'null' => false, 'default' => null) ) ) ); $this->assertEqual($expected, $compare); }
test comparing '' and null and making sure they are different. @return void
testCompareEmptyStringAndNull
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testTableParametersAndIndexComparison() { $old = array( 'posts' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), 'author_id' => array('type' => 'integer', 'null' => false), 'title' => array('type' => 'string', 'null' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => true) ), 'tableParameters' => array( 'charset' => 'latin1', 'collate' => 'latin1_general_ci' ) ), 'comments' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'comment' => array('type' => 'text'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => true), 'post_id' => array('column' => 'post_id'), ), 'tableParameters' => array( 'engine' => 'InnoDB', 'charset' => 'latin1', 'collate' => 'latin1_general_ci' ) ) ); $new = array( 'posts' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), 'author_id' => array('type' => 'integer', 'null' => false), 'title' => array('type' => 'string', 'null' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => true), 'author_id' => array('column' => 'author_id'), ), 'tableParameters' => array( 'charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM' ) ), 'comments' => array( 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), 'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'comment' => array('type' => 'text'), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => true), ), 'tableParameters' => array( 'charset' => 'utf8', 'collate' => 'utf8_general_ci' ) ) ); $compare = $this->Schema->compare($old, $new); $expected = array( 'posts' => array( 'add' => array( 'indexes' => array('author_id' => array('column' => 'author_id')), ), 'change' => array( 'tableParameters' => array( 'charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM' ) ) ), 'comments' => array( 'drop' => array( 'indexes' => array('post_id' => array('column' => 'post_id')), ), 'change' => array( 'tableParameters' => array( 'charset' => 'utf8', 'collate' => 'utf8_general_ci', ) ) ) ); $this->assertEqual($compare, $expected); }
Test comparing tableParameters and indexes. @return void
testTableParametersAndIndexComparison
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaLoading() { $Other =& $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests')); $this->assertEqual($Other->name, 'MyOtherApp'); $this->assertEqual($Other->tables, $this->Schema->tables); }
testSchemaLoading method @access public @return void
testSchemaLoading
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaLoadingFromPlugin() { App::build(array( 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) )); $Other =& $this->Schema->load(array('name' => 'TestPluginApp', 'plugin' => 'TestPlugin')); $this->assertEqual($Other->name, 'TestPluginApp'); $this->assertEqual(array_keys($Other->tables), array('acos')); App::build(); }
test loading schema files inside of plugins. @return void
testSchemaLoadingFromPlugin
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function testSchemaCreateTable() { $db =& ConnectionManager::getDataSource('test_suite'); $db->cacheSources = false; $Schema =& new CakeSchema(array( 'connection' => 'test_suite', 'testdescribes' => array( 'id' => array('type' => 'integer', 'key' => 'primary'), 'int_null' => array('type' => 'integer', 'null' => true), 'int_not_null' => array('type' => 'integer', 'null' => false), ), )); $sql = $db->createSchema($Schema); $col = $Schema->tables['testdescribes']['int_null']; $col['name'] = 'int_null'; $column = $this->db->buildColumn($col); $this->assertPattern('/' . preg_quote($column, '/') . '/', $sql); $col = $Schema->tables['testdescribes']['int_not_null']; $col['name'] = 'int_not_null'; $column = $this->db->buildColumn($col); $this->assertPattern('/' . preg_quote($column, '/') . '/', $sql); }
testSchemaCreateTable method @access public @return void
testSchemaCreateTable
php
Datawalke/Coordino
cake/tests/cases/libs/model/cake_schema.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/cake_schema.test.php
MIT
function setUp() { $this->ConnectionManager =& ConnectionManager::getInstance(); }
setUp method @access public @return void
setUp
php
Datawalke/Coordino
cake/tests/cases/libs/model/connection_manager.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php
MIT
function testInstantiation() { $this->assertTrue(is_a($this->ConnectionManager, 'ConnectionManager')); }
testInstantiation method @access public @return void
testInstantiation
php
Datawalke/Coordino
cake/tests/cases/libs/model/connection_manager.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php
MIT
function testEnumConnectionObjects() { $sources = ConnectionManager::enumConnectionObjects(); $this->assertTrue(count($sources) >= 1); $connections = array('default', 'test', 'test_suite'); $this->assertTrue(count(array_intersect(array_keys($sources), $connections)) >= 1); }
testEnumConnectionObjects method @access public @return void
testEnumConnectionObjects
php
Datawalke/Coordino
cake/tests/cases/libs/model/connection_manager.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php
MIT
function testGetDataSource() { $connections = ConnectionManager::enumConnectionObjects(); $this->assertTrue(count(array_keys($connections) >= 1)); $source = ConnectionManager::getDataSource(key($connections)); $this->assertTrue(is_object($source)); $this->expectError(new PatternExpectation('/Non-existent data source/i')); $source = ConnectionManager::getDataSource('non_existent_source'); $this->assertEqual($source, null); }
testGetDataSource method @access public @return void
testGetDataSource
php
Datawalke/Coordino
cake/tests/cases/libs/model/connection_manager.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/model/connection_manager.test.php
MIT