Fix tests on unset session data

Thanks Robbie!
This commit is contained in:
Ingo Schommer 2018-07-18 21:15:56 +12:00 committed by Daniel Hensby
parent 76ac8465de
commit 74b655d3fc
No known key found for this signature in database
GPG Key ID: D8DEBC4C8E7BC8B9
2 changed files with 6 additions and 5 deletions

View File

@ -206,7 +206,7 @@ class Director implements TemplateGlobalProvider
if ($session instanceof Session) { if ($session instanceof Session) {
// Note: If passing $session as object, ensure that changes are written back // Note: If passing $session as object, ensure that changes are written back
// This is important for classes such as FunctionalTest which emulate cross-request persistence // This is important for classes such as FunctionalTest which emulate cross-request persistence
$newVars['_SESSION'] = $sessionArray = $session->getAll(); $newVars['_SESSION'] = $sessionArray = $session->getAll() ?: [];
$finally[] = function () use ($session, $sessionArray) { $finally[] = function () use ($session, $sessionArray) {
if (isset($_SESSION)) { if (isset($_SESSION)) {
// Set new / updated keys // Set new / updated keys

View File

@ -262,8 +262,8 @@ class Session
public function requestContainsSessionId(HTTPRequest $request) public function requestContainsSessionId(HTTPRequest $request)
{ {
$secure = Director::is_https($request) && $this->config()->get('cookie_secure'); $secure = Director::is_https($request) && $this->config()->get('cookie_secure');
$name = $secure ? $this->config()->get('cookie_name_secure') : session_name(); $name = $secure ? $this->config()->get('cookie_name_secure') : session_name();
return (bool)Cookie::get($name); return (bool)Cookie::get($name);
} }
/** /**
@ -330,9 +330,9 @@ class Session
$this->recursivelyApply((array)$this->data, $data); $this->recursivelyApply((array)$this->data, $data);
} else { } else {
// Use in-memory data if the session is lazy started // Use in-memory data if the session is lazy started
$data = isset($this->data) ? $this->data : []; $data = $this->data;
} }
$this->data = $data; $this->data = $data ?: [];
} else { } else {
$this->data = []; $this->data = [];
} }
@ -615,6 +615,7 @@ class Session
*/ */
protected function recursivelyApplyChanges($changes, $source, &$destination) protected function recursivelyApplyChanges($changes, $source, &$destination)
{ {
$source = $source ?: [];
foreach ($changes as $key => $changed) { foreach ($changes as $key => $changed) {
if ($changed === true) { if ($changed === true) {
// Determine if replacement or removal // Determine if replacement or removal