Changeset 13322
- Timestamp:
- 11/24/08 23:20:35 (7 months ago)
- Files:
-
- branches/1.2/lib/routing/sfRoute.class.php (modified) (7 diffs)
- branches/1.2/test/unit/routing/sfRouteTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/routing/sfRoute.class.php
r12976 r13322 151 151 152 152 // all $variables must be defined in the $tparams array 153 if (array_diff_key($this->variables, array_filter($tparams)))153 if (array_diff_key($this->variables, $tparams)) 154 154 { 155 155 return false; … … 159 159 foreach (array_keys($this->variables) as $variable) 160 160 { 161 if (!is_null($tparams[$variable]) && !preg_match('#'.$this->requirements[$variable].'#', $tparams[$variable])) 161 if (!$tparams[$variable]) 162 { 163 continue; 164 } 165 166 if (!preg_match('#'.$this->requirements[$variable].'#', $tparams[$variable])) 162 167 { 163 168 return false; … … 168 173 if (!$this->options['extra_parameters_as_query_string']) 169 174 { 170 if (false === strpos($this->regex, '<_star>') && array_diff_key( array_filter($params), $this->variables, $defaults))175 if (false === strpos($this->regex, '<_star>') && array_diff_key($params, $this->variables, $defaults)) 171 176 { 172 177 return false; … … 175 180 176 181 // check that $params does not override a default value that is not a variable 177 foreach ( array_filter($defaults)as $key => $value)182 foreach ($defaults as $key => $value) 178 183 { 179 184 if (!isset($this->variables[$key]) && $tparams[$key] != $value) … … 207 212 208 213 // all params must be given 209 if ($diff = array_diff_key($this->variables, array_filter($tparams)))214 if ($diff = array_diff_key($this->variables, $tparams)) 210 215 { 211 216 throw new InvalidArgumentException(sprintf('The "%s" route has some missing mandatory parameters (%s).', $this->pattern, implode(', ', $diff))); … … 498 503 { 499 504 // a text 500 $this->tokens[] = array('text', $currentSeparator, $match[1] );505 $this->tokens[] = array('text', $currentSeparator, $match[1], null); 501 506 502 507 $currentSeparator = ''; … … 507 512 { 508 513 // a separator 509 $this->tokens[] = array('separator', $currentSeparator, $match[0] );514 $this->tokens[] = array('separator', $currentSeparator, $match[0], null); 510 515 511 516 $currentSeparator = $match[0]; branches/1.2/test/unit/routing/sfRouteTest.php
r12969 r13322 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(4 3, new lime_output_color());13 $t = new lime_test(49, new lime_output_color()); 14 14 15 15 // ->matchesUrl() … … 31 31 $t->is($route->matchesUrl('/'), array('foo' => 'bar'), '->matchesUrl() matches routes with an optional parameter at the end'); 32 32 33 $route = new sfRoute('/:foo', array('foo' => null)); 34 $t->is($route->matchesUrl('/'), array('foo' => null), '->matchesUrl() matches routes with an optional parameter at the end, even if it is null'); 35 36 $route = new sfRoute('/:foo', array('foo' => '')); 37 $t->is($route->matchesUrl('/'), array('foo' => ''), '->matchesUrl() matches routes with an optional parameter at the end, even if it is empty'); 38 39 $route = new sfRoute('/:foo/bar', array('foo' => null)); 40 $t->is($route->matchesUrl('//bar'), false, '->matchesUrl() does not match routes with an empty parameter not at the end'); 41 $t->is($route->matchesUrl('/bar'), false, '->matchesUrl() does not match routes with an empty parameter not at the end'); 42 33 43 $route = new sfRoute('/foo/:foo/bar/:bar', array('foo' => 'bar', 'bar' => 'foo')); 34 44 $t->is($route->matchesUrl('/foo/bar/bar'), array('foo' => 'bar', 'bar' => 'foo'), '->matchesUrl() matches routes with an optional parameter at the end'); … … 70 80 71 81 $route = new sfRoute('/:foo'); 72 $t->is($route->matchesParameters(array('foo' => '')), false, '->matchesParameters() checks that parameters are not empty'); 82 $t->is($route->matchesParameters(array('foo' => '')), true, '->matchesParameters() matches if optional parameters empty'); 83 $t->is($route->matchesParameters(array('foo' => null)), true, '->matchesParameters() matches if optional parameters empty'); 84 85 /* 86 $route = new sfRoute('/:foo/bar'); 87 $t->is($route->matchesParameters(array('foo' => '')), false, '->matchesParameters() does not match is required parameters are empty'); 88 $t->is($route->matchesParameters(array('foo' => null)), false, '->matchesParameters() does not match is required parameters are empty'); 89 */ 73 90 74 91 $route = new sfRoute('/:foo'); … … 105 122 106 123 $route = new sfRoute('/:foo'); 124 $t->is($route->generate(array('foo' => '')), '/', '->generate() generates a route if a variable is empty'); 125 $t->is($route->generate(array('foo' => null)), '/', '->generate() generates a route if a variable is empty'); 126 /* 127 $route = new sfRoute('/:foo/bar'); 107 128 try 108 129 { 109 130 $route->generate(array('foo' => '')); 110 $t->fail('->generate() cannot generate a route if a variable is empty ');131 $t->fail('->generate() cannot generate a route if a variable is empty and mandatory'); 111 132 } 112 133 catch (Exception $e) 113 134 { 114 $t->pass('->generate() cannot generate a route if a variable is empty'); 115 } 116 135 $t->pass('->generate() cannot generate a route if a variable is empty and mandatory'); 136 } 137 try 138 { 139 $route->generate(array('foo' => null)); 140 $t->fail('->generate() cannot generate a route if a variable is empty and mandatory'); 141 } 142 catch (Exception $e) 143 { 144 $t->pass('->generate() cannot generate a route if a variable is empty and mandatory'); 145 } 146 */ 117 147 $route = new sfRoute('/:foo'); 118 148 $t->is($route->generate(array('foo' => 'bar', 'bar' => 'foo')), '/bar?bar=foo', '->generate() generates extra parameters as a query string');

