Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 53... Línea 53...
53
        parent::setUp();
53
        parent::setUp();
54
        $this->resetAfterTest();
54
        $this->resetAfterTest();
55
        $this->testpage = new testable_moodle_page();
55
        $this->testpage = new testable_moodle_page();
56
    }
56
    }
Línea 57... Línea 57...
57
 
57
 
58
    public function test_course_returns_site_before_set() {
58
    public function test_course_returns_site_before_set(): void {
59
        global $SITE;
59
        global $SITE;
60
        // Validated.
60
        // Validated.
61
        $this->assertSame($SITE, $this->testpage->course);
61
        $this->assertSame($SITE, $this->testpage->course);
Línea 62... Línea 62...
62
    }
62
    }
63
 
63
 
64
    public function test_setting_course_works() {
64
    public function test_setting_course_works(): void {
65
        // Setup fixture.
65
        // Setup fixture.
66
        $course = $this->getDataGenerator()->create_course();
66
        $course = $this->getDataGenerator()->create_course();
67
        $this->testpage->set_context(\context_system::instance()); // Avoid trying to set the context.
67
        $this->testpage->set_context(\context_system::instance()); // Avoid trying to set the context.
68
        // Exercise SUT.
68
        // Exercise SUT.
69
        $this->testpage->set_course($course);
69
        $this->testpage->set_course($course);
70
        // Validated.
70
        // Validated.
Línea 71... Línea 71...
71
        $this->assertEquals($course, $this->testpage->course);
71
        $this->assertEquals($course, $this->testpage->course);
72
    }
72
    }
73
 
73
 
74
    public function test_global_course_and_page_course_are_same_with_global_page() {
74
    public function test_global_course_and_page_course_are_same_with_global_page(): void {
75
        global $COURSE, $PAGE;
75
        global $COURSE, $PAGE;
76
        // Setup fixture.
76
        // Setup fixture.
Línea 81... Línea 81...
81
        $this->testpage->set_course($course);
81
        $this->testpage->set_course($course);
82
        // Validated.
82
        // Validated.
83
        $this->assertSame($COURSE, $this->testpage->course);
83
        $this->assertSame($COURSE, $this->testpage->course);
84
    }
84
    }
Línea 85... Línea 85...
85
 
85
 
86
    public function test_global_course_not_changed_with_non_global_page() {
86
    public function test_global_course_not_changed_with_non_global_page(): void {
87
        global $COURSE;
87
        global $COURSE;
88
        $originalcourse = $COURSE;
88
        $originalcourse = $COURSE;
89
        // Setup fixture.
89
        // Setup fixture.
90
        $course = $this->getDataGenerator()->create_course();
90
        $course = $this->getDataGenerator()->create_course();
Línea 93... Línea 93...
93
        $this->testpage->set_course($course);
93
        $this->testpage->set_course($course);
94
        // Validated.
94
        // Validated.
95
        $this->assertSame($originalcourse, $COURSE);
95
        $this->assertSame($originalcourse, $COURSE);
96
    }
96
    }
Línea 97... Línea 97...
97
 
97
 
98
    public function test_cannot_set_course_once_theme_set() {
98
    public function test_cannot_set_course_once_theme_set(): void {
99
        // Setup fixture.
99
        // Setup fixture.
100
        $this->testpage->force_theme(\theme_config::DEFAULT_THEME);
100
        $this->testpage->force_theme(\theme_config::DEFAULT_THEME);
Línea 101... Línea 101...
101
        $course = $this->getDataGenerator()->create_course();
101
        $course = $this->getDataGenerator()->create_course();
102
 
102
 
103
        // Exercise SUT.
103
        // Exercise SUT.
104
        $this->expectException(\coding_exception::class);
104
        $this->expectException(\coding_exception::class);
Línea 105... Línea 105...
105
        $this->testpage->set_course($course);
105
        $this->testpage->set_course($course);
106
    }
106
    }
107
 
107
 
Línea 108... Línea 108...
108
    public function test_cannot_set_category_once_theme_set() {
108
    public function test_cannot_set_category_once_theme_set(): void {
109
        // Setup fixture.
109
        // Setup fixture.
110
        $this->testpage->force_theme(\theme_config::DEFAULT_THEME);
110
        $this->testpage->force_theme(\theme_config::DEFAULT_THEME);
111
 
111
 
Línea 112... Línea 112...
112
        // Exercise SUT.
112
        // Exercise SUT.
113
        $this->expectException(\coding_exception::class);
113
        $this->expectException(\coding_exception::class);
114
        $this->testpage->set_category_by_id(123);
114
        $this->testpage->set_category_by_id(123);
115
    }
115
    }
116
 
116
 
