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.
This commit is contained in:
Andrew Nicols
2016-11-22 09:05:31 +08:00
parent aabebc7516
commit aacdf8e280
2 changed files with 9 additions and 7 deletions
+3 -1
View File
@@ -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);
}
/**
+6 -6
View File
@@ -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()
);
}