Proyectos de Subversion Moodle

Rev

| 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\task;
18
 
19
use advanced_testcase;
20
use mod_bigbluebuttonbn\instance;
21
use mod_bigbluebuttonbn\recording;
22
use mod_bigbluebuttonbn\test\testcase_helper_trait;
23
 
24
/**
25
 * Test class for the check_pending_recordings and check_dismissed_recordings task
26
 *
27
 * @package   mod_bigbluebuttonbn
28
 * @copyright 2022 onwards, Blindside Networks Inc
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 * @covers \mod_bigbluebuttonbn\task\check_dismissed_recordings
31
 * @covers \mod_bigbluebuttonbn\task\check_pending_recordings
32
 * @covers \mod_bigbluebuttonbn\recording::sync_pending_recordings_from_server
33
 */
34
class check_recordings_task_test extends advanced_testcase {
35
 
36
    use testcase_helper_trait;
37
 
38
    /**
39
     * @var $RECORDINGS_DATA array fake recording data.
40
     */
41
    const RECORDINGS_DATA = [
42
        ['name' => 'Recording 1'],
43
        ['name' => 'Recording 2'],
44
        ['name' => 'Recording 3'],
45
        ['name' => 'Recording 4'],
46
    ];
47
 
48
    /**
49
     * Setup for test
50
     */
51
    public function setUp(): void {
52
        parent::setUp();
53
        $this->initialise_mock_server();
54
        $this->resetAfterTest();
55
    }
56
 
57
    /**
58
     * Test that dismissed recordings are retrieved
59
     */
60
    public function test_check_dismissed_recordings(): void {
61
        $this->create_meeting_and_recordings(recording::RECORDING_STATUS_DISMISSED);
62
        $this->assertEquals(4, recording::count_records());
63
        $this->assertEquals(0, recording::count_records(['status' => recording::RECORDING_STATUS_PROCESSED]));
64
        $task = new check_dismissed_recordings();
65
        ob_start();
66
        $task->execute();
67
        ob_end_clean();
68
        $this->assertEquals(4, recording::count_records(['status' => recording::RECORDING_STATUS_PROCESSED]));
69
    }
70
 
71
    /**
72
     * Test that pending recordings are retrieved
73
     */
74
    public function test_check_pending_recordings(): void {
75
        $this->create_meeting_and_recordings();
76
        $this->assertEquals(4, recording::count_records());
77
        $this->assertEquals(0, recording::count_records(['status' => recording::RECORDING_STATUS_PROCESSED]));
78
        $task = new check_pending_recordings();
79
        ob_start();
80
        $task->execute();
81
        ob_end_clean();
82
        $this->assertEquals(4, recording::count_records(['status' => recording::RECORDING_STATUS_PROCESSED]));
83
    }
84
 
85
    /**
86
     * Create sample meeting and recording.
87
     *
88
     * @param int $status status for the newly created recordings
89
     * @return array recording data (not the persistent class but plain object)
90
     */
91
    private function create_meeting_and_recordings(int $status = recording::RECORDING_STATUS_AWAITING): array {
92
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
93
        $course = $this->getDataGenerator()->create_course();
94
        $activity = $generator->create_instance([
95
            'course' => $course->id,
96
            'type' => instance::TYPE_ALL
97
        ]);
98
        $instance = instance::get_from_instanceid($activity->id);
99
        $generator->create_meeting([
100
            'instanceid' => $instance->get_instance_id(),
101
            'groupid' => $instance->get_group_id()
102
        ]);
103
        foreach (self::RECORDINGS_DATA as $data) {
104
            $rdata = $generator->create_recording(
105
                array_merge([
106
                    'bigbluebuttonbnid' => $instance->get_instance_id(),
107
                    'groupid' => $instance->get_group_id()
108
                ], $data)
109
            );
110
            $recording = new recording($rdata->id);
111
            $recording->set('status', $status);
112
            $recording->save();
113
            $recordings[] = $rdata;
114
        }
115
        return $recordings;
116
    }
117
}