Línea 117... Línea 117...
117
    public function test_cannot_set_category_once_course_set() {
117
    public function test_cannot_set_category_once_course_set(): void {
118
        // Setup fixture.
118
        // Setup fixture.
119
        $course = $this->getDataGenerator()->create_course();
119
        $course = $this->getDataGenerator()->create_course();
120
        $this->testpage->set_context(\context_system::instance()); // Avoid trying to set the context.
120
        $this->testpage->set_context(\context_system::instance()); // Avoid trying to set the context.
Línea 121... Línea 121...
121
        $this->testpage->set_course($course);
121
        $this->testpage->set_course($course);
122
 
122
 
123
        // Exercise SUT.
123
        // Exercise SUT.
124
        $this->expectException(\coding_exception::class);
124
        $this->expectException(\coding_exception::class);
125
        $this->testpage->set_category_by_id(123);
125
        $this->testpage->set_category_by_id(123);
126
    }
126
    }
127
 
127
 
128
    public function test_categories_array_empty_for_front_page() {
128
    public function test_categories_array_empty_for_front_page(): void {
Línea 129... Línea 129...
129
        global $SITE;
129
        global $SITE;
130
        // Setup fixture.
130
        // Setup fixture.
131
        $this->testpage->set_context(\context_system::instance()); // Avoid trying to set the context.
131
        $this->testpage->set_context(\context_system::instance()); // Avoid trying to set the context.
132
        $this->testpage->set_course($SITE);
132
        $this->testpage->set_course($SITE);
Línea 133... Línea 133...
133
        // Exercise SUT and validate.
133
        // Exercise SUT and validate.
Línea 149... Línea 149...
149
 
149
 
150
        $this->testpage->set_state(\moodle_page::STATE_DONE);
150
        $this->testpage->set_state(\moodle_page::STATE_DONE);
151
        $this->assertEquals(\moodle_page::STATE_DONE, $this->testpage->state);
151
        $this->assertEquals(\moodle_page::STATE_DONE, $this->testpage->state);
Línea 152... Línea 152...
152
    }
152
    }
153
 
153
 
154
    public function test_set_state_cannot_skip_one() {
154
    public function test_set_state_cannot_skip_one(): void {
155
        // Exercise SUT.
155
        // Exercise SUT.
156
        $this->expectException(\coding_exception::class);
156
        $this->expectException(\coding_exception::class);
Línea 157... Línea 157...
157
        $this->testpage->set_state(\moodle_page::STATE_IN_BODY);
157
        $this->testpage->set_state(\moodle_page::STATE_IN_BODY);
158
    }
158
    }
159
 
159
 
160
    public function test_header_printed_false_initially() {
160
    public function test_header_printed_false_initially(): void {
Línea 161... Línea 161...
161
        // Validated.
161
        // Validated.
162
        $this->assertFalse($this->testpage->headerprinted);
162
        $this->assertFalse($this->testpage->headerprinted);
163
    }
163
    }
164
 
164
 
Línea 165... Línea 165...
165
    public function test_header_printed_becomes_true() {
165
    public function test_header_printed_becomes_true(): void {
Línea 172... Línea 172...
172
        $this->testpage->set_state(\moodle_page::STATE_IN_BODY);
172
        $this->testpage->set_state(\moodle_page::STATE_IN_BODY);
173
        // Validated.
173
        // Validated.
174
        $this->assertTrue($this->testpage->headerprinted);
174
        $this->assertTrue($this->testpage->headerprinted);
175
    }
175
    }
Línea 176... Línea 176...
176
 
176
 
177
    public function test_set_context() {
177
    public function test_set_context(): void {
178
        // Setup fixture.
178
        // Setup fixture.
179
        $course = $this->getDataGenerator()->create_course();
179
        $course = $this->getDataGenerator()->create_course();
180
        $context = \context_course::instance($course->id);
180
        $context = \context_course::instance($course->id);
181
        // Exercise SUT.
181
        // Exercise SUT.
182
        $this->testpage->set_context($context);
182
        $this->testpage->set_context($context);
183
        // Validated.
183
        // Validated.
184
        $this->assertSame($context, $this->testpage->context);
184
        $this->assertSame($context, $this->testpage->context);
Línea 185... Línea 185...
185
    }
185
    }
186
 
186
 
187
    public function test_pagetype_defaults_to_script() {
187
    public function test_pagetype_defaults_to_script(): void {
188
        global $SCRIPT;
188
        global $SCRIPT;
189
        // Exercise SUT and validate.
189
        // Exercise SUT and validate.
190
        $SCRIPT = '/index.php';
190
        $SCRIPT = '/index.php';
191
        $this->testpage->initialise_default_pagetype();
191
        $this->testpage->initialise_default_pagetype();
Línea 192... Línea 192...
192
        $this->assertSame('site-index', $this->testpage->pagetype);
192
        $this->assertSame('site-index', $this->testpage->pagetype);
193
    }
193
    }
194
 
194
 
195
    public function test_set_pagetype() {
195
    public function test_set_pagetype(): void {
196
        // Exercise SUT.
196
        // Exercise SUT.
197
        $this->testpage->set_pagetype('a-page-type');
197
        $this->testpage->set_pagetype('a-page-type');
Línea 198... Línea 198...
198
        // Validated.
198
        // Validated.
199
        $this->assertSame('a-page-type', $this->testpage->pagetype);
199
        $this->assertSame('a-page-type', $this->testpage->pagetype);
200
    }
200
    }
201
 
201
 
202
    public function test_initialise_default_pagetype() {
202
    public function test_initialise_default_pagetype(): void {
203
        // Exercise SUT.
203
        // Exercise SUT.
Línea 204... Línea 204...
204
        $this->testpage->initialise_default_pagetype('admin/tool/unittest/index.php');
204
        $this->testpage->initialise_default_pagetype('admin/tool/unittest/index.php');
205
        // Validated.
205
        // Validated.
206
        $this->assertSame('admin-tool-unittest-index', $this->testpage->pagetype);
206
        $this->assertSame('admin-tool-unittest-index', $this->testpage->pagetype);
207
    }
207
    }
208
 
208
 
209
    public function test_initialise_default_pagetype_fp() {
209
    public function test_initialise_default_pagetype_fp(): void {
Línea 210... Línea 210...
210
        // Exercise SUT.
210
        // Exercise SUT.
211
        $this->testpage->initialise_default_pagetype('index.php');
211
        $this->testpage->initialise_default_pagetype('index.php');
212
        // Validated.
212
        // Validated.
213
        $this->assertSame('site-index', $this->testpage->pagetype);
213
        $this->assertSame('site-index', $this->testpage->pagetype);
Línea 214... Línea 214...
214
    }
214
    }
215
 
215
 
216
    public function test_get_body_classes_empty() {
216
    public function test_get_body_classes_empty(): void {
217
        // Validated.
217
        // Validated.
218
        $this->assertSame('', $this->testpage->bodyclasses);
218
        $this->assertSame('', $this->testpage->bodyclasses);
219
    }
219
    }
Línea 220... Línea 220...
220
 
220
 
221
    public function test_get_body_classes_single() {
221
    public function test_get_body_classes_single(): void {
222
        // Exercise SUT.
222
        // Exercise SUT.
223
        $this->testpage->add_body_class('aclassname');
223
        $this->testpage->add_body_class('aclassname');
224
        // Validated.
224
        // Validated.
225
        $this->assertSame('aclassname', $this->testpage->bodyclasses);
225
        $this->assertSame('aclassname', $this->testpage->bodyclasses);
Línea 226... Línea 226...
226
    }
226
    }
227
 
227
 
228
    public function test_get_body_classes() {
228
    public function test_get_body_classes(): void {
229
        // Exercise SUT.
229
        // Exercise SUT.
230
        $this->testpage->add_body_classes(array('aclassname', 'anotherclassname'));
230
        $this->testpage->add_body_classes(array('aclassname', 'anotherclassname'));
231
        // Validated.
231
        // Validated.
Línea 232... Línea 232...
232
        $this->assertSame('aclassname anotherclassname', $this->testpage->bodyclasses);
232
        $this->assertSame('aclassname anotherclassname', $this->testpage->bodyclasses);
233
    }
233
    }
234
 
234
 
235
    public function test_url_to_class_name() {
235
    public function test_url_to_class_name(): void {
236
        $this->assertSame('example-com', $this->testpage->url_to_class_name('http://example.com'));
236
        $this->assertSame('example-com', $this->testpage->url_to_class_name('http://example.com'));
237
        $this->assertSame('example-com--80', $this->testpage->url_to_class_name('http://example.com:80'));
237
        $this->assertSame('example-com--80', $this->testpage->url_to_class_name('http://example.com:80'));
Línea 238... Línea 238...
238
        $this->assertSame('example-com--moodle', $this->testpage->url_to_class_name('https://example.com/moodle'));
238
        $this->assertSame('example-com--moodle', $this->testpage->url_to_class_name('https://example.com/moodle'));
239
        $this->assertSame('example-com--8080--nested-moodle', $this->testpage->url_to_class_name('https://example.com:8080/nested/moodle'));
239
        $this->assertSame('example-com--8080--nested-moodle', $this->testpage->url_to_class_name('https://example.com:8080/nested/moodle'));
240
    }
240
    }
241
 
241
 
242
    public function test_set_docs_path() {
242
    public function test_set_docs_path(): void {
243
        // Exercise SUT.
243
        // Exercise SUT.
Línea 244... Línea 244...
244
        $this->testpage->set_docs_path('a/file/path');
244
        $this->testpage->set_docs_path('a/file/path');
245
        // Validated.
245
        // Validated.
246
        $this->assertSame('a/file/path', $this->testpage->docspath);
246
        $this->assertSame('a/file/path', $this->testpage->docspath);
247
    }
247
    }
248
 
248
 
