Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 77... Línea 77...
77
            $return = $record;
77
            $return = $record;
78
        }
78
        }
79
        return $return;
79
        return $return;
80
    }
80
    }
Línea 81... Línea 81...
81
 
81
 
82
    public function test_no_regions_initially() {
82
    public function test_no_regions_initially(): void {
83
        // Exercise SUT & Validate.
83
        // Exercise SUT & Validate.
84
        $this->assertEquals(array(), $this->blockmanager->get_regions());
84
        $this->assertEquals(array(), $this->blockmanager->get_regions());
Línea 85... Línea 85...
85
    }
85
    }
86
 
86
 
87
    public function test_add_region() {
87
    public function test_add_region(): void {
88
        // Exercise SUT.
88
        // Exercise SUT.
89
        $this->blockmanager->add_region('a-region-name', false);
89
        $this->blockmanager->add_region('a-region-name', false);
90
        // Validate.
90
        // Validate.
Línea 91... Línea 91...
91
        $this->assertEquals(array('a-region-name'), $this->blockmanager->get_regions());
91
        $this->assertEquals(array('a-region-name'), $this->blockmanager->get_regions());
92
    }
92
    }
93
 
93
 
94
    public function test_add_regions() {
94
    public function test_add_regions(): void {
95
        // Set up fixture.
95
        // Set up fixture.
96
        $regions = array('a-region', 'another-region');
96
        $regions = array('a-region', 'another-region');
97
        // Exercise SUT.
97
        // Exercise SUT.
98
        $this->blockmanager->add_regions($regions, false);
98
        $this->blockmanager->add_regions($regions, false);
Línea 99... Línea 99...
99
        // Validate.
99
        // Validate.
100
        $this->assertEqualsCanonicalizing($regions, $this->blockmanager->get_regions());
100
        $this->assertEqualsCanonicalizing($regions, $this->blockmanager->get_regions());
101
    }
101
    }
102
 
102
 
103
    public function test_add_region_twice() {
103
    public function test_add_region_twice(): void {
104
        // Exercise SUT.
104
        // Exercise SUT.
105
        $this->blockmanager->add_region('a-region-name', false);
105
        $this->blockmanager->add_region('a-region-name', false);
Línea 106... Línea 106...
106
        $this->blockmanager->add_region('another-region', false);
106
        $this->blockmanager->add_region('another-region', false);
107
        // Validate.
107
        // Validate.
108
        $this->assertEqualsCanonicalizing(array('a-region-name', 'another-region'), $this->blockmanager->get_regions());
108
        $this->assertEqualsCanonicalizing(array('a-region-name', 'another-region'), $this->blockmanager->get_regions());
109
    }
109
    }
110
 
110
 
111
    public function test_cannot_add_region_after_loaded() {
111
    public function test_cannot_add_region_after_loaded(): void {
112
        // Set up fixture.
112
        // Set up fixture.
Línea 113... Línea 113...
113
        $this->blockmanager->mark_loaded();
113
        $this->blockmanager->mark_loaded();
114
        // Exercise SUT.
114
        // Exercise SUT.
115
        $this->expectException(\coding_exception::class);
115
        $this->expectException(\coding_exception::class);
116
        $this->blockmanager->add_region('too-late', false);
116
        $this->blockmanager->add_region('too-late', false);
117
    }
117
    }
118
 
118
 
119
    /**
119
    /**
120
     * Testing adding a custom region.
120
     * Testing adding a custom region.
121
     */
121
     */
Línea 132... Línea 132...
132
    }
132
    }
Línea 133... Línea 133...
133
 
133
 
134
    /**
134
    /**
135
     * Test adding two custom regions using add_regions method.
135
     * Test adding two custom regions using add_regions method.
136
     */
136
     */
137
    public function test_add_custom_regions() {
137
    public function test_add_custom_regions(): void {
138
        global $SESSION;
138
        global $SESSION;
139
        // Set up fixture.
139
        // Set up fixture.
140
        $regions = array('a-region', 'another-custom-region');
140
        $regions = array('a-region', 'another-custom-region');
141
        // Exercise SUT.
141
        // Exercise SUT.
Línea 148... Línea 148...
148
    }
148
    }
Línea 149... Línea 149...
149
 
149
 
150
    /**
150
    /**
151
     * Test adding two custom block regions.
151
     * Test adding two custom block regions.
152
     */
152
     */
153
    public function test_add_custom_region_twice() {
153
    public function test_add_custom_region_twice(): void {
154
        // Exercise SUT.
154
        // Exercise SUT.
155
        $this->blockmanager->add_region('a-custom-region-name');
155
        $this->blockmanager->add_region('a-custom-region-name');
156
        $this->blockmanager->add_region('another-custom-region');
156
        $this->blockmanager->add_region('another-custom-region');
157
        // Validate.
157
        // Validate.
Línea 161... Línea 161...
161
    }
161
    }
