Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core_courseformat\local\overview;
18
 
19
/**
20
 * Tests for resource overview
21
 *
22
 * @package    core_courseformat
23
 * @category   test
24
 * @copyright  2025 Ferran Recio <ferran@moodle.com>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @covers     \core_courseformat\local\overview\resourceoverview
27
 */
28
final class resourceoverview_test extends \advanced_testcase {
29
    /**
30
     * Test get_extra_overview_items method.
31
     *
32
     * @covers ::get_extra_overview_items
33
     */
34
    public function test_get_extra_overview_items(): void {
35
        $this->resetAfterTest();
36
        $this->setAdminUser();
37
 
38
        $generator = $this->getDataGenerator();
39
        $course = $generator->create_course();
40
        $activity = $this->getDataGenerator()->create_module('url', ['course' => $course->id]);
41
        $modinfo = get_fast_modinfo($course);
42
        $cm = $modinfo->get_cm($activity->cmid);
43
 
44
        $overview = overviewfactory::create($cm);
45
 
46
        $result = $overview->get_extra_overview_items();
47
        $this->assertCount(1, $result);
48
        $this->assertArrayHasKey('type', $result);
49
        $this->assertInstanceOf(\core_courseformat\local\overview\overviewitem::class, $result['type']);
50
    }
51
 
52
    /**
53
     * Test get_extra_type_overview method.
54
     *
55
     * @covers ::get_extra_overview_items
56
     * @covers ::get_extra_type_overview
57
     * @dataProvider get_extra_type_overview_provider
58
     * @param string $resourcetype
59
     * @param string|null $expected
60
     */
61
    public function test_get_extra_type_overview(
62
        string $resourcetype,
63
        ?string $expected,
64
    ): void {
65
        $this->resetAfterTest();
66
        $this->setAdminUser();
67
 
68
        $generator = $this->getDataGenerator();
69
        $course = $generator->create_course();
70
        $activity = $this->getDataGenerator()->create_module($resourcetype, ['course' => $course->id]);
71
        $modinfo = get_fast_modinfo($course);
72
        $cm = $modinfo->get_cm($activity->cmid);
73
 
74
        $overview = overviewfactory::create($cm);
75
 
76
        $items = $overview->get_extra_overview_items();
77
        $result = $items['type'];
78
 
79
        if ($expected === null) {
80
            $this->assertNull($result);
81
            return;
82
        }
83
 
84
        $this->assertEquals(get_string('resource_type'), $result->get_name());
85
        $this->assertEquals($expected, $result->get_value());
86
        $this->assertEquals($expected, $result->get_content());
87
    }
88
 
89
    /**
90
     * Data provider for test_get_extra_type_overview.
91
     *
92
     * @return array
93
     */
94
    public static function get_extra_type_overview_provider(): array {
95
        return [
96
            'book' => [
97
                'resourcetype' => 'book',
98
                'expected' => 'Book',
99
            ],
100
            'folder' => [
101
                'resourcetype' => 'folder',
102
                'expected' => 'Folder',
103
            ],
104
            'page' => [
105
                'resourcetype' => 'page',
106
                'expected' => 'Page',
107
            ],
108
            'resource' => [
109
                'resourcetype' => 'resource',
110
                'expected' => 'File',
111
            ],
112
            'url' => [
113
                'resourcetype' => 'url',
114
                'expected' => 'URL',
115
            ],
116
            // Activities without integration.
117
            'bigbluebuttonbn' => [
118
                'resourcetype' => 'bigbluebuttonbn',
119
                'expected' => null,
120
            ],
121
            'choice' => [
122
                'resourcetype' => 'choice',
123
                'expected' => null,
124
            ],
125
            'data' => [
126
                'resourcetype' => 'data',
127
                'expected' => null,
128
            ],
129
            'forum' => [
130
                'resourcetype' => 'forum',
131
                'expected' => null,
132
            ],
133
            'glossary' => [
134
                'resourcetype' => 'glossary',
135
                'expected' => null,
136
            ],
137
            'h5pactivity' => [
138
                'resourcetype' => 'h5pactivity',
139
                'expected' => null,
140
            ],
141
            'lesson' => [
142
                'resourcetype' => 'lesson',
143
                'expected' => null,
144
            ],
145
            'lti' => [
146
                'resourcetype' => 'lti',
147
                'expected' => null,
148
            ],
149
            'qbank' => [
150
                'resourcetype' => 'qbank',
151
                'expected' => null,
152
            ],
153
            'quiz' => [
154
                'resourcetype' => 'quiz',
155
                'expected' => null,
156
            ],
157
            'scorm' => [
158
                'resourcetype' => 'scorm',
159
                'expected' => null,
160
            ],
161
            'wiki' => [
162
                'resourcetype' => 'wiki',
163
                'expected' => null,
164
            ],
165
        ];
166
    }
167
}