249
    public function test_docs_path_defaults_from_pagetype() {
249
    public function test_docs_path_defaults_from_pagetype(): void {
250
        // Exercise SUT.
250
        // Exercise SUT.
Línea 251... Línea 251...
251
        $this->testpage->set_pagetype('a-page-type');
251
        $this->testpage->set_pagetype('a-page-type');
252
        // Validated.
252
        // Validated.
253
        $this->assertSame('a/page/type', $this->testpage->docspath);
253
        $this->assertSame('a/page/type', $this->testpage->docspath);
254
    }
254
    }
255
 
255
 
256
    public function test_set_url_root() {
256
    public function test_set_url_root(): void {
257
        global $CFG;
257
        global $CFG;
Línea 258... Línea 258...
258
        // Exercise SUT.
258
        // Exercise SUT.
259
        $this->testpage->set_url('/');
259
        $this->testpage->set_url('/');
260
        // Validated.
260
        // Validated.
261
        $this->assertSame($CFG->wwwroot . '/', $this->testpage->url->out());
261
        $this->assertSame($CFG->wwwroot . '/', $this->testpage->url->out());
262
    }
262
    }
263
 
263
 
264
    public function test_set_url_one_param() {
264
    public function test_set_url_one_param(): void {
Línea 265... Línea 265...
265
        global $CFG;
265
        global $CFG;
266
        // Exercise SUT.
266
        // Exercise SUT.
267
        $this->testpage->set_url('/mod/quiz/attempt.php', array('attempt' => 123));
267
        $this->testpage->set_url('/mod/quiz/attempt.php', array('attempt' => 123));
268
        // Validated.
268
        // Validated.
269
        $this->assertSame($CFG->wwwroot . '/mod/quiz/attempt.php?attempt=123', $this->testpage->url->out());
269
        $this->assertSame($CFG->wwwroot . '/mod/quiz/attempt.php?attempt=123', $this->testpage->url->out());
270
    }
270
    }
271
 
271
 
272
    public function test_set_url_two_params() {
272
    public function test_set_url_two_params(): void {
273
        global $CFG;
273
        global $CFG;
Línea 274... Línea 274...
274
        // Exercise SUT.
274
        // Exercise SUT.
275
        $this->testpage->set_url('/mod/quiz/attempt.php', array('attempt' => 123, 'page' => 7));
275
        $this->testpage->set_url('/mod/quiz/attempt.php', array('attempt' => 123, 'page' => 7));
276
        // Validated.
276
        // Validated.
277
        $this->assertSame($CFG->wwwroot . '/mod/quiz/attempt.php?attempt=123&page=7', $this->testpage->url->out());
277
        $this->assertSame($CFG->wwwroot . '/mod/quiz/attempt.php?attempt=123&page=7', $this->testpage->url->out());
278
    }
278
    }
279
 
279
 
Línea 280... Línea 280...
280
    public function test_set_url_using_moodle_url() {
280
    public function test_set_url_using_moodle_url(): void {
281
        global $CFG;
281
        global $CFG;
282
        // Fixture setup.
282
        // Fixture setup.
283
        $url = new \moodle_url('/mod/workshop/allocation.php', array('cmid' => 29, 'method' => 'manual'));
283
        $url = new \moodle_url('/mod/workshop/allocation.php', array('cmid' => 29, 'method' => 'manual'));
284
        // Exercise SUT.
284
        // Exercise SUT.
285
        $this->testpage->set_url($url);
285
        $this->testpage->set_url($url);
286
        // Validated.
286
        // Validated.
287
        $this->assertSame($CFG->wwwroot . '/mod/workshop/allocation.php?cmid=29&method=manual', $this->testpage->url->out());
287
        $this->assertSame($CFG->wwwroot . '/mod/workshop/allocation.php?cmid=29&method=manual', $this->testpage->url->out());
Línea 288... Línea 288...
288
    }
288
    }
289
 
289
 
290
    public function test_set_url_sets_page_type() {
290
    public function test_set_url_sets_page_type(): void {
291
        // Exercise SUT.
291
        // Exercise SUT.
292
        $this->testpage->set_url('/mod/quiz/attempt.php', array('attempt' => 123, 'page' => 7));
292
        $this->testpage->set_url('/mod/quiz/attempt.php', array('attempt' => 123, 'page' => 7));
293
        // Validated.
293
        // Validated.
Línea 294... Línea 294...
294
        $this->assertSame('mod-quiz-attempt', $this->testpage->pagetype);
294
        $this->assertSame('mod-quiz-attempt', $this->testpage->pagetype);
295
    }
295
    }
296
 
296
 
297
    public function test_set_url_does_not_change_explicit_page_type() {
297
    public function test_set_url_does_not_change_explicit_page_type(): void {
298
        // Setup fixture.
298
        // Setup fixture.
Línea 389... Línea 389...
389
        $this->testpage->set_title($title, $appendsitename);
389
        $this->testpage->set_title($title, $appendsitename);
390
        // Validated.
390
        // Validated.
391
        $this->assertSame($expectedtitle, $this->testpage->title);
391
        $this->assertSame($expectedtitle, $this->testpage->title);
392
    }
392
    }
