[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Tag related unit tests. 19 * 20 * @package core_tag 21 * @category test 22 * @copyright 2014 Mark Nelson <[email protected]> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 30 require_once($CFG->dirroot . '/tag/lib.php'); 31 32 class core_tag_taglib_testcase extends advanced_testcase { 33 34 /** 35 * Test set up. 36 * 37 * This is executed before running any test in this file. 38 */ 39 public function setUp() { 40 $this->resetAfterTest(); 41 } 42 43 /** 44 * Test the tag_set function. 45 */ 46 public function test_tag_set() { 47 global $DB; 48 49 // Create a course to tag. 50 $course = $this->getDataGenerator()->create_course(); 51 52 // Create the tag and tag instance. 53 tag_set('course', $course->id, array('A random tag'), 'core', context_course::instance($course->id)->id); 54 55 // Get the tag instance that should have been created. 56 $taginstance = $DB->get_record('tag_instance', array('itemtype' => 'course', 'itemid' => $course->id), '*', MUST_EXIST); 57 $this->assertEquals('core', $taginstance->component); 58 $this->assertEquals(context_course::instance($course->id)->id, $taginstance->contextid); 59 60 // Now call the tag_set function without specifying the component or contextid and 61 // ensure the function debugging is called. 62 tag_set('course', $course->id, array('Another tag')); 63 $this->assertDebuggingCalled(); 64 } 65 66 /** 67 * Test the tag_set_add function. 68 */ 69 public function test_tag_set_add() { 70 global $DB; 71 72 // Create a course to tag. 73 $course = $this->getDataGenerator()->create_course(); 74 75 // Create the tag and tag instance. 76 tag_set_add('course', $course->id, 'A random tag', 'core', context_course::instance($course->id)->id); 77 78 // Get the tag instance that should have been created. 79 $taginstance = $DB->get_record('tag_instance', array('itemtype' => 'course', 'itemid' => $course->id), '*', MUST_EXIST); 80 $this->assertEquals('core', $taginstance->component); 81 $this->assertEquals(context_course::instance($course->id)->id, $taginstance->contextid); 82 83 // Remove the tag we just created. 84 $tag = $DB->get_record('tag', array('rawname' => 'A random tag')); 85 tag_delete($tag->id); 86 87 // Now call the tag_set_add function without specifying the component or 88 // contextid and ensure the function debugging is called. 89 tag_set_add('course', $course->id, 'Another tag'); 90 $this->assertDebuggingCalled(); 91 } 92 93 /** 94 * Test the tag_set_delete function. 95 */ 96 public function test_tag_set_delete() { 97 global $DB; 98 99 // Create a course to tag. 100 $course = $this->getDataGenerator()->create_course(); 101 102 // Create the tag and tag instance we are going to delete. 103 tag_set_add('course', $course->id, 'A random tag', 'core', context_course::instance($course->id)->id); 104 105 // Call the tag_set_delete function. 106 tag_set_delete('course', $course->id, 'a random tag', 'core', context_course::instance($course->id)->id); 107 108 // Now check that there are no tags or tag instances. 109 $this->assertEquals(0, $DB->count_records('tag')); 110 $this->assertEquals(0, $DB->count_records('tag_instance')); 111 112 // Recreate the tag and tag instance. 113 tag_set_add('course', $course->id, 'A random tag', 'core', context_course::instance($course->id)->id); 114 115 // Now call the tag_set_delete function without specifying the component or 116 // contextid and ensure the function debugging is called. 117 tag_set_delete('course', $course->id, 'A random tag'); 118 $this->assertDebuggingCalled(); 119 } 120 121 /** 122 * Test the tag_assign function. 123 */ 124 public function test_tag_assign() { 125 global $DB; 126 127 // Create a course to tag. 128 $course = $this->getDataGenerator()->create_course(); 129 130 // Create the tag. 131 $tag = $this->getDataGenerator()->create_tag(); 132 133 // Tag the course with the tag we created. 134 tag_assign('course', $course->id, $tag->id, 0, 0, 'core', context_course::instance($course->id)->id); 135 136 // Get the tag instance that should have been created. 137 $taginstance = $DB->get_record('tag_instance', array('itemtype' => 'course', 'itemid' => $course->id), '*', MUST_EXIST); 138 $this->assertEquals('core', $taginstance->component); 139 $this->assertEquals(context_course::instance($course->id)->id, $taginstance->contextid); 140 141 // Now call the tag_assign function without specifying the component or 142 // contextid and ensure the function debugging is called. 143 tag_assign('course', $course->id, $tag->id, 0, 0); 144 $this->assertDebuggingCalled(); 145 } 146 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |