Changeset 4892
- Timestamp:
- 08/24/07 10:35:56 (1 year ago)
- Files:
-
- trunk/lib/config/sfFactoryConfigHandler.class.php (modified) (1 diff)
- trunk/lib/request/sfWebRequest.class.php (modified) (12 diffs)
- trunk/lib/routing/sfNoRouting.class.php (modified) (3 diffs)
- trunk/lib/routing/sfPathInfoRouting.class.php (added)
- trunk/lib/routing/sfPatternRouting.class.php (modified) (19 diffs)
- trunk/lib/routing/sfRouting.class.php (modified) (4 diffs)
- trunk/lib/user/sfUser.class.php (modified) (1 diff)
- trunk/test/unit/action/sfComponentTest.php (modified) (1 diff)
- trunk/test/unit/response/sfWebResponseTest.php (modified) (1 diff)
- trunk/test/unit/routing/sfNoRoutingTest.php (modified) (2 diffs)
- trunk/test/unit/routing/sfPathInfoRoutingTest.php (added)
- trunk/test/unit/routing/sfPatternRoutingTest.php (modified) (6 diffs)
- trunk/test/unit/sfContextMock.class.php (modified) (1 diff)
- trunk/test/unit/user/sfBasicSecurityUserTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/config/sfFactoryConfigHandler.class.php
r4890 r4892 185 185 186 186 // append instance initialization 187 $inits[] = sprintf(" \$this->factories['routing']->initialize(\$this , sfConfig::get('sf_factory_routing_parameters', %s));", var_export($parameters, true));187 $inits[] = sprintf(" \$this->factories['routing']->initialize(\$this->factories['logger'], array_merge(array('load_configuration' => true, 'suffix' => sfConfig::get('sf_suffix'), 'default_module' => sfConfig::get('sf_default_module'), 'default_action' => sfConfig::get('sf_default_action')), sfConfig::get('sf_factory_routing_parameters', %s)));", var_export(is_array($parameters) ? $parameters : array(), true)); 188 188 break; 189 189 trunk/lib/request/sfWebRequest.class.php
r4887 r4892 24 24 class sfWebRequest extends sfRequest 25 25 { 26 /** 27 * A list of languages accepted by the browser. 28 * @var array 29 */ 30 protected $languages = null; 31 32 /** 33 * A list of charsets accepted by the browser 34 * @var array 35 */ 36 protected $charsets = null; 37 38 /** 39 * @var array List of content types accepted by the client. 40 */ 41 protected $acceptableContentTypes = null; 42 43 protected $pathInfoArray = null; 44 45 protected $relativeUrlRoot = null; 26 protected 27 $languages = null, 28 $charsets = null, 29 $acceptableContentTypes = null, 30 $pathInfoArray = null, 31 $relativeUrlRoot = null, 32 $getParameters = null, 33 $postParameters = null, 34 $routingParameters = null; 46 35 47 36 /** … … 54 43 public function getFile($name) 55 44 { 56 return ($this->hasFile($name) ? $this->getFileValues($name) : null);45 return $this->hasFile($name) ? $this->getFileValues($name) : null; 57 46 } 58 47 … … 77 66 public function getFileError($name) 78 67 { 79 return ($this->hasFile($name) ? $this->getFileValue($name, 'error') : UPLOAD_ERR_NO_FILE);68 return $this->hasFile($name) ? $this->getFileValue($name, 'error') : UPLOAD_ERR_NO_FILE; 80 69 } 81 70 … … 89 78 public function getFileName($name) 90 79 { 91 return ($this->hasFile($name) ? $this->getFileValue($name, 'name') : null);80 return $this->hasFile($name) ? $this->getFileValue($name, 'name') : null; 92 81 } 93 82 … … 121 110 public function getFilePath($name) 122 111 { 123 return ($this->hasFile($name) ? $this->getFileValue($name, 'tmp_name') : null);112 return $this->hasFile($name) ? $this->getFileValue($name, 'tmp_name') : null; 124 113 } 125 114 … … 133 122 public function getFileSize($name) 134 123 { 135 return ($this->hasFile($name) ? $this->getFileValue($name, 'size') : null);124 return $this->hasFile($name) ? $this->getFileValue($name, 'size') : null; 136 125 } 137 126 … … 148 137 public function getFileType($name) 149 138 { 150 return ($this->hasFile($name) ? $this->getFileValue($name, 'type') : null);139 return $this->hasFile($name) ? $this->getFileValue($name, 'type') : null; 151 140 } 152 141 … … 179 168 public function hasFileError($name) 180 169 { 181 return ($this->hasFile($name) ? ($this->getFileValue($name, 'error') != UPLOAD_ERR_OK) : false);170 return $this->hasFile($name) ? ($this->getFileValue($name, 'error') != UPLOAD_ERR_OK) : false; 182 171 } 183 172 … … 330 319 331 320 /** 332 * Returns the array that contains all request information ($_SERVER or $_ENV).333 *334 * This information is stored in the [sf_path_info_array] constant.335 *336 * @return array Path information337 */338 protected function getPathInfoArray()339 {340 if (!$this->pathInfoArray)341 {342 // parse PATH_INFO343 switch (sfConfig::get('sf_path_info_array'))344 {345 case 'SERVER':346 $this->pathInfoArray =& $_SERVER;347 break;348 349 case 'ENV':350 default:351 $this->pathInfoArray =& $_ENV;352 }353 }354 355 return $this->pathInfoArray;356 }357 358 /**359 321 * Retrieves the uniform resource identifier for the current web request. 360 322 * … … 421 383 422 384 // simulate PATH_INFO if needed 423 $sf_path_info_key = sfConfig::get('sf_path_info_key' );385 $sf_path_info_key = sfConfig::get('sf_path_info_key', 'PATH_INFO'); 424 386 if (!isset($pathArray[$sf_path_info_key]) || !$pathArray[$sf_path_info_key]) 425 387 { … … 458 420 } 459 421 460 /** 461 * Loads GET, PATH_INFO and POST data into the parameter list. 462 * 463 */ 464 protected function loadParameters() 465 { 466 // merge GET parameters 467 if (get_magic_quotes_gpc()) 468 { 469 $_GET = sfToolkit::stripslashesDeep($_GET); 470 } 471 $this->getParameterHolder()->addByRef($_GET); 472 473 $pathInfo = $this->getPathInfo(); 474 if ($pathInfo) 475 { 476 // routing map defined? 477 $r = $this->context->getRouting(); 478 if ($r->hasRoutes()) 479 { 480 $results = $r->parse($pathInfo); 481 if ($results !== null) 482 { 483 $this->getParameterHolder()->addByRef($results); 484 } 485 else 486 { 487 $this->setParameter('module', sfConfig::get('sf_error_404_module')); 488 $this->setParameter('action', sfConfig::get('sf_error_404_action')); 489 } 490 } 491 else 492 { 493 $array = explode('/', trim($pathInfo, '/')); 494 $count = count($array); 495 496 for ($i = 0; $i < $count; $i++) 497 { 498 // see if there's a value associated with this parameter, 499 // if not we're done with path data 500 if ($count > ($i + 1)) 501 { 502 $this->getParameterHolder()->setByRef($array[$i], $array[++$i]); 503 } 504 } 505 } 506 } 507 508 // merge POST parameters 509 if (get_magic_quotes_gpc()) 510 { 511 $_POST = sfToolkit::stripslashesDeep((array) $_POST); 512 } 513 $this->getParameterHolder()->addByRef($_POST); 514 515 // move symfony parameters in a protected namespace (parameters prefixed with _sf_) 516 foreach ($this->getParameterHolder()->getAll() as $key => $value) 517 { 518 if (0 === stripos($key, '_sf_')) 519 { 520 $this->getParameterHolder()->remove($key); 521 $this->setParameter($key, $value, 'symfony/request/sfWebRequest'); 522 unset($_GET[$key]); 523 } 524 } 525 526 if (sfConfig::get('sf_logging_enabled')) 527 { 528 $this->context->getLogger()->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))); 529 } 422 public function getGetParameters() 423 { 424 return $this->getParameters; 425 } 426 427 public function getPostParameters() 428 { 429 return $this->postParameters; 430 } 431 432 public function getRoutingParameters() 433 { 434 return $this->routingParameters; 530 435 } 531 436 … … 854 759 return array_keys($values); 855 760 } 761 762 /** 763 * Returns the array that contains all request information ($_SERVER or $_ENV). 764 * 765 * This information is stored in the [sf_path_info_array] constant. 766 * 767 * @return array Path information 768 */ 769 protected function getPathInfoArray() 770 { 771 if (!$this->pathInfoArray) 772 { 773 // parse PATH_INFO 774 switch (sfConfig::get('sf_path_info_array', 'SERVER')) 775 { 776 case 'SERVER': 777 $this->pathInfoArray =& $_SERVER; 778 break; 779 780 case 'ENV': 781 default: 782 $this->pathInfoArray =& $_ENV; 783 } 784 } 785 786 return $this->pathInfoArray; 787 } 788 789 protected function parseRoutingParameters() 790 { 791 $parameters = $this->context->getRouting()->parse($this->getPathInfo()); 792 if (!is_null($parameters)) 793 { 794 if (!isset($parameters['module'])) 795 { 796 $parameters['module'] = sfConfig::get('sf_default_module'); 797 } 798 799 if (!isset($parameters['action'])) 800 { 801 $parameters['action'] = sfConfig::get('sf_default_action'); 802 } 803 } 804 else 805 { 806 $parameters['module'] = sfConfig::get('sf_error_404_module'); 807 $parameters['action'] = sfConfig::get('sf_error_404_action'); 808 } 809 810 $this->routingParameters = $parameters; 811 } 812 813 /** 814 * Loads GET, PATH_INFO and POST data into the parameter list. 815 * 816 */ 817 protected function loadParameters() 818 { 819 // GET parameters 820 $this->getParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_GET) : $_GET; 821 $this->parameterHolder->add($this->getParameters); 822 823 // routing parameters 824 $this->parseRoutingParameters(); 825 $this->parameterHolder->add($this->routingParameters); 826 827 // POST parameters 828 $this->postParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_POST) : $_POST; 829 $this->parameterHolder->add($this->postParameters); 830 831 // move symfony parameters in a protected namespace (parameters prefixed with _sf_) 832 foreach ($this->parameterHolder->getAll() as $key => $value) 833 { 834 if (0 === stripos($key, '_sf_')) 835 { 836 $this->parameterHolder->remove($key); 837 $this->setParameter($key, $value, 'symfony/request/sfWebRequest'); 838 } 839 } 840 841 if (sfConfig::get('sf_logging_enabled')) 842 { 843 $this->context->getLogger()->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))); 844 } 845 } 856 846 } trunk/lib/routing/sfNoRouting.class.php
r4435 r4892 13 13 * 14 14 * @package symfony 15 * @subpackage controller15 * @subpackage routing 16 16 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 17 17 * @version SVN: $Id$ … … 29 29 public function getCurrentInternalUri($with_route_name = false) 30 30 { 31 $ request = $this->context->getRequest();31 $parameters = $_GET; 32 32 33 $parameters = $_GET; 34 unset($parameters['module']); 35 unset($parameters['action']); 33 // module/action 34 $module = isset($parameters['module']) ? $parameters['module'] : $this->parameterHolder->get('default_module'); 35 $action = isset($parameters['action']) ? $parameters['action'] : $this->parameterHolder->get('default_action'); 36 37 // other parameters 38 unset($parameters['module'], $parameters['action']); 39 ksort($parameters); 36 40 $parameters = count($parameters) ? '?'.http_build_query($parameters) : ''; 37 41 38 return sprintf('%s/%s%s', $request->getParameter('module', sfConfig::get('sf_default_module')), $request->getParameter('action', sfConfig::get('sf_default_action')), $parameters); 42 return sprintf('%s/%s%s', $module, $action, $parameters); 43 } 44 45 /** 46 * Generates a valid URLs for parameters. 47 * 48 * @param array The parameter values 49 * @param string The divider between key/value pairs 50 * @param string The equal sign to use between key and value 51 * 52 * @return string The generated URL 53 */ 54 public function generate($name, $params, $querydiv = '/', $divider = '/', $equals = '/') 55 { 56 $parameters = http_build_query(array_merge($this->defaultParameters, $params)); 57 58 return '/'.($parameters ? '?'.$parameters : ''); 59 } 60 61 /** 62 * Parses a URL to find a matching route. 63 * 64 * Returns null if no route match the URL. 65 * 66 * @param string URL to be parsed 67 * 68 * @return array An array of parameters 69 */ 70 public function parse($url) 71 { 72 return array(); 39 73 } 40 74 … … 77 111 { 78 112 } 79 80 /**81 * Generates a valid URLs for parameters.82 *83 * @param array The parameter values84 * @param string The divider between key/value pairs85 * @param string The equal sign to use between key and value86 *87 * @return string The generated URL88 */89 public function generate($name, $params, $querydiv = '/', $divider = '/', $equals = '/')90 {91 $parameters = http_build_query($params);92 93 return '/'.($parameters ? '?'.$parameters : '');94 }95 96 /**97 * Parses a URL to find a matching route.98 *99 * Returns null if no route match the URL.100 *101 * @param string URL to be parsed102 *103 * @return array An array of parameters104 */105 public function parse($url)106 {107 $parameters = parse_url($url);108 if (isset($parameters['query']))109 {110 parse_str($parameters['query'], $parameters);111 }112 else113 {114 $parameters = array();115 }116 117 return array_merge(array('module' => sfConfig::get('sf_default_module'), 'action' => sfConfig::get('sf_default_action')), $parameters);118 }119 113 } trunk/lib/routing/sfPatternRouting.class.php
r4887 r4892 17 17 * 18 18 * @package symfony 19 * @subpackage controller19 * @subpackage routing 20 20 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 21 21 * @version SVN: $Id$ … … 24 24 { 25 25 protected 26 $currentRouteName = null, 27 $currentInternalUri = null, 28 $routes = array(); 26 $currentRouteName = null, 27 $currentInternalUri = null, 28 $currentRouteParameters = null, 29 $defaultSuffix = '', 30 $routes = array(); 29 31 30 32 /** 31 33 * Initialize this Routing. 32 34 * 33 * @param sf Context A sfContext instance.34 * @param array An associative array of initialization parameters.35 * @param sfLogger A sfLogger instance (or null) 36 * @param array An associative array of initialization parameters. 35 37 * 36 38 * @return bool true, if initialization completes successfully, otherwise false. … … 38 40 * @throws <b>sfInitializationException</b> If an error occurs while initializing this User. 39 41 */ 40 public function initialize($context, $parameters = array()) 41 { 42 parent::initialize($context, $parameters); 43 44 if ($config = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name').'/routing.yml', true)) 45 { 46 include($config); 42 public function initialize(sfLogger $logger = null, $parameters = array()) 43 { 44 parent::initialize($logger, $parameters); 45 46 $this->defaultSuffix = $this->parameterHolder->get('suffix', ''); 47 48 if ($this->parameterHolder->get('load_configuration', false)) 49 { 50 if ($config = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name').'/routing.yml', true)) 51 { 52 include($config); 53 } 47 54 } 48 55 } … … 56 63 * @return string The current internal URI 57 64 */ 58 public function getCurrentInternalUri($with _route_name = false)65 public function getCurrentInternalUri($withRouteName = false) 59 66 { 60 67 if (is_null($this->currentRouteName)) … … 65 72 if (is_null($this->currentInternalUri)) 66 73 { 74 $parameters = $this->currentRouteParameters; 75 67 76 list($url, $regexp, $names, $namesHash, $defaults, $requirements, $suffix) = $this->routes[$this->currentRouteName]; 68 77 69 $request = $this->context->getRequest(); 70 71 if ($with_route_name) 78 if ($withRouteName) 72 79 { 73 80 $internalUri = '@'.$this->currentRouteName; … … 75 82 else 76 83 { 77 $internalUri = $request->getParameter('module', isset($defaults['module']) ? $defaults['module'] : '').'/'.$request->getParameter('action', isset($defaults['action']) ? $defaults['action'] : ''); 84 $module = isset($parameters['module']) ? $parameters['module'] : $this->parameterHolder->get('default_module'); 85 $action = isset($parameters['action']) ? $parameters['action'] : $this->parameterHolder->get('default_action'); 86 87 $internalUri = $module.'/'.$action; 78 88 } 79 89 … … 85 95 if ($name == 'module' || $name == 'action') continue; 86 96 87 $params[] = $name.'='. $request->getParameter($name,isset($defaults[$name]) ? $defaults[$name] : '');97 $params[] = $name.'='.isset($parameters[$name]) ? $parameters[$name] : (isset($defaults[$name]) ? $defaults[$name] : ''); 88 98 } 89 99 … … 91 101 if (strpos($url, '*')) 92 102 { 93 foreach ($ request->getParameterHolder()->getAll()as $key => $value)103 foreach ($parameters as $key => $value) 94 104 { 95 105 if ($key == 'module' || $key == 'action' || in_array($key, $names)) … … 111 121 } 112 122 123 public function setDefaultSuffix($suffix) 124 { 125 $this->defaultSuffix = '.' == $suffix ? '' : $suffix; 126 } 127 113 128 /** 114 129 * Gets the current compiled route array. … … 148 163 public function clearRoutes() 149 164 { 150 if ( sfConfig::get('sf_logging_enabled'))151 { 152 $this-> context->getLogger()->info('{sfRouting} clear all current routes');165 if (!is_null($this->logger)) 166 { 167 $this->logger->info('{sfRouting} clear all current routes'); 153 168 } 154 169 … … 225 240 $parsed = array(); 226 241 $names = array(); 227 $suffix = (($sf_suffix = sfConfig::get('sf_suffix')) == '.') ? '' : $sf_suffix;242 $suffix = $this->defaultSuffix; 228 243 229 244 // used for performance reasons … … 256 271 if (preg_match('/^(.+)(\.\w*)$/i', $elements[count($elements) - 1], $matches)) 257 272 { 258 $suffix = ($matches[2] == '.')? '' : $matches[2];273 $suffix = '.' == $matches[2] ? '' : $matches[2]; 259 274 $elements[count($elements) - 1] = $matches[1]; 260 275 $route = '/'.implode('/', $elements); … … 309 324 } 310 325 311 if ( sfConfig::get('sf_logging_enabled'))312 { 313 $this-> context->getLogger()->info('{sfRouting} connect "'.$route.'"'.($suffix ? ' ("'.$suffix.'" suffix)' : ''));326 if (!is_null($this->logger)) 327 { 328 $this->logger->info(sprintf('{sfRouting} connect "%s"%s', $route, $suffix ? ' ("'.$suffix.'" suffix)' : '')); 314 329 } 315 330 … … 328 343 public function generate($name, $params, $querydiv = '/', $divider = '/', $equals = '/') 329 344 { 330 $globalDefaults = sfConfig::get('sf_routing_defaults', null);331 332 345 // named route? 333 346 if ($name) … … 339 352 340 353 list($url, $regexp, $names, $namesHash, $defaults, $requirements, $suffix) = $this->routes[$name]; 341 if ($globalDefaults !== null) 342 { 343 $defaults = array_merge($defaults, $globalDefaults); 344 } 354 $defaults = array_merge($defaults, $this->defaultParameters); 345 355 346 356 // all params must be given … … 360 370 { 361 371 list($url, $regexp, $names, $namesHash, $defaults, $requirements, $suffix) = $route; 362 if ($globalDefaults !== null) 363 { 364 $defaults = array_merge($defaults, $globalDefaults); 365 } 372 $defaults = array_merge($defaults, $this->defaultParameters); 366 373 367 374 $tparams = array_merge($defaults, $params); … … 481 488 // we remove multiple / 482 489 $url = preg_replace('#/+#', '/', $url); 483 foreach ($this->routes as $route_name => $route) 490 $out = array(); 491 $break = false; 492 foreach ($this->routes as $routeName => $route) 484 493 { 485 494 $out = array(); … … 560 569 { 561 570 // we store route name 562 $this->currentRouteName = $route _name;571 $this->currentRouteName = $routeName; 563 572 $this->currentInternalUri = null; 564 573 565 if ( sfConfig::get('sf_logging_enabled'))566 { 567 $this-> context->getLogger()->info('{sfRouting} match route ['.$route_name.'] "'.$route.'"');574 if (!is_null($this->logger)) 575 { 576 $this->logger->info(sprintf('{sfRouting} match route [%s] "%s"', $routeName, $route)); 568 577 } 569 578 … … 572 581 } 573 582 } 583 584 $this->currentRouteParameters = $out; 574 585 575 586 // no route found 576 587 if (!$break) 577 588 { 578 if ( sfConfig::get('sf_logging_enabled'))579 { 580 $this-> context->getLogger()->info('{sfRouting} no matching route found');581 } 582 583 returnnull;584 } 585 586 return $ out;589 if (!is_null($this->logger)) 590 { 591 $this->logger->info('{sfRouting} no matching route found'); 592 } 593 594 $this->currentRouteParameters = null; 595 } 596 597 return $this->currentRouteParameters; 587 598 } 588 599 } trunk/lib/routing/sfRouting.class.php
r4597 r4892 13 13 * 14 14 * @package symfony 15 * @subpackage controller15 * @subpackage routing 16 16 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 17 17 * @version SVN: $Id$ … … 20 20 { 21 21 protected 22 $context = null, 23 $parameterHolder = null; 22 $logger = null, 23 $defaultParameters = array(), 24 $parameterHolder = null; 24 25 25 26 /** … … 48 49 * Initializes this sfRouting instance. 49 50 * 50 * @param sf Context A sfContext instance.51 * @param array An associative array of initialization parameters.51 * @param sfLogger A sfLogger instance (or null) 52 * @param array An associative array of initialization parameters. 52 53 * 53 * @return bool true, if initialization completes successfully, otherwise false.54 * @return bool true, if initialization completes successfully, otherwise false. 54 55 * 55 56 * @throws <b>sfInitializationException</b> If an error occurs while initializing this User. 56 57 */ 57 public function initialize( $context, $parameters = array())58 public function initialize(sfLogger $logger = null, $parameters = array()) 58 59 { 59 $this->context = $context; 60 $this->logger = $logger; 61 62 if (!isset($parameters['default_module'])) 63 { 64 $parameters['default_module'] = 'default'; 65 } 66 67 if (!isset($parameters['default_action'])) 68 { 69 $parameters['default_action'] = 'index'; 70 } 60 71 61 72 $this->parameterHolder = new sfParameterHolder(); … … 124 135 125 136 /** 137 * Sets a default parameter for URL generation. 138 * 139 * @param string The key 140 * @param string The value 141 */ 142 public function setDefaultParameter($key, $value) 143 { 144 $this->defaultParameters[$key] = $value; 145 } 146 147 /** 148 * Sets the default parameters for URL generation. 149 * 150 * @param array An array of default parameters 151 */ 152 public function setDefaultParameters($parameters) 153 { 154 $this->defaultParameters = $parameters; 155 } 156 157 /** 126 158 * Execute the shutdown procedure. 127 159 * trunk/lib/user/sfUser.class.php
r4597 r4892 131 131 } 132 132 133 // addthe culture in the routing default parameters134 sfConfig::set('sf_routing_defaults', array_merge((array) sfConfig::get('sf_routing_defaults'), array('sf_culture' => $culture)));133 // change the culture in the routing default parameters 134 $this->context->getRouting()->setDefaultParameter('sf_culture', $culture); 135 135 } 136 136 } trunk/test/unit/action/sfComponentTest.php
r4440 r4892 20 20 21 21 $context = sfContext::getInstance(array( 22 'routing' => 'sfNoRouting',23 'request' => 'sfWebRequest',22 'routing' => 'sfNoRouting', 23 'request' => 'sfWebRequest', 24 24 )); 25 25 trunk/test/unit/response/sfWebResponseTest.php
r4534 r4892 247 247 248 248 sfLoader::loadHelpers(array('Helper', 'Tag', 'Url', 'Asset')); 249 $_SERVER['SCRIPT_NAME'] = ''; 249 250 250 251 // use and get javascript() trunk/test/unit/routing/sfNoRoutingTest.php
r4440 r4892 10 10 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 require_once($_test_dir.'/unit/sfContextMock.class.php');13 12 14 13 $t = new lime_test(12, new lime_output_color()); 15 14 16 sfConfig::set('sf_default_module', 'main'); 17 sfConfig::set('sf_default_action', 'index'); 18 19 $context = sfContext::getInstance(array('routing' => 'sfNoRouting', 'request' => 'sfWebRequest')); 20 $request = $context->request; 21 $routing = $context->routing; 15 $routing = new sfNoRouting(); 16 $routing->initialize(); 22 17 23 18 // ->getCurrentInternalUri() … … 25 20 26 21 $_GET = array(); 27 $request->initialize($context); 28 $t->is($routing->getCurrentInternalUri(), 'main/index', '->getCurrentInternalUri() returns the current internal URI'); 22 $t->is($routing->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the current internal URI'); 29 23 30 24 $_GET = array('foo' => 'bar'); 31 $request->initialize($context); 32 $t->is($routing->getCurrentInternalUri(), 'main/index?foo=bar', '->getCurrentInternalUri() returns the current internal URI'); 25 $t->is($routing->getCurrentInternalUri(), 'default/index?foo=bar', '->getCurrentInternalUri() returns the current internal URI'); 33 26 34 27 $_GET = array('module' => 'foo', 'action' => 'bar'); 35 $request->initialize($context);36 28 $t->is($routing->getCurrentInternalUri(), 'foo/bar', '->getCurrentInternalUri() returns the current internal URI'); 37 29 38 30 $_GET = array('module' => 'foo', 'action' => 'bar', 'foo' => 'bar'); 39 $request->initialize($context);40 31 $t->is($routing->getCurrentInternalUri(), 'foo/bar?foo=bar', '->getCurrentInternalUri() returns the current internal URI'); 41 32 42 33 // ->parse() 43 34 $t->diag('parse'); 44 $t->is($routing->parse(''), array( 'module' => 'main', 'action' => 'index'), '->parse() parses a URL');45 $t->is($routing->parse('?foo=bar'), array( 'foo' => 'bar', 'module' => 'main', 'action' => 'index'), '->parse() parses a URL');46 $t->is($routing->parse('?module=foo&action=bar'), array( 'module' => 'foo', 'action' => 'bar'), '->parse() parses a URL');47 $t->is($routing->parse('?module=foo&action=bar&foo=bar'), array( 'foo' => 'bar', 'module' => 'foo', 'action' => 'bar'), '->parse() parses a URL');35 $t->is($routing->parse(''), array(), '->parse() parses a URL'); 36 $t->is($routing->parse('?foo=bar'), array(), '->parse() parses a URL'); 37 $t->is($routing->parse('?module=foo&action=bar'), array(), '->parse() parses a URL'); 38 $t->is($routing->parse('?module=foo&action=bar&foo=bar'), array(), '->parse() parses a URL'); 48 39 49 40 // ->generate() trunk/test/unit/routing/sfPatternRoutingTest.php
r4435 r4892 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(6 1, new lime_output_color());13 $t = new lime_test(63, new lime_output_color()); 14 14 15 15 class sfPatternRoutingTest extends sfPatternRouting … … 23 23 // public methods 24 24 $r = new sfPatternRoutingTest(); 25 $r->initialize(); 25 26 foreach (array('clearRoutes', 'connect', 'generate', 'getCurrentInternalUri', 'getCurrentRouteName', 'getRoutes', 'hasRoutes', 'parse', 'setRoutes') as $method) 26 27 { … … 80 81 // suffix 81 82 $r->clearRoutes(); 82 sfConfig::set('sf_suffix','.html');83 $r->setDefaultSuffix('.html'); 83 84 $r->connect('foo', '/foo/:module/:action/:param.foo', array('module' => 'default', 'action' => 'index')); 84 85 $url = '/foo/default/index/foo.foo'; … … 93 94 $t->is($r->generate('', array('module' => 'default', 'action' => 'index1', 'param1' => 'foo1')), $url1, '->generate() routes can remove the default suffix'); 94 95 $t->is($r->generate('', array('module' => 'default', 'action' => 'index2', 'param2' => 'foo2')), $url2, '->generate() routes does not have suffix when they end by /'); 95 $t->is($r->generate('', array('module' => 'default', 'action' => 'index3', 'param3' => 'foo3')), $url3, '->generate() routes takes a suffix defined by "sf_suffix"');96 $t->is($r->generate('', array('module' => 'default', 'action' => 'index3', 'param3' => 'foo3')), $url3, '->generate() routes takes a suffix defined by the "suffix" parameter'); 96 97 97 98 $t->is($r->parse($url), array('module' => 'default', 'action' => 'index', 'param' => 'foo'), '->parse() routes can override the default suffix'); 98 99 $t->is($r->parse($url1), array('module' => 'default', 'action' => 'index1', 'param1' => 'foo1'), '->parse() routes can remove the default suffix'); 99 100 $t->is($r->parse($url2), array('module' => 'default', 'action' => 'index2', 'param2' => 'foo2'), '->parse() routes does not have suffix when they end by /'); 100 $t->is($r->parse($url3), array('module' => 'default', 'action' => 'index3', 'param3' => 'foo3'), '->parse() routes takes a suffix defined by "sf_suffix"');101 sfConfig::set('sf_suffix', '');101 $t->is($r->parse($url3), array('module' => 'default', 'action' => 'index3', 'param3' => 'foo3'), '->parse() routes takes a suffix defined by the "suffix" parameter'); 102 $r->setDefaultSuffix('.'); 102 103 103 104 // duplicate names … … 232 233 233 234 // routing defaults parameters 234 sfConfig::set('sf_routing_defaults', array('foo' => 'bar'));235 $r->setDefaultParameter('foo', 'bar'); 235 236 $r->clearRoutes(); 236 237 $r->connect('test', '/test/:foo/:id', array('module' => 'default', 'action' => 'index')); 237 238 $params = array('module' => 'default', 'action' => 'index', 'id' => 12); 238 239 $url = '/test/bar/12'; 239 $t->is($r->generate('', $params), $url, '->generate() merge parameters with defaults from "sf_routing_defaults"'); 240 $t->is($r->generate('', $params), $url, '->generate() merge parameters with defaults parameters'); 241 $r->setDefaultParameters(array()); 240 242 241 243 // ->appendRoute() … … 261 263 $p_route_names = array_keys($r->getRoutes()); 262 264 $t->is(implode('-', $p_route_names), implode('-', array_reverse($route_names)), '->prependRoute() adds new routes at the beginning of the existings ones'); 265 266 // ->getCurrentInternalUri() 267 $t->diag('->getCurrentInternalUri()'); 268 $r->clearRoutes(); 269 $r->connect('test', '/:module', array('action' => 'index')); 270 $r->connect('test1', '/:module/:action/*', array()); 271 $r->parse('/'); 272 $t->is($r->getCurrentInternalUri(), 'default/index', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); 273 $r->parse('/foo/bar/bar/foo/a/b'); 274 $t->is($r->getCurrentInternalUri(), 'foo/bar?a=b&bar=foo', '->getCurrentInternalUri() returns the internal URI for last parsed URL'); trunk/test/unit/sfContextMock.class.php
r4890 r4892 80 80 } 81 81 82 public function inject($type, $class )82 public function inject($type, $class, $parameters = array()) 83 83 { 84 84 $object = new $class(); 85 85 if (method_exists($object, 'initialize')) 86 86 { 87 $object->initialize($this);87 in_array($type, array('routing')) ? $object->initialize(null, $parameters) : $object->initialize($this, $parameters); 88 88 } 89 89 $this->$type = $object; trunk/test/unit/user/sfBasicSecurityUserTest.php
r4440 r4892 26 26 27 27 $context = sfContext::getInstance(array( 28 'routing' => 'sfPatternRouting', 28 29 'request' => 'myRequest', 29 'user' => 'sfBasicSecurityUser',30 'user' => 'sfBasicSecurityUser', 30 31 )); 31 32 $user = $context->user;