Línea 393... Línea 393...
393
 
393
 
394
    public function test_default_pagelayout() {
394
    public function test_default_pagelayout(): void {
395
        // Exercise SUT and Validate.
395
        // Exercise SUT and Validate.
396
        $this->assertSame('base', $this->testpage->pagelayout);
396
        $this->assertSame('base', $this->testpage->pagelayout);
Línea 397... Línea 397...
397
    }
397
    }
398
 
398
 
399
    public function test_set_pagelayout() {
399
    public function test_set_pagelayout(): void {
400
        // Exercise SUT.
400
        // Exercise SUT.
401
        $this->testpage->set_pagelayout('type');
401
        $this->testpage->set_pagelayout('type');
402
        // Validated.
402
        // Validated.
Línea 403... Línea 403...
403
        $this->assertSame('type', $this->testpage->pagelayout);
403
        $this->assertSame('type', $this->testpage->pagelayout);
404
    }
404
    }
405
 
405
 
406
    public function test_setting_course_sets_context() {
406
    public function test_setting_course_sets_context(): void {
Línea 407... Línea 407...
407
        // Setup fixture.
407
        // Setup fixture.
Línea 413... Línea 413...
413
 
413
 
414
        // Validated.
414
        // Validated.
415
        $this->assertSame($context, $this->testpage->context);
415
        $this->assertSame($context, $this->testpage->context);
Línea 416... Línea 416...
416
    }
416
    }
417
 
417
 
418
    public function test_set_category_top_level() {
418
    public function test_set_category_top_level(): void {
419
        global $DB;
419
        global $DB;
420
        // Setup fixture.
420
        // Setup fixture.
421
        $cat = $this->getDataGenerator()->create_category();
421
        $cat = $this->getDataGenerator()->create_category();
Línea 425... Línea 425...
425
        // Validated.
425
        // Validated.
426
        $this->assertEquals($catdbrecord, $this->testpage->category);
426
        $this->assertEquals($catdbrecord, $this->testpage->category);
427
        $this->assertSame(\context_coursecat::instance($cat->id), $this->testpage->context);
427
        $this->assertSame(\context_coursecat::instance($cat->id), $this->testpage->context);
428
    }
428
    }
Línea 429... Línea 429...
429
 
429
 
430
    public function test_set_nested_categories() {
430
    public function test_set_nested_categories(): void {
431
        global $DB;
431
        global $DB;
432
        // Setup fixture.
432
        // Setup fixture.
433
        $topcat = $this->getDataGenerator()->create_category();
433
        $topcat = $this->getDataGenerator()->create_category();
434
        $topcatdbrecord = $DB->get_record('course_categories', array('id' => $topcat->id));
434
        $topcatdbrecord = $DB->get_record('course_categories', array('id' => $topcat->id));
Línea 441... Línea 441...
441
        $this->assertCount(2, $categories);
441
        $this->assertCount(2, $categories);
442
        $this->assertEquals($topcatdbrecord, array_pop($categories));
442
        $this->assertEquals($topcatdbrecord, array_pop($categories));
443
        $this->assertEquals($subcatdbrecord, array_pop($categories));
443
        $this->assertEquals($subcatdbrecord, array_pop($categories));
444
    }
444
    }
Línea 445... Línea 445...
445
 
445
 
446
    public function test_cm_null_initially() {
446
    public function test_cm_null_initially(): void {
447
        // Validated.
447
        // Validated.
448
        $this->assertNull($this->testpage->cm);
448
        $this->assertNull($this->testpage->cm);
Línea 449... Línea 449...
449
    }
449
    }
450
 
450
 
451
    public function test_set_cm() {
451
    public function test_set_cm(): void {
452
        // Setup fixture.
452
        // Setup fixture.
453
        $course = $this->getDataGenerator()->create_course();
453
        $course = $this->getDataGenerator()->create_course();
454
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
454
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
455
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
455
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
456
        // Exercise SUT.
456
        // Exercise SUT.
457
        $this->testpage->set_cm($cm);
457
        $this->testpage->set_cm($cm);
458
        // Validated.
458
        // Validated.
Línea 459... Línea 459...
459
        $this->assertEquals($cm->id, $this->testpage->cm->id);
459
        $this->assertEquals($cm->id, $this->testpage->cm->id);
460
    }
460
    }
461
 
461
 
462
    public function test_cannot_set_activity_record_before_cm() {
462
    public function test_cannot_set_activity_record_before_cm(): void {
463
        // Setup fixture.
463
        // Setup fixture.
464
        $course = $this->getDataGenerator()->create_course();
464
        $course = $this->getDataGenerator()->create_course();
465
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
465
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
466
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
466
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
467
        // Exercise SUT.
467
        // Exercise SUT.
Línea 468... Línea 468...
468
        $this->expectException(\coding_exception::class);
468
        $this->expectException(\coding_exception::class);
469
        $this->testpage->set_activity_record($forum);
469
        $this->testpage->set_activity_record($forum);
470
    }
470
    }
