Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 30... Línea 30...
30
global $CFG;
30
global $CFG;
Línea 31... Línea 31...
31
 
31
 
32
// Used to create a wiki page to tag.
32
// Used to create a wiki page to tag.
Línea 33... Línea 33...
33
require_once($CFG->dirroot . '/mod/wiki/locallib.php');
33
require_once($CFG->dirroot . '/mod/wiki/locallib.php');
Línea 34... Línea 34...
34
 
34
 
35
class events_test extends \advanced_testcase {
35
final class events_test extends \advanced_testcase {
36
 
36
 
37
    /**
37
    /**
38
     * Test set up.
38
     * Test set up.
39
     *
39
     *
-
 
40
     * This is executed before running any test in this file.
40
     * This is executed before running any test in this file.
41
     */
41
     */
42
    public function setUp(): void {
Línea 42... Línea 43...
42
    public function setUp(): void {
43
        parent::setUp();
43
        $this->resetAfterTest();
44
        $this->resetAfterTest();
Línea 97... Línea 98...
97
     */
98
     */
98
    public function test_tag_added(): void {
99
    public function test_tag_added(): void {
99
        global $DB;
100
        global $DB;
Línea 100... Línea 101...
100
 
101
 
101
        // Create a course to tag.
102
        // Create a course to tag.
-
 
103
        $course = self::getDataGenerator()->create_course();
-
 
104
        $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $course->id]);
Línea 102... Línea 105...
102
        $course = $this->getDataGenerator()->create_course();
105
        $qbankcontext = \context_module::instance($qbank->cmid);
103
 
106
 
104
        // Trigger and capture the event for tagging a course.
107
        // Trigger and capture the event for tagging a course.
105
        $sink = $this->redirectEvents();
108
        $sink = $this->redirectEvents();
Línea 112... Línea 115...
112
        $this->assertInstanceOf('\core\event\tag_added', $event);
115
        $this->assertInstanceOf('\core\event\tag_added', $event);
113
        $this->assertEquals(\context_course::instance($course->id), $event->get_context());
116
        $this->assertEquals(\context_course::instance($course->id), $event->get_context());
Línea 114... Línea 117...
114
 
117
 
115
        // Create a question to tag.
118
        // Create a question to tag.
116
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
119
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
117
        $cat = $questiongenerator->create_question_category();
120
        $cat = $questiongenerator->create_question_category(['contextid' => $qbankcontext->id]);
Línea 118... Línea 121...
118
        $question = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
121
        $question = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
119
 
122
 
120
        // Trigger and capture the event for tagging a question.
123
        // Trigger and capture the event for tagging a question.
Línea 126... Línea 129...
126
        $event = reset($events);
129
        $event = reset($events);
Línea 127... Línea 130...
127
 
130
 
128
        // Check that the tag was added to the question and the event data is valid.
131
        // Check that the tag was added to the question and the event data is valid.
129
        $this->assertEquals(1, $DB->count_records('tag_instance', array('component' => 'core')));
132
        $this->assertEquals(1, $DB->count_records('tag_instance', array('component' => 'core')));
130
        $this->assertInstanceOf('\core\event\tag_added', $event);
133
        $this->assertInstanceOf('\core\event\tag_added', $event);
131
        $this->assertEquals(\context_system::instance(), $event->get_context());
134
        $this->assertEquals($qbankcontext, $event->get_context());
Línea 132... Línea 135...
132
    }
135
    }
133
 
136
 
134
    /**
137
    /**