Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 21... Línea 21...
21
 *
21
 *
22
 * @package core_availability
22
 * @package core_availability
23
 * @copyright 2014 The Open University
23
 * @copyright 2014 The Open University
24
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
25
 */
26
class info_test extends \advanced_testcase {
26
final class info_test extends \advanced_testcase {
27
    public function setUp(): void {
27
    public function setUp(): void {
28
        // Load the mock condition so that it can be used.
28
        // Load the mock condition so that it can be used.
29
        require_once(__DIR__ . '/fixtures/mock_condition.php');
29
        require_once(__DIR__ . '/fixtures/mock_condition.php');
-
 
30
        parent::setUp();
30
    }
31
    }
Línea 31... Línea 32...
31
 
32
 
32
    /**
33
    /**
33
     * Tests the info_module class (is_available, get_full_information).
34
     * Tests the info_module class (is_available, get_full_information).
Línea 556... Línea 557...
556
        // Now, enable availability restrictions, and check again.
557
        // Now, enable availability restrictions, and check again.
557
        // This time, we expect it to return false, because of the access restriction.
558
        // This time, we expect it to return false, because of the access restriction.
558
        $CFG->enableavailability = 1;
559
        $CFG->enableavailability = 1;
559
        $this->assertFalse($info->is_available_for_all());
560
        $this->assertFalse($info->is_available_for_all());
560
    }
561
    }
-
 
562
 
-
 
563
    /**
-
 
564
     * Test update_display_mode function.
-
 
565
     *
-
 
566
     * @covers \core\plugininfo\availability::update_display_mode
-
 
567
     * @dataProvider update_display_mode_provider
-
 
568
     *
-
 
569
     * @param string $plugin The plugin name.
-
 
570
     * @param string $expected The expected data.
-
 
571
     */
-
 
572
    public function test_update_display_mode(string $plugin, string $expected): void {
-
 
573
        global $DB;
-
 
574
 
-
 
575
        $this->resetAfterTest();
-
 
576
 
-
 
577
        // Get default value for default display mode.
-
 
578
        $availabilityvalue = $DB->get_field('config_plugins', 'value',
-
 
579
            ['name' => 'defaultdisplaymode', 'plugin' => "availability_$plugin"]);
-
 
580
        $updatedisplaymode = \core\plugininfo\availability::update_display_mode($plugin, true);
-
 
581
 
-
 
582
        // The default value is not inserted into the table.
-
 
583
        // Or the display is updated but the display mode is the same value as the default.
-
 
584
        $this->assertFalse($availabilityvalue);
-
 
585
        $this->assertFalse($updatedisplaymode);
-
 
586
 
-
 
587
        // Update display mode for plugins.
-
 
588
        $updatedisplaymode = \core\plugininfo\availability::update_display_mode($plugin, false);
-
 
589
 
-
 
590
        // The function should return true because the display mode value has changed.
-
 
591
        $this->assertTrue($updatedisplaymode);
-
 
592
 
-
 
593
        // Get the updated value for the default display mode.
-
 
594
        $availabilityvalue = $DB->get_field('config_plugins', 'value',
-
 
595
            ['name' => 'defaultdisplaymode', 'plugin' => "availability_$plugin"]);
-
 
596
        $this->assertEquals($expected, $availabilityvalue);
-
 
597
    }
-
 
598
 
-
 
599
    /**
-
 
600
     * Data provider for test_update_display_mode().
-
 
601
     *
-
 
602
     * @return array
-
 
603
     */
-
 
604
    public static function update_display_mode_provider(): array {
-
 
605
        return [
-
 
606
            'Update display mode for completion' => [
-
 
607
                'completion',
-
 
608
                '1',
-
 
609
            ],
-
 
610
            'Update display mode for grade' => [
-
 
611
                'grade',
-
 
612
                '1',
-
 
613
            ],
-
 
614
            'Update display mode for group' => [
-
 
615
                'group',
-
 
616
                '1',
-
 
617
            ],
-
 
618
        ];
-
 
619
    }
561
}
620
}