Línea 162... Línea 162...
162
 
162
 
163
    /**
163
    /**
164
     * Test to ensure that we cannot add a region after the blocks have been loaded.
164
     * Test to ensure that we cannot add a region after the blocks have been loaded.
165
     */
165
     */
166
    public function test_cannot_add_custom_region_after_loaded() {
166
    public function test_cannot_add_custom_region_after_loaded(): void {
167
        // Set up fixture.
167
        // Set up fixture.
168
        $this->blockmanager->mark_loaded();
168
        $this->blockmanager->mark_loaded();
169
        // Exercise SUT.
169
        // Exercise SUT.
170
        $this->expectException(\coding_exception::class);
170
        $this->expectException(\coding_exception::class);
171
        $this->blockmanager->add_region('too-late');
171
        $this->blockmanager->add_region('too-late');
Línea 172... Línea 172...
172
    }
172
    }
173
 
173
 
174
    public function test_set_default_region() {
174
    public function test_set_default_region(): void {
175
        // Set up fixture.
175
        // Set up fixture.
176
        $this->blockmanager->add_region('a-region-name', false);
176
        $this->blockmanager->add_region('a-region-name', false);
177
        // Exercise SUT.
177
        // Exercise SUT.
178
        $this->blockmanager->set_default_region('a-region-name');
178
        $this->blockmanager->set_default_region('a-region-name');
179
        // Validate.
179
        // Validate.
Línea 180... Línea 180...
180
        $this->assertEquals('a-region-name', $this->blockmanager->get_default_region());
180
        $this->assertEquals('a-region-name', $this->blockmanager->get_default_region());
181
    }
181
    }
182
 
182
 
183
    public function test_cannot_set_unknown_region_as_default() {
183
    public function test_cannot_set_unknown_region_as_default(): void {
184
        // Exercise SUT.
184
        // Exercise SUT.
Línea 185... Línea 185...
185
        $this->expectException(\coding_exception::class);
185
        $this->expectException(\coding_exception::class);
186
        $this->blockmanager->set_default_region('a-region-name');
186
        $this->blockmanager->set_default_region('a-region-name');
187
    }
187
    }
188
 
188
 
189
    public function test_cannot_change_default_region_after_loaded() {
189
    public function test_cannot_change_default_region_after_loaded(): void {
190
        // Set up fixture.
190
        // Set up fixture.
191
        $this->blockmanager->mark_loaded();
191
        $this->blockmanager->mark_loaded();
Línea 192... Línea 192...
192
        // Exercise SUT.
192
        // Exercise SUT.
193
        $this->expectException(\coding_exception::class);
193
        $this->expectException(\coding_exception::class);
194
        $this->blockmanager->set_default_region('too-late');
194
        $this->blockmanager->set_default_region('too-late');
Línea 195... Línea 195...
195
    }
195
    }
196
 
196
 
Línea 241... Línea 241...
241
            $this->assertEquals($blocktype, $block->name(), "Block types do not match at postition $i %s.");
241
            $this->assertEquals($blocktype, $block->name(), "Block types do not match at postition $i %s.");
242
            $i++;
242
            $i++;
243
        }
243
        }
244
    }
244
    }
Línea 245... Línea 245...
245
 
245
 
246
    public function test_empty_initially() {
246
    public function test_empty_initially(): void {
Línea 247... Línea 247...
247
        $this->purge_blocks();
247
        $this->purge_blocks();
248
 
248
 
249
        // Set up fixture.
249
        // Set up fixture.
Línea 254... Línea 254...
254
        // Validate.
254
        // Validate.
255
        $blocks = $blockmanager->get_loaded_blocks();
255
        $blocks = $blockmanager->get_loaded_blocks();
256
        $this->assertEquals(array('a-region' => array()), $blocks);
256
        $this->assertEquals(array('a-region' => array()), $blocks);
257
    }
257
    }
Línea 258... Línea 258...
258
 
258
 
259
    public function test_adding_and_retrieving_one_block() {
259
    public function test_adding_and_retrieving_one_block(): void {
Línea 260... Línea 260...
260
        $this->purge_blocks();
260
        $this->purge_blocks();
261
 
261
 
262
        // Set up fixture.
262
        // Set up fixture.
Línea 273... Línea 273...
273
        // Validate.
273
        // Validate.
274
        $blocks = $blockmanager->get_blocks_for_region($regionname);
274
        $blocks = $blockmanager->get_blocks_for_region($regionname);
275
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
275
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
276
    }
276
    }
Línea 277... Línea 277...
277
 
277
 
