Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 71... Línea 71...
71
        $hiddendemo1->hidden = true;
71
        $hiddendemo1->hidden = true;
72
        $hiddendemo1->add('hiddendemo2', $inactiveurl, navigation_node::TYPE_COURSE, null, 'hiddendemo2', new pix_icon('i/course', ''))->helpbutton = 'Here is a help button';
72
        $hiddendemo1->add('hiddendemo2', $inactiveurl, navigation_node::TYPE_COURSE, null, 'hiddendemo2', new pix_icon('i/course', ''))->helpbutton = 'Here is a help button';
73
        $hiddendemo1->add('hiddendemo3', $inactiveurl, navigation_node::TYPE_COURSE, null, 'hiddendemo3', new pix_icon('i/course', ''))->display = false;
73
        $hiddendemo1->add('hiddendemo3', $inactiveurl, navigation_node::TYPE_COURSE, null, 'hiddendemo3', new pix_icon('i/course', ''))->display = false;
74
    }
74
    }
Línea 75... Línea 75...
75
 
75
 
76
    public function test_node__construct() {
76
    public function test_node__construct(): void {
Línea 77... Línea 77...
77
        $this->setup_node();
77
        $this->setup_node();
78
 
78
 
79
        $fakeproperties = array(
79
        $fakeproperties = array(
Línea 89... Línea 89...
89
        $this->assertSame($fakeproperties['key'], $node->key);
89
        $this->assertSame($fakeproperties['key'], $node->key);
90
        $this->assertSame($fakeproperties['type'], $node->type);
90
        $this->assertSame($fakeproperties['type'], $node->type);
91
        $this->assertSame($fakeproperties['action'], $node->action);
91
        $this->assertSame($fakeproperties['action'], $node->action);
92
    }
92
    }
Línea 93... Línea 93...
93
 
93
 
94
    public function test_node_add() {
94
    public function test_node_add(): void {
Línea 95... Línea 95...
95
        $this->setup_node();
95
        $this->setup_node();
96
 
96
 
97
        // Add a node with all args set.
97
        // Add a node with all args set.
Línea 115... Línea 115...
115
 
115
 
116
        $ref = $this->node->get($node3->key, $node3->type);
116
        $ref = $this->node->get($node3->key, $node3->type);
117
        $this->assertSame($node3, $ref);
117
        $this->assertSame($node3, $ref);
Línea 118... Línea 118...
118
    }
118
    }
119
 
119
 
Línea 120... Línea 120...
120
    public function test_node_add_before() {
120
    public function test_node_add_before(): void {
121
        $this->setup_node();
121
        $this->setup_node();
122
 
122
 
Línea 138... Línea 138...
138
        $this->assertSame('testadd1', $keys[count($keys)-3]);
138
        $this->assertSame('testadd1', $keys[count($keys)-3]);
139
        $this->assertSame('testadd2', $keys[count($keys)-2]);
139
        $this->assertSame('testadd2', $keys[count($keys)-2]);
140
        $this->assertSame('testadd3', $keys[count($keys)-1]);
140
        $this->assertSame('testadd3', $keys[count($keys)-1]);
141
    }
141
    }
Línea 142... Línea 142...
142
 
142
 
143
    public function test_node_add_class() {
143
    public function test_node_add_class(): void {
Línea 144... Línea 144...
144
        $this->setup_node();
144
        $this->setup_node();
145
 
145
 
146
        $node = $this->node->get('demo1');
146
        $node = $this->node->get('demo1');
Línea 166... Línea 166...
166
            $attribute = reset($node->attributes);
166
            $attribute = reset($node->attributes);
167
            $this->assertEqualsCanonicalizing(['name' => 'data-foo', 'value' => 'bar'], $attribute);
167
            $this->assertEqualsCanonicalizing(['name' => 'data-foo', 'value' => 'bar'], $attribute);
168
        }
168
        }
169
    }
169
    }
Línea 170... Línea 170...
170
 
170
 
171
    public function test_node_check_if_active() {
171
    public function test_node_check_if_active(): void {
Línea 172... Línea 172...
172
        $this->setup_node();
172
        $this->setup_node();
173
 
173
 
174
        // First test the string urls
174
        // First test the string urls
Línea 183... Línea 183...
183
        if ($this->assertInstanceOf('navigation_node', $demo2)) {
183
        if ($this->assertInstanceOf('navigation_node', $demo2)) {
184
            $this->assertFalse($demo2->check_if_active());
184
            $this->assertFalse($demo2->check_if_active());
185
        }
185
        }
186
    }
186
    }
