MDL-66804 user: consistent user access times in privacy export.
[moodle.git] / user / tests / privacy_test.php
index bd630f1..8a1a9f8 100644 (file)
@@ -28,6 +28,7 @@ global $CFG;
 use \core_privacy\tests\provider_testcase;
 use \core_user\privacy\provider;
 use \core_privacy\local\request\approved_userlist;
+use \core_privacy\local\request\transform;
 
 require_once($CFG->dirroot . "/user/lib.php");
 
@@ -59,7 +60,11 @@ class core_user_privacy_testcase extends provider_testcase {
      */
     public function test_export_user_data() {
         $this->resetAfterTest();
-        $user = $this->getDataGenerator()->create_user();
+        $user = $this->getDataGenerator()->create_user([
+            'firstaccess' => 1535760000,
+            'lastaccess' => 1541030400,
+            'currentlogin' => 1541030400,
+        ]);
         $course = $this->getDataGenerator()->create_course();
         $context = \context_user::instance($user->id);
 
@@ -125,6 +130,11 @@ class core_user_privacy_testcase extends provider_testcase {
         $this->assertTrue(array_key_exists('firstname', $userdata));
         $this->assertTrue(array_key_exists('lastname', $userdata));
         $this->assertTrue(array_key_exists('email', $userdata));
+        // Check access times.
+        $this->assertEquals(transform::datetime($user->firstaccess), $userdata['firstaccess']);
+        $this->assertEquals(transform::datetime($user->lastaccess), $userdata['lastaccess']);
+        $this->assertNull($userdata['lastlogin']);
+        $this->assertEquals(transform::datetime($user->currentlogin), $userdata['currentlogin']);
     }
 
     /**