| @@ 205-234 (lines=30) @@ | ||
| 202 | /** |
|
| 203 | * @covers Router::generate |
|
| 204 | */ |
|
| 205 | public function testGenerate() |
|
| 206 | { |
|
| 207 | $params = array( |
|
| 208 | 'controller' => 'test', |
|
| 209 | 'action' => 'someaction' |
|
| 210 | ); |
|
| 211 | ||
| 212 | $this->router->map('GET', '/[:controller]/[:action]', function () { |
|
| 213 | }, 'foo_route'); |
|
| 214 | ||
| 215 | $this->assertEquals( |
|
| 216 | ||
| 217 | '/test/someaction', |
|
| 218 | $this->router->generate('foo_route', $params) |
|
| 219 | ||
| 220 | ); |
|
| 221 | ||
| 222 | $params = array( |
|
| 223 | 'controller' => 'test', |
|
| 224 | 'action' => 'someaction', |
|
| 225 | 'type' => 'json' |
|
| 226 | ); |
|
| 227 | ||
| 228 | $this->assertEquals( |
|
| 229 | ||
| 230 | '/test/someaction', |
|
| 231 | $this->router->generate('foo_route', $params) |
|
| 232 | ||
| 233 | ); |
|
| 234 | } |
|
| 235 | ||
| 236 | public function testGenerateWithOptionalUrlParts() |
|
| 237 | { |
|
| @@ 236-265 (lines=30) @@ | ||
| 233 | ); |
|
| 234 | } |
|
| 235 | ||
| 236 | public function testGenerateWithOptionalUrlParts() |
|
| 237 | { |
|
| 238 | $this->router->map('GET', '/[:controller]/[:action].[:type]?', function () { |
|
| 239 | }, 'bar_route'); |
|
| 240 | ||
| 241 | $params = array( |
|
| 242 | 'controller' => 'test', |
|
| 243 | 'action' => 'someaction' |
|
| 244 | ); |
|
| 245 | ||
| 246 | $this->assertEquals( |
|
| 247 | ||
| 248 | '/test/someaction', |
|
| 249 | $this->router->generate('bar_route', $params) |
|
| 250 | ||
| 251 | ); |
|
| 252 | ||
| 253 | $params = array( |
|
| 254 | 'controller' => 'test', |
|
| 255 | 'action' => 'someaction', |
|
| 256 | 'type' => 'json' |
|
| 257 | ); |
|
| 258 | ||
| 259 | $this->assertEquals( |
|
| 260 | ||
| 261 | '/test/someaction.json', |
|
| 262 | $this->router->generate('bar_route', $params) |
|
| 263 | ||
| 264 | ); |
|
| 265 | } |
|
| 266 | ||
| 267 | public function testGenerateWithNonexistingRoute() |
|
| 268 | { |
|
| @@ 324-341 (lines=18) @@ | ||
| 321 | $this->assertFalse($this->router->match('/users/1/create', 'GET')); |
|
| 322 | } |
|
| 323 | ||
| 324 | public function testMatchWithServerVars() |
|
| 325 | { |
|
| 326 | $this->router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route'); |
|
| 327 | ||
| 328 | $_SERVER['REQUEST_URI'] = '/foo/test/do'; |
|
| 329 | $_SERVER['REQUEST_METHOD'] = 'GET'; |
|
| 330 | ||
| 331 | $this->router->setServer($_SERVER); |
|
| 332 | ||
| 333 | $this->assertEquals(array( |
|
| 334 | 'target' => 'foo_action', |
|
| 335 | 'params' => array( |
|
| 336 | 'controller' => 'test', |
|
| 337 | 'action' => 'do' |
|
| 338 | ), |
|
| 339 | 'name' => 'foo_route' |
|
| 340 | ), $this->router->match()); |
|
| 341 | } |
|
| 342 | ||
| 343 | public function testMatchWithOptionalUrlParts() |
|
| 344 | { |
|