-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\HTTP; | ||
|
||
use CodeIgniter\Config\Factories; | ||
use CodeIgniter\Test\CIUnitTestCase; | ||
use Config\App; | ||
|
||
/** | ||
* @backupGlobals enabled | ||
* | ||
* @internal | ||
* | ||
* @group Others | ||
*/ | ||
final class URIFactoryTest extends CIUnitTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$_GET = $_SERVER = []; | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
Factories::reset('config'); | ||
} | ||
|
||
public function testCreateCurrentURI() | ||
{ | ||
// http://localhost:8080/index.php/woot?code=good#pos | ||
$_SERVER['REQUEST_URI'] = '/index.php/woot?code=good'; | ||
$_SERVER['SCRIPT_NAME'] = '/index.php'; | ||
$_SERVER['QUERY_STRING'] = 'code=good'; | ||
$_SERVER['HTTP_HOST'] = 'localhost:8080'; | ||
$_SERVER['PATH_INFO'] = '/woot'; | ||
|
||
$_GET['code'] = 'good'; | ||
|
||
$factory = new URIFactory($_SERVER, $_GET, new App()); | ||
|
||
$uri = $factory->createCurrentURI(); | ||
|
||
$this->assertInstanceOf(URI::class, $uri); | ||
$this->assertSame('http://localhost:8080/woot?code=good', (string) $uri); | ||
$this->assertSame('woot', $uri->getPath()); | ||
$this->assertSame('woot', $uri->getRoutePath()); | ||
} | ||
} |