From aacdf8e2801facbe2bcb45ba6693bb6b18152ebb Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 22 Nov 2016 09:01:22 +0800 Subject: [PATCH] MDL-57023 tool_usertours: Ensure that the tour key is unique The tour key was already unique, but this change makes it unique to the current user too. --- admin/tool/usertours/classes/tour.php | 4 +++- admin/tool/usertours/tests/tour_test.php | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/admin/tool/usertours/classes/tour.php b/admin/tool/usertours/classes/tour.php index 473a077fa58..5717e24af88 100644 --- a/admin/tool/usertours/classes/tour.php +++ b/admin/tool/usertours/classes/tour.php @@ -608,6 +608,8 @@ class tour { * This is used in the session cookie to determine whether the user has seen this tour before. */ public function get_tour_key() { + global $USER; + $tourtime = $this->get_config('majorupdatetime', null); if ($tourtime === null) { @@ -622,7 +624,7 @@ class tour { $tourtime = max($tourtime, $userresetdate); } - return sprintf('tool_usertours_%d_%s', $this->get_id(), $tourtime); + return sprintf('tool_usertours_%d_%d_%s', $USER->id, $this->get_id(), $tourtime); } /** diff --git a/admin/tool/usertours/tests/tour_test.php b/admin/tool/usertours/tests/tour_test.php index 75a64948c87..d08a9df79b9 100644 --- a/admin/tool/usertours/tests/tour_test.php +++ b/admin/tool/usertours/tests/tour_test.php @@ -729,7 +729,7 @@ class tour_testcase extends advanced_testcase { $this->greaterThanOrEqual($time), true, null, - sprintf('tool_usertours_%d_%s', $id, $time), + sprintf('tool_usertours_\d_%d_%s', $id, $time), ], 'Initial tour time, no user pref' => [ @@ -738,7 +738,7 @@ class tour_testcase extends advanced_testcase { null, false, null, - sprintf('tool_usertours_%d_%s', $id, $time), + sprintf('tool_usertours_\d_%d_%s', $id, $time), ], 'Initial tour time, with user reset lower' => [ $id, @@ -746,7 +746,7 @@ class tour_testcase extends advanced_testcase { null, false, $time - DAYSECS, - sprintf('tool_usertours_%d_%s', $id, $time), + sprintf('tool_usertours_\d_%d_%s', $id, $time), ], 'Initial tour time, with user reset higher' => [ $id, @@ -754,7 +754,7 @@ class tour_testcase extends advanced_testcase { null, false, $time + DAYSECS, - sprintf('tool_usertours_%d_%s', $id, $time + DAYSECS), + sprintf('tool_usertours_\d_%d_%s', $id, $time + DAYSECS), ], ]; } @@ -823,8 +823,8 @@ class tour_testcase extends advanced_testcase { set_user_preference(\tool_usertours\tour::TOUR_REQUESTED_BY_USER . $id, $userpref); } - $this->assertEquals( - $expectation, + $this->assertRegExp( + '/' . $expectation . '/', $tour->get_tour_key() ); } -- 2.43.0