From c1c4ae95f2ee87241f9e69697a5d4b0a1db1b0ae Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 5 Nov 2020 19:48:29 +0000 Subject: [PATCH] MDL-70126 tag: correct thrown exception class name. --- tag/classes/tag.php | 4 ++-- tag/tests/taglib_test.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tag/classes/tag.php b/tag/classes/tag.php index ba04be8dc5f..a84efcabeee 100644 --- a/tag/classes/tag.php +++ b/tag/classes/tag.php @@ -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); diff --git a/tag/tests/taglib_test.php b/tag/tests/taglib_test.php index 28c62f9b7cb..bad9b14c242 100644 --- a/tag/tests/taglib_test.php +++ b/tag/tests/taglib_test.php @@ -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