|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of CodeIgniter 4 framework. |
| 5 | + * |
| 6 | + * (c) CodeIgniter Foundation <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view |
| 9 | + * the LICENSE file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace CodeIgniter\HTTP; |
| 13 | + |
| 14 | +use CodeIgniter\Config\Factories; |
| 15 | +use CodeIgniter\Test\CIUnitTestCase; |
| 16 | +use Config\App; |
| 17 | + |
| 18 | +/** |
| 19 | + * @backupGlobals enabled |
| 20 | + * |
| 21 | + * @internal |
| 22 | + * |
| 23 | + * @group Others |
| 24 | + */ |
| 25 | +final class URIFactoryTest extends CIUnitTestCase |
| 26 | +{ |
| 27 | + protected function setUp(): void |
| 28 | + { |
| 29 | + parent::setUp(); |
| 30 | + |
| 31 | + $_GET = $_SERVER = []; |
| 32 | + } |
| 33 | + |
| 34 | + protected function tearDown(): void |
| 35 | + { |
| 36 | + Factories::reset('config'); |
| 37 | + } |
| 38 | + |
| 39 | + public function testCreateCurrentURI() |
| 40 | + { |
| 41 | + // http://localhost:8080/index.php/woot?code=good#pos |
| 42 | + $_SERVER['REQUEST_URI'] = '/index.php/woot?code=good'; |
| 43 | + $_SERVER['SCRIPT_NAME'] = '/index.php'; |
| 44 | + $_SERVER['QUERY_STRING'] = 'code=good'; |
| 45 | + $_SERVER['HTTP_HOST'] = 'localhost:8080'; |
| 46 | + $_SERVER['PATH_INFO'] = '/woot'; |
| 47 | + |
| 48 | + $_GET['code'] = 'good'; |
| 49 | + |
| 50 | + $factory = new URIFactory($_SERVER, $_GET, new App()); |
| 51 | + |
| 52 | + $uri = $factory->createCurrentURI(); |
| 53 | + |
| 54 | + $this->assertInstanceOf(URI::class, $uri); |
| 55 | + $this->assertSame('http://localhost:8080/woot?code=good', (string) $uri); |
| 56 | + $this->assertSame('woot', $uri->getPath()); |
| 57 | + $this->assertSame('woot', $uri->getRoutePath()); |
| 58 | + } |
| 59 | +} |
0 commit comments