Exemplo n.º 1
0
 /**
  * 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();
 }
Exemplo n.º 2
0
/**
 * Reset all the internal static variables.
 * Convenience method for using in tests
 *
 * @return void
 */
	public static function reload() {
		Configure::write('I18nRoute.routes', array());
		self::$__defaultsMapped = false;
		Router::reload();
	}
Exemplo n.º 3
0
/**
 * Test that lang route promotion makes a correct permutation with the default language
 * 
 * @return void
 * @access public
 */
	public function testPromoteLangRoutes() {
		$Router = Router::getInstance();

		Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'), array('routeClass' => 'I18nRoute'));
		Router::connect('/:controller/:action/*', array('action' => 'index'), array('routeClass' => 'I18nRoute'));
		Router::connect('/admin/:controller/:action/*', array('action' => 'index', 'admin' => true), array('routeClass' => 'I18nRoute'));
		Router::connect('/foo', array('controller' => 'foo', 'action' => 'index'));

		$this->assertEqual(count($Router->routes), 7);
		$beforePromotionRoutes = $Router->routes;
		I18nRoute::promoteLangRoutes();

		$Router = Router::getInstance();
		$this->assertIdentical($Router->routes[0], $beforePromotionRoutes[1]);
		$this->assertIdentical($Router->routes[1], $beforePromotionRoutes[0]);
		$this->assertIdentical($Router->routes[2], $beforePromotionRoutes[3]);
		$this->assertIdentical($Router->routes[3], $beforePromotionRoutes[2]);
		$this->assertIdentical($Router->routes[4], $beforePromotionRoutes[5]);
		$this->assertIdentical($Router->routes[5], $beforePromotionRoutes[4]);
		$this->assertIdentical($Router->routes[6], $beforePromotionRoutes[6]);
	}
Exemplo n.º 4
0
 public function testMatch_ShouldNotRemoveDefaultLangWhenUsedInRouteContent()
 {
     $routeStartsChunk = '/' . $this->__defaultLang . '/pages';
     $route = new I18nRoute($routeStartsChunk . '/*', array('controller' => 'pages', 'action' => 'display', 'lang' => $this->__defaultLang), array('disableAutoNamedLang' => true));
     $result = $route->match(array('controller' => 'pages', 'action' => 'display', 'home', 'lang' => $this->__defaultLang));
     $this->assertEquals($routeStartsChunk . '/home', $result);
 }
Exemplo n.º 5
0
 /**
  * Constructor for a Route
  *
  * @param string $template Template string with parameter placeholders
  * @param array $defaults Array of defaults for the route.
  * @param array $options Array of parameters and additional options for the Route
  * @return void
  */
 public function __construct($template, $defaults = array(), $options = array())
 {
     parent::__construct($template, $defaults, $options);
     $this->_Sluggable = new SluggableRoute($this->template, $defaults, $options);
 }
Exemplo n.º 6
0
 /**
  * Checks to see if the given URL can be parsed by this route.
  * If the route can be parsed an array of parameters will be returned if not
  * false will be returned. String urls are parsed if they match a routes regular expression.
  *
  * @param string $url The url to attempt to parse.
  * @return mixed Boolean false on failure, otherwise an array or parameters
  * @access public
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (empty($params)) {
         return false;
     }
     if (isset($this->options['models']) && isset($params['_args_'])) {
         $index = -1;
         foreach ($this->options['models'] as $checkNamed => $slugField) {
             $index++;
             if (is_numeric($checkNamed)) {
                 $checkNamed = $slugField;
                 $slugField = null;
             }
             $slugSet = $this->_Sluggable->getSlugs($checkNamed, $slugField);
             if ($slugSet === false) {
                 continue;
             }
             $slugSet = array_flip($slugSet);
             $passed = explode('/', $params['_args_']);
             foreach ($passed as $key => $pass) {
                 if (isset($slugSet[$pass])) {
                     unset($passed[$key]);
                     $passed[$index] = $slugSet[$pass];
                 }
             }
             $params['_args_'] = implode('/', $passed);
         }
         return $params;
     }
     return false;
 }
Exemplo n.º 7
0
 /**
  * Reverse route plugin shortcut urls.  If the plugin and controller
  * are not the same the match is an auto fail.
  *
  * @param array $url Array of parameters to convert to a string.
  * @return mixed either false or a string url.
  */
 public function match($url)
 {
     if (isset($url['controller']) && isset($url['plugin']) && $url['plugin'] != $url['controller']) {
         return false;
     }
     $this->defaults['controller'] = $url['controller'];
     $result = parent::match($url);
     unset($this->defaults['controller']);
     return $result;
 }