Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 22... Línea 22...
22
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
Línea 24... Línea 24...
24
 
24
 
Línea 25... Línea -...
25
namespace core_question\event;
-
 
26
 
25
namespace core_question\event;
27
use qbank_managecategories\question_category_object;
26
 
28
use qtype_description;
27
use qtype_description;
29
use qtype_description_edit_form;
28
use qtype_description_edit_form;
Línea 34... Línea 33...
34
 
33
 
Línea 35... Línea 34...
35
global $CFG;
34
global $CFG;
Línea 36... Línea 35...
36
 
35
 
Línea 37... Línea 36...
37
require_once($CFG->dirroot . '/question/editlib.php');
36
require_once($CFG->dirroot . '/question/editlib.php');
38
 
37
 
39
class events_test extends \advanced_testcase {
38
final class events_test extends \advanced_testcase {
40
 
39
 
-
 
40
    /**
41
    /**
41
     * Tests set up.
42
     * Tests set up.
42
     */
Línea 43... Línea 43...
43
     */
43
    public function setUp(): void {
44
    public function setUp(): void {
44
        parent::setUp();
Línea 53... Línea 53...
53
    public function test_questions_imported(): void {
53
    public function test_questions_imported(): void {
Línea 54... Línea 54...
54
 
54
 
55
        $this->setAdminUser();
55
        $this->setAdminUser();
56
        $course = $this->getDataGenerator()->create_course();
56
        $course = $this->getDataGenerator()->create_course();
-
 
57
        $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
Línea 57... Línea 58...
57
        $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
58
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
Línea 58... Línea 59...
58
 
59
 
59
        $contexts = new \core_question\local\bank\question_edit_contexts(\context_module::instance($quiz->cmid));
-
 
Línea 60... Línea 60...
60
 
60
        $contexts = new \core_question\local\bank\question_edit_contexts(\context_module::instance($quiz->cmid));
61
        $defaultcategoryobj = question_make_default_categories([$contexts->lowest()]);
-
 
62
        $defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
-
 
63
 
-
 
64
        $qcobject = new question_category_object(
61
 
65
                1,
62
        $defaultcategory = question_get_default_category($contexts->lowest()->id, true);
66
                new \moodle_url('/mod/quiz/edit.php', ['cmid' => $quiz->cmid]),
63
 
67
                $contexts->having_one_edit_tab_cap('categories'),
-
 
68
                $defaultcategoryobj->id,
-
 
69
                $defaultcategory,
-
 
70
                null,
-
 
Línea 71... Línea 64...
71
                $contexts->having_cap('moodle/question:add'));
64
        $category = $questiongenerator->create_question_category([
72
 
65
            'name' => 'newcategory',
73
        // Create the category.
66
            'parent' => $defaultcategory->id,
74
        $categoryid = $qcobject->add_category($defaultcategory, 'newcategory', '', true);
67
        ]);
75
 
68
 
Línea 76... Línea 69...
76
        // Log the view of this category.
69
        // Log the view of this category.
Línea 77... Línea 70...
77
        $params = [
70
        $params = [
Línea 88... Línea 81...
88
        $event = reset($events);
81
        $event = reset($events);
Línea 89... Línea 82...
89
 
82
 
90
        // Check that the event data is valid.
83
        // Check that the event data is valid.
91
        $this->assertInstanceOf('\core\event\questions_imported', $event);
84
        $this->assertInstanceOf('\core\event\questions_imported', $event);
92
        $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context());
85
        $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context());
93
        $this->assertEquals($categoryid, $event->other['categoryid']);
86
        $this->assertEquals($category->id, $event->other['categoryid']);
94
        $this->assertEquals('testformat', $event->other['format']);
87
        $this->assertEquals('testformat', $event->other['format']);
Línea 95... Línea 88...
95
        $this->assertDebuggingNotCalled();
88
        $this->assertDebuggingNotCalled();
Línea 104... Línea 97...
104
    public function test_questions_exported(): void {
97
    public function test_questions_exported(): void {
Línea 105... Línea 98...
105
 
98
 
106
        $this->setAdminUser();
99
        $this->setAdminUser();
107
        $course = $this->getDataGenerator()->create_course();
100
        $course = $this->getDataGenerator()->create_course();
-
 
101
        $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
Línea 108... Línea 102...
108
        $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
102
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
Línea 109... Línea 103...
109
 
103
 
110
        $contexts = new \core_question\local\bank\question_edit_contexts(\context_module::instance($quiz->cmid));
-
 
111
 
-
 
112
        $defaultcategoryobj = question_make_default_categories([$contexts->lowest()]);
-
 
113
        $defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
-
 
114
 
-
 
115
        $qcobject = new question_category_object(
-
 
116
                1,
-
 
117
                new \moodle_url('/mod/quiz/edit.php', ['cmid' => $quiz->cmid]),
-
 
118
                $contexts->having_one_edit_tab_cap('categories'),
-
 
119
                $defaultcategoryobj->id,
-
 
Línea -... Línea 104...
-
 
104
        $contexts = new \core_question\local\bank\question_edit_contexts(\context_module::instance($quiz->cmid));
120
                $defaultcategory,
105
 
121
                null,
106
        $defaultcategory = question_get_default_category($contexts->lowest()->id, true);
-
 
107
 
Línea 122... Línea 108...
122
                $contexts->having_cap('moodle/question:add'));
108
        $category = $questiongenerator->create_question_category([
123
 
109
            'name' => 'newcategory',
124
        // Create the category.
110
            'parent' => $defaultcategory->id,
125
        $categoryid = $qcobject->add_category($defaultcategory, 'newcategory', '', true);
111
        ]);
126
 
112
 
Línea 127... Línea 113...
127
        // Log the view of this category.
113
        // Log the view of this category.
Línea 128... Línea 114...
128
        $params = [
114
        $params = [
Línea 139... Línea 125...
139
        $event = reset($events);
125
        $event = reset($events);
Línea 140... Línea 126...
140
 
126
 
141
        // Check that the event data is valid.
127
        // Check that the event data is valid.
142
        $this->assertInstanceOf('\core\event\questions_exported', $event);
128
        $this->assertInstanceOf('\core\event\questions_exported', $event);
143
        $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context());
129
        $this->assertEquals(\context_module::instance($quiz->cmid), $event->get_context());
144
        $this->assertEquals($categoryid, $event->other['categoryid']);
130
        $this->assertEquals($category->id, $event->other['categoryid']);
145
        $this->assertEquals('testformat', $event->other['format']);
131
        $this->assertEquals('testformat', $event->other['format']);
Línea 146... Línea 132...
146
        $this->assertDebuggingNotCalled();
132
        $this->assertDebuggingNotCalled();