UrlRuleTest.php 16.9 KB
Newer Older
Qiang Xue committed
1 2 3 4
<?php

namespace yiiunit\framework\web;

Qiang Xue committed
5
use yii\web\UrlManager;
Qiang Xue committed
6
use yii\web\UrlRule;
Qiang Xue committed
7
use yii\web\Request;
Alexander Makarov committed
8
use yiiunit\TestCase;
Qiang Xue committed
9

10 11 12
/**
 * @group web
 */
Alexander Makarov committed
13
class UrlRuleTest extends TestCase
Qiang Xue committed
14
{
15 16 17 18 19 20
	protected function setUp()
	{
		parent::setUp();
		$this->mockApplication();
	}

Qiang Xue committed
21 22
	public function testCreateUrl()
	{
Alexander Makarov committed
23
		$manager = new UrlManager(['cache' => null]);
Qiang Xue committed
24 25 26 27 28 29
		$suites = $this->getTestsForCreateUrl();
		foreach ($suites as $i => $suite) {
			list ($name, $config, $tests) = $suite;
			$rule = new UrlRule($config);
			foreach ($tests as $j => $test) {
				list ($route, $params, $expected) = $test;
Qiang Xue committed
30
				$url = $rule->createUrl($manager, $route, $params);
Qiang Xue committed
31 32 33 34 35
				$this->assertEquals($expected, $url, "Test#$i-$j: $name");
			}
		}
	}

Qiang Xue committed
36
	public function testParseRequest()
Qiang Xue committed
37
	{
Alexander Makarov committed
38 39
		$manager = new UrlManager(['cache' => null]);
		$request = new Request(['hostInfo' => 'http://en.example.com']);
Qiang Xue committed
40
		$suites = $this->getTestsForParseRequest();
Qiang Xue committed
41 42 43 44
		foreach ($suites as $i => $suite) {
			list ($name, $config, $tests) = $suite;
			$rule = new UrlRule($config);
			foreach ($tests as $j => $test) {
Qiang Xue committed
45
				$request->pathInfo = $test[0];
Qiang Xue committed
46
				$route = $test[1];
Alexander Makarov committed
47
				$params = isset($test[2]) ? $test[2] : [];
Qiang Xue committed
48
				$result = $rule->parseRequest($manager, $request);
Qiang Xue committed
49 50 51
				if ($route === false) {
					$this->assertFalse($result, "Test#$i-$j: $name");
				} else {
Alexander Makarov committed
52
					$this->assertEquals([$route, $params], $result, "Test#$i-$j: $name");
Qiang Xue committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66
				}
			}
		}
	}

	protected function getTestsForCreateUrl()
	{
		// structure of each test
		//   message for the test
		//   config for the URL rule
		//   list of inputs and outputs
		//     route
		//     params
		//     expected output
Alexander Makarov committed
67 68
		return [
			[
Qiang Xue committed
69
				'empty pattern',
Alexander Makarov committed
70
				[
Qiang Xue committed
71 72
					'pattern' => '',
					'route' => 'post/index',
Alexander Makarov committed
73 74 75 76 77 78 79 80
				],
				[
					['post/index', [], ''],
					['comment/index', [], false],
					['post/index', ['page' => 1], '?page=1'],
				],
			],
			[
Qiang Xue committed
81
				'without param',
Alexander Makarov committed
82
				[
Qiang Xue committed
83 84
					'pattern' => 'posts',
					'route' => 'post/index',
Alexander Makarov committed
85 86 87 88 89 90 91 92
				],
				[
					['post/index', [], 'posts'],
					['comment/index', [], false],
					['post/index', ['page' => 1], 'posts?page=1'],
				],
			],
			[
Qiang Xue committed
93
				'parsing only',
Alexander Makarov committed
94
				[
Qiang Xue committed
95 96 97
					'pattern' => 'posts',
					'route' => 'post/index',
					'mode' => UrlRule::PARSING_ONLY,
Alexander Makarov committed
98 99 100 101 102 103
				],
				[
					['post/index', [], false],
				],
			],
			[
Qiang Xue committed
104
				'with param',
Alexander Makarov committed
105
				[
Qiang Xue committed
106 107
					'pattern' => 'post/<page>',
					'route' => 'post/index',
Alexander Makarov committed
108 109 110 111 112 113 114 115 116
				],
				[
					['post/index', [], false],
					['comment/index', [], false],
					['post/index', ['page' => 1], 'post/1'],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post/1?tag=a'],
				],
			],
			[
Qiang Xue committed
117
				'with param requirement',
Alexander Makarov committed
118
				[
Qiang Xue committed
119 120
					'pattern' => 'post/<page:\d+>',
					'route' => 'post/index',
Alexander Makarov committed
121 122 123 124 125 126 127 128
				],
				[
					['post/index', ['page' => 'abc'], false],
					['post/index', ['page' => 1], 'post/1'],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post/1?tag=a'],
				],
			],
			[
Qiang Xue committed
129
				'with multiple params',
Alexander Makarov committed
130
				[
Qiang Xue committed
131 132
					'pattern' => 'post/<page:\d+>-<tag>',
					'route' => 'post/index',
Alexander Makarov committed
133 134 135 136 137 138 139 140
				],
				[
					['post/index', ['page' => '1abc'], false],
					['post/index', ['page' => 1], false],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post/1-a'],
				],
			],
			[
Qiang Xue committed
141
				'with optional param',
Alexander Makarov committed
142
				[
Qiang Xue committed
143 144
					'pattern' => 'post/<page:\d+>/<tag>',
					'route' => 'post/index',
Alexander Makarov committed
145 146 147 148 149 150 151 152 153 154
					'defaults' => ['page' => 1],
				],
				[
					['post/index', ['page' => 1], false],
					['post/index', ['page' => '1abc', 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post/a'],
					['post/index', ['page' => 2, 'tag' => 'a'], 'post/2/a'],
				],
			],
			[
Qiang Xue committed
155
				'with optional param not in pattern',
Alexander Makarov committed
156
				[
Qiang Xue committed
157 158
					'pattern' => 'post/<tag>',
					'route' => 'post/index',
Alexander Makarov committed
159 160 161 162 163 164 165 166 167 168
					'defaults' => ['page' => 1],
				],
				[
					['post/index', ['page' => 1], false],
					['post/index', ['page' => '1abc', 'tag' => 'a'], false],
					['post/index', ['page' => 2, 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post/a'],
				],
			],
			[
Qiang Xue committed
169
				'multiple optional params',
Alexander Makarov committed
170
				[
Qiang Xue committed
171 172
					'pattern' => 'post/<page:\d+>/<tag>/<sort:yes|no>',
					'route' => 'post/index',
Alexander Makarov committed
173 174 175 176 177 178 179 180 181 182 183 184 185
					'defaults' => ['page' => 1, 'sort' => 'yes'],
				],
				[
					['post/index', ['page' => 1], false],
					['post/index', ['page' => '1abc', 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a', 'sort' => 'YES'], false],
					['post/index', ['page' => 1, 'tag' => 'a', 'sort' => 'yes'], 'post/a'],
					['post/index', ['page' => 2, 'tag' => 'a', 'sort' => 'yes'], 'post/2/a'],
					['post/index', ['page' => 2, 'tag' => 'a', 'sort' => 'no'], 'post/2/a/no'],
					['post/index', ['page' => 1, 'tag' => 'a', 'sort' => 'no'], 'post/a/no'],
				],
			],
			[
Qiang Xue committed
186
				'optional param and required param separated by dashes',
Alexander Makarov committed
187
				[
Qiang Xue committed
188 189
					'pattern' => 'post/<page:\d+>-<tag>',
					'route' => 'post/index',
Alexander Makarov committed
190 191 192 193 194 195 196 197 198 199
					'defaults' => ['page' => 1],
				],
				[
					['post/index', ['page' => 1], false],
					['post/index', ['page' => '1abc', 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post/-a'],
					['post/index', ['page' => 2, 'tag' => 'a'], 'post/2-a'],
				],
			],
			[
Qiang Xue committed
200
				'optional param at the end',
Alexander Makarov committed
201
				[
Qiang Xue committed
202 203
					'pattern' => 'post/<tag>/<page:\d+>',
					'route' => 'post/index',
Alexander Makarov committed
204 205 206 207 208 209 210 211 212 213
					'defaults' => ['page' => 1],
				],
				[
					['post/index', ['page' => 1], false],
					['post/index', ['page' => '1abc', 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post/a'],
					['post/index', ['page' => 2, 'tag' => 'a'], 'post/a/2'],
				],
			],
			[
Qiang Xue committed
214
				'consecutive optional params',
Alexander Makarov committed
215
				[
Qiang Xue committed
216 217
					'pattern' => 'post/<page:\d+>/<tag>',
					'route' => 'post/index',
Alexander Makarov committed
218 219 220 221 222 223 224 225 226 227 228 229
					'defaults' => ['page' => 1, 'tag' => 'a'],
				],
				[
					['post/index', ['page' => 1], false],
					['post/index', ['page' => '1abc', 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post'],
					['post/index', ['page' => 2, 'tag' => 'a'], 'post/2'],
					['post/index', ['page' => 1, 'tag' => 'b'], 'post/b'],
					['post/index', ['page' => 2, 'tag' => 'b'], 'post/2/b'],
				],
			],
			[
Qiang Xue committed
230
				'consecutive optional params separated by dash',
Alexander Makarov committed
231
				[
Qiang Xue committed
232 233
					'pattern' => 'post/<page:\d+>-<tag>',
					'route' => 'post/index',
Alexander Makarov committed
234 235 236 237 238 239 240 241 242 243 244 245
					'defaults' => ['page' => 1, 'tag' => 'a'],
				],
				[
					['post/index', ['page' => 1], false],
					['post/index', ['page' => '1abc', 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a'], 'post/-'],
					['post/index', ['page' => 1, 'tag' => 'b'], 'post/-b'],
					['post/index', ['page' => 2, 'tag' => 'a'], 'post/2-'],
					['post/index', ['page' => 2, 'tag' => 'b'], 'post/2-b'],
				],
			],
			[
Qiang Xue committed
246
				'route has parameters',
Alexander Makarov committed
247
				[
Qiang Xue committed
248 249
					'pattern' => '<controller>/<action>',
					'route' => '<controller>/<action>',
Alexander Makarov committed
250 251 252 253 254 255 256 257
					'defaults' => [],
				],
				[
					['post/index', ['page' => 1], 'post/index?page=1'],
					['module/post/index', [], false],
				],
			],
			[
Qiang Xue committed
258
				'route has parameters with regex',
Alexander Makarov committed
259
				[
Qiang Xue committed
260 261
					'pattern' => '<controller:post|comment>/<action>',
					'route' => '<controller>/<action>',
Alexander Makarov committed
262 263 264 265 266 267 268 269 270 271 272 273
					'defaults' => [],
				],
				[
					['post/index', ['page' => 1], 'post/index?page=1'],
					['comment/index', ['page' => 1], 'comment/index?page=1'],
					['test/index', ['page' => 1], false],
					['post', [], false],
					['module/post/index', [], false],
					['post/index', ['controller' => 'comment'], 'post/index?controller=comment'],
				],
			],
			[
Qiang Xue committed
274
				'route has default parameter',
Alexander Makarov committed
275
				[
Qiang Xue committed
276 277
					'pattern' => '<controller:post|comment>/<action>',
					'route' => '<controller>/<action>',
Alexander Makarov committed
278 279 280 281 282 283 284 285 286 287 288
					'defaults' => ['action' => 'index'],
				],
				[
					['post/view', ['page' => 1], 'post/view?page=1'],
					['comment/view', ['page' => 1], 'comment/view?page=1'],
					['test/view', ['page' => 1], false],
					['test/index', ['page' => 1], false],
					['post/index', ['page' => 1], 'post?page=1'],
				],
			],
			[
Qiang Xue committed
289
				'empty pattern with suffix',
Alexander Makarov committed
290
				[
Qiang Xue committed
291 292 293
					'pattern' => '',
					'route' => 'post/index',
					'suffix' => '.html',
Alexander Makarov committed
294 295 296 297 298 299 300 301
				],
				[
					['post/index', [], ''],
					['comment/index', [], false],
					['post/index', ['page' => 1], '?page=1'],
				],
			],
			[
Qiang Xue committed
302
				'regular pattern with suffix',
Alexander Makarov committed
303
				[
Qiang Xue committed
304 305 306
					'pattern' => 'posts',
					'route' => 'post/index',
					'suffix' => '.html',
Alexander Makarov committed
307 308 309 310 311 312 313 314
				],
				[
					['post/index', [], 'posts.html'],
					['comment/index', [], false],
					['post/index', ['page' => 1], 'posts.html?page=1'],
				],
			],
			[
Qiang Xue committed
315
				'empty pattern with slash suffix',
Alexander Makarov committed
316
				[
Qiang Xue committed
317 318 319
					'pattern' => '',
					'route' => 'post/index',
					'suffix' => '/',
Alexander Makarov committed
320 321 322 323 324 325 326 327
				],
				[
					['post/index', [], ''],
					['comment/index', [], false],
					['post/index', ['page' => 1], '?page=1'],
				],
			],
			[
Qiang Xue committed
328
				'regular pattern with slash suffix',
Alexander Makarov committed
329
				[
Qiang Xue committed
330 331 332
					'pattern' => 'posts',
					'route' => 'post/index',
					'suffix' => '/',
Alexander Makarov committed
333 334 335 336 337 338 339 340
				],
				[
					['post/index', [], 'posts/'],
					['comment/index', [], false],
					['post/index', ['page' => 1], 'posts/?page=1'],
				],
			],
			[
341
				'with host info',
Alexander Makarov committed
342
				[
Qiang Xue committed
343
					'pattern' => 'post/<page:\d+>/<tag>',
344
					'route' => 'post/index',
Alexander Makarov committed
345
					'defaults' => ['page' => 1],
Qiang Xue committed
346
					'host' => 'http://<lang:en|fr>.example.com',
Alexander Makarov committed
347 348 349 350 351 352
				],
				[
					['post/index', ['page' => 1, 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a', 'lang' => 'en'], 'http://en.example.com/post/a'],
				],
			],
353 354 355 356 357 358 359 360 361 362 363 364
			[
				'with host info in pattern',
				[
					'pattern' => 'http://<lang:en|fr>.example.com/post/<page:\d+>/<tag>',
					'route' => 'post/index',
					'defaults' => ['page' => 1],
				],
				[
					['post/index', ['page' => 1, 'tag' => 'a'], false],
					['post/index', ['page' => 1, 'tag' => 'a', 'lang' => 'en'], 'http://en.example.com/post/a'],
				],
			],
Alexander Makarov committed
365
		];
Qiang Xue committed
366 367
	}

Qiang Xue committed
368
	protected function getTestsForParseRequest()
Qiang Xue committed
369 370 371 372 373 374 375 376
	{
		// structure of each test
		//   message for the test
		//   config for the URL rule
		//   list of inputs and outputs
		//     pathInfo
		//     expected route, or false if the rule doesn't apply
		//     expected params, or not set if empty
Alexander Makarov committed
377 378
		return [
			[
Qiang Xue committed
379
				'empty pattern',
Alexander Makarov committed
380
				[
Qiang Xue committed
381 382
					'pattern' => '',
					'route' => 'post/index',
Alexander Makarov committed
383 384 385 386 387 388 389
				],
				[
					['', 'post/index'],
					['a', false],
				],
			],
			[
Qiang Xue committed
390
				'without param',
Alexander Makarov committed
391
				[
Qiang Xue committed
392 393
					'pattern' => 'posts',
					'route' => 'post/index',
Alexander Makarov committed
394 395 396 397 398 399 400
				],
				[
					['posts', 'post/index'],
					['a', false],
				],
			],
			[
401
				'with dot', // https://github.com/yiisoft/yii/issues/2945
Alexander Makarov committed
402
				[
403 404
					'pattern' => 'posts.html',
					'route' => 'post/index',
Alexander Makarov committed
405 406 407 408 409 410 411
				],
				[
					['posts.html', 'post/index'],
					['postsahtml', false],
				],
			],
			[
Qiang Xue committed
412
				'creation only',
Alexander Makarov committed
413
				[
Qiang Xue committed
414 415 416
					'pattern' => 'posts',
					'route' => 'post/index',
					'mode' => UrlRule::CREATION_ONLY,
Alexander Makarov committed
417 418 419 420 421 422
				],
				[
					['posts', false],
				],
			],
			[
Qiang Xue committed
423
				'with param',
Alexander Makarov committed
424
				[
Qiang Xue committed
425 426
					'pattern' => 'post/<page>',
					'route' => 'post/index',
Alexander Makarov committed
427 428 429 430 431 432 433 434 435
				],
				[
					['post/1', 'post/index', ['page' => '1']],
					['post/a', 'post/index', ['page' => 'a']],
					['post', false],
					['posts', false],
				],
			],
			[
Qiang Xue committed
436
				'with param requirement',
Alexander Makarov committed
437
				[
Qiang Xue committed
438 439
					'pattern' => 'post/<page:\d+>',
					'route' => 'post/index',
Alexander Makarov committed
440 441 442 443 444 445 446 447
				],
				[
					['post/1', 'post/index', ['page' => '1']],
					['post/a', false],
					['post/1/a', false],
				],
			],
			[
Qiang Xue committed
448
				'with multiple params',
Alexander Makarov committed
449
				[
Qiang Xue committed
450 451
					'pattern' => 'post/<page:\d+>-<tag>',
					'route' => 'post/index',
Alexander Makarov committed
452 453 454 455 456 457 458 459 460
				],
				[
					['post/1-a', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/a', false],
					['post/1', false],
					['post/1/a', false],
				],
			],
			[
Qiang Xue committed
461
				'with optional param',
Alexander Makarov committed
462
				[
Qiang Xue committed
463 464
					'pattern' => 'post/<page:\d+>/<tag>',
					'route' => 'post/index',
Alexander Makarov committed
465 466 467 468 469 470 471 472 473 474
					'defaults' => ['page' => 1],
				],
				[
					['post/1/a', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/2/a', 'post/index', ['page' => '2', 'tag' => 'a']],
					['post/a', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/1', 'post/index', ['page' => '1', 'tag' => '1']],
				],
			],
			[
Qiang Xue committed
475
				'with optional param not in pattern',
Alexander Makarov committed
476
				[
Qiang Xue committed
477 478
					'pattern' => 'post/<tag>',
					'route' => 'post/index',
Alexander Makarov committed
479 480 481 482 483 484 485 486 487
					'defaults' => ['page' => 1],
				],
				[
					['post/a', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/1', 'post/index', ['page' => '1', 'tag' => '1']],
					['post', false],
				],
			],
			[
Qiang Xue committed
488
				'multiple optional params',
Alexander Makarov committed
489
				[
Qiang Xue committed
490 491
					'pattern' => 'post/<page:\d+>/<tag>/<sort:yes|no>',
					'route' => 'post/index',
Alexander Makarov committed
492 493 494 495 496 497 498 499 500 501 502 503 504
					'defaults' => ['page' => 1, 'sort' => 'yes'],
				],
				[
					['post/1/a/yes', 'post/index', ['page' => '1', 'tag' => 'a', 'sort' => 'yes']],
					['post/1/a/no', 'post/index', ['page' => '1', 'tag' => 'a', 'sort' => 'no']],
					['post/2/a/no', 'post/index', ['page' => '2', 'tag' => 'a', 'sort' => 'no']],
					['post/2/a', 'post/index', ['page' => '2', 'tag' => 'a', 'sort' => 'yes']],
					['post/a/no', 'post/index', ['page' => '1', 'tag' => 'a', 'sort' => 'no']],
					['post/a', 'post/index', ['page' => '1', 'tag' => 'a', 'sort' => 'yes']],
					['post', false],
				],
			],
			[
Qiang Xue committed
505
				'optional param and required param separated by dashes',
Alexander Makarov committed
506
				[
Qiang Xue committed
507 508
					'pattern' => 'post/<page:\d+>-<tag>',
					'route' => 'post/index',
Alexander Makarov committed
509 510 511 512 513 514 515 516 517 518 519
					'defaults' => ['page' => 1],
				],
				[
					['post/1-a', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/2-a', 'post/index', ['page' => '2', 'tag' => 'a']],
					['post/-a', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/a', false],
					['post-a', false],
				],
			],
			[
Qiang Xue committed
520
				'optional param at the end',
Alexander Makarov committed
521
				[
Qiang Xue committed
522 523
					'pattern' => 'post/<tag>/<page:\d+>',
					'route' => 'post/index',
Alexander Makarov committed
524 525 526 527 528 529 530 531 532 533 534
					'defaults' => ['page' => 1],
				],
				[
					['post/a/1', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/a/2', 'post/index', ['page' => '2', 'tag' => 'a']],
					['post/a', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/2', 'post/index', ['page' => '1', 'tag' => '2']],
					['post', false],
				],
			],
			[
Qiang Xue committed
535
				'consecutive optional params',
Alexander Makarov committed
536
				[
Qiang Xue committed
537 538
					'pattern' => 'post/<page:\d+>/<tag>',
					'route' => 'post/index',
Alexander Makarov committed
539 540 541 542 543 544 545 546 547 548 549
					'defaults' => ['page' => 1, 'tag' => 'a'],
				],
				[
					['post/2/b', 'post/index', ['page' => '2', 'tag' => 'b']],
					['post/2', 'post/index', ['page' => '2', 'tag' => 'a']],
					['post', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post/b', 'post/index', ['page' => '1', 'tag' => 'b']],
					['post//b', false],
				],
			],
			[
Qiang Xue committed
550
				'consecutive optional params separated by dash',
Alexander Makarov committed
551
				[
Qiang Xue committed
552 553
					'pattern' => 'post/<page:\d+>-<tag>',
					'route' => 'post/index',
Alexander Makarov committed
554 555 556 557 558 559 560 561 562 563 564
					'defaults' => ['page' => 1, 'tag' => 'a'],
				],
				[
					['post/2-b', 'post/index', ['page' => '2', 'tag' => 'b']],
					['post/2-', 'post/index', ['page' => '2', 'tag' => 'a']],
					['post/-b', 'post/index', ['page' => '1', 'tag' => 'b']],
					['post/-', 'post/index', ['page' => '1', 'tag' => 'a']],
					['post', false],
				],
			],
			[
Qiang Xue committed
565
				'route has parameters',
Alexander Makarov committed
566
				[
Qiang Xue committed
567 568
					'pattern' => '<controller>/<action>',
					'route' => '<controller>/<action>',
Alexander Makarov committed
569 570 571 572 573 574 575 576
					'defaults' => [],
				],
				[
					['post/index', 'post/index'],
					['module/post/index', false],
				],
			],
			[
Qiang Xue committed
577
				'route has parameters with regex',
Alexander Makarov committed
578
				[
Qiang Xue committed
579 580
					'pattern' => '<controller:post|comment>/<action>',
					'route' => '<controller>/<action>',
Alexander Makarov committed
581 582 583 584 585 586 587 588 589 590 591
					'defaults' => [],
				],
				[
					['post/index', 'post/index'],
					['comment/index', 'comment/index'],
					['test/index', false],
					['post', false],
					['module/post/index', false],
				],
			],
			[
Qiang Xue committed
592
				'route has default parameter',
Alexander Makarov committed
593
				[
Qiang Xue committed
594 595
					'pattern' => '<controller:post|comment>/<action>',
					'route' => '<controller>/<action>',
Alexander Makarov committed
596 597 598 599 600 601 602 603 604 605 606 607 608
					'defaults' => ['action' => 'index'],
				],
				[
					['post/view', 'post/view'],
					['comment/view', 'comment/view'],
					['test/view', false],
					['post', 'post/index'],
					['posts', false],
					['test', false],
					['index', false],
				],
			],
			[
Qiang Xue committed
609
				'empty pattern with suffix',
Alexander Makarov committed
610
				[
Qiang Xue committed
611 612 613
					'pattern' => '',
					'route' => 'post/index',
					'suffix' => '.html',
Alexander Makarov committed
614 615 616 617 618 619 620 621
				],
				[
					['', 'post/index'],
					['.html', false],
					['a.html', false],
				],
			],
			[
Qiang Xue committed
622
				'regular pattern with suffix',
Alexander Makarov committed
623
				[
Qiang Xue committed
624 625 626
					'pattern' => 'posts',
					'route' => 'post/index',
					'suffix' => '.html',
Alexander Makarov committed
627 628 629 630 631 632 633 634 635 636
				],
				[
					['posts.html', 'post/index'],
					['posts', false],
					['posts.HTML', false],
					['a.html', false],
					['a', false],
				],
			],
			[
Qiang Xue committed
637
				'empty pattern with slash suffix',
Alexander Makarov committed
638
				[
Qiang Xue committed
639 640 641
					'pattern' => '',
					'route' => 'post/index',
					'suffix' => '/',
Alexander Makarov committed
642 643 644 645 646 647 648
				],
				[
					['', 'post/index'],
					['a', false],
				],
			],
			[
Qiang Xue committed
649
				'regular pattern with slash suffix',
Alexander Makarov committed
650
				[
Qiang Xue committed
651 652 653
					'pattern' => 'posts',
					'route' => 'post/index',
					'suffix' => '/',
Alexander Makarov committed
654 655 656 657 658 659 660 661
				],
				[
					['posts/', 'post/index'],
					['posts', false],
					['a', false],
				],
			],
			[
662
				'with host info',
Alexander Makarov committed
663
				[
Qiang Xue committed
664
					'pattern' => 'post/<page:\d+>',
665
					'route' => 'post/index',
Qiang Xue committed
666
					'host' => 'http://<lang:en|fr>.example.com',
Alexander Makarov committed
667 668 669 670 671 672 673
				],
				[
					['post/1', 'post/index', ['page' => '1', 'lang' => 'en']],
					['post/a', false],
					['post/1/a', false],
				],
			],
674 675 676 677 678 679 680 681 682 683 684 685
			[
				'with host info in pattern',
				[
					'pattern' => 'http://<lang:en|fr>.example.com/post/<page:\d+>',
					'route' => 'post/index',
				],
				[
					['post/1', 'post/index', ['page' => '1', 'lang' => 'en']],
					['post/a', false],
					['post/1/a', false],
				],
			],
Alexander Makarov committed
686
		];
Qiang Xue committed
687 688
	}
}