Skip to content

Commit

Permalink
Merge branch 'MDL-70126-39' of git://github.com/paulholden/moodle int…
Browse files Browse the repository at this point in the history
…o MOODLE_39_STABLE
  • Loading branch information
andrewnicols committed Nov 11, 2020
2 parents 28de3d7 + 97a03ba commit 7a2d0fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tag/classes/tag.php
Expand Up @@ -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;
}
Expand Down Expand Up @@ -753,7 +753,7 @@ public static function get_item_tags_array($component, $itemtype, $itemid, $stan
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);
Expand Down
11 changes: 11 additions & 0 deletions tag/tests/taglib_test.php
Expand Up @@ -275,6 +275,17 @@ public function test_tag_bulk_delete_instances() {
$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
Expand Down

0 comments on commit 7a2d0fb

Please sign in to comment.