Skip to content

Commit

Permalink
test: set $_SERVER['SCRIPT_NAME']
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 3, 2023
1 parent 1bdaddc commit 80465c6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/system/CodeIgniterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function testRunClosureRoute()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/pages/about';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand Down Expand Up @@ -193,6 +194,7 @@ public function testControllersCanReturnString()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/pages/about';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand All @@ -216,6 +218,7 @@ public function testControllersCanReturnResponseObject()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/pages/about';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand Down Expand Up @@ -244,6 +247,7 @@ public function testControllersCanReturnDownloadResponseObject()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/pages/about';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand All @@ -268,6 +272,7 @@ public function testRunExecuteFilterByClassName()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/pages/about';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand Down Expand Up @@ -298,6 +303,7 @@ public function testRegisterSameFilterTwiceWithDifferentArgument()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/pages/about';
$_SERVER['SCRIPT_NAME'] = '/index.php';

$routes = Services::routes();
$routes->add(
Expand Down Expand Up @@ -331,6 +337,7 @@ public function testDisableControllerFilters()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/pages/about';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand Down Expand Up @@ -452,6 +459,7 @@ public function testRunRedirectionWithNamed()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/example';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand All @@ -475,6 +483,7 @@ public function testRunRedirectionWithURI()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/example';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand All @@ -501,6 +510,7 @@ public function testRunRedirectionWithGET()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/example';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['REQUEST_METHOD'] = 'GET';

Expand All @@ -527,6 +537,7 @@ public function testRunRedirectionWithGETAndHTTPCode301()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/example';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['REQUEST_METHOD'] = 'GET';

Expand All @@ -551,6 +562,7 @@ public function testRunRedirectionWithPOSTAndHTTPCode301()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/example';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['REQUEST_METHOD'] = 'POST';

Expand Down Expand Up @@ -615,6 +627,7 @@ public function testNotStoresPreviousURL()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/example';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['REQUEST_METHOD'] = 'GET';

Expand All @@ -638,6 +651,7 @@ public function testNotStoresPreviousURLByCheckingContentType()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/image';
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Inject mock router.
$routes = Services::routes();
Expand Down Expand Up @@ -679,6 +693,7 @@ public function testRunCLIRoute()
$_SERVER['argc'] = 2;

$_SERVER['REQUEST_URI'] = '/cli';
$_SERVER['SCRIPT_NAME'] = 'public/index.php';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['REQUEST_METHOD'] = 'CLI';

Expand All @@ -698,6 +713,7 @@ public function testSpoofRequestMethodCanUsePUT()
$_SERVER['argc'] = 1;

$_SERVER['REQUEST_URI'] = '/';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['REQUEST_METHOD'] = 'POST';

Expand All @@ -722,6 +738,7 @@ public function testSpoofRequestMethodCannotUseGET()
$_SERVER['argc'] = 1;

$_SERVER['REQUEST_URI'] = '/';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['REQUEST_METHOD'] = 'POST';

Expand Down Expand Up @@ -754,6 +771,7 @@ public function testPageCacheSendSecureHeaders()
command('cache:clear');

$_SERVER['REQUEST_URI'] = '/test';
$_SERVER['SCRIPT_NAME'] = '/index.php';

$routes = Services::routes();
$routes->add('test', static function () {
Expand Down Expand Up @@ -832,6 +850,7 @@ public function testPageCacheWithCacheQueryString(
foreach ($testingUrls as $testingUrl) {
$this->resetServices();
$_SERVER['REQUEST_URI'] = '/' . $testingUrl;
$_SERVER['SCRIPT_NAME'] = '/index.php';
$this->codeigniter = new MockCodeIgniter(new App());

$routes = Services::routes(true);
Expand Down

0 comments on commit 80465c6

Please sign in to comment.