/** * startTest method * * @access public * @return void */ public function startTest() { //Router::connect('/users', array('plugin' => null, 'controller' => 'users', 'action' => 'index'), array('routeClass' => 'I18nRoute')); $this->_routing = Configure::read('Routing'); $this->_config = Configure::read('Config'); Configure::write('Config.language', 'spa'); Configure::write('Config.languages', array('eng', 'fre', 'spa')); Configure::write('Routing', array('admin' => null, 'prefixes' => array())); if (defined('DEFAULT_LANGUAGE')) { $this->__defaultLang = DEFAULT_LANGUAGE; } else { define('DEFAULT_LANGUAGE', $this->__defaultLang); } I18nRoute::reload(); }
/** * test that created routes are parsed correctly. * * @return void * @access public */ public function testParsing() { Configure::write('Routing.prefixes', array('admin')); I18nRoute::reload(); Router::defaults(false); Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'), array('routeClass' => 'I18nRoute')); Router::connect('/admin/:controller/:action/*', array('action' => 'index', 'admin' => true), array('routeClass' => 'I18nRoute')); Router::connect('/:controller/:action/*', array('action' => 'index'), array('routeClass' => 'I18nRoute')); // This call is needed to work since the "default language" route is created from the constructor I18nRoute::promoteLangRoutes(); $result = Router::parse('/'); $expected = array( 'plugin' => null, 'controller' => 'pages', 'action' => 'display', 'named' => array(), 'pass' => array('home'), 'lang' => $this->__defaultLang ); $this->assertEqual($result, $expected); $this->assertEqual(Configure::read('Config.language'), $this->__defaultLang); $result = Router::parse('/posts/view/42'); $expected = array( 'plugin' => null, 'controller' => 'posts', 'action' => 'view', 'named' => array(), 'pass' => array(42), 'lang' => $this->__defaultLang ); $this->assertEqual($result, $expected); $result = Router::parse('/admin/posts/view/42'); $expected = array( 'plugin' => null, 'controller' => 'posts', 'action' => 'view', 'named' => array(), 'pass' => array(42), 'lang' => $this->__defaultLang, 'admin' => true, 'prefix' => 'admin' ); $this->assertEqual($result, $expected); $result = Router::parse('/spa'); $expected = array( 'plugin' => null, 'controller' => 'pages', 'action' => 'display', 'named' => array(), 'pass' => array('home'), 'lang' => 'spa' ); $this->assertEqual($result, $expected); $this->assertEqual(Configure::read('Config.language'), 'spa'); $result = Router::parse('/spa/posts/view/42'); $expected = array( 'plugin' => null, 'controller' => 'posts', 'action' => 'view', 'named' => array(), 'pass' => array(42), 'lang' => 'spa' ); $this->assertEqual($result, $expected); $result = Router::parse('/spa/admin/posts/view/42'); $expected = array( 'plugin' => null, 'controller' => 'posts', 'action' => 'view', 'named' => array(), 'pass' => array(42), 'lang' => 'spa', 'admin' => true, 'prefix' => 'admin' ); $this->assertEqual($result, $expected); }