From 4a8589bc0ef2ed0c360f32902ea09a3a8699bbd6 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Fri, 19 Aug 2022 16:50:20 +0800 Subject: [PATCH] MDL-72592 block_myprofile: behat and other code fixes This commit fixes few things: - Fix correct language string order. - Change the code in myprofile.php to be consistent with other checks. - Update provided test to fix behat failure. --- blocks/myprofile/classes/output/myprofile.php | 9 +++------ blocks/myprofile/lang/en/block_myprofile.php | 2 +- blocks/myprofile/tests/behat/block_myprofile.feature | 4 +++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/blocks/myprofile/classes/output/myprofile.php b/blocks/myprofile/classes/output/myprofile.php index 6d3a0e4ebd2..b07d7811f8e 100644 --- a/blocks/myprofile/classes/output/myprofile.php +++ b/blocks/myprofile/classes/output/myprofile.php @@ -120,13 +120,10 @@ class myprofile implements renderable, templatable { $data->userlastip = $USER->lastip; } - if (!empty($this->config->display_lastlogin)) { - if (empty($USER->lastlogin)) { - $data->userlastlogin = 0; - } else { - $data->userlastlogin = userdate($USER->lastlogin); - } + if (!empty($this->config->display_lastlogin) && !empty($USER->lastlogin)) { + $data->userlastlogin = userdate($USER->lastlogin); } + return $data; } } diff --git a/blocks/myprofile/lang/en/block_myprofile.php b/blocks/myprofile/lang/en/block_myprofile.php index d6ad3b8b368..79c4342b0e2 100644 --- a/blocks/myprofile/lang/en/block_myprofile.php +++ b/blocks/myprofile/lang/en/block_myprofile.php @@ -36,8 +36,8 @@ $string['display_address'] = 'Display address'; $string['display_firstaccess'] = 'Display first access'; $string['display_lastaccess'] = 'Display last access'; $string['display_currentlogin'] = 'Display current login'; -$string['display_lastlogin'] = 'Display last login'; $string['display_lastip'] = 'Display last IP'; +$string['display_lastlogin'] = 'Display last login'; $string['myprofile:addinstance'] = 'Add a new logged in user block'; $string['myprofile:myaddinstance'] = 'Add a new logged in user block to Dashboard'; $string['myprofile_settings'] = 'Visible user information'; diff --git a/blocks/myprofile/tests/behat/block_myprofile.feature b/blocks/myprofile/tests/behat/block_myprofile.feature index bbcecd2155d..346bee77118 100644 --- a/blocks/myprofile/tests/behat/block_myprofile.feature +++ b/blocks/myprofile/tests/behat/block_myprofile.feature @@ -237,7 +237,7 @@ Feature: The logged in user block allows users to view their profile information | username | firstname | lastname | email | | teacher1 | Teacher | One | teacher1@example.com | And I log in as "teacher1" - And I press "Customise this page" + And I turn editing mode on When I add the "Logged in user" block And I configure the "Logged in user" block And I set the following fields to these values: @@ -249,4 +249,6 @@ Feature: The logged in user block allows users to view their profile information And I set the following fields to these values: | Display last login | Yes | And I press "Save changes" + And I log out + And I log in as "teacher1" And I should see "Last login:" in the "Logged in user" "block"