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 testLog() { @unlink(LOGS . 'error.log'); $this->assertTrue($this->object->log('Test warning 1')); $this->assertTrue($this->object->log(array('Test' => 'warning 2'))); $result = file(LOGS . 'error.log'); $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Test warning 1$/', $result[0]); $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Array$/', $result[1]); $this->assertPattern('/^\($/', $result[2]); $this->assertPattern('/\[Test\] => warning 2$/', $result[3]); $this->assertPattern('/^\)$/', $result[4]); unlink(LOGS . 'error.log'); @unlink(LOGS . 'error.log'); $this->assertTrue($this->object->log('Test warning 1', LOG_WARNING)); $this->assertTrue($this->object->log(array('Test' => 'warning 2'), LOG_WARNING)); $result = file(LOGS . 'error.log'); $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1$/', $result[0]); $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Array$/', $result[1]); $this->assertPattern('/^\($/', $result[2]); $this->assertPattern('/\[Test\] => warning 2$/', $result[3]); $this->assertPattern('/^\)$/', $result[4]); unlink(LOGS . 'error.log'); }
testLog method @access public @return void
testLog
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testSet() { $this->object->_set('a string'); $this->assertEqual($this->object->firstName, 'Joel'); $this->object->_set(array('firstName')); $this->assertEqual($this->object->firstName, 'Joel'); $this->object->_set(array('firstName' => 'Ashley')); $this->assertEqual($this->object->firstName, 'Ashley'); $this->object->_set(array('firstName' => 'Joel', 'lastName' => 'Moose')); $this->assertEqual($this->object->firstName, 'Joel'); $this->assertEqual($this->object->lastName, 'Moose'); }
testSet method @access public @return void
testSet
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testPersist() { ClassRegistry::flush(); $cacheDisable = Configure::read('Cache.disable'); Configure::write('Cache.disable', false); @unlink(CACHE . 'persistent' . DS . 'testmodel.php'); $test = new stdClass; $this->assertFalse($this->object->testPersist('TestModel', null, $test)); $this->assertFalse($this->object->testPersist('TestModel', true, $test)); $this->assertTrue($this->object->testPersist('TestModel', null, $test)); $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'testmodel.php')); $this->assertTrue($this->object->testPersist('TestModel', true, $test)); $this->assertEqual($this->object->TestModel, $test); @unlink(CACHE . 'persistent' . DS . 'testmodel.php'); $model =& new ObjectTestModel(); $expected = ClassRegistry::keys(); ClassRegistry::flush(); $data = array('object_test_model' => $model); $this->assertFalse($this->object->testPersist('ObjectTestModel', true, $data)); $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'objecttestmodel.php')); $this->object->testPersist('ObjectTestModel', true, $model, 'registry'); $result = ClassRegistry::keys(); $this->assertEqual($result, $expected); $newModel = ClassRegistry::getObject('object_test_model'); $this->assertEqual('ObjectTestModel', $newModel->name); @unlink(CACHE . 'persistent' . DS . 'objecttestmodel.php'); Configure::write('Cache.disable', $cacheDisable); }
testPersist method @access public @return void
testPersist
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testPersistWithBehavior() { ClassRegistry::flush(); $cacheDisable = Configure::read('Cache.disable'); Configure::write('Cache.disable', false); App::build(array( 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS), 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'. DS), 'behaviors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS), ), true); $this->assertFalse(class_exists('PersisterOneBehaviorBehavior')); $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior')); $this->assertFalse(class_exists('TestPluginPersisterBehavior')); $this->assertFalse(class_exists('TestPluginAuthors')); $Controller = new RequestActionPersistentController(); $Controller->persistModel = true; $Controller->constructClasses(); $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php')); $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php')); $contents = file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'); $contents = str_replace('"PersisterOne"', '"PersisterTwo"', $contents); $contents = str_replace('persister_one', 'persister_two', $contents); $contents = str_replace('test_plugin_comment', 'test_plugin_authors', $contents); $result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents); $this->assertTrue(class_exists('PersisterOneBehaviorBehavior')); $this->assertTrue(class_exists('TestPluginPersisterOneBehavior')); $this->assertTrue(class_exists('TestPluginComment')); $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior')); $this->assertFalse(class_exists('TestPluginPersisterTwoBehavior')); $this->assertFalse(class_exists('TestPluginAuthors')); $Controller = new RequestActionPersistentController(); $Controller->persistModel = true; $Controller->constructClasses(); $this->assertTrue(class_exists('PersisterOneBehaviorBehavior')); $this->assertTrue(class_exists('PersisterTwoBehaviorBehavior')); $this->assertTrue(class_exists('TestPluginPersisterTwoBehavior')); $this->assertTrue(class_exists('TestPluginAuthors')); @unlink(CACHE . 'persistent' . DS . 'persisterone.php'); @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php'); }
testPersistWithRequestAction method @access public @return void
testPersistWithBehavior
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testPersistWithBehaviorAndRequestAction() { ClassRegistry::flush(); $cacheDisable = Configure::read('Cache.disable'); Configure::write('Cache.disable', false); $this->assertFalse(class_exists('ContainableBehavior')); App::build(array( 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS), 'behaviors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS), ), true); $this->assertFalse(class_exists('PersistOneBehaviorBehavior')); $this->assertFalse(class_exists('PersistTwoBehaviorBehavior')); $Controller = new RequestActionPersistentController(); $Controller->persistModel = true; $Controller->constructClasses(); $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php')); $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php')); $keys = ClassRegistry::keys(); $this->assertEqual($keys, array( 'persister_one', 'comment', 'test_plugin_comment', 'test_plugin.test_plugin_comment', 'persister_one_behavior_behavior', 'test_plugin_persister_one_behavior', 'test_plugin.test_plugin_persister_one_behavior' )); ob_start(); $Controller->set('content_for_layout', 'cool'); $Controller->render('index', 'ajax', '/layouts/ajax'); $result = ob_get_clean(); $keys = ClassRegistry::keys(); $this->assertEqual($keys, array( 'persister_one', 'comment', 'test_plugin_comment', 'test_plugin.test_plugin_comment', 'persister_one_behavior_behavior', 'test_plugin_persister_one_behavior', 'test_plugin.test_plugin_persister_one_behavior', 'view' )); $result = $this->object->requestAction('/request_action_persistent/index'); $expected = 'This is a test'; $this->assertEqual($result, $expected); @unlink(CACHE . 'persistent' . DS . 'persisterone.php'); @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php'); $Controller = new RequestActionPersistentController(); $Controller->persistModel = true; $Controller->constructClasses(); @unlink(CACHE . 'persistent' . DS . 'persisterone.php'); @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php'); Configure::write('Cache.disable', $cacheDisable); }
testPersistWithBehaviorAndRequestAction method @see testPersistWithBehavior @access public @return void
testPersistWithBehaviorAndRequestAction
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testToString() { $result = strtolower($this->object->toString()); $this->assertEqual($result, 'testobject'); }
testToString method @access public @return void
testToString
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testMethodDispatching() { $this->object->emptyMethod(); $expected = array('emptyMethod'); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->oneParamMethod('Hello'); $expected[] = array('oneParamMethod' => array('Hello')); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->twoParamMethod(true, false); $expected[] = array('twoParamMethod' => array(true, false)); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->threeParamMethod(true, false, null); $expected[] = array('threeParamMethod' => array(true, false, null)); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->crazyMethod(1, 2, 3, 4, 5, 6, 7); $expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7)); $this->assertIdentical($this->object->methodCalls, $expected); $this->object = new TestObject(); $this->assertIdentical($this->object->methodCalls, array()); $this->object->dispatchMethod('emptyMethod'); $expected = array('emptyMethod'); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->dispatchMethod('oneParamMethod', array('Hello')); $expected[] = array('oneParamMethod' => array('Hello')); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->dispatchMethod('twoParamMethod', array(true, false)); $expected[] = array('twoParamMethod' => array(true, false)); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->dispatchMethod('threeParamMethod', array(true, false, null)); $expected[] = array('threeParamMethod' => array(true, false, null)); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->dispatchMethod('fourParamMethod', array(1, 2, 3, 4)); $expected[] = array('fourParamMethod' => array(1, 2, 3, 4)); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->dispatchMethod('fiveParamMethod', array(1, 2, 3, 4, 5)); $expected[] = array('fiveParamMethod' => array(1, 2, 3, 4, 5)); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->dispatchMethod('crazyMethod', array(1, 2, 3, 4, 5, 6, 7)); $expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7)); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->dispatchMethod('methodWithOptionalParam', array('Hello')); $expected[] = array('methodWithOptionalParam' => array("Hello")); $this->assertIdentical($this->object->methodCalls, $expected); $this->object->dispatchMethod('methodWithOptionalParam'); $expected[] = array('methodWithOptionalParam' => array(null)); $this->assertIdentical($this->object->methodCalls, $expected); }
testMethodDispatching method @access public @return void
testMethodDispatching
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testRequestAction() { App::build(array( 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS), 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS), 'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS) )); $result = $this->object->requestAction(''); $this->assertFalse($result); $result = $this->object->requestAction('/request_action/test_request_action'); $expected = 'This is a test'; $this->assertEqual($result, $expected);; $result = $this->object->requestAction('/request_action/another_ra_test/2/5'); $expected = 7; $this->assertEqual($result, $expected); $result = $this->object->requestAction('/tests_apps/index', array('return')); $expected = 'This is the TestsAppsController index view'; $this->assertEqual($result, $expected); $result = $this->object->requestAction('/tests_apps/some_method'); $expected = 5; $this->assertEqual($result, $expected); $result = $this->object->requestAction('/request_action/paginate_request_action'); $this->assertTrue($result); $result = $this->object->requestAction('/request_action/normal_request_action'); $expected = 'Hello World'; $this->assertEqual($result, $expected); App::build(); }
testRequestAction method @access public @return void
testRequestAction
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testRequestActionPlugins() { App::build(array( 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), )); App::objects('plugin', null, false); Router::reload(); $result = $this->object->requestAction('/test_plugin/tests/index', array('return')); $expected = 'test plugin index'; $this->assertEqual($result, $expected); $result = $this->object->requestAction('/test_plugin/tests/index/some_param', array('return')); $expected = 'test plugin index'; $this->assertEqual($result, $expected); $result = $this->object->requestAction( array('controller' => 'tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return') ); $expected = 'test plugin index'; $this->assertEqual($result, $expected); $result = $this->object->requestAction('/test_plugin/tests/some_method'); $expected = 25; $this->assertEqual($result, $expected); $result = $this->object->requestAction( array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin') ); $expected = 25; $this->assertEqual($result, $expected); App::build(); App::objects('plugin', null, false); }
test requestAction() and plugins. @return void
testRequestActionPlugins
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testRequestActionArray() { App::build(array( 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS), 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS), 'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS) )); $result = $this->object->requestAction( array('controller' => 'request_action', 'action' => 'test_request_action') ); $expected = 'This is a test'; $this->assertEqual($result, $expected); $result = $this->object->requestAction( array('controller' => 'request_action', 'action' => 'another_ra_test'), array('pass' => array('5', '7')) ); $expected = 12; $this->assertEqual($result, $expected); $result = $this->object->requestAction( array('controller' => 'tests_apps', 'action' => 'index'), array('return') ); $expected = 'This is the TestsAppsController index view'; $this->assertEqual($result, $expected); $result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method')); $expected = 5; $this->assertEqual($result, $expected); $result = $this->object->requestAction( array('controller' => 'request_action', 'action' => 'normal_request_action') ); $expected = 'Hello World'; $this->assertEqual($result, $expected); $result = $this->object->requestAction( array('controller' => 'request_action', 'action' => 'paginate_request_action') ); $this->assertTrue($result); $result = $this->object->requestAction( array('controller' => 'request_action', 'action' => 'paginate_request_action'), array('pass' => array(5), 'named' => array('param' => 'value')) ); $this->assertTrue($result); App::build(); }
test requestAction() with arrays. @return void
testRequestActionArray
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testRequestActionParamParseAndPass() { $result = $this->object->requestAction('/request_action/params_pass'); $this->assertTrue(isset($result['url']['url'])); $this->assertEqual($result['url']['url'], '/request_action/params_pass'); $this->assertEqual($result['controller'], 'request_action'); $this->assertEqual($result['action'], 'params_pass'); $this->assertEqual($result['form'], array()); $this->assertEqual($result['plugin'], null); $result = $this->object->requestAction('/request_action/params_pass/sort:desc/limit:5'); $expected = array('sort' => 'desc', 'limit' => 5,); $this->assertEqual($result['named'], $expected); $result = $this->object->requestAction( array('controller' => 'request_action', 'action' => 'params_pass'), array('named' => array('sort' => 'desc', 'limit' => 5)) ); $this->assertEqual($result['named'], $expected); }
Test that requestAction() is populating $this->params properly @access public @return void
testRequestActionParamParseAndPass
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function testRequestActionPostPassing() { $_tmp = $_POST; $_POST = array('data' => array( 'item' => 'value' )); $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass')); $expected = array(); $this->assertEqual($expected, $result); $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'), array('data' => $_POST['data'])); $expected = $_POST['data']; $this->assertEqual($expected, $result); $result = $this->object->requestAction('/request_action/post_pass'); $expected = $_POST['data']; $this->assertEqual($expected, $result); $_POST = $_tmp; }
test requestAction and POST parameter passing, and not passing when url is an array. @access public @return void
testRequestActionPostPassing
php
Datawalke/Coordino
cake/tests/cases/libs/object.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/object.test.php
MIT
function skip() { $this->skipIf(true, ' %s OverloadableTest not implemented'); }
skip method @access public @return void
skip
php
Datawalke/Coordino
cake/tests/cases/libs/overloadable.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/overloadable.test.php
MIT
function setUp() { $this->_routing = Configure::read('Routing'); Configure::write('Routing', array('admin' => null, 'prefixes' => array())); Router::reload(); $this->router =& Router::getInstance(); }
setUp method @access public @return void
setUp
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function endTest() { Configure::write('Routing', $this->_routing); }
end the test and reset the environment @return void
endTest
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testReturnedInstanceReference() { $this->router->testVar = 'test'; $this->assertIdentical($this->router, Router::getInstance()); unset($this->router->testVar); }
testReturnedInstanceReference method @access public @return void
testReturnedInstanceReference
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testFullBaseURL() { $this->assertPattern('/^http(s)?:\/\//', Router::url('/', true)); $this->assertPattern('/^http(s)?:\/\//', Router::url(null, true)); $this->assertPattern('/^http(s)?:\/\//', Router::url(array('full_base' => true))); $this->assertIdentical(FULL_BASE_URL . '/', Router::url(array('full_base' => true))); }
testFullBaseURL method @access public @return void
testFullBaseURL
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRouteDefaultParams() { Router::connect('/:controller', array('controller' => 'posts')); $this->assertEqual(Router::url(array('action' => 'index')), '/'); }
testRouteDefaultParams method @access public @return void
testRouteDefaultParams
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRouterIdentity() { $router2 = new Router(); $this->assertEqual(get_object_vars($this->router), get_object_vars($router2)); }
testRouterIdentity method @access public @return void
testRouterIdentity
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testResourceRoutes() { Router::mapResources('Posts'); $_SERVER['REQUEST_METHOD'] = 'GET'; $result = Router::parse('/posts'); $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => 'GET')); $this->assertEqual($this->router->__resourceMapped, array('posts')); $_SERVER['REQUEST_METHOD'] = 'GET'; $result = Router::parse('/posts/13'); $this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => '13', '[method]' => 'GET')); $this->assertEqual($this->router->__resourceMapped, array('posts')); $_SERVER['REQUEST_METHOD'] = 'POST'; $result = Router::parse('/posts'); $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST')); $this->assertEqual($this->router->__resourceMapped, array('posts')); $_SERVER['REQUEST_METHOD'] = 'PUT'; $result = Router::parse('/posts/13'); $this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '13', '[method]' => 'PUT')); $this->assertEqual($this->router->__resourceMapped, array('posts')); $result = Router::parse('/posts/475acc39-a328-44d3-95fb-015000000000'); $this->assertEqual($result, array('pass' => array('475acc39-a328-44d3-95fb-015000000000'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '475acc39-a328-44d3-95fb-015000000000', '[method]' => 'PUT')); $this->assertEqual($this->router->__resourceMapped, array('posts')); $_SERVER['REQUEST_METHOD'] = 'DELETE'; $result = Router::parse('/posts/13'); $this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'delete', 'id' => '13', '[method]' => 'DELETE')); $this->assertEqual($this->router->__resourceMapped, array('posts')); $_SERVER['REQUEST_METHOD'] = 'GET'; $result = Router::parse('/posts/add'); $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'add')); $this->assertEqual($this->router->__resourceMapped, array('posts')); Router::reload(); Router::mapResources('Posts', array('id' => '[a-z0-9_]+')); $_SERVER['REQUEST_METHOD'] = 'GET'; $result = Router::parse('/posts/add'); $this->assertEqual($result, array('pass' => array('add'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => 'add', '[method]' => 'GET')); $this->assertEqual($this->router->__resourceMapped, array('posts')); $_SERVER['REQUEST_METHOD'] = 'PUT'; $result = Router::parse('/posts/name'); $this->assertEqual($result, array('pass' => array('name'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => 'name', '[method]' => 'PUT')); $this->assertEqual($this->router->__resourceMapped, array('posts')); }
testResourceRoutes method @access public @return void
testResourceRoutes
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testMultipleResourceRoute() { Router::connect('/:controller', array('action' => 'index', '[method]' => array('GET', 'POST'))); $_SERVER['REQUEST_METHOD'] = 'GET'; $result = Router::parse('/posts'); $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => array('GET', 'POST'))); $_SERVER['REQUEST_METHOD'] = 'POST'; $result = Router::parse('/posts'); $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => array('GET', 'POST'))); }
testMultipleResourceRoute method @access public @return void
testMultipleResourceRoute
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testGenerateUrlResourceRoute() { Router::mapResources('Posts'); $result = Router::url(array('controller' => 'posts', 'action' => 'index', '[method]' => 'GET')); $expected = '/posts'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'view', '[method]' => 'GET', 'id' => 10)); $expected = '/posts/10'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'add', '[method]' => 'POST')); $expected = '/posts'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'id' => 10)); $expected = '/posts/10'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'delete', '[method]' => 'DELETE', 'id' => 10)); $expected = '/posts/10'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'edit', '[method]' => 'POST', 'id' => 10)); $expected = '/posts/10'; $this->assertEqual($result, $expected); }
testGenerateUrlResourceRoute method @access public @return void
testGenerateUrlResourceRoute
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlNormalization() { $expected = '/users/logout'; $result = Router::normalize('/users/logout/'); $this->assertEqual($result, $expected); $result = Router::normalize('//users//logout//'); $this->assertEqual($result, $expected); $result = Router::normalize('users/logout'); $this->assertEqual($result, $expected); $result = Router::normalize(array('controller' => 'users', 'action' => 'logout')); $this->assertEqual($result, $expected); $result = Router::normalize('/'); $this->assertEqual($result, '/'); $result = Router::normalize('http://google.com/'); $this->assertEqual($result, 'http://google.com/'); $result = Router::normalize('http://google.com//'); $this->assertEqual($result, 'http://google.com//'); $result = Router::normalize('/users/login/scope://foo'); $this->assertEqual($result, '/users/login/scope:/foo'); $result = Router::normalize('/recipe/recipes/add'); $this->assertEqual($result, '/recipe/recipes/add'); Router::setRequestInfo(array(array(), array('base' => '/us'))); $result = Router::normalize('/us/users/logout/'); $this->assertEqual($result, '/users/logout'); Router::reload(); Router::setRequestInfo(array(array(), array('base' => '/cake_12'))); $result = Router::normalize('/cake_12/users/logout/'); $this->assertEqual($result, '/users/logout'); Router::reload(); $_back = Configure::read('App.baseUrl'); Configure::write('App.baseUrl', '/'); Router::setRequestInfo(array(array(), array('base' => '/'))); $result = Router::normalize('users/login'); $this->assertEqual($result, '/users/login'); Configure::write('App.baseUrl', $_back); Router::reload(); Router::setRequestInfo(array(array(), array('base' => 'beer'))); $result = Router::normalize('beer/admin/beers_tags/add'); $this->assertEqual($result, '/admin/beers_tags/add'); $result = Router::normalize('/admin/beers_tags/add'); $this->assertEqual($result, '/admin/beers_tags/add'); }
testUrlNormalization method @access public @return void
testUrlNormalization
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlGenerationBasic() { extract(Router::getNamedExpressions()); Router::setRequestInfo(array( array( 'pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'subscribe', 'admin' => true, 'url' => array('url' => '') ), array( 'base' => '/magazine', 'here' => '/magazine', 'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2), ) )); $result = Router::url(); $this->assertEqual('/magazine', $result); Router::reload(); Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); $out = Router::url(array('controller' => 'pages', 'action' => 'display', 'home')); $this->assertEqual($out, '/'); Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 'about')); $expected = '/pages/about'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/:plugin/:id/*', array('controller' => 'posts', 'action' => 'view'), array('id' => $ID)); Router::parse('/'); $result = Router::url(array('plugin' => 'cake_plugin', 'controller' => 'posts', 'action' => 'view', 'id' => '1')); $expected = '/cake_plugin/1'; $this->assertEqual($result, $expected); $result = Router::url(array('plugin' => 'cake_plugin', 'controller' => 'posts', 'action' => 'view', 'id' => '1', '0')); $expected = '/cake_plugin/1/0'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/:controller/:action/:id', array(), array('id' => $ID)); Router::parse('/'); $result = Router::url(array('controller' => 'posts', 'action' => 'view', 'id' => '1')); $expected = '/posts/view/1'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/:controller/:id', array('action' => 'view')); Router::parse('/'); $result = Router::url(array('controller' => 'posts', 'action' => 'view', 'id' => '1')); $expected = '/posts/1'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'index', '0')); $expected = '/posts/index/0'; $this->assertEqual($result, $expected); Router::connect('/view/*', array('controller' => 'posts', 'action' => 'view')); Router::promote(); $result = Router::url(array('controller' => 'posts', 'action' => 'view', '1')); $expected = '/view/1'; $this->assertEqual($result, $expected); Router::reload(); Router::setRequestInfo(array( array('pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'real_controller_name', 'url' => array('url' => '')), array( 'base' => '/', 'here' => '/', 'webroot' => '/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2), ) )); Router::connect('short_controller_name/:action/*', array('controller' => 'real_controller_name')); Router::parse('/'); $result = Router::url(array('controller' => 'real_controller_name', 'page' => '1')); $expected = '/short_controller_name/index/page:1'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'add')); $expected = '/short_controller_name/add'; $this->assertEqual($result, $expected); Router::reload(); Router::parse('/'); Router::setRequestInfo(array( array('pass' => array(), 'action' => 'index', 'plugin' => null, 'controller' => 'users', 'url' => array('url' => 'users')), array( 'base' => '/', 'here' => '/', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), ) )); $result = Router::url(array('action' => 'login')); $expected = '/users/login'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/page/*', array('plugin' => null, 'controller' => 'pages', 'action' => 'view')); Router::parse('/'); $result = Router::url(array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'view', 'my-page')); $expected = '/my_plugin/pages/view/my-page'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/contact/:action', array('plugin' => 'contact', 'controller' => 'contact')); Router::parse('/'); $result = Router::url(array('plugin' => 'contact', 'controller' => 'contact', 'action' => 'me')); $expected = '/contact/me'; $this->assertEqual($result, $expected); Router::reload(); Router::setRequestInfo(array( array( 'pass' => array(), 'action' => 'index', 'plugin' => 'myplugin', 'controller' => 'mycontroller', 'admin' => false, 'url' => array('url' => array()) ), array( 'base' => '/', 'here' => '/', 'webroot' => '/', 'passedArgs' => array(), 'namedArgs' => array(), ) )); $result = Router::url(array('plugin' => null, 'controller' => 'myothercontroller')); $expected = '/myothercontroller'; $this->assertEqual($result, $expected); }
test generation of basic urls. @access public @return void
testUrlGenerationBasic
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlGenerationWithQueryStrings() { $result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => 'var=test&var2=test2')); $expected = '/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', '0', '?' => 'var=test&var2=test2')); $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', '0', '?' => array('var' => 'test', 'var2' => 'test2'))); $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', '0', '?' => array('var' => null))); $this->assertEqual($result, '/posts/index/0'); $result = Router::url(array('controller' => 'posts', '0', '?' => 'var=test&var2=test2', '#' => 'unencoded string %')); $expected = '/posts/index/0?var=test&var2=test2#unencoded+string+%25'; $this->assertEqual($result, $expected); }
Test generation of routes with query string parameters. @return void
testUrlGenerationWithQueryStrings
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlGenerationWithRegexQualifiedParams() { Router::connect( ':language/galleries', array('controller' => 'galleries', 'action' => 'index'), array('language' => '[a-z]{3}') ); Router::connect( '/:language/:admin/:controller/:action/*', array('admin' => 'admin'), array('language' => '[a-z]{3}', 'admin' => 'admin') ); Router::connect('/:language/:controller/:action/*', array(), array('language' => '[a-z]{3}') ); $result = Router::url(array('admin' => false, 'language' => 'dan', 'action' => 'index', 'controller' => 'galleries')); $expected = '/dan/galleries'; $this->assertEqual($result, $expected); $result = Router::url(array('admin' => false, 'language' => 'eng', 'action' => 'index', 'controller' => 'galleries')); $expected = '/eng/galleries'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/:language/pages', array('controller' => 'pages', 'action' => 'index'), array('language' => '[a-z]{3}') ); Router::connect('/:language/:controller/:action/*', array(), array('language' => '[a-z]{3}')); $result = Router::url(array('language' => 'eng', 'action' => 'index', 'controller' => 'pages')); $expected = '/eng/pages'; $this->assertEqual($result, $expected); $result = Router::url(array('language' => 'eng', 'controller' => 'pages')); $this->assertEqual($result, $expected); $result = Router::url(array('language' => 'eng', 'controller' => 'pages', 'action' => 'add')); $expected = '/eng/pages/add'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/forestillinger/:month/:year/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'), array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}') ); Router::parse('/'); $result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'month' => 10, 'year' => 2007, 'min-forestilling')); $expected = '/forestillinger/10/2007/min-forestilling'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/kalender/:month/:year/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'), array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}') ); Router::connect('/kalender/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar')); Router::parse('/'); $result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'min-forestilling')); $expected = '/kalender/min-forestilling'; $this->assertEqual($result, $expected); $result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'min-forestilling')); $expected = '/kalender/10/2007/min-forestilling'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/:controller/:action/*', array(), array( 'controller' => 'source|wiki|commits|tickets|comments|view', 'action' => 'branches|history|branch|logs|view|start|add|edit|modify' )); Router::defaults(false); $result = Router::parse('/foo/bar'); $expected = array('pass' => array(), 'named' => array()); $this->assertEqual($result, $expected); }
test that regex validation of keyed route params is working. @return void
testUrlGenerationWithRegexQualifiedParams
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlGenerationWithAdminPrefix() { Configure::write('Routing.admin', 'admin'); Router::reload(); Router::connectNamed(array('event', 'lang')); Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); Router::connect('/pages/contact_us', array('controller' => 'pages', 'action' => 'contact_us')); Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); Router::connect('/reset/*', array('admin' => true, 'controller' => 'users', 'action' => 'reset')); Router::connect('/tests', array('controller' => 'tests', 'action' => 'index')); Router::parseExtensions('rss'); Router::setRequestInfo(array( array('pass' => array(), 'named' => array(), 'controller' => 'registrations', 'action' => 'admin_index', 'plugin' => '', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/registrations/index'), 'form' => array()), array('base' => '', 'here' => '/admin/registrations/index', 'webroot' => '/') )); $result = Router::url(array('page' => 2)); $expected = '/admin/registrations/index/page:2'; $this->assertEqual($result, $expected); Router::reload(); Router::setRequestInfo(array( array( 'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscriptions', 'admin' => true, 'url' => array('url' => 'admin/subscriptions/index/page:2'), ), array( 'base' => '/magazine', 'here' => '/magazine/admin/subscriptions/index/page:2', 'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), ) )); Router::parse('/'); $result = Router::url(array('page' => 3)); $expected = '/magazine/admin/subscriptions/index/page:3'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/admin/subscriptions/:action/*', array('controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin')); Router::parse('/'); Router::setRequestInfo(array( array( 'pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'subscribe', 'admin' => true, 'url' => array('url' => 'admin/subscriptions/edit/1') ), array( 'base' => '/magazine', 'here' => '/magazine/admin/subscriptions/edit/1', 'webroot' => '/magazine/', 'passedArgs' => array('page' => 2), 'namedArgs' => array('page' => 2), ) )); $result = Router::url(array('action' => 'edit', 1)); $expected = '/magazine/admin/subscriptions/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('admin' => true, 'controller' => 'users', 'action' => 'login')); $expected = '/magazine/admin/users/login'; $this->assertEqual($result, $expected); Router::reload(); Router::setRequestInfo(array( array('pass' => array(), 'admin' => true, 'action' => 'index', 'plugin' => null, 'controller' => 'users', 'url' => array('url' => 'users')), array( 'base' => '/', 'here' => '/', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), ) )); Router::connect('/page/*', array('controller' => 'pages', 'action' => 'view', 'admin' => true, 'prefix' => 'admin')); Router::parse('/'); $result = Router::url(array('admin' => true, 'controller' => 'pages', 'action' => 'view', 'my-page')); $expected = '/page/my-page'; $this->assertEqual($result, $expected); Configure::write('Routing.admin', 'admin'); Router::reload(); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/add')), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/') )); Router::parse('/'); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false)); $expected = '/admin/pages/add'; $this->assertEqual($result, $expected); Router::reload(); Router::parse('/'); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/add')), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/') )); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false)); $expected = '/admin/pages/add'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/admin/:controller/:action/:id', array('admin' => true), array('id' => '[0-9]+')); Router::parse('/'); Router::setRequestInfo(array( array ('plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array('284'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/edit/284')), array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/') )); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 'id' => '284')); $expected = '/admin/pages/edit/284'; $this->assertEqual($result, $expected); Router::reload(); Router::parse('/'); Router::setRequestInfo(array( array ('plugin' => null, 'controller' => 'pages', 'action' => 'admin_add', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/add')), array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/add', 'webroot' => '/') )); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'add', 'id' => false)); $expected = '/admin/pages/add'; $this->assertEqual($result, $expected); Router::reload(); Router::parse('/'); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'pages', 'action' => 'admin_edit', 'pass' => array('284'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/pages/edit/284')), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/pages/edit/284', 'webroot' => '/') )); $result = Router::url(array('plugin' => null, 'controller' => 'pages', 'action' => 'edit', 284)); $expected = '/admin/pages/edit/284'; $this->assertEqual($result, $expected); Router::reload(); Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true)); Router::parse('/'); Router::setRequestInfo(array( array('pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'posts', 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/posts')), array('base' => '', 'here' => '/admin/posts', 'webroot' => '/') )); $result = Router::url(array('all')); $expected = '/admin/posts/all'; $this->assertEqual($result, $expected); }
Test url generation with an admin prefix @access public @return void
testUrlGenerationWithAdminPrefix
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlGenerationWithExtensions() { Router::parse('/'); $result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'id' => null, 'ext' => 'json')); $expected = '/articles/add.json'; $this->assertEqual($result, $expected); $result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'add', 'ext' => 'json')); $expected = '/articles/add.json'; $this->assertEqual($result, $expected); $result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'id' => null, 'ext' => 'json')); $expected = '/articles.json'; $this->assertEqual($result, $expected); $result = Router::url(array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'ext' => 'json')); $expected = '/articles.json'; $this->assertEqual($result, $expected); }
testUrlGenerationWithExtensions method @access public @return void
testUrlGenerationWithExtensions
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlGenerationPlugins() { Router::setRequestInfo(array( array( 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => 'test' ), array( 'base' => '/base', 'here' => '/clients/sage/portal/donations', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array() ) )); $this->assertEqual(Router::url('read/1'), '/base/test/controller/read/1'); Router::reload(); Router::connect('/:lang/:plugin/:controller/*', array('action' => 'index')); Router::setRequestInfo(array( array( 'lang' => 'en', 'plugin' => 'shows', 'controller' => 'shows', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'en/shows/')), array('plugin' => NULL, 'controller' => NULL, 'action' => NULL, 'base' => '', 'here' => '/en/shows/', 'webroot' => '/') )); Router::parse('/en/shows/'); $result = Router::url(array( 'lang' => 'en', 'controller' => 'shows', 'action' => 'index', 'page' => '1', )); $expected = '/en/shows/shows/page:1'; $this->assertEqual($result, $expected); }
testPluginUrlGeneration method @access public @return void
testUrlGenerationPlugins
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testCanLeavePlugin() { Router::reload(); Router::connect( '/admin/other/:controller/:action/*', array( 'admin' => 1, 'plugin' => 'aliased', 'prefix' => 'admin' ) ); Router::setRequestInfo(array( array( 'pass' => array(), 'admin' => true, 'prefix' => 'admin', 'plugin' => 'this', 'action' => 'admin_index', 'controller' => 'interesting', 'url' => array('url' => 'admin/this/interesting/index'), ), array( 'base' => '', 'here' => '/admin/this/interesting/index', 'webroot' => '/', 'passedArgs' => array(), ) )); $result = Router::url(array('plugin' => null, 'controller' => 'posts', 'action' => 'index')); $this->assertEqual($result, '/admin/posts'); $result = Router::url(array('controller' => 'posts', 'action' => 'index')); $this->assertEqual($result, '/admin/this/posts'); $result = Router::url(array('plugin' => 'aliased', 'controller' => 'posts', 'action' => 'index')); $this->assertEqual($result, '/admin/other/posts/index'); }
test that you can leave active plugin routes with plugin = null @return void
testCanLeavePlugin
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlParsing() { extract(Router::getNamedExpressions()); Router::connect('/posts/:value/:somevalue/:othervalue/*', array('controller' => 'posts', 'action' => 'view'), array('value','somevalue', 'othervalue')); $result = Router::parse('/posts/2007/08/01/title-of-post-here'); $expected = array('value' => '2007', 'somevalue' => '08', 'othervalue' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array()); $this->assertEqual($result, $expected); $this->router->routes = array(); Router::connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day)); $result = Router::parse('/posts/2007/08/01/title-of-post-here'); $expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array()); $this->assertEqual($result, $expected); $this->router->routes = array(); Router::connect('/posts/:day/:year/:month/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day)); $result = Router::parse('/posts/01/2007/08/title-of-post-here'); $expected = array('day' => '01', 'year' => '2007', 'month' => '08', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array()); $this->assertEqual($result, $expected); $this->router->routes = array(); Router::connect('/posts/:month/:day/:year/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day)); $result = Router::parse('/posts/08/01/2007/title-of-post-here'); $expected = array('month' => '08', 'day' => '01', 'year' => '2007', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array()); $this->assertEqual($result, $expected); $this->router->routes = array(); Router::connect('/posts/:year/:month/:day/*', array('controller' => 'posts', 'action' => 'view')); $result = Router::parse('/posts/2007/08/01/title-of-post-here'); $expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'), 'named' => array()); $this->assertEqual($result, $expected); Router::reload(); $result = Router::parse('/pages/display/home'); $expected = array('plugin' => null, 'pass' => array('home'), 'controller' => 'pages', 'action' => 'display', 'named' => array()); $this->assertEqual($result, $expected); $result = Router::parse('pages/display/home/'); $this->assertEqual($result, $expected); $result = Router::parse('pages/display/home'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/page/*', array('controller' => 'test')); $result = Router::parse('/page/my-page'); $expected = array('pass' => array('my-page'), 'plugin' => null, 'controller' => 'test', 'action' => 'index'); Router::reload(); Router::connect('/:language/contact', array('language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'), array('language' => '[a-z]{3}')); $result = Router::parse('/eng/contact'); $expected = array('pass' => array(), 'named' => array(), 'language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/forestillinger/:month/:year/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'), array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}') ); $result = Router::parse('/forestillinger/10/2007/min-forestilling'); $expected = array('pass' => array('min-forestilling'), 'plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'named' => array()); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/:controller/:action/*'); Router::connect('/', array('plugin' => 'pages', 'controller' => 'pages', 'action' => 'display')); $result = Router::parse('/'); $expected = array('pass' => array(), 'named' => array(), 'controller' => 'pages', 'action' => 'display', 'plugin' => 'pages'); $this->assertEqual($result, $expected); $result = Router::parse('/posts/edit/0'); $expected = array('pass' => array(0), 'named' => array(), 'controller' => 'posts', 'action' => 'edit', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/posts/:id::url_title', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\d]+')); $result = Router::parse('/posts/5:sample-post-title'); $expected = array('pass' => array('5', 'sample-post-title'), 'named' => array(), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/posts/:id::url_title/*', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\d]+')); $result = Router::parse('/posts/5:sample-post-title/other/params/4'); $expected = array('pass' => array('5', 'sample-post-title', 'other', 'params', '4'), 'named' => array(), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/posts/:url_title-(uuid::id)', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => $UUID)); $result = Router::parse('/posts/sample-post-title-(uuid:47fc97a9-019c-41d1-a058-1fa3cbdd56cb)'); $expected = array('pass' => array('47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'sample-post-title'), 'named' => array(), 'id' => '47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('named' => false)); $result = Router::parse('/posts/view/foo:bar/routing:fun'); $expected = array('pass' => array('foo:bar', 'routing:fun'), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'view'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('named' => array('foo', 'answer'))); $result = Router::parse('/posts/view/foo:bar/routing:fun/answer:42'); $expected = array('pass' => array('routing:fun'), 'named' => array('foo' => 'bar', 'answer' => '42'), 'plugin' => null, 'controller' => 'posts', 'action' => 'view'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('named' => array('foo', 'answer'), 'greedy' => true)); $result = Router::parse('/posts/view/foo:bar/routing:fun/answer:42'); $expected = array('pass' => array(), 'named' => array('foo' => 'bar', 'routing' => 'fun', 'answer' => '42'), 'plugin' => null, 'controller' => 'posts', 'action' => 'view'); $this->assertEqual($result, $expected); }
testUrlParsing method @access public @return void
testUrlParsing
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testPersistentParameters() { Router::reload(); Router::connect( '/:lang/:color/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('persist' => array('lang', 'color') )); Router::connect( '/:lang/:color/posts/index', array('controller' => 'posts', 'action' => 'index'), array('persist' => array('lang') )); Router::connect('/:lang/:color/posts/edit/*', array('controller' => 'posts', 'action' => 'edit')); Router::connect('/about', array('controller' => 'pages', 'action' => 'view', 'about')); Router::parse('/en/red/posts/view/5'); Router::setRequestInfo(array( array('controller' => 'posts', 'action' => 'view', 'lang' => 'en', 'color' => 'red', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/', 'here' => '/en/red/posts/view/5', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) )); $expected = '/en/red/posts/view/6'; $result = Router::url(array('controller' => 'posts', 'action' => 'view', 6)); $this->assertEqual($result, $expected); $expected = '/en/blue/posts/index'; $result = Router::url(array('controller' => 'posts', 'action' => 'index', 'color' => 'blue')); $this->assertEqual($result, $expected); $expected = '/posts/edit/6'; $result = Router::url(array('controller' => 'posts', 'action' => 'edit', 6, 'color' => null, 'lang' => null)); $this->assertEqual($result, $expected); $expected = '/posts'; $result = Router::url(array('controller' => 'posts', 'action' => 'index')); $this->assertEqual($result, $expected); $expected = '/posts/edit/7'; $result = Router::url(array('controller' => 'posts', 'action' => 'edit', 7)); $this->assertEqual($result, $expected); $expected = '/about'; $result = Router::url(array('controller' => 'pages', 'action' => 'view', 'about')); $this->assertEqual($result, $expected); }
test that the persist key works. @return void
testPersistentParameters
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUuidRoutes() { Router::connect( '/subjects/add/:category_id', array('controller' => 'subjects', 'action' => 'add'), array('category_id' => '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}') ); $result = Router::parse('/subjects/add/4795d601-19c8-49a6-930e-06a8b01d17b7'); $expected = array('pass' => array(), 'named' => array(), 'category_id' => '4795d601-19c8-49a6-930e-06a8b01d17b7', 'plugin' => null, 'controller' => 'subjects', 'action' => 'add'); $this->assertEqual($result, $expected); }
testUuidRoutes method @access public @return void
testUuidRoutes
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRouteSymmetry() { Router::connect( "/:extra/page/:slug/*", array('controller' => 'pages', 'action' => 'view', 'extra' => null), array("extra" => '[a-z1-9_]*', "slug" => '[a-z1-9_]+', "action" => 'view') ); $result = Router::parse('/some_extra/page/this_is_the_slug'); $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'view', 'slug' => 'this_is_the_slug', 'extra' => 'some_extra'); $this->assertEqual($result, $expected); $result = Router::parse('/page/this_is_the_slug'); $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'view', 'slug' => 'this_is_the_slug', 'extra' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect( "/:extra/page/:slug/*", array('controller' => 'pages', 'action' => 'view', 'extra' => null), array("extra" => '[a-z1-9_]*', "slug" => '[a-z1-9_]+') ); Router::parse('/'); $result = Router::url(array('admin' => null, 'plugin' => null, 'controller' => 'pages', 'action' => 'view', 'slug' => 'this_is_the_slug', 'extra' => null)); $expected = '/page/this_is_the_slug'; $this->assertEqual($result, $expected); $result = Router::url(array('admin' => null, 'plugin' => null, 'controller' => 'pages', 'action' => 'view', 'slug' => 'this_is_the_slug', 'extra' => 'some_extra')); $expected = '/some_extra/page/this_is_the_slug'; $this->assertEqual($result, $expected); }
testRouteSymmetry method @access public @return void
testRouteSymmetry
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRoutingPrefixesSetting() { $restore = Configure::read('Routing'); Configure::write('Routing.admin', 'admin'); Configure::write('Routing.prefixes', array('member', 'super_user')); Router::reload(); $result = Router::prefixes(); $expected = array('admin', 'member', 'super_user'); $this->assertEqual($result, $expected); Configure::write('Routing.prefixes', 'member'); Router::reload(); $result = Router::prefixes(); $expected = array('admin', 'member'); $this->assertEqual($result, $expected); Configure::write('Routing', $restore); }
Test that Routing.prefixes and Routing.admin are used when a Router instance is created or reset @return void
testRoutingPrefixesSetting
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testAdminRoutingCompatibility() { Configure::write('Routing.admin', 'admin'); Router::reload(); Router::connect('/admin', array('admin' => true, 'controller' => 'users')); $result = Router::parse('/admin'); $expected = array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'users', 'action' => 'index', 'admin' => true, 'prefix' => 'admin'); $this->assertEqual($result, $expected); $result = Router::url(array('admin' => true, 'controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2')); $expected = '/admin/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); Router::reload(); Router::parse('/'); $result = Router::url(array('admin' => false, 'controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2')); $expected = '/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); Router::reload(); Router::setRequestInfo(array( array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) )); Router::parse('/'); $result = Router::url(array('admin' => false, 'controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2')); $expected = '/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2')); $expected = '/admin/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); Router::reload(); $result = Router::parse('admin/users/view/'); $expected = array('pass' => array(), 'named' => array(), 'controller' => 'users', 'action' => 'view', 'plugin' => null, 'prefix' => 'admin', 'admin' => true); $this->assertEqual($result, $expected); Configure::write('Routing.admin', 'beheer'); Router::reload(); Router::setRequestInfo(array( array('beheer' => true, 'controller' => 'posts', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/', 'here' => '/beheer/posts/index', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) )); $result = Router::parse('beheer/users/view/'); $expected = array('pass' => array(), 'named' => array(), 'controller' => 'users', 'action' => 'view', 'plugin' => null, 'prefix' => 'beheer', 'beheer' => true); $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2')); $expected = '/beheer/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); }
test compatibility with old Routing.admin config setting. @access public @return void @todo Once Routing.admin is removed update these tests.
testAdminRoutingCompatibility
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testPrefixRoutingAndPlugins() { Configure::write('Routing.prefixes', array('admin')); $paths = App::path('plugins'); App::build(array( 'plugins' => array( TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS ) ), true); App::objects('plugin', null, false); Router::reload(); Router::setRequestInfo(array( array('admin' => true, 'controller' => 'controller', 'action' => 'action', 'form' => array(), 'url' => array(), 'plugin' => null, 'prefix' => 'admin'), array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) )); Router::parse('/'); $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index')); $expected = '/admin/test_plugin'; $this->assertEqual($result, $expected); Router::reload(); Router::parse('/'); Router::setRequestInfo(array( array( 'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'admin_edit', 'pass' => array('6'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/shows/show_tickets/edit/6') ), array( 'plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/' ) )); $result = Router::url(array( 'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'edit', 6, 'admin' => true, 'prefix' => 'admin' )); $expected = '/admin/test_plugin/show_tickets/edit/6'; $this->assertEqual($result, $expected); $result = Router::url(array( 'plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'index', 'admin' => true )); $expected = '/admin/test_plugin/show_tickets'; $this->assertEqual($result, $expected); App::build(array('plugins' => $paths)); }
Test prefix routing and plugin combinations @return void
testPrefixRoutingAndPlugins
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testExtensionParsingSetting() { $router =& Router::getInstance(); $this->assertFalse($this->router->__parseExtensions); $router->parseExtensions(); $this->assertTrue($this->router->__parseExtensions); }
testExtensionParsingSetting method @access public @return void
testExtensionParsingSetting
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testExtensionParsing() { Router::parseExtensions(); $result = Router::parse('/posts.rss'); $expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'url' => array('ext' => 'rss'), 'pass'=> array(), 'named' => array()); $this->assertEqual($result, $expected); $result = Router::parse('/posts/view/1.rss'); $expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'pass' => array('1'), 'named' => array(), 'url' => array('ext' => 'rss'), 'named' => array()); $this->assertEqual($result, $expected); $result = Router::parse('/posts/view/1.rss?query=test'); $this->assertEqual($result, $expected); $result = Router::parse('/posts/view/1.atom'); $expected['url'] = array('ext' => 'atom'); $this->assertEqual($result, $expected); Router::reload(); Router::parseExtensions('rss', 'xml'); $result = Router::parse('/posts.xml'); $expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', 'url' => array('ext' => 'xml'), 'pass'=> array(), 'named' => array()); $this->assertEqual($result, $expected); $result = Router::parse('/posts.atom?hello=goodbye'); $expected = array('plugin' => null, 'controller' => 'posts.atom', 'action' => 'index', 'pass' => array(), 'named' => array(), 'url' => array('ext' => 'html')); $this->assertEqual($result, $expected); Router::reload(); Router::parseExtensions(); $result = $this->router->__parseExtension('/posts.atom'); $expected = array('ext' => 'atom', 'url' => '/posts'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', 'url' => array('ext' => 'rss'))); $result = Router::parse('/controller/action'); $expected = array('controller' => 'controller', 'action' => 'action', 'plugin' => null, 'url' => array('ext' => 'rss'), 'named' => array(), 'pass' => array()); $this->assertEqual($result, $expected); Router::reload(); Router::parseExtensions('rss'); Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', 'url' => array('ext' => 'rss'))); $result = Router::parse('/controller/action'); $expected = array('controller' => 'controller', 'action' => 'action', 'plugin' => null, 'url' => array('ext' => 'rss'), 'named' => array(), 'pass' => array()); $this->assertEqual($result, $expected); }
testExtensionParsing method @access public @return void
testExtensionParsing
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testQuerystringGeneration() { $result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => 'var=test&var2=test2')); $expected = '/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2'))); $this->assertEqual($result, $expected); $expected .= '&more=test+data'; $result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2', 'more' => 'test data'))); $this->assertEqual($result, $expected); // Test bug #4614 $restore = ini_get('arg_separator.output'); ini_set('arg_separator.output', '&'); $result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2', 'more' => 'test data'))); $this->assertEqual($result, $expected); ini_set('arg_separator.output', $restore); $result = Router::url(array('controller' => 'posts', 'action'=>'index', '0', '?' => array('var' => 'test', 'var2' => 'test2')), array('escape' => true)); $expected = '/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); }
testQuerystringGeneration method @access public @return void
testQuerystringGeneration
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testConnectNamed() { $named = Router::connectNamed(false, array('default' => true)); $this->assertFalse($named['greedy']); $this->assertEqual(array_keys($named['rules']), $named['default']); Router::reload(); Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar')); Router::connectNamed(array(), array('argSeparator' => '=')); $result = Router::parse('/foo/param1=value1/param2=value2'); $expected = array('pass' => array(), 'named' => array('param1' => 'value1', 'param2' => 'value2'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/controller/action/*', array('controller' => 'controller', 'action' => 'action'), array('named' => array('param1' => 'value[\d]'))); Router::connectNamed(array(), array('greedy' => false, 'argSeparator' => '=')); $result = Router::parse('/controller/action/param1=value1/param2=value2'); $expected = array('pass' => array('param2=value2'), 'named' => array('param1' => 'value1'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/:controller/:action/*'); Router::connectNamed(array('page'), array('default' => false, 'greedy' => false)); $result = Router::parse('/categories/index?limit=5'); $this->assertTrue(empty($result['named'])); }
testConnectNamed method @access public @return void
testConnectNamed
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testNamedArgsUrlGeneration() { $result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 1, 'deleted' => 1)); $expected = '/posts/index/published:1/deleted:1'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 0, 'deleted' => 0)); $expected = '/posts/index/published:0/deleted:0'; $this->assertEqual($result, $expected); Router::reload(); extract(Router::getNamedExpressions()); Router::connectNamed(array('file'=> '[\w\.\-]+\.(html|png)')); Router::connect('/', array('controller' => 'graphs', 'action' => 'index')); Router::connect('/:id/*', array('controller' => 'graphs', 'action' => 'view'), array('id' => $ID)); $result = Router::url(array('controller' => 'graphs', 'action' => 'view', 'id' => 12, 'file' => 'asdf.png')); $expected = '/12/file:asdf.png'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'graphs', 'action' => 'view', 12, 'file' => 'asdf.foo')); $expected = '/graphs/view/12/file:asdf.foo'; $this->assertEqual($result, $expected); Configure::write('Routing.admin', 'admin'); Router::reload(); Router::setRequestInfo(array( array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) )); Router::parse('/'); $result = Router::url(array('page' => 1, 0 => null, 'sort' => 'controller', 'direction' => 'asc', 'order' => null)); $expected = "/admin/controller/index/page:1/sort:controller/direction:asc"; $this->assertEqual($result, $expected); Router::reload(); Router::setRequestInfo(array( array('admin' => true, 'controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array('type'=> 'whatever'), 'argSeparator' => ':', 'namedArgs' => array('type'=> 'whatever')) )); $result = Router::parse('/admin/controller/index/type:whatever'); $result = Router::url(array('type'=> 'new')); $expected = "/admin/controller/index/type:new"; $this->assertEqual($result, $expected); }
testNamedArgsUrlGeneration method @access public @return void
testNamedArgsUrlGeneration
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testNamedArgsUrlParsing() { $Router =& Router::getInstance(); Router::reload(); $result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param:value'); $expected = array('pass' => array(), 'named' => array('param1' => 'value1:1', 'param2' => 'value2:3', 'param' => 'value'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); $result = Router::connectNamed(false); $this->assertEqual(array_keys($result['rules']), array()); $this->assertFalse($result['greedy']); $result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param:value'); $expected = array('pass' => array('param1:value1:1', 'param2:value2:3', 'param:value'), 'named' => array(), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); $result = Router::connectNamed(true); $this->assertEqual(array_keys($result['rules']), $Router->named['default']); $this->assertTrue($result['greedy']); Router::reload(); Router::connectNamed(array('param1' => 'not-matching')); $result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param:value'); $expected = array('pass' => array('param1:value1:1'), 'named' => array('param2' => 'value2:3', 'param' => 'value'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/foo/:action/*', array('controller' => 'bar'), array('named' => array('param1' => array('action' => 'index')), 'greedy' => true)); $result = Router::parse('/foo/index/param1:value1:1/param2:value2:3/param:value'); $expected = array('pass' => array(), 'named' => array('param1' => 'value1:1', 'param2' => 'value2:3', 'param' => 'value'), 'controller' => 'bar', 'action' => 'index', 'plugin' => null); $this->assertEqual($result, $expected); $result = Router::parse('/foo/view/param1:value1:1/param2:value2:3/param:value'); $expected = array('pass' => array('param1:value1:1'), 'named' => array('param2' => 'value2:3', 'param' => 'value'), 'controller' => 'bar', 'action' => 'view', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connectNamed(array('param1' => '[\d]', 'param2' => '[a-z]', 'param3' => '[\d]')); $result = Router::parse('/controller/action/param1:1/param2:2/param3:3'); $expected = array('pass' => array('param2:2'), 'named' => array('param1' => '1', 'param3' => '3'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connectNamed(array('param1' => '[\d]', 'param2' => true, 'param3' => '[\d]')); $result = Router::parse('/controller/action/param1:1/param2:2/param3:3'); $expected = array('pass' => array(), 'named' => array('param1' => '1', 'param2' => '2', 'param3' => '3'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connectNamed(array('param1' => 'value[\d]+:[\d]+'), array('greedy' => false)); $result = Router::parse('/controller/action/param1:value1:1/param2:value2:3/param3:value'); $expected = array('pass' => array('param2:value2:3', 'param3:value'), 'named' => array('param1' => 'value1:1'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar'), array('named' => array('param1' => 'value[\d]:[\d]'))); Router::connectNamed(array(), array('greedy' => false)); $result = Router::parse('/foo/param1:value1:1/param2:value2:3/param3:value'); $expected = array('pass' => array('param2:value2:3', 'param3:value'), 'named' => array('param1' => 'value1:1'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null); $this->assertEqual($result, $expected); }
testNamedArgsUrlParsing method @access public @return void
testNamedArgsUrlParsing
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlGenerationWithLegacyPrefixes() { Router::reload(); Router::connect('/protected/:controller/:action/*', array( 'prefix' => 'protected', 'protected' => true )); Router::parse('/'); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => null, 'admin' => false, 'form' => array(), 'url' => array('url' => 'images/index')), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/images/index', 'webroot' => '/') )); $result = Router::url(array('protected' => true)); $expected = '/protected/images/index'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'images', 'action' => 'add')); $expected = '/images/add'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true)); $expected = '/protected/images/add'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'edit', 1)); $expected = '/images/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'edit', 1, 'protected' => true)); $expected = '/protected/images/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'protected_edit', 1, 'protected' => true)); $expected = '/protected/images/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'edit', 1, 'protected' => true)); $expected = '/protected/images/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1)); $expected = '/others/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true)); $expected = '/protected/others/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'page' => 1)); $expected = '/protected/others/edit/1/page:1'; $this->assertEqual($result, $expected); Router::connectNamed(array('random')); $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'random' => 'my-value')); $expected = '/protected/others/edit/1/random:my-value'; $this->assertEqual($result, $expected); }
test url generation with legacy (1.2) style prefix routes. @access public @return void @todo Remove tests related to legacy style routes. @see testUrlGenerationWithAutoPrefixes
testUrlGenerationWithLegacyPrefixes
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlGenerationWithAutoPrefixes() { Configure::write('Routing.prefixes', array('protected')); Router::reload(); Router::parse('/'); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => null, 'protected' => false, 'form' => array(), 'url' => array('url' => 'images/index')), array('base' => '', 'here' => '/images/index', 'webroot' => '/') )); $result = Router::url(array('controller' => 'images', 'action' => 'add')); $expected = '/images/add'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true)); $expected = '/protected/images/add'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'edit', 1)); $expected = '/images/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'edit', 1, 'protected' => true)); $expected = '/protected/images/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'protected_edit', 1, 'protected' => true)); $expected = '/protected/images/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'protectededit', 1, 'protected' => true)); $expected = '/protected/images/protectededit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'edit', 1, 'protected' => true)); $expected = '/protected/images/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1)); $expected = '/others/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true)); $expected = '/protected/others/edit/1'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'page' => 1)); $expected = '/protected/others/edit/1/page:1'; $this->assertEqual($result, $expected); Router::connectNamed(array('random')); $result = Router::url(array('controller' => 'others', 'action' => 'edit', 1, 'protected' => true, 'random' => 'my-value')); $expected = '/protected/others/edit/1/random:my-value'; $this->assertEqual($result, $expected); }
test newer style automatically generated prefix routes. @return void
testUrlGenerationWithAutoPrefixes
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testAutoPrefixRoutePersistence() { Configure::write('Routing.prefixes', array('protected')); Router::reload(); Router::parse('/'); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => 'protected', 'protected' => true, 'form' => array(), 'url' => array('url' => 'protected/images/index')), array('base' => '', 'here' => '/protected/images/index', 'webroot' => '/') )); $result = Router::url(array('controller' => 'images', 'action' => 'add')); $expected = '/protected/images/add'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => false)); $expected = '/images/add'; $this->assertEqual($result, $expected); }
test that auto-generated prefix routes persist @return void
testAutoPrefixRoutePersistence
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testPrefixOverride() { Configure::write('Routing.prefixes', array('protected', 'admin')); Router::reload(); Router::parse('/'); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => 'protected', 'protected' => true, 'form' => array(), 'url' => array('url' => 'protected/images/index')), array('base' => '', 'here' => '/protected/images/index', 'webroot' => '/') )); $result = Router::url(array('controller' => 'images', 'action' => 'add', 'admin' => true)); $expected = '/admin/images/add'; $this->assertEqual($result, $expected); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/images/index')), array('base' => '', 'here' => '/admin/images/index', 'webroot' => '/') )); $result = Router::url(array('controller' => 'images', 'action' => 'add', 'protected' => true)); $expected = '/protected/images/add'; $this->assertEqual($result, $expected); }
test that setting a prefix override the current one @return void
testPrefixOverride
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRemoveBase() { Router::setRequestInfo(array( array('controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'bare' => 0, 'plugin' => null), array('base' => '/base', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) )); $result = Router::url(array('controller' => 'my_controller', 'action' => 'my_action')); $expected = '/base/my_controller/my_action'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'my_controller', 'action' => 'my_action', 'base' => false)); $expected = '/my_controller/my_action'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'my_controller', 'action' => 'my_action', 'base' => true)); $expected = '/base/my_controller/my_action/base:1'; $this->assertEqual($result, $expected); }
testRemoveBase method @access public @return void
testRemoveBase
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testPagesUrlParsing() { Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); $result = Router::parse('/'); $expected = array('pass'=> array('home'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display'); $this->assertEqual($result, $expected); $result = Router::parse('/pages/home/'); $expected = array('pass' => array('home'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); $result = Router::parse('/pages/display/home/parameter:value'); $expected = array('pass' => array('home'), 'named' => array('parameter' => 'value'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); $result = Router::parse('/'); $expected = array('pass' => array('home'), 'named' => array(), 'plugin' => null, 'controller' => 'pages', 'action' => 'display'); $this->assertEqual($result, $expected); $result = Router::parse('/pages/display/home/event:value'); $expected = array('pass' => array('home'), 'named' => array('event' => 'value'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display'); $this->assertEqual($result, $expected); $result = Router::parse('/pages/display/home/event:Val_u2'); $expected = array('pass' => array('home'), 'named' => array('event' => 'Val_u2'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display'); $this->assertEqual($result, $expected); $result = Router::parse('/pages/display/home/event:val-ue'); $expected = array('pass' => array('home'), 'named' => array('event' => 'val-ue'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display'); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/', array('controller' => 'posts', 'action' => 'index')); Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); $result = Router::parse('/pages/contact/'); $expected = array('pass'=>array('contact'), 'named' => array(), 'plugin'=> null, 'controller'=>'pages', 'action'=>'display'); $this->assertEqual($result, $expected); }
testPagesUrlParsing method @access public @return void
testPagesUrlParsing
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testParsingWithTrailingPeriod() { Router::reload(); $result = Router::parse('/posts/view/something.'); $this->assertEqual($result['pass'][0], 'something.', 'Period was chopped off %s'); $result = Router::parse('/posts/view/something. . .'); $this->assertEqual($result['pass'][0], 'something. . .', 'Period was chopped off %s'); }
test that requests with a trailing dot don't loose the do. @return void
testParsingWithTrailingPeriod
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testParsingWithTrailingPeriodAndParseExtensions() { Router::reload(); Router::parseExtensions('json'); $result = Router::parse('/posts/view/something.'); $this->assertEqual($result['pass'][0], 'something.', 'Period was chopped off %s'); $result = Router::parse('/posts/view/something. . .'); $this->assertEqual($result['pass'][0], 'something. . .', 'Period was chopped off %s'); }
test that requests with a trailing dot don't loose the do. @return void
testParsingWithTrailingPeriodAndParseExtensions
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testParsingWithPatternOnAction() { Router::reload(); Router::connect( '/blog/:action/*', array('controller' => 'blog_posts'), array('action' => 'other|actions') ); $result = Router::parse('/blog/other'); $expected = array( 'plugin' => null, 'controller' => 'blog_posts', 'action' => 'other', 'pass' => array(), 'named' => array() ); $this->assertEqual($expected, $result); $result = Router::parse('/blog/foobar'); $expected = array( 'plugin' => null, 'controller' => 'blog', 'action' => 'foobar', 'pass' => array(), 'named' => array() ); $this->assertEqual($expected, $result); $result = Router::url(array('controller' => 'blog_posts', 'action' => 'foo')); $this->assertEqual('/blog_posts/foo', $result); $result = Router::url(array('controller' => 'blog_posts', 'action' => 'actions')); $this->assertEqual('/blog/actions', $result); }
test that patterns work for :action @return void
testParsingWithPatternOnAction
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testParsingWithPrefixes() { $adminParams = array('prefix' => 'admin', 'admin' => true); Router::connect('/admin/:controller', $adminParams); Router::connect('/admin/:controller/:action', $adminParams); Router::connect('/admin/:controller/:action/*', $adminParams); Router::setRequestInfo(array( array('controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/base', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) )); $result = Router::parse('/admin/posts/'); $expected = array('pass' => array(), 'named' => array(), 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'admin' => true); $this->assertEqual($result, $expected); $result = Router::parse('/admin/posts'); $this->assertEqual($result, $expected); $result = Router::url(array('admin' => true, 'controller' => 'posts')); $expected = '/base/admin/posts'; $this->assertEqual($result, $expected); $result = Router::prefixes(); $expected = array('admin'); $this->assertEqual($result, $expected); Router::reload(); $prefixParams = array('prefix' => 'members', 'members' => true); Router::connect('/members/:controller', $prefixParams); Router::connect('/members/:controller/:action', $prefixParams); Router::connect('/members/:controller/:action/*', $prefixParams); Router::setRequestInfo(array( array('controller' => 'controller', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/base', 'here' => '/', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) )); $result = Router::parse('/members/posts/index'); $expected = array('pass' => array(), 'named' => array(), 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'members' => true); $this->assertEqual($result, $expected); $result = Router::url(array('members' => true, 'controller' => 'posts', 'action' =>'index', 'page' => 2)); $expected = '/base/members/posts/index/page:2'; $this->assertEqual($result, $expected); $result = Router::url(array('members' => true, 'controller' => 'users', 'action' => 'add')); $expected = '/base/members/users/add'; $this->assertEqual($result, $expected); $result = Router::parse('/posts/index'); $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'index'); $this->assertEqual($result, $expected); }
testParsingWithPrefixes method @access public @return void
testParsingWithPrefixes
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlWritingWithPrefixes() { Router::connect('/company/:controller/:action/*', array('prefix' => 'company', 'company' => true)); Router::connect('/login', array('controller' => 'users', 'action' => 'login')); $result = Router::url(array('controller' => 'users', 'action' => 'login', 'company' => true)); $expected = '/company/users/login'; $this->assertEqual($result, $expected); Router::setRequestInfo(array( array('controller' => 'users', 'action' => 'login', 'company' => true, 'form' => array(), 'url' => array(), 'plugin' => null), array('base' => '/', 'here' => '/', 'webroot' => '/base/') )); $result = Router::url(array('controller' => 'users', 'action' => 'login', 'company' => false)); $expected = '/login'; $this->assertEqual($result, $expected); }
Tests URL generation with flags and prefixes in and out of context @access public @return void
testUrlWritingWithPrefixes
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUrlWritingWithPrefixesAndCustomRoutes() { Router::connect( '/admin/login', array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => true) ); Router::setRequestInfo(array( array('controller' => 'posts', 'action' => 'index', 'admin' => true, 'prefix' => 'admin', 'form' => array(), 'url' => array(), 'plugin' => null ), array('base' => '/', 'here' => '/', 'webroot' => '/') )); $result = Router::url(array('controller' => 'users', 'action' => 'login', 'admin' => true)); $this->assertEqual($result, '/admin/login'); $result = Router::url(array('controller' => 'users', 'action' => 'login')); $this->assertEqual($result, '/admin/login'); $result = Router::url(array('controller' => 'users', 'action' => 'admin_login')); $this->assertEqual($result, '/admin/login'); }
test url generation with prefixes and custom routes @return void
testUrlWritingWithPrefixesAndCustomRoutes
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testPassedArgsOrder() { Router::connect('/test-passed/*', array('controller' => 'pages', 'action' => 'display', 'home')); Router::connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2)); Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1)); Router::parse('/'); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 1, 'whatever')); $expected = '/test/whatever'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 2, 'whatever')); $expected = '/test2/whatever'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 'home', 'whatever')); $expected = '/test-passed/whatever'; $this->assertEqual($result, $expected); Configure::write('Routing.prefixes', array('admin')); Router::reload(); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'named' => array(), 'prefix' => 'protected', 'protected' => true, 'form' => array(), 'url' => array ('url' => 'protected/images/index')), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/protected/images/index', 'webroot' => '/') )); Router::connect('/protected/:controller/:action/*', array( 'controller' => 'users', 'action' => 'index', 'prefix' => 'protected' )); Router::parse('/'); $result = Router::url(array('controller' => 'images', 'action' => 'add')); $expected = '/protected/images/add'; $this->assertEqual($result, $expected); $result = Router::prefixes(); $expected = array('admin', 'protected'); $this->assertEqual($result, $expected); }
testPassedArgsOrder method @access public @return void
testPassedArgsOrder
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRegexRouteMatching() { Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng')); $result = Router::parse('/test/test_action'); $expected = array('pass' => array(), 'named' => array(), 'controller' => 'test', 'action' => 'test_action', 'plugin' => null); $this->assertEqual($result, $expected); $result = Router::parse('/eng/test/test_action'); $expected = array('pass' => array(), 'named' => array(), 'locale' => 'eng', 'controller' => 'test', 'action' => 'test_action', 'plugin' => null); $this->assertEqual($result, $expected); $result = Router::parse('/badness/test/test_action'); $expected = array('pass' => array('test_action'), 'named' => array(), 'controller' => 'badness', 'action' => 'test', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng')); Router::setRequestInfo(array( array('plugin' => null, 'controller' => 'test', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array ('url' => 'test/test_action')), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/test/test_action', 'webroot' => '/') )); $result = Router::url(array('action' => 'test_another_action')); $expected = '/test/test_another_action'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'test_another_action', 'locale' => 'eng')); $expected = '/eng/test/test_another_action'; $this->assertEqual($result, $expected); $result = Router::url(array('action' => 'test_another_action', 'locale' => 'badness')); $expected = '/test/test_another_action/locale:badness'; $this->assertEqual($result, $expected); }
testRegexRouteMatching method @access public @return void
testRegexRouteMatching
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testCurrentRoute() { $url = array('controller' => 'pages', 'action' => 'display', 'government'); Router::connect('/government', $url); Router::parse('/government'); $route =& Router::currentRoute(); $this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults); }
testCurentRoute This test needs some improvement and actual requestAction() usage @return void @access public
testCurrentRoute
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testDefaultsMethod() { Router::defaults(false); Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 2)); $result = Router::parse('/posts/edit/5'); $this->assertFalse(isset($result['controller'])); $this->assertFalse(isset($result['action'])); }
test that connectDefaults() can disable default route connection @return void
testDefaultsMethod
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testConnectDefaultRoutes() { App::build(array( 'plugins' => array( TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS ) ), true); App::objects('plugin', null, false); Router::reload(); $result = Router::url(array('plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index')); $this->assertEqual($result, '/plugin_js/js_file'); $result = Router::parse('/plugin_js/js_file'); $expected = array( 'plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index', 'named' => array(), 'pass' => array() ); $this->assertEqual($result, $expected); $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index')); $this->assertEqual($result, '/test_plugin'); $result = Router::parse('/test_plugin'); $expected = array( 'plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index', 'named' => array(), 'pass' => array() ); $this->assertEqual($result, $expected, 'Plugin shortcut route broken. %s'); }
test that the required default routes are connected. @return void
testConnectDefaultRoutes
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testUsingCustomRouteClass() { Mock::generate('CakeRoute', 'MockConnectedRoute'); $routes = Router::connect( '/:slug', array('controller' => 'posts', 'action' => 'view'), array('routeClass' => 'MockConnectedRoute', 'slug' => '[a-z_-]+') ); $this->assertTrue(is_a($routes[0], 'MockConnectedRoute'), 'Incorrect class used. %s'); $expected = array('controller' => 'posts', 'action' => 'view', 'slug' => 'test'); $routes[0]->setReturnValue('parse', $expected); $result = Router::parse('/test'); $this->assertEqual($result, $expected); }
test using a custom route class for route connection @return void
testUsingCustomRouteClass
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRouterReverse() { $params = array( 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array(), 'autoRender' => 1, 'bare' => 1, 'return' => 1, 'requested' => 1 ); $result = Router::reverse($params); $this->assertEqual($result, '/posts/view/1'); $params = array( 'controller' => 'posts', 'action' => 'index', 'pass' => array(1), 'named' => array('page' => 1, 'sort' => 'Article.title', 'direction' => 'desc'), 'url' => array() ); $result = Router::reverse($params); $this->assertEqual($result, '/posts/index/1/page:1/sort:Article.title/direction:desc'); Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}')); $params = array( 'lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array('url' => 'eng/posts/view/1') ); $result = Router::reverse($params); $this->assertEqual($result, '/eng/posts/view/1'); $params = array( 'lang' => 'eng', 'controller' => 'posts', 'action' => 'view', 'pass' => array(1), 'named' => array(), 'url' => array('url' => 'eng/posts/view/1', 'foo' => 'bar', 'baz' => 'quu'), 'paging' => array(), 'models' => array() ); $result = Router::reverse($params); $this->assertEqual($result, '/eng/posts/view/1?foo=bar&baz=quu'); }
test reversing parameter arrays back into strings. @return void
testRouterReverse
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function startTest() { $this->_routing = Configure::read('Routing'); Configure::write('Routing', array('admin' => null, 'prefixes' => array())); Router::reload(); }
startTest method @access public @return void
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function endTest() { Configure::write('Routing', $this->_routing); }
end the test and reset the environment @return void
endTest
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testConstruction() { $route =& new CakeRoute('/:controller/:action/:id', array(), array('id' => '[0-9]+')); $this->assertEqual($route->template, '/:controller/:action/:id'); $this->assertEqual($route->defaults, array()); $this->assertEqual($route->options, array('id' => '[0-9]+')); $this->assertFalse($route->compiled()); }
Test the construction of a CakeRoute @return void
testConstruction
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testHyphenNames() { $route =& new CakeRoute('/articles/:date-from/:date-to', array( 'controller' => 'articles', 'action' => 'index' )); $expected = array( 'controller' => 'articles', 'action' => 'index', 'date-from' => '2009-07-31', 'date-to' => '2010-07-31', 'named' => array(), 'pass' => array() ); $result = $route->parse('/articles/2009-07-31/2010-07-31'); $this->assertEqual($result, $expected); }
test route names with - in them. @return void
testHyphenNames
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRouteParameterOverlap() { $route =& new CakeRoute('/invoices/add/:idd/:id', array('controller' => 'invoices', 'action' => 'add')); $result = $route->compile(); $this->assertPattern($result, '/invoices/add/1/3'); $route =& new CakeRoute('/invoices/add/:id/:idd', array('controller' => 'invoices', 'action' => 'add')); $result = $route->compile(); $this->assertPattern($result, '/invoices/add/1/3'); }
test that route parameters that overlap don't cause errors. @return void
testRouteParameterOverlap
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testRouteCompilingWithParamPatterns() { extract(Router::getNamedExpressions()); $route = new CakeRoute( '/:controller/:action/:id', array(), array('id' => $ID) ); $result = $route->compile(); $this->assertPattern($result, '/posts/edit/1'); $this->assertPattern($result, '/posts/view/518098'); $this->assertNoPattern($result, '/posts/edit/name-of-post'); $this->assertNoPattern($result, '/posts/edit/4/other:param'); $this->assertEqual($route->keys, array('controller', 'action', 'id')); $route =& new CakeRoute( '/:lang/:controller/:action/:id', array('controller' => 'testing4'), array('id' => $ID, 'lang' => '[a-z]{3}') ); $result = $route->compile(); $this->assertPattern($result, '/eng/posts/edit/1'); $this->assertPattern($result, '/cze/articles/view/1'); $this->assertNoPattern($result, '/language/articles/view/2'); $this->assertNoPattern($result, '/eng/articles/view/name-of-article'); $this->assertEqual($route->keys, array('lang', 'controller', 'action', 'id')); foreach (array(':', '@', ';', '$', '-') as $delim) { $route =& new CakeRoute('/posts/:id' . $delim . ':title'); $result = $route->compile(); $this->assertPattern($result, '/posts/1' . $delim . 'name-of-article'); $this->assertPattern($result, '/posts/13244' . $delim . 'name-of_Article[]'); $this->assertNoPattern($result, '/posts/11!nameofarticle'); $this->assertNoPattern($result, '/posts/11'); $this->assertEqual($route->keys, array('id', 'title')); } $route =& new CakeRoute( '/posts/:id::title/:year', array('controller' => 'posts', 'action' => 'view'), array('id' => $ID, 'year' => $Year, 'title' => '[a-z-_]+') ); $result = $route->compile(); $this->assertPattern($result, '/posts/1:name-of-article/2009/'); $this->assertPattern($result, '/posts/13244:name-of-article/1999'); $this->assertNoPattern($result, '/posts/hey_now:nameofarticle'); $this->assertNoPattern($result, '/posts/:nameofarticle/2009'); $this->assertNoPattern($result, '/posts/:nameofarticle/01'); $this->assertEqual($route->keys, array('id', 'title', 'year')); $route =& new CakeRoute( '/posts/:url_title-(uuid::id)', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => $ID) ); $result = $route->compile(); $this->assertPattern($result, '/posts/some_title_for_article-(uuid:12534)/'); $this->assertPattern($result, '/posts/some_title_for_article-(uuid:12534)'); $this->assertNoPattern($result, '/posts/'); $this->assertNoPattern($result, '/posts/nameofarticle'); $this->assertNoPattern($result, '/posts/nameofarticle-12347'); $this->assertEqual($route->keys, array('url_title', 'id')); }
test compiling routes with keys that have patterns @return void
testRouteCompilingWithParamPatterns
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testComplexRouteCompilingAndParsing() { extract(Router::getNamedExpressions()); $route =& new CakeRoute( '/posts/:month/:day/:year/*', array('controller' => 'posts', 'action' => 'view'), array('year' => $Year, 'month' => $Month, 'day' => $Day) ); $result = $route->compile(); $this->assertPattern($result, '/posts/08/01/2007/title-of-post'); $result = $route->parse('/posts/08/01/2007/title-of-post'); $this->assertEqual(count($result), 8); $this->assertEqual($result['controller'], 'posts'); $this->assertEqual($result['action'], 'view'); $this->assertEqual($result['year'], '2007'); $this->assertEqual($result['month'], '08'); $this->assertEqual($result['day'], '01'); $route =& new CakeRoute( "/:extra/page/:slug/*", array('controller' => 'pages', 'action' => 'view', 'extra' => null), array("extra" => '[a-z1-9_]*', "slug" => '[a-z1-9_]+', "action" => 'view') ); $result = $route->compile(); $this->assertPattern($result, '/some_extra/page/this_is_the_slug'); $this->assertPattern($result, '/page/this_is_the_slug'); $this->assertEqual($route->keys, array('extra', 'slug')); $this->assertEqual($route->options, array('extra' => '[a-z1-9_]*', 'slug' => '[a-z1-9_]+', 'action' => 'view')); $expected = array( 'controller' => 'pages', 'action' => 'view', 'extra' => null, ); $this->assertEqual($route->defaults, $expected); $route =& new CakeRoute( '/:controller/:action/*', array('project' => false), array( 'controller' => 'source|wiki|commits|tickets|comments|view', 'action' => 'branches|history|branch|logs|view|start|add|edit|modify' ) ); $this->assertFalse($route->parse('/chaw_test/wiki')); $result = $route->compile(); $this->assertNoPattern($result, '/some_project/source'); $this->assertPattern($result, '/source/view'); $this->assertPattern($result, '/source/view/other/params'); $this->assertNoPattern($result, '/chaw_test/wiki'); $this->assertNoPattern($result, '/source/wierd_action'); }
test more complex route compiling & parsing with mid route greedy stars and optional routing parameters @return void
testComplexRouteCompilingAndParsing
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testMatchBasic() { $route = new CakeRoute('/:controller/:action/:id', array('plugin' => null)); $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null)); $this->assertFalse($result); $result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 0)); $this->assertFalse($result); $result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'id' => 1)); $this->assertEqual($result, '/posts/view/1'); $route =& new CakeRoute('/', array('controller' => 'pages', 'action' => 'display', 'home')); $result = $route->match(array('controller' => 'pages', 'action' => 'display', 'home')); $this->assertEqual($result, '/'); $result = $route->match(array('controller' => 'pages', 'action' => 'display', 'about')); $this->assertFalse($result); $route =& new CakeRoute('/pages/*', array('controller' => 'pages', 'action' => 'display')); $result = $route->match(array('controller' => 'pages', 'action' => 'display', 'home')); $this->assertEqual($result, '/pages/home'); $result = $route->match(array('controller' => 'pages', 'action' => 'display', 'about')); $this->assertEqual($result, '/pages/about'); $route =& new CakeRoute('/blog/:action', array('controller' => 'posts')); $result = $route->match(array('controller' => 'posts', 'action' => 'view')); $this->assertEqual($result, '/blog/view'); $result = $route->match(array('controller' => 'nodes', 'action' => 'view')); $this->assertFalse($result); $result = $route->match(array('controller' => 'posts', 'action' => 'view', 1)); $this->assertFalse($result); $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'id' => 2)); $this->assertFalse($result); $route =& new CakeRoute('/foo/:controller/:action', array('action' => 'index')); $result = $route->match(array('controller' => 'posts', 'action' => 'view')); $this->assertEqual($result, '/foo/posts/view'); $route =& new CakeRoute('/:plugin/:id/*', array('controller' => 'posts', 'action' => 'view')); $result = $route->match(array('plugin' => 'test', 'controller' => 'posts', 'action' => 'view', 'id' => '1')); $this->assertEqual($result, '/test/1/'); $result = $route->match(array('plugin' => 'fo', 'controller' => 'posts', 'action' => 'view', 'id' => '1', '0')); $this->assertEqual($result, '/fo/1/0'); $result = $route->match(array('plugin' => 'fo', 'controller' => 'nodes', 'action' => 'view', 'id' => 1)); $this->assertFalse($result); $result = $route->match(array('plugin' => 'fo', 'controller' => 'posts', 'action' => 'edit', 'id' => 1)); $this->assertFalse($result); $route =& new CakeRoute('/admin/subscriptions/:action/*', array( 'controller' => 'subscribe', 'admin' => true, 'prefix' => 'admin' )); $url = array('controller' => 'subscribe', 'admin' => true, 'action' => 'edit', 1); $result = $route->match($url); $expected = '/admin/subscriptions/edit/1'; $this->assertEqual($result, $expected); $route =& new CakeRoute('/articles/:date-from/:date-to', array( 'controller' => 'articles', 'action' => 'index' )); $url = array( 'controller' => 'articles', 'action' => 'index', 'date-from' => '2009-07-31', 'date-to' => '2010-07-31' ); $result = $route->match($url); $expected = '/articles/2009-07-31/2010-07-31'; $this->assertEqual($result, $expected); }
test that routes match their pattern. @return void
testMatchBasic
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testMatchWithNamedParametersAndPassedArgs() { Router::connectNamed(true); $route = new CakeRoute('/:controller/:action/*', array('plugin' => null)); $result = $route->match(array('controller' => 'posts', 'action' => 'index', 'plugin' => null, 'page' => 1)); $this->assertEqual($result, '/posts/index/page:1'); $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5)); $this->assertEqual($result, '/posts/view/5'); $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5, 'page' => 1, 'limit' => 20, 'order' => 'title')); $this->assertEqual($result, '/posts/view/5/page:1/limit:20/order:title'); $route =& new CakeRoute('/test2/*', array('controller' => 'pages', 'action' => 'display', 2)); $result = $route->match(array('controller' => 'pages', 'action' => 'display', 1)); $this->assertFalse($result); $result = $route->match(array('controller' => 'pages', 'action' => 'display', 2, 'something')); $this->assertEqual($result, '/test2/something'); $result = $route->match(array('controller' => 'pages', 'action' => 'display', 5, 'something')); $this->assertFalse($result); }
test match() with greedy routes, named parameters and passed args. @return void
testMatchWithNamedParametersAndPassedArgs
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testMatchWithPatterns() { $route =& new CakeRoute('/:controller/:action/:id', array('plugin' => null), array('id' => '[0-9]+')); $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'id' => 'foo')); $this->assertFalse($result); $result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'id' => '9')); $this->assertEqual($result, '/posts/view/9'); $result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'id' => '922')); $this->assertEqual($result, '/posts/view/922'); $result = $route->match(array('plugin' => null, 'controller' => 'posts', 'action' => 'view', 'id' => 'a99')); $this->assertFalse($result); }
test that match with patterns works. @return void
testMatchWithPatterns
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testProtocolUrls() { $url = 'svn+ssh://example.com'; $this->assertEqual($url, Router::url($url)); $url = '://example.com'; $this->assertEqual($url, Router::url($url)); }
Test protocol relative urls. @return void
testProtocolUrls
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testPatternOnAction() { $route =& new CakeRoute( '/blog/:action/*', array('controller' => 'blog_posts'), array('action' => 'other|actions') ); $result = $route->match(array('controller' => 'blog_posts', 'action' => 'foo')); $this->assertFalse($result); $result = $route->match(array('controller' => 'blog_posts', 'action' => 'actions')); $this->assertTrue($result); $result = $route->parse('/blog/other'); $expected = array('controller' => 'blog_posts', 'action' => 'other', 'pass' => array(), 'named' => array()); $this->assertEqual($expected, $result); $result = $route->parse('/blog/foobar'); $this->assertFalse($result); }
test that patterns work for :action @return void
testPatternOnAction
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testPersistParams() { $route =& new CakeRoute( '/:lang/:color/blog/:action', array('controller' => 'posts'), array('persist' => array('lang', 'color')) ); $url = array('controller' => 'posts', 'action' => 'index'); $params = array('lang' => 'en', 'color' => 'blue'); $result = $route->persistParams($url, $params); $this->assertEqual($result['lang'], 'en'); $this->assertEqual($result['color'], 'blue'); $url = array('controller' => 'posts', 'action' => 'index', 'color' => 'red'); $params = array('lang' => 'en', 'color' => 'blue'); $result = $route->persistParams($url, $params); $this->assertEqual($result['lang'], 'en'); $this->assertEqual($result['color'], 'red'); }
test persistParams ability to persist parameters from $params and remove params. @return void
testPersistParams
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testParse() { extract(Router::getNamedExpressions()); $route =& new CakeRoute('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $ID)); $route->compile(); $result = $route->parse('/posts/view/1'); $this->assertEqual($result['controller'], 'posts'); $this->assertEqual($result['action'], 'view'); $this->assertEqual($result['id'], '1'); $route =& new Cakeroute( '/admin/:controller', array('prefix' => 'admin', 'admin' => 1, 'action' => 'index') ); $route->compile(); $result = $route->parse('/admin/'); $this->assertFalse($result); $result = $route->parse('/admin/posts'); $this->assertEqual($result['controller'], 'posts'); $this->assertEqual($result['action'], 'index'); }
test the parse method of CakeRoute. @return void
testParse
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function startTest() { $this->_routing = Configure::read('Routing'); Configure::write('Routing', array('admin' => null, 'prefixes' => array())); Router::reload(); }
startTest method @access public @return void
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function endTest() { Configure::write('Routing', $this->_routing); }
end the test and reset the environment @return void
endTest
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testParsing() { $route =& new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar')); $result = $route->parse('/foo'); $this->assertEqual($result['plugin'], 'foo'); $this->assertEqual($result['controller'], 'foo'); $this->assertEqual($result['action'], 'index'); $result = $route->parse('/wrong'); $this->assertFalse($result, 'Wrong plugin name matched %s'); }
test the parsing of routes. @return void
testParsing
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function testMatch() { $route =& new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar')); $result = $route->match(array('plugin' => 'foo', 'controller' => 'posts', 'action' => 'index')); $this->assertFalse($result, 'plugin controller mismatch was converted. %s'); $result = $route->match(array('plugin' => 'foo', 'controller' => 'foo', 'action' => 'index')); $this->assertEqual($result, '/foo'); }
test the reverse routing of the plugin shortcut urls. @return void
testMatch
php
Datawalke/Coordino
cake/tests/cases/libs/router.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/router.test.php
MIT
function startTest($method) { parent::startTest($method); $this->_initDb(); }
startTest method @param mixed $method @access public @return void
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function testEscapeAlphaNumeric() { $resultAlpha = Sanitize::escape('abc', 'test_suite'); $this->assertEqual($resultAlpha, 'abc'); $resultNumeric = Sanitize::escape('123', 'test_suite'); $this->assertEqual($resultNumeric, '123'); $resultNumeric = Sanitize::escape(1234, 'test_suite'); $this->assertEqual($resultNumeric, 1234); $resultNumeric = Sanitize::escape(1234.23, 'test_suite'); $this->assertEqual($resultNumeric, 1234.23); $resultNumeric = Sanitize::escape('#1234.23', 'test_suite'); $this->assertEqual($resultNumeric, '#1234.23'); $resultNull = Sanitize::escape(null, 'test_suite'); $this->assertEqual($resultNull, null); $resultNull = Sanitize::escape(false, 'test_suite'); $this->assertEqual($resultNull, false); $resultNull = Sanitize::escape(true, 'test_suite'); $this->assertEqual($resultNull, true); }
testEscapeAlphaNumeric method @access public @return void
testEscapeAlphaNumeric
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function testHtml() { $string = '<p>This is a <em>test string</em> & so is this</p>'; $expected = 'This is a test string &amp; so is this'; $result = Sanitize::html($string, array('remove' => true)); $this->assertEqual($result, $expected); $string = 'The "lazy" dog \'jumped\' & flew over the moon. If (1+1) = 2 <em>is</em> true, (2-1) = 1 is also true'; $expected = 'The &quot;lazy&quot; dog &#039;jumped&#039; &amp; flew over the moon. If (1+1) = 2 &lt;em&gt;is&lt;/em&gt; true, (2-1) = 1 is also true'; $result = Sanitize::html($string); $this->assertEqual($result, $expected); $string = 'The "lazy" dog \'jumped\''; $expected = 'The &quot;lazy&quot; dog \'jumped\''; $result = Sanitize::html($string, array('quotes' => ENT_COMPAT)); $this->assertEqual($result, $expected); $string = 'The "lazy" dog \'jumped\''; $result = Sanitize::html($string, array('quotes' => ENT_NOQUOTES)); $this->assertEqual($result, $string); $string = 'The "lazy" dog \'jumped\' & flew over the moon. If (1+1) = 2 <em>is</em> true, (2-1) = 1 is also true'; $expected = 'The &quot;lazy&quot; dog &#039;jumped&#039; &amp; flew over the moon. If (1+1) = 2 &lt;em&gt;is&lt;/em&gt; true, (2-1) = 1 is also true'; $result = Sanitize::html($string); $this->assertEqual($result, $expected); }
testHtml method @access public @return void
testHtml
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function testParanoid() { $string = 'I would like to !%@#% & dance & sing ^$&*()-+'; $expected = 'Iwouldliketodancesing'; $result = Sanitize::paranoid($string); $this->assertEqual($result, $expected); $string = array('This |s th% s0ng that never ends it g*es', 'on and on my friends, b^ca#use it is the', 'so&g th===t never ends.'); $expected = array('This s th% s0ng that never ends it g*es', 'on and on my friends bcause it is the', 'sog tht never ends.'); $result = Sanitize::paranoid($string, array('%', '*', '.', ' ')); $this->assertEqual($result, $expected); $string = "anything' OR 1 = 1"; $expected = 'anythingOR11'; $result = Sanitize::paranoid($string); $this->assertEqual($result, $expected); $string = "x' AND email IS NULL; --"; $expected = 'xANDemailISNULL'; $result = Sanitize::paranoid($string); $this->assertEqual($result, $expected); $string = "x' AND 1=(SELECT COUNT(*) FROM users); --"; $expected = "xAND1SELECTCOUNTFROMusers"; $result = Sanitize::paranoid($string); $this->assertEqual($result, $expected); $string = "x'; DROP TABLE members; --"; $expected = "xDROPTABLEmembers"; $result = Sanitize::paranoid($string); $this->assertEqual($result, $expected); }
testParanoid method @access public @return void
testParanoid
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function testStripImages() { $string = '<img src="/img/test.jpg" alt="my image" />'; $expected = 'my image<br />'; $result = Sanitize::stripImages($string); $this->assertEqual($result, $expected); $string = '<img src="javascript:alert(\'XSS\');" />'; $expected = ''; $result = Sanitize::stripImages($string); $this->assertEqual($result, $expected); $string = '<a href="http://www.badsite.com/phising"><img src="/img/test.jpg" alt="test image alt" title="test image title" id="myImage" class="image-left"/></a>'; $expected = '<a href="http://www.badsite.com/phising">test image alt</a><br />'; $result = Sanitize::stripImages($string); $this->assertEqual($result, $expected); $string = '<a onclick="medium()" href="http://example.com"><img src="foobar.png" onclick="evilFunction(); return false;"/></a>'; $expected = '<a onclick="medium()" href="http://example.com"></a>'; $result = Sanitize::stripImages($string); $this->assertEqual($result, $expected); }
testStripImages method @access public @return void
testStripImages
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function testStripScripts() { $string = '<link href="/css/styles.css" media="screen" rel="stylesheet" />'; $expected = ''; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); $string = '<link href="/css/styles.css" media="screen" rel="stylesheet" />' . "\n" . '<link rel="icon" href="/favicon.ico" type="image/x-icon" />' . "\n" . '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />' . "\n" . '<link rel="alternate" href="/feed.xml" title="RSS Feed" type="application/rss+xml" />'; $expected = "\n" . '<link rel="icon" href="/favicon.ico" type="image/x-icon" />' . "\n" . '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />'."\n".'<link rel="alternate" href="/feed.xml" title="RSS Feed" type="application/rss+xml" />'; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); $string = '<script type="text/javascript"> alert("hacked!");</script>'; $expected = ''; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); $string = '<script> alert("hacked!");</script>'; $expected = ''; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); $string = '<style>#content { display:none; }</style>'; $expected = ''; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); $string = '<style type="text/css"><!-- #content { display:none; } --></style>'; $expected = ''; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); $string = <<<HTML text <style type="text/css"> <!-- #content { display:none; } --> </style> text HTML; $expected = "text\n\ntext"; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); $string = <<<HTML text <script type="text/javascript"> <!-- alert('wooo'); --> </script> text HTML; $expected = "text\n\ntext"; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); }
testStripScripts method @access public @return void
testStripScripts
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function testStripAll() { $string = '<img """><script>alert("xss")</script>"/>'; $expected ='"/>'; $result = Sanitize::stripAll($string); $this->assertEqual($result, $expected); $string = '<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>'; $expected = ''; $result = Sanitize::stripAll($string); $this->assertEqual($result, $expected); $string = '<<script>alert("XSS");//<</script>'; $expected = '<'; $result = Sanitize::stripAll($string); $this->assertEqual($result, $expected); $string = '<img src="http://google.com/images/logo.gif" onload="window.location=\'http://sam.com/\'" />'."\n". "<p>This is ok \t\n text</p>\n". '<link rel="stylesheet" href="/css/master.css" type="text/css" media="screen" title="my sheet" charset="utf-8">'."\n". '<script src="xss.js" type="text/javascript" charset="utf-8"></script>'; $expected = '<p>This is ok text</p>'; $result = Sanitize::stripAll($string); $this->assertEqual($result, $expected); }
testStripAll method @access public @return void
testStripAll
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function testStripTags() { $string = '<h2>Headline</h2><p><a href="http://example.com">My Link</a> could go to a bad site</p>'; $expected = 'Headline<p>My Link could go to a bad site</p>'; $result = Sanitize::stripTags($string, 'h2', 'a'); $this->assertEqual($result, $expected); $string = '<script type="text/javascript" src="http://evildomain.com"> </script>'; $expected = ' '; $result = Sanitize::stripTags($string, 'script'); $this->assertEqual($result, $expected); $string = '<h2>Important</h2><p>Additional information here <a href="/about"><img src="/img/test.png" /></a>. Read even more here</p>'; $expected = 'Important<p>Additional information here <img src="/img/test.png" />. Read even more here</p>'; $result = Sanitize::stripTags($string, 'h2', 'a'); $this->assertEqual($result, $expected); $string = '<h2>Important</h2><p>Additional information here <a href="/about"><img src="/img/test.png" /></a>. Read even more here</p>'; $expected = 'Important<p>Additional information here . Read even more here</p>'; $result = Sanitize::stripTags($string, 'h2', 'a', 'img'); $this->assertEqual($result, $expected); $string = '<b>Important message!</b><br>This message will self destruct!'; $expected = 'Important message!<br>This message will self destruct!'; $result = Sanitize::stripTags($string, 'b'); $this->assertEqual($result, $expected); $string = '<b>Important message!</b><br />This message will self destruct!'; $expected = 'Important message!<br />This message will self destruct!'; $result = Sanitize::stripTags($string, 'b'); $this->assertEqual($result, $expected); $string = '<h2 onclick="alert(\'evil\'); onmouseover="badness()">Important</h2><p>Additional information here <a href="/about"><img src="/img/test.png" /></a>. Read even more here</p>'; $expected = 'Important<p>Additional information here . Read even more here</p>'; $result = Sanitize::stripTags($string, 'h2', 'a', 'img'); $this->assertEqual($result, $expected); }
testStripTags method @access public @return void
testStripTags
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function testFormatColumns() { $this->loadFixtures('DataTest', 'Article'); $this->DataTest =& new SanitizeDataTest(array('alias' => 'DataTest')); $data = array('DataTest' => array( 'id' => 'z', 'count' => '12a', 'float' => '2.31456', 'updated' => '2008-01-01' ) ); $this->DataTest->set($data); $expected = array('DataTest' => array( 'id' => '0', 'count' => '12', 'float' => 2.31456, 'updated' => '2008-01-01 00:00:00', )); Sanitize::formatColumns($this->DataTest); $result = $this->DataTest->data; $this->assertEqual($result, $expected); $this->Article =& new SanitizeArticle(array('alias' => 'Article')); $data = array('Article' => array( 'id' => 'ZB', 'user_id' => '12', 'title' => 'title of article', 'body' => 'body text', 'published' => 'QQQQQQQ', )); $this->Article->set($data); $expected = array('Article' => array( 'id' => '0', 'user_id' => '12', 'title' => 'title of article', 'body' => 'body text', 'published' => 'QQQQQQQ', )); Sanitize::formatColumns($this->Article); $result = $this->Article->data; $this->assertEqual($result, $expected); }
testFormatColumns method @access public @return void
testFormatColumns
php
Datawalke/Coordino
cake/tests/cases/libs/sanitize.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/sanitize.test.php
MIT
function setUp() { $this->sut =& Security::getInstance(); }
setUp method @access public @return void
setUp
php
Datawalke/Coordino
cake/tests/cases/libs/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/security.test.php
MIT
function testInactiveMins() { Configure::write('Security.level', 'high'); $this->assertEqual(10, Security::inactiveMins()); Configure::write('Security.level', 'medium'); $this->assertEqual(100, Security::inactiveMins()); Configure::write('Security.level', 'low'); $this->assertEqual(300, Security::inactiveMins()); }
testInactiveMins method @access public @return void
testInactiveMins
php
Datawalke/Coordino
cake/tests/cases/libs/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/security.test.php
MIT
function testGenerateAuthkey() { $this->assertEqual(strlen(Security::generateAuthKey()), 40); }
testGenerateAuthkey method @access public @return void
testGenerateAuthkey
php
Datawalke/Coordino
cake/tests/cases/libs/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/security.test.php
MIT
function testValidateAuthKey() { $authKey = Security::generateAuthKey(); $this->assertTrue(Security::validateAuthKey($authKey)); }
testValidateAuthKey method @access public @return void
testValidateAuthKey
php
Datawalke/Coordino
cake/tests/cases/libs/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/security.test.php
MIT
function testHash() { $Security =& Security::getInstance(); $_hashType = $Security->hashType; $key = 'someKey'; $hash = 'someHash'; $this->assertIdentical(strlen(Security::hash($key, null, false)), 40); $this->assertIdentical(strlen(Security::hash($key, 'sha1', false)), 40); $this->assertIdentical(strlen(Security::hash($key, null, true)), 40); $this->assertIdentical(strlen(Security::hash($key, 'sha1', true)), 40); $result = Security::hash($key, null, $hash); $this->assertIdentical($result, 'e38fcb877dccb6a94729a81523851c931a46efb1'); $result = Security::hash($key, 'sha1', $hash); $this->assertIdentical($result, 'e38fcb877dccb6a94729a81523851c931a46efb1'); $hashType = 'sha1'; Security::setHash($hashType); $this->assertIdentical($this->sut->hashType, $hashType); $this->assertIdentical(strlen(Security::hash($key, null, true)), 40); $this->assertIdentical(strlen(Security::hash($key, null, false)), 40); $this->assertIdentical(strlen(Security::hash($key, 'md5', false)), 32); $this->assertIdentical(strlen(Security::hash($key, 'md5', true)), 32); $hashType = 'md5'; Security::setHash($hashType); $this->assertIdentical($this->sut->hashType, $hashType); $this->assertIdentical(strlen(Security::hash($key, null, false)), 32); $this->assertIdentical(strlen(Security::hash($key, null, true)), 32); if (!function_exists('hash') && !function_exists('mhash')) { $this->assertIdentical(strlen(Security::hash($key, 'sha256', false)), 32); $this->assertIdentical(strlen(Security::hash($key, 'sha256', true)), 32); } else { $this->assertIdentical(strlen(Security::hash($key, 'sha256', false)), 64); $this->assertIdentical(strlen(Security::hash($key, 'sha256', true)), 64); } Security::setHash($_hashType); }
testHash method @access public @return void
testHash
php
Datawalke/Coordino
cake/tests/cases/libs/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/security.test.php
MIT
function testCipher() { $length = 10; $txt = ''; for ($i = 0; $i < $length; $i++) { $txt .= mt_rand(0, 255); } $key = 'my_key'; $result = Security::cipher($txt, $key); $this->assertEqual(Security::cipher($result, $key), $txt); $txt = ''; $key = 'my_key'; $result = Security::cipher($txt, $key); $this->assertEqual(Security::cipher($result, $key), $txt); $txt = 'some_text'; $key = ''; $result = Security::cipher($txt, $key); $this->assertError(); $this->assertIdentical($result, ''); $txt = 123456; $key = 'my_key'; $result = Security::cipher($txt, $key); $this->assertEqual(Security::cipher($result, $key), $txt); $txt = '123456'; $key = 'my_key'; $result = Security::cipher($txt, $key); $this->assertEqual(Security::cipher($result, $key), $txt); }
testCipher method @access public @return void
testCipher
php
Datawalke/Coordino
cake/tests/cases/libs/security.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/security.test.php
MIT
function testNumericKeyExtraction() { $data = array('plugin' => null, 'controller' => '', 'action' => '', 1, 'whatever'); $this->assertIdentical(Set::extract($data, '{n}'), array(1, 'whatever')); $this->assertIdentical(Set::diff($data, Set::extract($data, '{n}')), array('plugin' => null, 'controller' => '', 'action' => '')); }
testNumericKeyExtraction method @access public @return void
testNumericKeyExtraction
php
Datawalke/Coordino
cake/tests/cases/libs/set.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/set.test.php
MIT
function testEnum() { $result = Set::enum(1, 'one, two'); $this->assertIdentical($result, 'two'); $result = Set::enum(2, 'one, two'); $this->assertNull($result); $set = array('one', 'two'); $result = Set::enum(0, $set); $this->assertIdentical($result, 'one'); $result = Set::enum(1, $set); $this->assertIdentical($result, 'two'); $result = Set::enum(1, array('one', 'two')); $this->assertIdentical($result, 'two'); $result = Set::enum(2, array('one', 'two')); $this->assertNull($result); $result = Set::enum('first', array('first' => 'one', 'second' => 'two')); $this->assertIdentical($result, 'one'); $result = Set::enum('third', array('first' => 'one', 'second' => 'two')); $this->assertNull($result); $result = Set::enum('no', array('no' => 0, 'yes' => 1)); $this->assertIdentical($result, 0); $result = Set::enum('not sure', array('no' => 0, 'yes' => 1)); $this->assertNull($result); $result = Set::enum(0); $this->assertIdentical($result, 'no'); $result = Set::enum(1); $this->assertIdentical($result, 'yes'); $result = Set::enum(2); $this->assertNull($result); }
testEnum method @access public @return void
testEnum
php
Datawalke/Coordino
cake/tests/cases/libs/set.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/set.test.php
MIT
function testFilter() { $result = Set::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false))); $expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be', false)); $this->assertIdentical($result, $expected); }
testFilter method @access public @return void
testFilter
php
Datawalke/Coordino
cake/tests/cases/libs/set.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/set.test.php
MIT
function testNumericArrayCheck() { $data = array('one'); $this->assertTrue(Set::numeric(array_keys($data))); $data = array(1 => 'one'); $this->assertFalse(Set::numeric($data)); $data = array('one'); $this->assertFalse(Set::numeric($data)); $data = array('one' => 'two'); $this->assertFalse(Set::numeric($data)); $data = array('one' => 1); $this->assertTrue(Set::numeric($data)); $data = array(0); $this->assertTrue(Set::numeric($data)); $data = array('one', 'two', 'three', 'four', 'five'); $this->assertTrue(Set::numeric(array_keys($data))); $data = array(1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five'); $this->assertTrue(Set::numeric(array_keys($data))); $data = array('1' => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five'); $this->assertTrue(Set::numeric(array_keys($data))); $data = array('one', 2 => 'two', 3 => 'three', 4 => 'four', 'a' => 'five'); $this->assertFalse(Set::numeric(array_keys($data))); }
testNumericArrayCheck method @access public @return void
testNumericArrayCheck
php
Datawalke/Coordino
cake/tests/cases/libs/set.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/set.test.php
MIT
function testKeyCheck() { $data = array('Multi' => array('dimensonal' => array('array'))); $this->assertTrue(Set::check($data, 'Multi.dimensonal')); $this->assertFalse(Set::check($data, 'Multi.dimensonal.array')); $data = array( array( 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), 'Comment' => array( array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'), ), 'Tag' => array( array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') ) ), array( 'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), 'Comment' => array(), 'Tag' => array() ) ); $this->assertTrue(Set::check($data, '0.Article.user_id')); $this->assertTrue(Set::check($data, '0.Comment.0.id')); $this->assertFalse(Set::check($data, '0.Comment.0.id.0')); $this->assertTrue(Set::check($data, '0.Article.user_id')); $this->assertFalse(Set::check($data, '0.Article.user_id.a')); }
testKeyCheck method @access public @return void
testKeyCheck
php
Datawalke/Coordino
cake/tests/cases/libs/set.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/set.test.php
MIT