Skip to content

Commit

Permalink
MDL-62614 Privacy: Core tag provider delete_item_tags function not work
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 authored and zig-moodle committed Jun 18, 2018
1 parent d8832ae commit 70c2cb7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tag/classes/privacy/provider.php
Expand Up @@ -166,7 +166,7 @@ public static function delete_item_tags(\context $context, $component, $itemtype
$params['itemid'] = $itemid;
}
if ($userid) {
$params['userid'] = $userid;
$params['tiuserid'] = $userid;
}
$DB->delete_records('tag_instance', $params);
}
Expand Down
29 changes: 29 additions & 0 deletions tag/tests/privacy_test.php
Expand Up @@ -121,6 +121,35 @@ public function test_delete_item_tags() {
$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().
*/
Expand Down

0 comments on commit 70c2cb7

Please sign in to comment.