Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 4, 2023
1 parent 2dd6467 commit 745a93d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 25 deletions.
20 changes: 14 additions & 6 deletions tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,25 @@ public function testFormatByRequestNegotiateIfFormatIsNotJsonOrXML()
'negotiateLocale' => false,
'supportedLocales' => ['en'],
'CSPEnabled' => false,
'cookiePrefix' => '',
'cookieDomain' => '',
'cookiePath' => '/',
'cookieSecure' => false,
'cookieHTTPOnly' => false,
'proxyIPs' => [],
'cookieSameSite' => 'Lax',
] as $key => $value) {
$config->{$key} = $value;
}

$cookie = new Cookie();

foreach ([
'prefix' => '',
'domain' => '',
'path' => '/',
'secure' => false,
'httponly' => false,
'samesite' => 'Lax',
] as $key => $value) {
$cookie->{$key} = $value;
}
Factories::injectMock('config', 'Cookie', $cookie);

$request = new MockIncomingRequest($config, new URI($config->baseURL), null, new UserAgent());
$response = new MockResponse($config);

Expand Down
24 changes: 17 additions & 7 deletions tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CodeIgniter;

use CodeIgniter\Config\BaseService;
use CodeIgniter\Config\Factories;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RedirectResponse;
Expand All @@ -28,6 +29,7 @@
use CodeIgniter\Test\Mock\MockSession;
use CodeIgniter\Test\TestLogger;
use Config\App;
use Config\Cookie;
use Config\Logger;
use Config\Modules;
use Config\Services;
Expand Down Expand Up @@ -511,6 +513,8 @@ public function testSlashItemThrowsErrorOnNonStringableItem()

protected function injectSessionMock()
{
$appConfig = new App();

$defaults = [
'sessionDriver' => FileHandler::class,
'sessionCookieName' => 'ci_session',
Expand All @@ -519,19 +523,25 @@ protected function injectSessionMock()
'sessionMatchIP' => false,
'sessionTimeToUpdate' => 300,
'sessionRegenerateDestroy' => false,
'cookieDomain' => '',
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
'cookieSameSite' => 'Lax',
];

$appConfig = new App();

foreach ($defaults as $key => $config) {
$appConfig->{$key} = $config;
}

$cookie = new Cookie();

foreach ([
'prefix' => '',
'domain' => '',
'path' => '/',
'secure' => false,
'samesite' => 'Lax',
] as $key => $value) {
$cookie->{$key} = $value;
}
Factories::injectMock('config', 'Cookie', $cookie);

$session = new MockSession(new FileHandler($appConfig, '127.0.0.1'), $appConfig);
$session->setLogger(new TestLogger(new Logger()));
BaseService::injectMock('session', $session);
Expand Down
21 changes: 15 additions & 6 deletions tests/system/Security/SecurityCSRFSessionRandomizeTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use CodeIgniter\Test\Mock\MockSession;
use CodeIgniter\Test\TestLogger;
use Config\App as AppConfig;
use Config\Cookie;
use Config\Logger as LoggerConfig;
use Config\Security as SecurityConfig;

Expand Down Expand Up @@ -75,20 +76,28 @@ private function createSession($options = []): Session
'sessionMatchIP' => false,
'sessionTimeToUpdate' => 300,
'sessionRegenerateDestroy' => false,
'cookieDomain' => '',
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
'cookieSameSite' => 'Lax',
];
$config = array_merge($defaults, $options);

$config = array_merge($defaults, $options);
$appConfig = new AppConfig();

foreach ($config as $key => $c) {
$appConfig->{$key} = $c;
}

$cookie = new Cookie();

foreach ([
'prefix' => '',
'domain' => '',
'path' => '/',
'secure' => false,
'samesite' => 'Lax',
] as $key => $value) {
$cookie->{$key} = $value;
}
Factories::injectMock('config', 'Cookie', $cookie);

$session = new MockSession(new ArrayHandler($appConfig, '127.0.0.1'), $appConfig);
$session->setLogger(new TestLogger(new LoggerConfig()));

Expand Down
21 changes: 15 additions & 6 deletions tests/system/Security/SecurityCSRFSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use CodeIgniter\Test\Mock\MockSession;
use CodeIgniter\Test\TestLogger;
use Config\App as AppConfig;
use Config\Cookie;
use Config\Logger as LoggerConfig;
use Config\Security as SecurityConfig;

Expand Down Expand Up @@ -68,20 +69,28 @@ private function createSession($options = []): Session
'sessionMatchIP' => false,
'sessionTimeToUpdate' => 300,
'sessionRegenerateDestroy' => false,
'cookieDomain' => '',
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
'cookieSameSite' => 'Lax',
];
$config = array_merge($defaults, $options);

$config = array_merge($defaults, $options);
$appConfig = new AppConfig();

foreach ($config as $key => $c) {
$appConfig->{$key} = $c;
}

$cookie = new Cookie();

foreach ([
'prefix' => '',
'domain' => '',
'path' => '/',
'secure' => false,
'samesite' => 'Lax',
] as $key => $value) {
$cookie->{$key} = $value;
}
Factories::injectMock('config', 'Cookie', $cookie);

$session = new MockSession(new ArrayHandler($appConfig, '127.0.0.1'), $appConfig);
$session->setLogger(new TestLogger(new LoggerConfig()));

Expand Down

0 comments on commit 745a93d

Please sign in to comment.