471
 
471
 
472
    public function test_setting_cm_sets_context() {
472
    public function test_setting_cm_sets_context(): void {
473
        // Setup fixture.
473
        // Setup fixture.
474
        $course = $this->getDataGenerator()->create_course();
474
        $course = $this->getDataGenerator()->create_course();
475
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
475
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
476
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
476
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
477
        // Exercise SUT.
477
        // Exercise SUT.
Línea 478... Línea 478...
478
        $this->testpage->set_cm($cm);
478
        $this->testpage->set_cm($cm);
479
        // Validated.
479
        // Validated.
480
        $this->assertSame(\context_module::instance($cm->id), $this->testpage->context);
480
        $this->assertSame(\context_module::instance($cm->id), $this->testpage->context);
481
    }
481
    }
482
 
482
 
483
    public function test_activity_record_loaded_if_not_set() {
483
    public function test_activity_record_loaded_if_not_set(): void {
Línea 490... Línea 490...
490
        // Validated.
490
        // Validated.
491
        unset($forum->cmid);
491
        unset($forum->cmid);
492
        $this->assertEquals($forum, $this->testpage->activityrecord);
492
        $this->assertEquals($forum, $this->testpage->activityrecord);
493
    }
493
    }
Línea 494... Línea 494...
494
 
494
 
495
    public function test_set_activity_record() {
495
    public function test_set_activity_record(): void {
496
        // Setup fixture.
496
        // Setup fixture.
497
        $course = $this->getDataGenerator()->create_course();
497
        $course = $this->getDataGenerator()->create_course();
498
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
498
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
499
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
499
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
Línea 503... Línea 503...
503
        // Validated.
503
        // Validated.
504
        unset($forum->cmid);
504
        unset($forum->cmid);
505
        $this->assertEquals($forum, $this->testpage->activityrecord);
505
        $this->assertEquals($forum, $this->testpage->activityrecord);
506
    }
506
    }
Línea 507... Línea 507...
507
 
507
 
508
    public function test_cannot_set_inconsistent_activity_record_course() {
508
    public function test_cannot_set_inconsistent_activity_record_course(): void {
509
        // Setup fixture.
509
        // Setup fixture.
510
        $course = $this->getDataGenerator()->create_course();
510
        $course = $this->getDataGenerator()->create_course();
511
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
511
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
512
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
512
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
Línea 515... Línea 515...
515
        $forum->course = 13;
515
        $forum->course = 13;
516
        $this->expectException(\coding_exception::class);
516
        $this->expectException(\coding_exception::class);
517
        $this->testpage->set_activity_record($forum);
517
        $this->testpage->set_activity_record($forum);
518
    }
518
    }
Línea 519... Línea 519...
519
 
519
 
520
    public function test_cannot_set_inconsistent_activity_record_instance() {
520
    public function test_cannot_set_inconsistent_activity_record_instance(): void {
521
        // Setup fixture.
521
        // Setup fixture.
522
        $course = $this->getDataGenerator()->create_course();
522
        $course = $this->getDataGenerator()->create_course();
523
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
523
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
524
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
524
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
Línea 527... Línea 527...
527
        $forum->id = 13;
527
        $forum->id = 13;
528
        $this->expectException(\coding_exception::class);
528
        $this->expectException(\coding_exception::class);
529
        $this->testpage->set_activity_record($forum);
529
        $this->testpage->set_activity_record($forum);
530
    }
530
    }
Línea 531... Línea 531...
531
 
531
 
532
    public function test_setting_cm_sets_course() {
532
    public function test_setting_cm_sets_course(): void {
533
        // Setup fixture.
533
        // Setup fixture.
534
        $course = $this->getDataGenerator()->create_course();
534
        $course = $this->getDataGenerator()->create_course();
535
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
535
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
536
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
536
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
537
        // Exercise SUT.
537
        // Exercise SUT.
538
        $this->testpage->set_cm($cm);
538
        $this->testpage->set_cm($cm);
539
        // Validated.
539
        // Validated.
540
        $this->assertEquals($course->id, $this->testpage->course->id);
540
        $this->assertEquals($course->id, $this->testpage->course->id);
Línea 541... Línea 541...
541
    }
541
    }
542
 
542
 
543
    public function test_set_cm_with_course_and_activity_no_db() {
543
    public function test_set_cm_with_course_and_activity_no_db(): void {
544
        // Setup fixture.
544
        // Setup fixture.
545
        $course = $this->getDataGenerator()->create_course();
545
        $course = $this->getDataGenerator()->create_course();
546
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
546
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
Línea 553... Línea 553...
553
        $this->assertEquals($course->id, $this->testpage->course->id);
553
        $this->assertEquals($course->id, $this->testpage->course->id);
554
        unset($forum->cmid);
554
        unset($forum->cmid);
555
        $this->assertEquals($forum, $this->testpage->activityrecord);
555
        $this->assertEquals($forum, $this->testpage->activityrecord);
556
    }
556
    }