278
    public function test_adding_and_retrieving_two_blocks() {
278
    public function test_adding_and_retrieving_two_blocks(): void {
Línea 279... Línea 279...
279
        $this->purge_blocks();
279
        $this->purge_blocks();
280
 
280
 
281
        // Set up fixture.
281
        // Set up fixture.
Línea 293... Línea 293...
293
        // Validate.
293
        // Validate.
294
        $blocks = $blockmanager->get_blocks_for_region($regionname);
294
        $blocks = $blockmanager->get_blocks_for_region($regionname);
295
        $this->assertContainsBlocksOfType(array($blockname, $blockname), $blocks);
295
        $this->assertContainsBlocksOfType(array($blockname, $blockname), $blocks);
296
    }
296
    }
Línea 297... Línea 297...
297
 
297
 
298
    public function test_adding_blocks() {
298
    public function test_adding_blocks(): void {
Línea 299... Línea 299...
299
        $this->purge_blocks();
299
        $this->purge_blocks();
300
 
300
 
301
        // Set up fixture.
301
        // Set up fixture.
Línea 318... Línea 318...
318
    /**
318
    /**
319
     * Test block instances.
319
     * Test block instances.
320
     *
320
     *
321
     * @return null
321
     * @return null
322
     */
322
     */
323
    public function test_block_instances() {
323
    public function test_block_instances(): void {
324
        $this->purge_blocks();
324
        $this->purge_blocks();
Línea 325... Línea 325...
325
 
325
 
326
        // Set up fixture.
326
        // Set up fixture.
327
        $regionname = 'a-region';
327
        $regionname = 'a-region';
Línea 338... Línea 338...
338
 
338
 
339
        $this->assertInstanceOf('\block_base', block_instance($blockname, $blocks[0]->instance));
339
        $this->assertInstanceOf('\block_base', block_instance($blockname, $blocks[0]->instance));
340
        $this->assertInstanceOf('\block_base', block_instance_by_id($blocks[0]->instance->id));
340
        $this->assertInstanceOf('\block_base', block_instance_by_id($blocks[0]->instance->id));
Línea 341... Línea 341...
341
    }
341
    }
342
 
342
 
Línea 343... Línea 343...
343
    public function test_block_not_included_in_different_context() {
343
    public function test_block_not_included_in_different_context(): void {
344
        $this->purge_blocks();
344
        $this->purge_blocks();
345
 
345
 
Línea 360... Línea 360...
360
        // Validate.
360
        // Validate.
361
        $blocks = $viewbm->get_blocks_for_region($regionname);
361
        $blocks = $viewbm->get_blocks_for_region($regionname);
362
        $this->assertContainsBlocksOfType(array(), $blocks);
362
        $this->assertContainsBlocksOfType(array(), $blocks);
363
    }
363
    }
Línea 364... Línea 364...
364
 
364
 
365
    public function test_block_included_in_sub_context() {
365
    public function test_block_included_in_sub_context(): void {
Línea 366... Línea 366...
366
        $this->purge_blocks();
366
        $this->purge_blocks();
367
 
367
 
368
        // Set up fixture.
368
        // Set up fixture.
Línea 381... Línea 381...
381
        // Validate.
381
        // Validate.
382
        $blocks = $viewbm->get_blocks_for_region($regionname);
382
        $blocks = $viewbm->get_blocks_for_region($regionname);
383
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
383
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
384
    }
384
    }
Línea 385... Línea 385...
385
 
385
 
386
    public function test_block_not_included_on_different_page_type() {
386
    public function test_block_not_included_on_different_page_type(): void {
Línea 387... Línea 387...
387
        $this->purge_blocks();
387
        $this->purge_blocks();
388
 
388
 
389
        // Set up fixture.
389
        // Set up fixture.
Línea 401... Línea 401...
401
        // Validate.
401
        // Validate.
402
        $blocks = $viewbm->get_blocks_for_region($regionname);
402
        $blocks = $viewbm->get_blocks_for_region($regionname);
403
        $this->assertContainsBlocksOfType(array(), $blocks);
403
        $this->assertContainsBlocksOfType(array(), $blocks);
404
    }
404
    }
Línea 405... Línea 405...
405
 
405
 
406
    public function test_block_not_included_on_different_sub_page() {
406
    public function test_block_not_included_on_different_sub_page(): void {
Línea 407... Línea 407...
407
        $this->purge_blocks();
407
        $this->purge_blocks();
408
 
408
 
409
        // Set up fixture.
409
        // Set up fixture.
Línea 421... Línea 421...
421
        // Validate.
421
        // Validate.
422
        $blocks = $blockmanager->get_blocks_for_region($regionname);
422
        $blocks = $blockmanager->get_blocks_for_region($regionname);
423
        $this->assertContainsBlocksOfType(array(), $blocks);
423
        $this->assertContainsBlocksOfType(array(), $blocks);
424
    }
424
    }
Línea 425... Línea 425...
425
 
425
 
426
    public function test_block_included_with_explicit_sub_page() {
426
    public function test_block_included_with_explicit_sub_page(): void {
Línea 427... Línea 427...
427
        $this->purge_blocks();
427
        $this->purge_blocks();
428
 
428
 
429
        // Set up fixture.
429
        // Set up fixture.
Línea 441... Línea 441...
441
        // Validate.
441
        // Validate.
442
        $blocks = $blockmanager->get_blocks_for_region($regionname);
442
        $blocks = $blockmanager->get_blocks_for_region($regionname);
443
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
443
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
444
    }
444
    }
Línea 445... Línea 445...
445
 
445
 
446
    public function test_block_included_with_page_type_pattern() {
446
    public function test_block_included_with_page_type_pattern(): void {
Línea 447... Línea 447...
447
        $this->purge_blocks();
447
        $this->purge_blocks();
448
 
448
 
449
        // Set up fixture.
449
        // Set up fixture.
Línea 461... Línea 461...
461
        // Validate.
461
        // Validate.
462
        $blocks = $blockmanager->get_blocks_for_region($regionname);
462
        $blocks = $blockmanager->get_blocks_for_region($regionname);
463
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
463
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
464
    }
464
    }
Línea 465... Línea 465...
465
 
465
 
466
    public function test_matching_page_type_patterns_from_pattern() {
466
    public function test_matching_page_type_patterns_from_pattern(): void {
467
        $pattern = '*';
467
        $pattern = '*';
468
        $expected = array('*');
468
        $expected = array('*');
Línea 469... Línea 469...
469
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));
469
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));
Línea 511... Línea 511...
511
        $pattern = 'user-profile';
