/** * Test the tag_set_delete function. * This function was deprecated in 3.1 */ public function test_tag_set_delete() { global $DB; // Create a course to tag. $course = $this->getDataGenerator()->create_course(); // Create the tag and tag instance we are going to delete. tag_set_add('course', $course->id, 'A random tag', 'core', context_course::instance($course->id)->id); $this->assertDebuggingCalled(); // Call the tag_set_delete function. tag_set_delete('course', $course->id, 'a random tag', 'core', context_course::instance($course->id)->id); $this->assertDebuggingCalled(); // Now check that there are no tags or tag instances. $this->assertEquals(0, $DB->count_records('tag')); $this->assertEquals(0, $DB->count_records('tag_instance')); // Add tag again, add and remove related tag. tag_set_add('course', $course->id, 'A random tag', 'core', context_course::instance($course->id)->id); $this->assertDebuggingCalled(); $taginstance = $DB->get_record('tag_instance', array('itemtype' => 'course', 'itemid' => $course->id), '*', MUST_EXIST); $tagid = $taginstance->tagid; tag_set_add('tag', $tagid, 'Some related tag'); $this->assertDebuggingCalled(); tag_set_delete('tag', $tagid, 'Some related tag'); $this->assertDebuggingCalled(); $relatedtags = tag_get_related_tags($tagid); $this->assertDebuggingCalled(); $this->assertCount(0, $relatedtags); }
/** * Test the tag_set_delete function. */ public function test_tag_set_delete() { global $DB; // Create a course to tag. $course = $this->getDataGenerator()->create_course(); // Create the tag and tag instance we are going to delete. tag_set_add('course', $course->id, 'A random tag', 'core', context_course::instance($course->id)->id); // Call the tag_set_delete function. tag_set_delete('course', $course->id, 'a random tag', 'core', context_course::instance($course->id)->id); // Now check that there are no tags or tag instances. $this->assertEquals(0, $DB->count_records('tag')); $this->assertEquals(0, $DB->count_records('tag_instance')); // Recreate the tag and tag instance. tag_set_add('course', $course->id, 'A random tag', 'core', context_course::instance($course->id)->id); // Now call the tag_set_delete function without specifying the component or // contextid and ensure the function debugging is called. tag_set_delete('course', $course->id, 'A random tag'); $this->assertDebuggingCalled(); }
if (isguestuser()) { print_error('noguest'); } if (!confirm_sesskey()) { print_error('sesskey'); } switch ($action) { case 'addinterest': if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..) $tag = tag_get_name($id); } tag_set_add('user', $USER->id, $tag); redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag)); break; case 'removeinterest': if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..) $tag = tag_get_name($id); } tag_set_delete('user', $USER->id, $tag); redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag)); break; case 'flaginappropriate': tag_set_flag(tag_get_id($tag)); redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag), get_string('responsiblewillbenotified', 'tag')); break; default: print_error('unknowaction'); break; }
} if (!confirm_sesskey()) { print_error('sesskey'); } $usercontext = context_user::instance($USER->id); switch ($action) { case 'addinterest': if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..) $tag = tag_get_name($id); } tag_set_add('user', $USER->id, $tag, 'core', $usercontext->id); redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag)); break; case 'removeinterest': if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..) $tag = tag_get_name($id); } tag_set_delete('user', $USER->id, $tag, 'core', $usercontext->id); redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag)); break; case 'flaginappropriate': $tagid = tag_get_id($tag); tag_set_flag($tagid); redirect($CFG->wwwroot . '/tag/index.php?tag=' . rawurlencode($tag), get_string('responsiblewillbenotified', 'tag')); break; default: print_error('unknowaction'); break; }