Línea 557... Línea 557...
557
 
557
 
558
    public function test_cannot_set_cm_with_inconsistent_course() {
558
    public function test_cannot_set_cm_with_inconsistent_course(): void {
559
        // Setup fixture.
559
        // Setup fixture.
560
        $course = $this->getDataGenerator()->create_course();
560
        $course = $this->getDataGenerator()->create_course();
561
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
561
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
562
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
562
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
563
        // Exercise SUT.
563
        // Exercise SUT.
564
        $cm->course = 13;
564
        $cm->course = 13;
565
        $this->expectException(\coding_exception::class);
565
        $this->expectException(\coding_exception::class);
566
        $this->testpage->set_cm($cm, $course);
566
        $this->testpage->set_cm($cm, $course);
Línea 567... Línea 567...
567
    }
567
    }
568
 
568
 
569
    public function test_get_activity_name() {
569
    public function test_get_activity_name(): void {
570
        // Setup fixture.
570
        // Setup fixture.
571
        $course = $this->getDataGenerator()->create_course();
571
        $course = $this->getDataGenerator()->create_course();
572
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
572
        $forum = $this->getDataGenerator()->create_module('forum', array('course'=>$course->id));
573
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
573
        $cm = get_coursemodule_from_id('forum', $forum->cmid);
574
        // Exercise SUT.
574
        // Exercise SUT.
575
        $this->testpage->set_cm($cm, $course, $forum);
575
        $this->testpage->set_cm($cm, $course, $forum);
576
        // Validated.
576
        // Validated.
Línea 577... Línea 577...
577
        $this->assertSame('forum', $this->testpage->activityname);
577
        $this->assertSame('forum', $this->testpage->activityname);
578
    }
578
    }
579
 
579
 
Línea 580... Línea 580...
580
    public function test_user_is_editing_on() {
580
    public function test_user_is_editing_on(): void {
581
        // We are relying on the fact that unit tests are always run by admin, to
581
        // We are relying on the fact that unit tests are always run by admin, to
Línea 590... Línea 590...
590
        $USER->editing = true;
590
        $USER->editing = true;
591
        // Validated.
591
        // Validated.
592
        $this->assertTrue($this->testpage->user_is_editing());
592
        $this->assertTrue($this->testpage->user_is_editing());
593
    }
593
    }
Línea 594... Línea 594...
594
 
594
 
595
    public function test_user_is_editing_off() {
595
    public function test_user_is_editing_off(): void {
596
        // We are relying on the fact that unit tests are always run by admin, to
596
        // We are relying on the fact that unit tests are always run by admin, to
Línea 597... Línea 597...
597
        // ensure the user_allows_editing call returns true.
597
        // ensure the user_allows_editing call returns true.
598
 
598
 
Línea 605... Línea 605...
605
        $USER->editing = false;
605
        $USER->editing = false;
606
        // Validated.
606
        // Validated.
607
        $this->assertFalse($this->testpage->user_is_editing());
607
        $this->assertFalse($this->testpage->user_is_editing());
608
    }
608
    }
Línea 609... Línea 609...
609
 
609
 
610
    public function test_default_editing_capabilities() {
610
    public function test_default_editing_capabilities(): void {
611
        $this->testpage->set_context(\context_system::instance());
611
        $this->testpage->set_context(\context_system::instance());
Línea 612... Línea 612...
612
        $this->setAdminUser();
612
        $this->setAdminUser();
613
 
613
 
614
        // Validated.
614
        // Validated.
Línea 615... Línea 615...
615
        $this->assertEquals(array('moodle/site:manageblocks'), $this->testpage->all_editing_caps());
615
        $this->assertEquals(array('moodle/site:manageblocks'), $this->testpage->all_editing_caps());
616
    }
616
    }
617
 
617
 
Línea 618... Línea 618...
618
    public function test_other_block_editing_cap() {
618
    public function test_other_block_editing_cap(): void {
619
        $this->testpage->set_context(\context_system::instance());
619
        $this->testpage->set_context(\context_system::instance());
620
        $this->setAdminUser();
620
        $this->setAdminUser();
621
 
621
 
622
        // Exercise SUT.
622
        // Exercise SUT.
Línea 623... Línea 623...
623
        $this->testpage->set_blocks_editing_capability('moodle/my:manageblocks');
623
        $this->testpage->set_blocks_editing_capability('moodle/my:manageblocks');
624
        // Validated.
624
        // Validated.
625
        $this->assertEquals(array('moodle/my:manageblocks'), $this->testpage->all_editing_caps());
625
        $this->assertEquals(array('moodle/my:manageblocks'), $this->testpage->all_editing_caps());
Línea 626... Línea 626...
626
    }
626
    }
627
 
627
 
Línea 635... Línea 635...
635
        $actualcaps = $this->testpage->all_editing_caps();
