diff --git a/security/Member.php b/security/Member.php index d3e54929b..6dd42c0be 100644 --- a/security/Member.php +++ b/security/Member.php @@ -841,9 +841,8 @@ class Member extends DataObject implements TemplateGlobalProvider { $id = Member::currentUserID(); if($id) { - return DataObject::get_by_id('Member', $id); + return DataObject::get_by_id('Member', $id) ?: null; } - return null; } /** diff --git a/tests/security/MemberTest.php b/tests/security/MemberTest.php index de930f5d3..595b7a821 100644 --- a/tests/security/MemberTest.php +++ b/tests/security/MemberTest.php @@ -1041,6 +1041,16 @@ class MemberTest extends FunctionalTest { $this->assertTrue($fail, 'Passes with email and surname now (no firstname)'); } + public function testCurrentUser() { + $this->assertNull(Member::currentUser()); + + $adminMember = $this->objFromFixture('Member', 'admin'); + $this->logInAs($adminMember); + + $userFromSession = Member::currentUser(); + $this->assertEquals($adminMember->ID, $userFromSession->ID); + } + } /**