| @@ 1031-1077 (lines=47) @@ | ||
| 1028 | ); |
|
| 1029 | } |
|
| 1030 | ||
| 1031 | public function testTrailingMatch() |
|
| 1032 | { |
|
| 1033 | $this->klein_app->respond( |
|
| 1034 | '/?[*:trailing]/dog/?', |
|
| 1035 | function ($request) { |
|
| 1036 | echo 'yup'; |
|
| 1037 | } |
|
| 1038 | ); |
|
| 1039 | ||
| 1040 | ||
| 1041 | $this->assertSame( |
|
| 1042 | 'yup', |
|
| 1043 | $this->dispatchAndReturnOutput( |
|
| 1044 | MockRequestFactory::create('/cat/dog') |
|
| 1045 | ) |
|
| 1046 | ); |
|
| 1047 | $this->assertSame( |
|
| 1048 | 'yup', |
|
| 1049 | $this->dispatchAndReturnOutput( |
|
| 1050 | MockRequestFactory::create('/cat/cheese/dog') |
|
| 1051 | ) |
|
| 1052 | ); |
|
| 1053 | $this->assertSame( |
|
| 1054 | 'yup', |
|
| 1055 | $this->dispatchAndReturnOutput( |
|
| 1056 | MockRequestFactory::create('/cat/ball/cheese/dog/') |
|
| 1057 | ) |
|
| 1058 | ); |
|
| 1059 | $this->assertSame( |
|
| 1060 | 'yup', |
|
| 1061 | $this->dispatchAndReturnOutput( |
|
| 1062 | MockRequestFactory::create('/cat/ball/cheese/dog') |
|
| 1063 | ) |
|
| 1064 | ); |
|
| 1065 | $this->assertSame( |
|
| 1066 | 'yup', |
|
| 1067 | $this->dispatchAndReturnOutput( |
|
| 1068 | MockRequestFactory::create('cat/ball/cheese/dog/') |
|
| 1069 | ) |
|
| 1070 | ); |
|
| 1071 | $this->assertSame( |
|
| 1072 | 'yup', |
|
| 1073 | $this->dispatchAndReturnOutput( |
|
| 1074 | MockRequestFactory::create('cat/ball/cheese/dog') |
|
| 1075 | ) |
|
| 1076 | ); |
|
| 1077 | } |
|
| 1078 | ||
| 1079 | public function testTrailingPossessiveMatch() |
|
| 1080 | { |
|
| @@ 284-328 (lines=45) @@ | ||
| 281 | ); |
|
| 282 | } |
|
| 283 | ||
| 284 | public function testEmail() |
|
| 285 | { |
|
| 286 | $this->klein_app->respond( |
|
| 287 | '/[:test_param]', |
|
| 288 | function ($request, $response, $service) { |
|
| 289 | $service->validateParam('test_param') |
|
| 290 | ->notNull() |
|
| 291 | ->isEmail(); |
|
| 292 | ||
| 293 | // We should only get here if we passed our validations |
|
| 294 | echo 'yup!'; |
|
| 295 | } |
|
| 296 | ); |
|
| 297 | ||
| 298 | $this->assertSame( |
|
| 299 | 'yup!', |
|
| 300 | $this->dispatchAndReturnOutput( |
|
| 301 | MockRequestFactory::create('/[email protected]') |
|
| 302 | ) |
|
| 303 | ); |
|
| 304 | $this->assertSame( |
|
| 305 | 'yup!', |
|
| 306 | $this->dispatchAndReturnOutput( |
|
| 307 | MockRequestFactory::create('/[email protected]') |
|
| 308 | ) |
|
| 309 | ); |
|
| 310 | $this->assertSame( |
|
| 311 | 'fail', |
|
| 312 | $this->dispatchAndReturnOutput( |
|
| 313 | MockRequestFactory::create('/test') |
|
| 314 | ) |
|
| 315 | ); |
|
| 316 | $this->assertSame( |
|
| 317 | 'fail', |
|
| 318 | $this->dispatchAndReturnOutput( |
|
| 319 | MockRequestFactory::create('/test@') |
|
| 320 | ) |
|
| 321 | ); |
|
| 322 | $this->assertSame( |
|
| 323 | 'fail', |
|
| 324 | $this->dispatchAndReturnOutput( |
|
| 325 | MockRequestFactory::create('/2 5') |
|
| 326 | ) |
|
| 327 | ); |
|
| 328 | } |
|
| 329 | ||
| 330 | public function testUrl() |
|
| 331 | { |
|
| @@ 564-608 (lines=45) @@ | ||
| 561 | ); |
|
| 562 | } |
|
| 563 | ||
| 564 | public function testChars() |
|
| 565 | { |
|
| 566 | $this->klein_app->respond( |
|
| 567 | '/[:test_param]', |
|
| 568 | function ($request, $response, $service) { |
|
| 569 | $service->validateParam('test_param') |
|
| 570 | ->notNull() |
|
| 571 | ->isChars('c-f'); |
|
| 572 | ||
| 573 | // We should only get here if we passed our validations |
|
| 574 | echo 'yup!'; |
|
| 575 | } |
|
| 576 | ); |
|
| 577 | ||
| 578 | $this->assertSame( |
|
| 579 | 'yup!', |
|
| 580 | $this->dispatchAndReturnOutput( |
|
| 581 | MockRequestFactory::create('/cdef') |
|
| 582 | ) |
|
| 583 | ); |
|
| 584 | $this->assertSame( |
|
| 585 | 'yup!', |
|
| 586 | $this->dispatchAndReturnOutput( |
|
| 587 | MockRequestFactory::create('/cfed') |
|
| 588 | ) |
|
| 589 | ); |
|
| 590 | $this->assertSame( |
|
| 591 | 'yup!', |
|
| 592 | $this->dispatchAndReturnOutput( |
|
| 593 | MockRequestFactory::create('/cf') |
|
| 594 | ) |
|
| 595 | ); |
|
| 596 | $this->assertSame( |
|
| 597 | 'fail', |
|
| 598 | $this->dispatchAndReturnOutput( |
|
| 599 | MockRequestFactory::create('/cdefg') |
|
| 600 | ) |
|
| 601 | ); |
|
| 602 | $this->assertSame( |
|
| 603 | 'fail', |
|
| 604 | $this->dispatchAndReturnOutput( |
|
| 605 | MockRequestFactory::create('/dog') |
|
| 606 | ) |
|
| 607 | ); |
|
| 608 | } |
|
| 609 | ||
| 610 | public function testRegex() |
|
| 611 | { |
|