635
        $actualcaps = $this->testpage->all_editing_caps();
636
        $expectedcaps = array('moodle/course:manageactivities', 'moodle/site:manageblocks');
636
        $expectedcaps = array('moodle/course:manageactivities', 'moodle/site:manageblocks');
637
        $this->assertEquals(array_values($expectedcaps), array_values($actualcaps));
637
        $this->assertEquals(array_values($expectedcaps), array_values($actualcaps));
638
    }
638
    }
Línea 639... Línea 639...
639
 
639
 
640
    public function test_other_editing_caps() {
640
    public function test_other_editing_caps(): void {
641
        $this->testpage->set_context(\context_system::instance());
641
        $this->testpage->set_context(\context_system::instance());
Línea 642... Línea 642...
642
        $this->setAdminUser();
642
        $this->setAdminUser();
643
 
643
 
Línea 650... Línea 650...
650
    }
650
    }
Línea 651... Línea 651...
651
 
651
 
652
    /**
652
    /**
653
     * Test getting a renderer.
653
     * Test getting a renderer.
654
     */
654
     */
655
    public function test_get_renderer() {
655
    public function test_get_renderer(): void {
656
        global $OUTPUT, $PAGE;
656
        global $OUTPUT, $PAGE;
657
        $oldoutput = $OUTPUT;
657
        $oldoutput = $OUTPUT;
658
        $oldpage = $PAGE;
658
        $oldpage = $PAGE;
Línea 688... Línea 688...
688
    /**
688
    /**
689
     * Tests getting a renderer with a maintenance layout.
689
     * Tests getting a renderer with a maintenance layout.
690
     *
690
     *
691
     * This layout has special hacks in place in order to deliver a "maintenance" renderer.
691
     * This layout has special hacks in place in order to deliver a "maintenance" renderer.
692
     */
692
     */
693
    public function test_get_renderer_maintenance() {
693
    public function test_get_renderer_maintenance(): void {
694
        global $OUTPUT, $PAGE;
694
        global $OUTPUT, $PAGE;
695
        $oldoutput = $OUTPUT;
695
        $oldoutput = $OUTPUT;
696
        $oldpage = $PAGE;
696
        $oldpage = $PAGE;
697
        $PAGE = $this->testpage;
697
        $PAGE = $this->testpage;
Línea 720... Línea 720...
720
 
720
 
721
        $PAGE = $oldpage;
721
        $PAGE = $oldpage;
722
        $OUTPUT = $oldoutput;
722
        $OUTPUT = $oldoutput;
Línea 723... Línea 723...
723
    }
723
    }
724
 
724
 
Línea 725... Línea 725...
725
    public function test_render_to_cli() {
725
    public function test_render_to_cli(): void {
726
        global $OUTPUT;
726
        global $OUTPUT;
727
 
727
 
Línea 732... Línea 732...
732
    /**
732
    /**
733
     * Validate the theme value depending on the user theme and cohorts.
733
     * Validate the theme value depending on the user theme and cohorts.
734
     *
734
     *
735
     * @dataProvider get_user_theme_provider
735
     * @dataProvider get_user_theme_provider
736
     */
736
     */
737
    public function test_cohort_get_user_theme($usertheme, $sitetheme, $cohortthemes, $expected) {
737
    public function test_cohort_get_user_theme($usertheme, $sitetheme, $cohortthemes, $expected): void {
738
        global $DB, $PAGE, $USER;
738
        global $DB, $PAGE, $USER;
Línea 739... Línea 739...
739
 
739
 
Línea 740... Línea 740...
740
        $this->resetAfterTest();
740
        $this->resetAfterTest();
Línea 837... Línea 837...
837
 
837
 
838
    /**
838
    /**
839
     * Tests user_can_edit_blocks() returns the expected response.
839
     * Tests user_can_edit_blocks() returns the expected response.
840
     * @covers ::user_can_edit_blocks()
840
     * @covers ::user_can_edit_blocks()
841
     */
841
     */
842
    public function test_user_can_edit_blocks() {
842
    public function test_user_can_edit_blocks(): void {
Línea 843... Línea 843...
843
        global $DB;
843
        global $DB;
844
 
844
 
Línea 862... Línea 862...
862
 
862
 
863
    /**
863
    /**
864
     * Tests that calling force_lock_all_blocks() will cause user_can_edit_blocks() to return false, regardless of capabilities.
864
     * Tests that calling force_lock_all_blocks() will cause user_can_edit_blocks() to return false, regardless of capabilities.
865
     * @covers ::force_lock_all_blocks()
865
     * @covers ::force_lock_all_blocks()
866
     */
866
     */
867
    public function test_force_lock_all_blocks() {
867
    public function test_force_lock_all_blocks(): void {
868
        $this->testpage->set_context(\context_system::instance());
868
        $this->testpage->set_context(\context_system::instance());
Línea 869... Línea 869...
869
        $this->setAdminUser();
869
        $this->setAdminUser();
870
 
870