Línea 187... Línea 187...
187
 
187
 
188
    public function test_node_contains_active_node() {
188
    public function test_node_contains_active_node(): void {
Línea 189... Línea 189...
189
        $this->setup_node();
189
        $this->setup_node();
190
 
190
 
191
        // Demo5, and activity1 were set to active during setup.
191
        // Demo5, and activity1 were set to active during setup.
Línea 201... Línea 201...
201
        $this->assertTrue($this->node->get('demo3')->get('demo5')->get('activity1')->contains_active_node());
201
        $this->assertTrue($this->node->get('demo3')->get('demo5')->get('activity1')->contains_active_node());
202
        // Obviously duff.
202
        // Obviously duff.
203
        $this->assertFalse($this->node->get('demo3')->get('demo4')->contains_active_node());
203
        $this->assertFalse($this->node->get('demo3')->get('demo4')->contains_active_node());
204
    }
204
    }
Línea 205... Línea 205...
205
 
205
 
206
    public function test_node_find_active_node() {
206
    public function test_node_find_active_node(): void {
Línea 207... Línea 207...
207
        $this->setup_node();
207
        $this->setup_node();
208
 
208
 
Línea 215... Línea 215...
215
        }
215
        }
Línea 216... Línea 216...
216
 
216
 
217
        $this->assertNotInstanceOf('navigation_node', $activenode2);
217
        $this->assertNotInstanceOf('navigation_node', $activenode2);
Línea 218... Línea 218...
218
    }
218
    }
219
 
219
 
Línea 220... Línea 220...
220
    public function test_node_find() {
220
    public function test_node_find(): void {
221
        $this->setup_node();
221
        $this->setup_node();
222
 
222
 
Línea 228... Línea 228...
228
        $this->assertInstanceOf('navigation_node', $node2);
228
        $this->assertInstanceOf('navigation_node', $node2);
229
        $this->assertNotInstanceOf('navigation_node', $node3);
229
        $this->assertNotInstanceOf('navigation_node', $node3);
230
        $this->assertNotInstanceOf('navigation_node', $node4);
230
        $this->assertNotInstanceOf('navigation_node', $node4);
231
    }
231
    }
Línea 232... Línea 232...
232
 
232
 
233
    public function test_node_find_expandable() {
233
    public function test_node_find_expandable(): void {
Línea 234... Línea 234...
234
        $this->setup_node();
234
        $this->setup_node();
235
 
235
 
Línea 244... Línea 244...
244
            $name .= $expandable[3]['key'];
244
            $name .= $expandable[3]['key'];
245
            $this->assertSame('demo1demo2demo4hiddendemo2', $name);
245
            $this->assertSame('demo1demo2demo4hiddendemo2', $name);
246
        }
246
        }
247
    }
247
    }
Línea 248... Línea 248...
248
 
248
 
249
    public function test_node_get() {
249
    public function test_node_get(): void {
Línea 250... Línea 250...
250
        $this->setup_node();
250
        $this->setup_node();
251
 
251
 
252
        $node1 = $this->node->get('demo1'); // Exists.
252
        $node1 = $this->node->get('demo1'); // Exists.
Línea 257... Línea 257...
257
        $this->assertFalse($node2);
257
        $this->assertFalse($node2);
258
        $this->assertFalse($node3);
258
        $this->assertFalse($node3);
259
        $this->assertFalse($node4);
259
        $this->assertFalse($node4);
260
    }
260
    }
Línea 261... Línea 261...
261
 
261
 
262
    public function test_node_get_css_type() {
262
    public function test_node_get_css_type(): void {
Línea 263... Línea 263...
263
        $this->setup_node();
263
        $this->setup_node();
264
 
264
 
265
        $csstype1 = $this->node->get('demo3')->get_css_type();
265
        $csstype1 = $this->node->get('demo3')->get_css_type();
Línea 271... Línea 271...
271
        $this->assertSame('type_course', $csstype2);
271
        $this->assertSame('type_course', $csstype2);
272
        $this->assertSame('type_unknown', $csstype3);
272
        $this->assertSame('type_unknown', $csstype3);
273
        $this->assertSame('type_container', $csstype4);
273
        $this->assertSame('type_container', $csstype4);
274
    }
274
    }
