Ejemplo n.º 1
0
 /**
  * test redirecting with patterns and a routed target
  *
  * @expectedException Cake\Routing\Exception\RedirectException
  * @expectedExceptionMessage http://localhost/nl/preferred_controllers
  * @expectedExceptionCode 301
  * @return void
  */
 public function testParsePersistMatchesAnotherRoute()
 {
     Router::connect('/:lang/preferred_controllers', ['controller' => 'tags', 'action' => 'add'], ['lang' => '(nl|en)', 'persist' => ['lang']]);
     $route = new RedirectRoute('/:lang/my_controllers', ['controller' => 'tags', 'action' => 'add'], ['lang' => '(nl|en)', 'persist' => ['lang']]);
     $route->parse('/nl/my_controllers/');
 }
Ejemplo n.º 2
0
 /**
  * test the parsing of routes.
  *
  * @return void
  */
 public function testParsing()
 {
     Router::connect('/:controller', ['action' => 'index']);
     Router::connect('/:controller/:action/*');
     $route = new RedirectRoute('/home', ['controller' => 'posts']);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/home');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/posts', true), $header['Location']);
     $route = new RedirectRoute('/home', ['controller' => 'posts', 'action' => 'index']);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/home');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/posts', true), $header['Location']);
     $this->assertEquals(301, $route->response->statusCode());
     $route = new RedirectRoute('/google', 'http://google.com');
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/google');
     $header = $route->response->header();
     $this->assertEquals('http://google.com', $header['Location']);
     $route = new RedirectRoute('/posts/*', ['controller' => 'posts', 'action' => 'view'], ['status' => 302]);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/posts/2');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/posts/view', true), $header['Location']);
     $this->assertEquals(302, $route->response->statusCode());
     $route = new RedirectRoute('/posts/*', ['controller' => 'posts', 'action' => 'view'], ['persist' => true]);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/posts/2');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/posts/view/2', true), $header['Location']);
     $route = new RedirectRoute('/posts/*', '/test', ['persist' => true]);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/posts/2');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/test', true), $header['Location']);
     $route = new RedirectRoute('/my_controllers/:action/*', ['controller' => 'tags', 'action' => 'add'], ['persist' => true]);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/my_controllers/do_something/passme');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/tags/add/passme', true), $header['Location']);
     $route = new RedirectRoute('/my_controllers/:action/*', ['controller' => 'tags', 'action' => 'add']);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/my_controllers/do_something/passme');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/tags/add', true), $header['Location']);
     $route = new RedirectRoute('/:lang/my_controllers', ['controller' => 'tags', 'action' => 'add'], ['lang' => '(nl|en)', 'persist' => ['lang']]);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/nl/my_controllers/');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/tags/add?lang=nl', true), $header['Location']);
     Router::reload();
     // reset default routes
     Router::connect('/:lang/preferred_controllers', ['controller' => 'tags', 'action' => 'add'], ['lang' => '(nl|en)', 'persist' => ['lang']]);
     $route = new RedirectRoute('/:lang/my_controllers', ['controller' => 'tags', 'action' => 'add'], ['lang' => '(nl|en)', 'persist' => ['lang']]);
     $route->response = $this->getMock('Cake\\Network\\Response', ['_sendHeader', 'stop']);
     $result = $route->parse('/nl/my_controllers/');
     $header = $route->response->header();
     $this->assertEquals(Router::url('/nl/preferred_controllers', true), $header['Location']);
 }