MDL-62614 Privacy: Core tag provider delete_item_tags function not work
authorHuong Nguyen <huongnv13@gmail.com>
Thu, 31 May 2018 07:29:18 +0000 (14:29 +0700)
committerZig Tan <zig@moodle.com>
Mon, 18 Jun 2018 04:59:13 +0000 (12:59 +0800)
tag/classes/privacy/provider.php
tag/tests/privacy_test.php

index 744dae9..25379ce 100644 (file)
@@ -166,7 +166,7 @@ class provider implements
             $params['itemid'] = $itemid;
         }
         if ($userid) {
-            $params['userid'] = $userid;
+            $params['tiuserid'] = $userid;
         }
         $DB->delete_records('tag_instance', $params);
     }
index ccbda47..56c8ae9 100644 (file)
@@ -121,6 +121,35 @@ class core_tag_privacy_testcase extends provider_testcase {
         $this->assertEquals($expectedtagcount, $DB->count_records('tag_instance'));
     }
 
+    /**
+     * Test method delete_item_tags() with userid.
+     */
+    public function test_delete_item_tags_with_userid() {
+        global $DB;
+
+        $this->resetAfterTest(true);
+        // Create a course to tag.
+        $course = $this->getDataGenerator()->create_course();
+        $context = context_course::instance($course->id);
+
+        // Create a user to perform tagging.
+        $user = $this->getDataGenerator()->create_user();
+        $this->setUser($user);
+
+        // Tag courses.
+        core_tag_tag::set_item_tags('core_course', 'course', $course->id, $context, ['Tag 1', 'Tag 2'], $user->id);
+        $expectedtagcount = $DB->count_records('tag_instance');
+
+        // Delete tags for course. Use wrong userid.
+        core_tag\privacy\provider::delete_item_tags($context, 'core_course', 'course', null, 1);
+        $this->assertEquals($expectedtagcount, $DB->count_records('tag_instance'));
+
+        $expectedtagcount -= 2;
+        // Delete tags for course. Use correct userid.
+        core_tag\privacy\provider::delete_item_tags($context, 'core_course', 'course', null, $user->id);
+        $this->assertEquals($expectedtagcount, $DB->count_records('tag_instance'));
+    }
+
     /**
      * Test method delete_item_tags_select().
      */