From 6bf36fbd30c9d0e1375430e692b0e50206a0cfcb Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Wed, 9 Nov 2016 12:45:40 +0000 Subject: [PATCH] FIX: Correct return type for Member::currentUser() --- security/Member.php | 3 +-- tests/security/MemberTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/security/Member.php b/security/Member.php index 47e27395c..692ff61a5 100644 --- a/security/Member.php +++ b/security/Member.php @@ -837,9 +837,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); + } + } /**