Skip to content

Commit

Permalink
refactor code for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsde committed Sep 26, 2023
1 parent 49fd2c1 commit a054a4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
20 changes: 12 additions & 8 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,14 +1063,18 @@ public function storePreviousURL($uri)
$uri = new URI($uri);
}

if (isset($_SESSION)) {
session()->set('_ci_previous_url', URI::createURIString(
$uri->getScheme(),
$uri->getAuthority(),
$uri->getPath(),
$uri->getQuery(),
$uri->getFragment()
));
$previousUrl = URI::createURIString(
$uri->getScheme(),
$uri->getAuthority(),
$uri->getPath(),
$uri->getQuery(),
$uri->getFragment()
);

if (ENVIRONMENT === 'testing') {
$_SESSION['_ci_previous_url'] = $previousUrl;
} elseif (session_status() === PHP_SESSION_ACTIVE) {
session()->set('_ci_previous_url', $previousUrl);
}
}

Expand Down
6 changes: 5 additions & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,11 @@ public function getOldInput(string $key)
}

// Get previously saved in session
$old = session('_ci_old_input');
if (ENVIRONMENT === 'testing') {
$old = $_SESSION['_ci_old_input'] ?? null;
} else {
$old = session('_ci_old_input');
}

// If no data was previously saved, we're done.
if ($old === null) {
Expand Down
4 changes: 3 additions & 1 deletion system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function previous_url(bool $returnObject = false)
{
// Grab from the session first, if we have it,
// since it's more reliable and safer.
if (isset($_SESSION)) {
if (ENVIRONMENT === 'testing') {
$referer = $_SESSION['_ci_previous_url'] ?? null;
} else {
$referer = session('_ci_previous_url');
}

Expand Down

0 comments on commit a054a4a

Please sign in to comment.