Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 25... Línea 25...
25
 * @copyright  2023 Ferran Recio <ferran@moodle.com>
25
 * @copyright  2023 Ferran Recio <ferran@moodle.com>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @covers     \core_courseformat\sectiondelegate
27
 * @covers     \core_courseformat\sectiondelegate
28
 * @coversDefaultClass \core_courseformat\sectiondelegate
28
 * @coversDefaultClass \core_courseformat\sectiondelegate
29
 */
29
 */
30
class sectiondelegate_test extends \advanced_testcase {
30
final class sectiondelegate_test extends \advanced_testcase {
Línea 31... Línea 31...
31
 
31
 
32
    /**
32
    /**
33
     * Setup to ensure that fixtures are loaded.
33
     * Setup to ensure that fixtures are loaded.
34
     */
34
     */
35
    public static function setUpBeforeClass(): void {
35
    public static function setUpBeforeClass(): void {
36
        global $CFG;
36
        global $CFG;
-
 
37
        require_once($CFG->libdir . '/tests/fixtures/sectiondelegatetest.php');
37
        require_once($CFG->libdir . '/tests/fixtures/sectiondelegatetest.php');
38
        parent::setUpBeforeClass();
Línea 38... Línea 39...
38
    }
39
    }
39
 
40
 
40
    /**
41
    /**
Línea 74... Línea 75...
74
        $this->assertInstanceOf('\test_component\courseformat\sectiondelegate', sectiondelegate::instance($sectioninfos[2]));
75
        $this->assertInstanceOf('\test_component\courseformat\sectiondelegate', sectiondelegate::instance($sectioninfos[2]));
75
        $this->assertNull(sectiondelegate::instance($sectioninfos[3]));
76
        $this->assertNull(sectiondelegate::instance($sectioninfos[3]));
76
    }
77
    }
Línea 77... Línea 78...
77
 
78
 
-
 
79
    /**
-
 
80
     * Test that the instance method returns null when the delegate class is disabled.
-
 
81
     *
-
 
82
     * @covers ::instance
-
 
83
     */
-
 
84
    public function test_instance_disabled(): void {
-
 
85
        global $DB;
-
 
86
        $this->resetAfterTest();
-
 
87
 
-
 
88
        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 3]);
-
 
89
 
-
 
90
        // Section 2 has an existing delegate class.
-
 
91
        course_update_section(
-
 
92
            $course,
-
 
93
            $DB->get_record('course_sections', ['course' => $course->id, 'section' => 2]),
-
 
94
            [
-
 
95
                'component' => 'test_component',
-
 
96
                'itemid' => testsectiondelegate::DISABLEDITEMID,
-
 
97
            ]
-
 
98
        );
-
 
99
 
-
 
100
        $modinfo = get_fast_modinfo($course->id);
-
 
101
        $sectioninfos = $modinfo->get_section_info_all();
-
 
102
 
-
 
103
        $this->assertNull(sectiondelegate::instance($sectioninfos[2]));
-
 
104
    }
-
 
105
 
78
    /**
106
    /**
79
     * Test has_delegate_class().
107
     * Test has_delegate_class().
80
     *
108
     *
81
     * @covers ::has_delegate_class
109
     * @covers ::has_delegate_class
82
     */
110
     */
Línea 98... Línea 126...
98
 
126
 
Línea 99... Línea 127...
99
        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
127
        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
Línea 100... Línea 128...
100
 
128
 
101
        $sectioninfo = formatactions::section($course)->create_delegated('test_component', 1);
129
        $sectioninfo = formatactions::section($course)->create_delegated('test_component', 1);
Línea 102... Línea 130...
102
 
130
 
Línea 103... Línea 131...
103
        /** @var testsectiondelegate */
131
        /** @var testsectiondelegate $delegated */
104
        $delegated = $sectioninfo->get_component_instance();
132
        $delegated = $sectioninfo->get_component_instance();
105
 
133
 
106
        $format = course_get_format($course);
134
        $format = course_get_format($course);
107
 
135
 
Línea 108... Línea 136...
108
        $outputclass = $format->get_output_classname('content\\section\\controlmenu');
136
        $outputclass = $format->get_output_classname('content\\section\\controlmenu');
Línea 139... Línea 167...
139
        // When the delegated class return a null action menu.
167
        // When the delegated class return a null action menu.
140
        $delegated->set_section_action_menu(null);
168
        $delegated->set_section_action_menu(null);
141
        $result = $delegated->get_section_action_menu($format, $controlmenu, $renderer);
169
        $result = $delegated->get_section_action_menu($format, $controlmenu, $renderer);
142
        $this->assertNull($result);
170
        $this->assertNull($result);
143
    }
171
    }
-
 
172
 
-
 
173
    /**
-
 
174
     * Test get_parent_section().
-
 
175
     *
-
 
176
     * @covers ::get_parent_section
-
 
177
     */
-
 
178
    public function test_get_parent_section(): void {
-
 
179
        $this->resetAfterTest();
-
 
180
 
-
 
181
        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
-
 
182
        $sectioninfo = formatactions::section($course)->create_delegated('test_component', 1);
-
 
183
 
-
 
184
        /** @var testsectiondelegate $delegated */
-
 
185
        $delegated = $sectioninfo->get_component_instance();
-
 
186
 
-
 
187
        $this->assertNull($delegated->get_parent_section());
-
 
188
    }
144
}
189
}