Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 mod_bigbluebuttonbn\output;
18
 
19
use mod_bigbluebuttonbn\instance;
20
use mod_bigbluebuttonbn\recording;
21
use mod_bigbluebuttonbn\test\testcase_helper_trait;
22
 
23
/**
24
 * Recording row
25
 *
26
 * @package   mod_bigbluebuttonbn
27
 * @copyright 2010 onwards, Blindside Networks Inc
28
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @author    Laurent David  (laurent.david [at] call-learning [dt] fr)
30
 */
31
class recording_row_playback_test extends \advanced_testcase {
32
    use testcase_helper_trait;
33
 
34
    /**
35
     * Setup for test
36
     */
37
    public function setUp(): void {
38
        parent::setUp();
39
        $this->initialise_mock_server();
40
    }
41
 
42
    /**
43
     * Recording sample data
44
     */
45
    const RECORDING_DATA = [
46
        [
47
            'status' => recording::RECORDING_STATUS_PROCESSED,
48
            'playback' => [
49
                'format' =>
50
                    [
51
                        [
52
 
53
                            'type' => 'podcast',
54
                            'url' => 'http://mypodcast',
55
                            'processingTime' => 0,
56
                            'length' => 0,
57
 
58
                        ],
59
                        [
60
 
61
                            'type' => 'presentation',
62
                            'url' => 'http://mypresentation',
63
                            'processingTime' => 0,
64
                            'length' => 0,
65
 
66
                        ],
67
                        [
68
 
69
                            'type' => 'video',
70
                            'url' => 'http://myvideo',
71
                            'processingTime' => 0,
72
                            'length' => 0,
73
 
74
                        ],
75
                        [
76
 
77
                            'type' => 'settings',
78
                            'url' => 'http://mysettings',
79
                            'processingTime' => 0,
80
                            'length' => 0,
81
 
82
                        ]
83
                    ]
84
            ]
85
        ]
86
    ];
87
 
88
    /**
89
     * Should this recording be included ?
90
     *
91
     * @param string $role
92
     * @param array $canview
93
     * @param object|null $globalsettings
94
     * @return void
95
     * @covers       \recording_row_playback::should_be_included
96
     * @dataProvider should_be_included_data_provider
97
     */
11 efrain 98
    public function test_should_be_included(string $role, array $canview, object $globalsettings = null): void {
1 efrain 99
        global $PAGE;
100
        $this->resetAfterTest();
101
        ['recordings' => $recordingsdata, 'activity' => $activity] = $this->create_activity_with_recordings(
102
            $this->get_course(),
103
            instance::TYPE_ALL,
104
            self::RECORDING_DATA
105
        );
106
        $user = $this->getDataGenerator()->create_user();
107
        $this->getDataGenerator()->enrol_user($user->id, $activity->course, $role);
108
        if (!empty($globalsettings)) {
109
            foreach ((array) $globalsettings as $key => $value) {
110
                set_config($key, $value);
111
            }
112
        }
113
        $this->setUser($user);
114
        $recording = new recording(0, $recordingsdata[0]);
115
        $rowplayback = new recording_row_playback($recording, instance::get_from_instanceid($activity->id));
116
        $rowinfo = $rowplayback->export_for_template($PAGE->get_renderer('mod_bigbluebuttonbn'));
117
        $playbacktypes = array_map(function($playback) {
118
            foreach ($playback->attributes as $attributearray) {
119
                if (in_array('data-target', $attributearray)) {
120
                    return $attributearray['value'];
121
                }
122
            }
123
            return '';
124
        }, $rowinfo->playbacks);
125
        $this->assertEmpty(array_diff($canview, $playbacktypes));
126
    }
127
 
128
    /**
129
     * Data provider for the should be included method
130
     *
131
     * @return array
132
     */
133
    public function should_be_included_data_provider() {
134
        return [
135
            'editingteacher user should see all' => [
136
                'role' => 'editingteacher',
137
                'canview' => ['video', 'presentation', 'podcast', 'settings'],
138
            ],
139
            'student can see only default' => [
140
                'role' => 'student',
141
                'canview' => ['video', 'presentation'],
142
            ],
143
            'student can see only default except when we add more format to all users' => [
144
                'role' => 'student',
145
                'canview' => ['video', 'presentation', 'settings'],
146
                'globalsettings' => (object) ['bigbluebuttonbn_recording_safe_formats' => 'video,presentation,settings']
147
            ]
148
 
149
        ];
150
    }
151
 
152
    /**
153
     * Test recording link is rendered for imported recordings.
154
     *
155
     * @return void
156
     * @covers       \recording_row_playback::should_be_included
157
     */
158
    public function test_show_recording_links(): void {
159
        global $PAGE;
160
        $this->resetAfterTest();
161
        set_config('bigbluebuttonbn_importrecordings_enabled', 1);
162
        $plugingenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
163
        ['recordings' => $recordingsdata, 'activity' => $activity] = $this->create_activity_with_recordings(
164
            $this->get_course(),
165
            instance::TYPE_ALL,
166
            self::RECORDING_DATA
167
        );
168
        $recording = new recording(0, $recordingsdata[0]);
169
        $instance = instance::get_from_instanceid($activity->id);
170
        // Now create a new activity and import the recording.
171
        $newactivity = $plugingenerator->create_instance([
172
            'course' => $instance->get_course_id(),
173
            'type' => instance::TYPE_ALL,
174
            'name' => 'Example 2',
175
        ]);
176
        $plugingenerator->create_meeting([
177
            'instanceid' => $newactivity->id,
178
        ]);
179
        $newinstance = instance::get_from_instanceid($newactivity->id);
180
        // Import recording into new instance.
181
        $importedrecording = $recording->create_imported_recording($newinstance);
182
        $importedrowplayback = new recording_row_playback($importedrecording, $newinstance);
183
        $importedrowinfo = $importedrowplayback->export_for_template($PAGE->get_renderer('mod_bigbluebuttonbn'));
184
        $this->assertNotEmpty($importedrowinfo->playbacks);
185
    }
186
}