reset() public static method

Resets the Router to its default state, unloading all routes.
public static reset ( )
Beispiel #1
0
 public function tearDown()
 {
     Router::reset();
     foreach ($this->_routes as $route) {
         Router::connect($route);
     }
 }
Beispiel #2
0
 function teardown()
 {
     Router::reset();
     foreach ($this->_routes as $route) {
         Router::connect($route);
     }
     unset($this->analytics);
 }
Beispiel #3
0
 /**
  * Test if the routes.php file is loaded correctly and the
  * routes are connected to the router.
  */
 public function testRouteLoading()
 {
     $this->assertFalse(Router::get());
     $command = new Route(array('routes_file' => $this->_config['routes_file']));
     $this->assertEqual(4, count(Router::get()));
     Router::reset();
     $request = new Request();
     $request->params['env'] = 'production';
     $command = new Route(array('routes_file' => $this->_config['routes_file'], 'request' => $request));
     $this->assertEqual(2, count(Router::get()));
 }
 public function setUp()
 {
     $this->_routes = Router::get();
     Router::reset();
     Router::connect('/{:controller}/{:action}/page/{:page:[0-9]+}');
     $request = new Request();
     $request->params = array('controller' => 'posts', 'action' => 'index');
     $request->persist = array('controller');
     $this->context = new MockRenderer(compact('request'));
     $this->pagination = new Pagination(array('context' => $this->context));
 }
