コード例 #1
0
ファイル: router.test.php プロジェクト: aqua777/rackdoc
 /**
  * test compiling routes with keys that have patterns
  *
  * @return void
  **/
 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'));
 }
コード例 #2
0
 /**
  * test the parse method of CakeRoute.
  *
  * @return void
  */
 public function testParse()
 {
     $route = new CakeRoute('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => Router::ID));
     $route->compile();
     $result = $route->parse('/posts/view/1');
     $this->assertEquals('posts', $result['controller']);
     $this->assertEquals('view', $result['action']);
     $this->assertEquals('1', $result['id']);
     $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->assertEquals('posts', $result['controller']);
     $this->assertEquals('index', $result['action']);
 }
コード例 #3
0
ファイル: router.test.php プロジェクト: robksawyer/cakephp2x
 /**
  * test the parse method of CakeRoute.
  *
  * @return void
  */
 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');
 }