Merge branch 'MDL-70126' of git://github.com/paulholden/moodle

This commit is contained in:
Andrew Nicols 2020-11-11 10:20:00 +08:00
commit c3086f74fb
2 changed files with 13 additions and 2 deletions

View File

@ -81,7 +81,7 @@ class core_tag_tag {
*/
protected function __construct($record) {
if (empty($record->id)) {
throw new coding_exeption("Record must contain at least field 'id'");
throw new coding_exception("Record must contain at least field 'id'");
}
$this->record = $record;
}
@ -753,7 +753,7 @@ class core_tag_tag {
public static function set_item_tags($component, $itemtype, $itemid, context $context, $tagnames, $tiuserid = 0) {
if ($itemtype === 'tag') {
if ($tiuserid) {
throw new coding_exeption('Related tags can not have tag instance userid');
throw new coding_exception('Related tags can not have tag instance userid');
}
debugging('You can not use set_item_tags() for tagging a tag, please use set_related_tags()', DEBUG_DEVELOPER);
static::get($itemid, '*', MUST_EXIST)->set_related_tags($tagnames);

View File

@ -275,6 +275,17 @@ class core_tag_taglib_testcase extends advanced_testcase {
$this->assertEquals(0, $instancecount);
}
/**
* Test that setting a list of tags for "tag" item type throws exception if userid specified
*/
public function test_set_item_tags_with_invalid_userid(): void {
$user = $this->getDataGenerator()->create_user();
$this->expectException(coding_exception::class);
$this->expectExceptionMessage('Related tags can not have tag instance userid');
core_tag_tag::set_item_tags('core', 'tag', 1, context_system::instance(), ['all', 'night', 'long'], $user->id);
}
/**
* Prepares environment for testing tag correlations
* @return core_tag_tag[] list of used tags