Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 22... Línea 22...
22
 * Section format actions class tests.
22
 * Section format actions class tests.
23
 *
23
 *
24
 * @package    core_courseformat
24
 * @package    core_courseformat
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
 * @coversDefaultClass \core_courseformat\sectionactions
27
 * @coversDefaultClass \core_courseformat\local\sectionactions
28
 */
28
 */
29
class sectionactions_test extends \advanced_testcase {
29
final class sectionactions_test extends \advanced_testcase {
30
    /**
30
    /**
31
     * Setup to ensure that fixtures are loaded.
31
     * Setup to ensure that fixtures are loaded.
32
     */
32
     */
33
    public static function setUpBeforeClass(): void {
33
    public static function setUpBeforeClass(): void {
34
        global $CFG;
34
        global $CFG;
35
        require_once($CFG->dirroot . '/course/lib.php');
35
        require_once($CFG->dirroot . '/course/lib.php');
-
 
36
        parent::setUpBeforeClass();
36
    }
37
    }
Línea 37... Línea 38...
37
 
38
 
38
    /**
39
    /**
39
     * Test for create_delegated method.
40
     * Test for create_delegated method.
Línea 265... Línea 266...
265
     * @return array
266
     * @return array
266
     */
267
     */
267
    public static function create_if_missing_provider(): array {
268
    public static function create_if_missing_provider(): array {
268
        return [
269
        return [
269
            'existing section' => [
270
            'existing section' => [
270
                'sectionnum' => [1],
271
                'sectionnums' => [1],
271
                'expected' => false,
272
                'expected' => false,
272
            ],
273
            ],
273
            'unexisting section' => [
274
            'unexisting section' => [
274
                'sectionnum' => [3],
275
                'sectionnums' => [3],
275
                'expected' => true,
276
                'expected' => true,
276
            ],
277
            ],
277
            'several existing sections' => [
278
            'several existing sections' => [
278
                'sectionnum' => [1, 2],
279
                'sectionnums' => [1, 2],
279
                'expected' => false,
280
                'expected' => false,
280
            ],
281
            ],
281
            'several unexisting sections' => [
282
            'several unexisting sections' => [
282
                'sectionnum' => [3, 4],
283
                'sectionnums' => [3, 4],
283
                'expected' => true,
284
                'expected' => true,
284
            ],
285
            ],
285
            'empty array' => [
286
            'empty array' => [
286
                'sectionnum' => [],
287
                'sectionnums' => [],
287
                'expected' => false,
288
                'expected' => false,
288
            ],
289
            ],
289
            'existent and unexistent sections' => [
290
            'existent and unexistent sections' => [
290
                'sectionnum' => [1, 2, 3, 4],
291
                'sectionnums' => [1, 2, 3, 4],
291
                'expected' => true,
292
                'expected' => true,
292
            ],
293
            ],
293
        ];
294
        ];
294
    }
295
    }
Línea 899... Línea 900...
899
        $this->assertEquals('null_name', $section->name);
900
        $this->assertEquals('null_name', $section->name);
Línea 900... Línea 901...
900
 
901
 
901
        $sectioninfo = get_fast_modinfo($course->id)->get_section_info_by_id($section->id);
902
        $sectioninfo = get_fast_modinfo($course->id)->get_section_info_by_id($section->id);
902
        $this->assertEquals('null_name', $sectioninfo->name);
903
        $this->assertEquals('null_name', $sectioninfo->name);
-
 
904
    }
-
 
905
 
-
 
906
    /**
-
 
907
     * Test that the position of a new section in a course with deleghated sections.
-
 
908
     * @covers ::create
-
 
909
     * @covers ::create_delegated
-
 
910
     */
-
 
911
    public function test_create_position(): void {
-
 
912
        global $DB, $CFG;
-
 
913
        $this->resetAfterTest();
-
 
914
 
-
 
915
        require_once($CFG->libdir . '/tests/fixtures/sectiondelegatetest.php');
-
 
916
 
-
 
917
        $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
-
 
918
 
-
 
919
        $section1 = get_fast_modinfo($course->id)->get_section_info(1);
-
 
920
 
-
 
921
        $sectionactions = new sectionactions($course);
-
 
922
        $delegatedsection1 = $sectionactions->create_delegated('test_component', 1);
-
 
923
        $delegatedsection2 = $sectionactions->create_delegated('test_component', 2);
-
 
924
 
-
 
925
        $this->assertEquals(2, $delegatedsection1->section);
-
 
926
        $this->assertEquals(3, $delegatedsection2->section);
-
 
927
 
-
 
928
        // Create some regular sections with zero and none param.
-
 
929
        $newsection1 = $sectionactions->create(0);
-
 
930
        $newsection2 = $sectionactions->create();
-
 
931
 
-
 
932
        $this->assertEquals(2, $newsection1->section);
-
 
933
        $this->assertEquals(3, $newsection2->section);
-
 
934
 
-
 
935
        // Check the section order.
-
 
936
        $section = $sectioninfo = get_fast_modinfo($course->id)->get_section_info_all();
-
 
937
        $this->assertEquals($section1->id, $section[1]->id);
-
 
938
        $this->assertEquals($newsection1->id, $section[2]->id);
-
 
939
        $this->assertEquals($newsection2->id, $section[3]->id);
-
 
940
        $this->assertEquals($delegatedsection1->id, $section[4]->id);
-
 
941
        $this->assertEquals($delegatedsection2->id, $section[5]->id);
903
    }
942
    }