/** * Tests that the Dispatcher does not return an empty action * * @return void * @access public */ function testTrailingSlash() { $_POST = array(); $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; Router::reload(); $Dispatcher = new TestDispatcher(); Router::connect('/myalias/:action/*', array('controller' => 'my_controller', 'action' => null)); $Dispatcher->base = false; $url = 'myalias/'; //Fails $controller = $Dispatcher->dispatch($url, array('return' => 1)); $result = $Dispatcher->parseParams($url); $this->assertEqual('index', $result['action']); $url = 'myalias'; //Passes $controller = $Dispatcher->dispatch($url, array('return' => 1)); $result = $Dispatcher->parseParams($url); $this->assertEqual('index', $result['action']); }
/** * testPluginDispatch method * * @return void * @triggers DispatcherTest $Dispatcher, array('request' => $url) */ public function testPluginDispatch() { $_POST = array(); Router::reload(); $Dispatcher = new TestDispatcher(); Router::connect('/my_plugin/:controller/*', array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')); $url = new CakeRequest('my_plugin/some_pages/home/param:value/param2:value2'); $response = $this->getMock('CakeResponse'); $Dispatcher->dispatch($url, $response, array('return' => 1)); $event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $url)); $Dispatcher->parseParams($event); $expected = array('pass' => array('home'), 'named' => array('param' => 'value', 'param2' => 'value2'), 'plugin' => 'my_plugin', 'controller' => 'some_pages', 'action' => 'display'); foreach ($expected as $key => $value) { $this->assertEquals($value, $url[$key], 'Value mismatch ' . $key . ' %'); } $this->assertSame($Dispatcher->controller->plugin, 'MyPlugin'); $this->assertSame($Dispatcher->controller->name, 'SomePages'); $this->assertSame($Dispatcher->controller->params['controller'], 'some_pages'); $this->assertSame($Dispatcher->controller->passedArgs, array('0' => 'home', 'param' => 'value', 'param2' => 'value2')); }
/** * testPluginDispatch method * * @return void */ public function testPluginDispatch() { $_POST = array(); Router::reload(); $Dispatcher = new TestDispatcher(); Router::connect('/my_plugin/:controller/*', array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')); $url = new CakeRequest('my_plugin/some_pages/home/param:value/param2:value2'); $controller = $Dispatcher->dispatch($url, array('return' => 1)); $result = $Dispatcher->parseParams($url); $expected = array('pass' => array('home'), 'named' => array('param' => 'value', 'param2' => 'value2'), 'plugin' => 'my_plugin', 'controller' => 'some_pages', 'action' => 'display', 'form' => array()); foreach ($expected as $key => $value) { $this->assertEqual($result[$key], $value, 'Value mismatch ' . $key . ' %'); } $this->assertIdentical($controller->plugin, 'my_plugin'); $this->assertIdentical($controller->name, 'SomePages'); $this->assertIdentical($controller->params['controller'], 'some_pages'); $this->assertIdentical($controller->passedArgs, array('0' => 'home', 'param' => 'value', 'param2' => 'value2')); }