Beispiel #5
0
 /**
  * Clean up after the test.
  */
 public function tearDown()
 {
     Router::reset();
     foreach ($this->_routes as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     unset($this->html);
 }
Beispiel #6
0
 protected function _restoreCtrlContext()
 {
     Router::reset();
     foreach ($this->_context['routes'] as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     foreach ($this->_context['scopes'] as $scope => $attachment) {
         Router::attach($scope, $attachment);
     }
     Router::scope($this->_context['scope']);
 }
 /**
  * Tests that URLs are properly generated with route continuations.
  */
 public function testReversingContinuations()
 {
     Router::connect('/{:locale:en|de|it|jp}/{:args}', array(), array('continue' => true));
     Router::connect('/{:controller}/{:action}/{:id:[0-9]+}');
     Router::connect('/{:controller}/{:action}/{:args}');
     $result = Router::match(array('Posts::view', 'id' => 5, 'locale' => 'de'));
     $this->assertEqual($result, '/de/posts/view/5');
     $result = Router::match(array('Posts::index', 'locale' => 'en', '?' => array('page' => 2)));
     $this->assertEqual('/en/posts?page=2', $result);
     Router::reset();
     Router::connect('/{:locale:en|de|it|jp}/{:args}', array(), array('continue' => true));
     Router::connect('/pages/{:args}', 'Pages::view');
     $result = Router::match(array('Pages::view', 'locale' => 'en', 'args' => array('about')));
     $this->assertEqual('/en/pages/about', $result);
     Router::reset();
     Router::connect('/admin/{:args}', array('admin' => true), array('continue' => true));
     Router::connect('/login', 'Users::login');
     $result = Router::match(array('Users::login', 'admin' => true));
     $this->assertEqual('/admin/login', $result);
 }
Beispiel #8
0
 /**
  * Test if the routes.php file is loaded correctly and the
  * routes are connected to the router.
  */
 public function testRouteLoading()
 {
     $this->assertEmpty(Router::get(null, true));
     $command = new Route(array('routes' => $this->_config['routes']));
     $this->assertCount(4, Router::get(null, true));
     Router::reset();
     $request = new Request();
     $request->params['env'] = 'production';
     $command = new Route(compact('request') + array('routes' => $this->_config['routes']));
     $this->assertCount(2, Router::get(null, true));
 }
Beispiel #9
0
 public function tearDown()
 {
     Router::reset();
 }
Beispiel #10
0
 public function testConfigManipulation()
 {
     $config = MockDispatcher::config();
     $expected = array('rules' => array());
     $this->assertEqual($expected, $config);
     MockDispatcher::config(array('rules' => array('admin' => array('action' => 'admin_{:action}'))));
     Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'admin_test', 'controller' => 'Test', 'admin' => true);
     $this->assertEqual($expected, $result->params);
     MockDispatcher::config(array('rules' => array('action' => array('action' => function ($params) {
         return Inflector::camelize(strtolower($params['action']), false);
     }))));
     MockDispatcher::$dispatched = array();
     Router::reset();
     Router::connect('/', array('controller' => 'test', 'action' => 'TeST-camelize'));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'testCamelize', 'controller' => 'Test');
     $this->assertEqual($expected, $result->params);
     MockDispatcher::config(array('rules' => function ($params) {
         if (isset($params['admin'])) {
             return array('special' => array('action' => 'special_{:action}'));
         }
         return array();
     }));
     MockDispatcher::$dispatched = array();
     Router::reset();
     Router::connect('/', array('controller' => 'test', 'action' => 'test', 'admin' => true));
     Router::connect('/special', array('controller' => 'test', 'action' => 'test', 'admin' => true, 'special' => true));
     MockDispatcher::run(new Request(array('url' => '/')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'test', 'controller' => 'Test', 'admin' => true);
     $this->assertEqual($expected, $result->params);
     MockDispatcher::run(new Request(array('url' => '/special')));
     $result = end(MockDispatcher::$dispatched);
     $expected = array('action' => 'special_test', 'controller' => 'Test', 'admin' => true, 'special' => true);
     $this->assertEqual($expected, $result->params);
 }
Beispiel #11
0
 public function testProcessWithRelativeAndPrefixedAttachment()
 {
     Router::scope('app', function () {
         Router::connect('/home/welcome', array('Home::app'));
     });
     Router::scope('tests', function () {
         Router::connect('/home/welcome', array('Home::tests'));
     });
     Router::connect('/home/welcome', array('Home::default'));
     Router::attach('tests', array('absolute' => false, 'host' => 'tests.mysite.com', 'scheme' => 'http://', 'prefix' => '/prefix'));
     Router::attach('app', array('absolute' => false, 'host' => 'app.mysite.com', 'scheme' => 'http://', 'prefix' => '/prefix'));
     $request = new Request(array('url' => '/home/welcome'));
     $result = Router::process($request);
     $expected = array('controller' => 'Home', 'action' => 'default');
     $this->assertEqual($expected, $result->params);
     $this->assertIdentical(false, Router::scope());
     Router::reset();
     Router::scope('tests', function () {
         Router::connect('/home/welcome', array('Home::tests'));
     });
     Router::scope('app', function () {
         Router::connect('/home/welcome', array('Home::app'));
     });
     Router::connect('/home/welcome', array('Home::default'));
     Router::attach('tests', array('absolute' => false, 'host' => 'tests.mysite.com', 'scheme' => 'http://', 'prefix' => '/prefix1'));
     Router::attach('app', array('absolute' => false, 'host' => 'app.mysite.com', 'scheme' => 'http://', 'prefix' => '/prefix2'));
     $request = new Request(array('url' => '/prefix1/home/welcome'));
     $result = Router::process($request);
     $expected = array('library' => 'tests', 'controller' => 'Home', 'action' => 'tests');
     $this->assertEqual($expected, $result->params);
     $this->assertEqual('tests', Router::scope());
 }
Beispiel #12
0
 /**
  * Test matching routes with insert parameters which have default values.
  */
 public function testRouteMatchingWithInsertsAndDefaults()
 {
     Router::connect('/{:controller}/{:action}', array('action' => 'archive'));
     $this->assertEqual('/posts', Router::match(array('controller' => 'posts')));
     $result = Router::match(array('controller' => 'posts', 'action' => 'archive'));
     $this->assertEqual('/posts/archive', $result);
     Router::reset();
     Router::connect('/{:controller}/{:action}', array('controller' => 'users'));
     $result = Router::match(array('action' => 'view'));
     $this->assertEqual('/users/view', $result);
     $result = Router::match(array('controller' => 'posts', 'action' => 'view'));
     $this->assertEqual('/posts/view', $result);
     $ex = "No parameter match found for URL ";
     $ex .= "`('controller' => 'posts', 'action' => 'view', 'id' => '2')`.";
     $this->expectException($ex);
     Router::match(array('controller' => 'posts', 'action' => 'view', 'id' => '2'));
 }
Beispiel #13
0
 public function tearDown()
 {
     Router::reset();
     MockDispatcher::reset();
 }
Beispiel #14
0
 /**
  * Test matching routes with insert parameters which have default values.
  *
  * @return void
  */
 public function testRouteMatchingWithInsertsAndDefaults()
 {
     Router::connect('/{:controller}/{:action}', array('action' => 'archive'));
     $this->assertEqual('/posts', Router::match(array('controller' => 'posts')));
     $result = Router::match(array('controller' => 'posts', 'action' => 'archive'));
     $this->assertEqual('/posts/archive', $result);
     Router::reset();
     Router::connect('/{:controller}/{:action}', array('controller' => 'users'));
     $result = Router::match(array('action' => 'view'));
     $this->assertEqual('/users/view', $result);
     $result = Router::match(array('controller' => 'posts', 'action' => 'view'));
     $this->assertEqual('/posts/view', $result);
     $result = Router::match(array('controller' => 'posts', 'action' => 'view', 'id' => '2'));
     $this->assertFalse($result);
 }