511
        $pattern = 'user-profile';
512
        $expected = array('user-profile', 'user-profile-*', 'user-*', '*');
512
        $expected = array('user-profile', 'user-profile-*', 'user-*', '*');
513
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));
513
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));
514
    }
514
    }
Línea 515... Línea 515...
515
 
515
 
516
    public function test_delete_instances() {
516
    public function test_delete_instances(): void {
517
        global $DB;
517
        global $DB;
518
        $this->purge_blocks();
518
        $this->purge_blocks();
Línea 519... Línea 519...
519
        $this->setAdminUser();
519
        $this->setAdminUser();
Línea 574... Línea 574...
574
        $this->assertFalse(\context_block::instance($blockids[0], IGNORE_MISSING));
574
        $this->assertFalse(\context_block::instance($blockids[0], IGNORE_MISSING));
575
        $this->assertFalse(\context_block::instance($blockids[1], IGNORE_MISSING));
575
        $this->assertFalse(\context_block::instance($blockids[1], IGNORE_MISSING));
576
        \context_block::instance($tokeep);   // Would throw an exception if it was deleted.
576
        \context_block::instance($tokeep);   // Would throw an exception if it was deleted.
577
    }
577
    }
Línea 578... Línea 578...
578
 
578
 
579
    public function test_create_all_block_instances() {
579
    public function test_create_all_block_instances(): void {
Línea 580... Línea 580...
580
        global $CFG, $PAGE, $DB;
580
        global $CFG, $PAGE, $DB;
581
 
581
 
582
        $this->setAdminUser();
582
        $this->setAdminUser();
Línea 657... Línea 657...
657
    }
657
    }
Línea 658... Línea 658...
658
 
658
 
659
    /**
659
    /**
660
     * Test the block instance time fields (timecreated, timemodified).
660
     * Test the block instance time fields (timecreated, timemodified).
661
     */
661
     */
662
    public function test_block_instance_times() {
662
    public function test_block_instance_times(): void {
Línea 663... Línea 663...
663
        global $DB;
663
        global $DB;
Línea 664... Línea 664...
664
 
664
 
Línea 724... Línea 724...
724
    }
724
    }
Línea 725... Línea 725...
725
 
725
 
726
    /**
726
    /**
727
     * Tests that dashboard pages get their blocks loaded correctly.
727
     * Tests that dashboard pages get their blocks loaded correctly.
728
     */
728
     */
729
    public function test_default_dashboard() {
729
    public function test_default_dashboard(): void {
730
        global $CFG, $PAGE, $DB;
730
        global $CFG, $PAGE, $DB;
731
        $storedpage = $PAGE;
731
        $storedpage = $PAGE;
732
        require_once($CFG->dirroot . '/my/lib.php');
732
        require_once($CFG->dirroot . '/my/lib.php');
733
        $this->purge_blocks();
733
        $this->purge_blocks();