Línea 275... Línea 275...
275
 
275
 
276
    public function test_node_make_active() {
276
    public function test_node_make_active(): void {
277
        global $CFG;
277
        global $CFG;
Línea 278... Línea 278...
278
        $this->setup_node();
278
        $this->setup_node();
279
 
279
 
Línea 283... Línea 283...
283
        $this->node->get('anode2')->make_active();
283
        $this->node->get('anode2')->make_active();
284
        $this->assertTrue($node1->isactive);
284
        $this->assertTrue($node1->isactive);
285
        $this->assertTrue($this->node->get('anode2')->isactive);
285
        $this->assertTrue($this->node->get('anode2')->isactive);
286
    }
286
    }
Línea 287... Línea 287...
287
 
287
 
288
    public function test_node_remove() {
288
    public function test_node_remove(): void {
Línea 289... Línea 289...
289
        $this->setup_node();
289
        $this->setup_node();
290
 
290
 
291
        $remove1 = $this->node->add('child to remove 1', null, navigation_node::TYPE_CUSTOM, null, 'remove1');
291
        $remove1 = $this->node->add('child to remove 1', null, navigation_node::TYPE_CUSTOM, null, 'remove1');
Línea 322... Línea 322...
322
 
322
 
323
        $this->assertFalse($this->node->get('remove1'));
323
        $this->assertFalse($this->node->get('remove1'));
324
        $this->assertFalse($this->node->get('remove2'));
324
        $this->assertFalse($this->node->get('remove2'));
Línea 325... Línea 325...
325
    }
325
    }
326
 
326
 
Línea 327... Línea 327...
327
    public function test_node_remove_class() {
327
    public function test_node_remove_class(): void {
328
        $this->setup_node();
328
        $this->setup_node();
329
 
329
 
330
        $this->node->add_class('testclass');
330
        $this->node->add_class('testclass');
Línea 331... Línea 331...
331
        $this->assertTrue($this->node->remove_class('testclass'));
331
        $this->assertTrue($this->node->remove_class('testclass'));
332
        $this->assertNotContains('testclass', $this->node->classes);
332
        $this->assertNotContains('testclass', $this->node->classes);
333
    }
333
    }
334
 
334
 
335
    public function test_module_extends_navigation() {
335
    public function test_module_extends_navigation(): void {
336
        $node = new exposed_global_navigation();
336
        $node = new exposed_global_navigation();
Línea 356... Línea 356...
356
 
356
 
357
        $this->assertTrue($node->exposed_module_extends_navigation('data'));
357
        $this->assertTrue($node->exposed_module_extends_navigation('data'));
358
        $this->assertFalse($node->exposed_module_extends_navigation('test1'));
358
        $this->assertFalse($node->exposed_module_extends_navigation('test1'));
Línea 359... Línea 359...
359
    }
359
    }
360
 
360
 
