|
16 | 16 | use CodeIgniter\HTTP\Files\UploadedFile; |
17 | 17 | use CodeIgniter\Test\CIUnitTestCase; |
18 | 18 | use Config\App; |
| 19 | +use Generator; |
| 20 | +use InvalidArgumentException; |
19 | 21 | use TypeError; |
20 | 22 |
|
21 | 23 | /** |
@@ -615,6 +617,63 @@ public function testCanGrabGetRawInputVar($rawstring, $var, $expected, $filter, |
615 | 617 | $this->assertSame($expected, $request->getRawInputVar($var, $filter, $flag)); |
616 | 618 | } |
617 | 619 |
|
| 620 | + /** |
| 621 | + * @dataProvider provideIsHTTPMethods |
| 622 | + */ |
| 623 | + public function testIsHTTPMethodLowerCase(string $value) |
| 624 | + { |
| 625 | + $request = $this->request->withMethod($value); |
| 626 | + |
| 627 | + $this->assertTrue($request->is(strtolower($value))); |
| 628 | + } |
| 629 | + |
| 630 | + public function provideIsHTTPMethods(): Generator |
| 631 | + { |
| 632 | + yield from [ |
| 633 | + ['GET'], |
| 634 | + ['POST'], |
| 635 | + ['PUT'], |
| 636 | + ['DELETE'], |
| 637 | + ['HEAD'], |
| 638 | + ['PATCH'], |
| 639 | + ['OPTIONS'], |
| 640 | + ]; |
| 641 | + } |
| 642 | + |
| 643 | + /** |
| 644 | + * @dataProvider provideIsHTTPMethods |
| 645 | + */ |
| 646 | + public function testIsHTTPMethodUpperCase(string $value) |
| 647 | + { |
| 648 | + $request = $this->request->withMethod($value); |
| 649 | + |
| 650 | + $this->assertTrue($request->is($value)); |
| 651 | + } |
| 652 | + |
| 653 | + public function testIsInvalidValue() |
| 654 | + { |
| 655 | + $this->expectException(InvalidArgumentException::class); |
| 656 | + $this->expectExceptionMessage('Unknown type: invalid'); |
| 657 | + |
| 658 | + $request = $this->request->withMethod('GET'); |
| 659 | + |
| 660 | + $request->is('invalid'); |
| 661 | + } |
| 662 | + |
| 663 | + public function testIsJson() |
| 664 | + { |
| 665 | + $request = $this->request->setHeader('Content-Type', 'application/json'); |
| 666 | + |
| 667 | + $this->assertTrue($request->is('json')); |
| 668 | + } |
| 669 | + |
| 670 | + public function testIsWithAjax() |
| 671 | + { |
| 672 | + $request = $this->request->setHeader('X-Requested-With', 'XMLHttpRequest'); |
| 673 | + |
| 674 | + $this->assertTrue($request->is('ajax')); |
| 675 | + } |
| 676 | + |
618 | 677 | public function testIsCLI() |
619 | 678 | { |
620 | 679 | $this->assertFalse($this->request->isCLI()); |
|
0 commit comments