361
    public function test_navbar_prepend_and_add() {
361
    public function test_navbar_prepend_and_add(): \moodle_page {
362
        global $PAGE;
362
        global $PAGE;
Línea 363... Línea 363...
363
        // Unfortunate hack needed because people use global $PAGE around the place.
363
        // Unfortunate hack needed because people use global $PAGE around the place.
Línea 400... Línea 400...
400
 
400
 
401
    /**
401
    /**
402
     * @depends test_navbar_prepend_and_add
402
     * @depends test_navbar_prepend_and_add
403
     * @param $node
403
     * @param $node
404
     */
404
     */
405
    public function test_navbar_has_items(\moodle_page $page) {
405
    public function test_navbar_has_items(\moodle_page $page): void {
Línea 406... Línea 406...
406
        $this->resetAfterTest();
406
        $this->resetAfterTest();
407
 
407
 
Línea 408... Línea 408...
408
        $this->assertTrue($page->navbar->has_items());
408
        $this->assertTrue($page->navbar->has_items());
409
    }
409
    }
410
 
410
 
Línea 411... Línea 411...
411
    public function test_cache__get() {
411
    public function test_cache__get(): void {
412
        $cache = new navigation_cache('unittest_nav');
412
        $cache = new navigation_cache('unittest_nav');
413
        $cache->anysetvariable = true;
413
        $cache->anysetvariable = true;
Línea 414... Línea 414...
414
 
414
 
415
        $this->assertTrue($cache->anysetvariable);
415
        $this->assertTrue($cache->anysetvariable);
416
        $this->assertEquals($cache->notasetvariable, null);
416
        $this->assertEquals($cache->notasetvariable, null);
Línea 417... Línea 417...
417
    }
417
    }
418
 
418
 
419
    public function test_cache__set() {
419
    public function test_cache__set(): void {
420
        $cache = new navigation_cache('unittest_nav');
420
        $cache = new navigation_cache('unittest_nav');
Línea 421... Línea 421...
421
        $cache->anysetvariable = true;
421
        $cache->anysetvariable = true;
422
 
422
 
423
        $cache->myname = 'Sam Hemelryk';
423
        $cache->myname = 'Sam Hemelryk';
Línea 424... Línea 424...
424
        $this->assertTrue($cache->cached('myname'));
424
        $this->assertTrue($cache->cached('myname'));
425
        $this->assertSame('Sam Hemelryk', $cache->myname);
425
        $this->assertSame('Sam Hemelryk', $cache->myname);
426
    }
426
    }
Línea 427... Línea 427...
427
 
427
 
428
    public function test_cache_cached() {
428
    public function test_cache_cached(): void {
429
        $cache = new navigation_cache('unittest_nav');
429
        $cache = new navigation_cache('unittest_nav');
Línea 430... Línea 430...
430
        $cache->anysetvariable = true;
430
        $cache->anysetvariable = true;
431
 
431
 
432
        $this->assertTrue($cache->cached('anysetvariable'));
432
        $this->assertTrue($cache->cached('anysetvariable'));
433
        $this->assertFalse($cache->cached('notasetvariable'));
433
        $this->assertFalse($cache->cached('notasetvariable'));
434
    }
434
    }
Línea 435... Línea 435...
435
 
435
 
436
    public function test_cache_clear() {
436
    public function test_cache_clear(): void {
437
        $cache = new navigation_cache('unittest_nav');
437
        $cache = new navigation_cache('unittest_nav');
Línea 438... Línea 438...
438
        $cache->anysetvariable = true;
438
        $cache->anysetvariable = true;
439
 
439
 
440
        $cache = clone($cache);
440
        $cache = clone($cache);
441
        $this->assertTrue($cache->cached('anysetvariable'));
441
        $this->assertTrue($cache->cached('anysetvariable'));
Línea 442... Línea 442...
442
        $cache->clear();
442
        $cache->clear();
443
        $this->assertFalse($cache->cached('anysetvariable'));
443
        $this->assertFalse($cache->cached('anysetvariable'));
Línea 444... Línea 444...
444
    }
444
    }
Línea 445... Línea 445...
445
 
445
 
Línea 468... Línea 468...
468
    /**
468
    /**
469
     * @depends test_setting___construct
469
     * @depends test_setting___construct
470
     * @param mixed $node
470
     * @param mixed $node
471
     * @return mixed
471
     * @return mixed
472
     */
472
     */
473
    public function test_setting__initialise($node) {
473
    public function test_setting__initialise($node): settings_navigation {
474
        $this->resetAfterTest(false);
474
        $this->resetAfterTest(false);
Línea 475... Línea 475...
475
 
475
 
476
        $node->initialise();
476
        $node->initialise();
Línea 480... Línea 480...
480
    }
480
    }
Línea 481... Línea 481...
481
 
481
 
482
    /**
482
    /**
483
     * Test that users with the correct permissions can view the preferences page.
483
     * Test that users with the correct permissions can view the preferences page.
484
     */
484
     */
485
    public function test_can_view_user_preferences() {
485
    public function test_can_view_user_preferences(): void {
486
        global $PAGE, $DB, $SITE;
486
        global $PAGE, $DB, $SITE;
Línea 487... Línea 487...
487
        $this->resetAfterTest();
487
        $this->resetAfterTest();
488
 
488
 
Línea 521... Línea 521...
521
    /**
521
    /**
522
     * @depends test_setting__initialise
522
     * @depends test_setting__initialise
523
     * @param mixed $node
523
     * @param mixed $node
524
     * @return mixed
524
     * @return mixed
525
     */
525
     */
526
    public function test_setting_in_alternative_role($node) {
526
    public function test_setting_in_alternative_role($node): void {
527
        $this->resetAfterTest();
527
        $this->resetAfterTest();
Línea 528... Línea 528...
528
 
528
 
529
        $this->assertFalse($node->exposed_in_alternative_role());
529
        $this->assertFalse($node->exposed_in_alternative_role());
Línea 530... Línea 530...
530
    }
530
    }
531
 
531
 
532
 
532
 
533
    public function test_navigation_node_collection_remove_with_no_type() {
533
    public function test_navigation_node_collection_remove_with_no_type(): void {
Línea 534... Línea 534...
534
        $navigationnodecollection = new navigation_node_collection();
534
        $navigationnodecollection = new navigation_node_collection();
Línea 549... Línea 549...
549
 
549
 
550
        // Test it's empty again!
550
        // Test it's empty again!
551
        $this->assertEquals(0, count($navigationnodecollection->get_key_list()));
551
        $this->assertEquals(0, count($navigationnodecollection->get_key_list()));
Línea 552... Línea 552...
552
    }
552
    }
553
 
553
 
554
    public function test_navigation_node_collection_remove_with_type() {
554
    public function test_navigation_node_collection_remove_with_type(): void {
555
        $navigationnodecollection = new navigation_node_collection();
555
        $navigationnodecollection = new navigation_node_collection();
Línea 556... Línea 556...
556
        $this->setup_node();
556
        $this->setup_node();
Línea 577... Línea 577...
577
     *
577
     *
578
     * @param bool $haschildren       Whether the navigation node has children nodes
578
     * @param bool $haschildren       Whether the navigation node has children nodes
579
     * @param bool $forceintomoremenu Whether to force the navigation node and its children into the "more" menu
579
     * @param bool $forceintomoremenu Whether to force the navigation node and its children into the "more" menu
580
     * @dataProvider set_force_into_more_menu_provider
580
     * @dataProvider set_force_into_more_menu_provider
581
     */
581
     */
582
    public function test_set_force_into_more_menu(bool $haschildren, bool $forceintomoremenu) {
582
    public function test_set_force_into_more_menu(bool $haschildren, bool $forceintomoremenu): void {
583
        // Create a navigation node.
583
        // Create a navigation node.
584
        $node = new navigation_node(['text' => 'Navigation node', 'key' => 'navnode']);
584
        $node = new navigation_node(['text' => 'Navigation node', 'key' => 'navnode']);
Línea 585... Línea 585...
585
 
585
 
586
        // If required, add some children nodes to the navigation node.
586
        // If required, add some children nodes to the navigation node.
Línea 630... Línea 630...
630
     * @param navigation_node $node The sample navigation node
630
     * @param navigation_node $node The sample navigation node
631
     * @param bool $expected Whether the navigation node contains an action link
631
     * @param bool $expected Whether the navigation node contains an action link
632
     * @dataProvider is_action_link_provider
632
     * @dataProvider is_action_link_provider
633
     * @covers navigation_node::is_action_link
633
     * @covers navigation_node::is_action_link
634
     */
634
     */
635
    public function test_is_action_link(navigation_node $node, bool $expected) {
635
    public function test_is_action_link(navigation_node $node, bool $expected): void {
636
        $this->assertEquals($node->is_action_link(), $expected);
636
        $this->assertEquals($node->is_action_link(), $expected);
637
    }
637
    }
Línea 638... Línea 638...
638
 
638
 
639
    /**
639
    /**
Línea 663... Línea 663...
663
     *
663
     *
664
     * @param navigation_node $node The sample navigation node
664
     * @param navigation_node $node The sample navigation node
665
     * @dataProvider action_link_actions_provider
665
     * @dataProvider action_link_actions_provider
666
     * @covers navigation_node::action_link_actions
666
     * @covers navigation_node::action_link_actions
667
     */
667
     */
668
    public function test_action_link_actions(navigation_node $node) {
668
    public function test_action_link_actions(navigation_node $node): void {
669
        // Get the formatted array of action link actions.
669
        // Get the formatted array of action link actions.
670
        $data = $node->action_link_actions();
670
        $data = $node->action_link_actions();
671
        // The navigation node has an action link.
671
        // The navigation node has an action link.
672
        if ($node->action instanceof action_link) {
672
        if ($node->action instanceof action_link) {
673
            if (!empty($node->action->actions)) { // There are actions added to the action link.
673
            if (!empty($node->action->actions)) { // There are actions added to the action link.