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
/**
18
 * BBB Library tests class.
19
 *
20
 * @package   mod_bigbluebuttonbn
21
 * @copyright 2018 - present, Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @author    Laurent David (laurent@call-learning.fr)
24
 */
25
 
26
namespace mod_bigbluebuttonbn\local\helpers;
27
 
28
use mod_bigbluebuttonbn\instance;
29
use mod_bigbluebuttonbn\test\testcase_helper_trait;
30
 
31
/**
32
 * BBB Library tests class.
33
 *
34
 * @package   mod_bigbluebuttonbn
35
 * @copyright 2018 - present, Blindside Networks Inc
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @author    Laurent David (laurent@call-learning.fr)
38
 * @covers \mod_bigbluebuttonbn\local\helpers\mod_helper
39
 * @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\mod_helper
40
 */
41
class mod_helper_trait_test extends \advanced_testcase {
42
    use testcase_helper_trait;
43
 
44
    /**
45
     * Presave test
46
     */
11 efrain 47
    public function test_process_pre_save(): void {
1 efrain 48
        $this->resetAfterTest();
49
        list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
50
        $bbformdata = $this->get_form_data_from_instance($bbactivity);
51
        $bbformdata->participants = '<p>this -&gt; &quot;</p>\n';
52
        $bbformdata->timemodified = time();
53
        mod_helper::process_pre_save($bbformdata);
54
        $this->assertTrue($bbformdata->timemodified != 0);
55
        $this->assertEquals('<p>this -> "</p>\n', $bbformdata->participants);
56
    }
57
 
58
    /**
59
     * Presave instance
60
     */
11 efrain 61
    public function test_process_pre_save_instance(): void {
1 efrain 62
        $this->resetAfterTest();
63
        list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
64
        $bbformdata = $this->get_form_data_from_instance($bbactivity);
65
        $bbformdata->instance = 0;
66
        $bbformdata->timemodified = time();
67
        mod_helper::process_pre_save($bbformdata);
68
        $this->assertTrue($bbformdata->timemodified == 0);
69
    }
70
 
71
    /**
72
     * Presave checkboxes
73
     */
11 efrain 74
    public function test_process_pre_save_checkboxes(): void {
1 efrain 75
        $this->resetAfterTest();
76
        list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
77
        $bbformdata = $this->get_form_data_from_instance($bbactivity);
78
        unset($bbformdata->wait);
79
        unset($bbformdata->recordallfromstart);
80
        mod_helper::process_pre_save($bbformdata);
81
        $this->assertTrue(isset($bbformdata->wait));
82
        $this->assertTrue(isset($bbformdata->recordallfromstart));
83
    }
84
 
85
    /**
86
     * Presave common
87
     */
11 efrain 88
    public function test_process_pre_save_common(): void {
1 efrain 89
        global $CFG;
90
        $this->resetAfterTest();
91
 
92
        list($bbactivitycontext, $bbactivitycm, $bbactivity) =
93
            $this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
94
        $bbformdata = $this->get_form_data_from_instance($bbactivity);
95
 
96
        $bbformdata->groupmode = '1';
97
        mod_helper::process_pre_save($bbformdata);
98
        $this->assertEquals(0, $bbformdata->groupmode);
99
    }
100
 
101
    /**
102
     * Post save
103
     */
11 efrain 104
    public function test_process_post_save(): void {
1 efrain 105
        $this->resetAfterTest();
106
 
107
        $generator = $this->getDataGenerator();
108
        list($bbactivitycontext, $bbactivitycm, $bbactivity) =
109
            $this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
110
        // Reset some static caches used by this test after enabling the plugin.
111
        get_module_types_names(false, true);
112
 
113
        $bbformdata = $this->get_form_data_from_instance($bbactivity);
114
 
115
        // Enrol users in a course so he will receive the message.
116
        $teacher = $generator->create_user(['role' => 'editingteacher']);
117
        $generator->enrol_user($teacher->id, $this->get_course()->id);
118
 
119
        // Mark the form to trigger notification.
120
        $bbformdata->coursecontentnotification = true;
121
        $bbformdata->update = false;
122
        $messagesink = $this->redirectMessages();
123
        mod_helper::process_post_save($bbformdata);
124
        edit_module_post_actions($bbformdata, $this->course);
125
        // Now run cron.
126
        ob_start();
127
        $this->runAdhocTasks();
128
        ob_get_clean(); // Suppress output as it can fail the test.
129
        $this->assertEquals(1, $messagesink->count());
130
        $firstmessage = $messagesink->get_messages()[0];
131
        $this->assertStringContainsString('is new in', $firstmessage->smallmessage);
132
    }
133
 
134
    /**
135
     * Post save notification
136
     */
11 efrain 137
    public function test_process_post_save_with_add(): void {
1 efrain 138
        $this->resetAfterTest();
139
 
140
        $generator = $this->getDataGenerator();
141
        list($bbactivitycontext, $bbactivitycm, $bbactivity) =
142
            $this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
143
        // Reset some static caches used by this test after enabling the plugin.
144
        get_module_types_names(false, true);
145
 
146
        $bbformdata = $this->get_form_data_from_instance($bbactivity);
147
 
148
        $bbformdata->update = false;
149
        $messagesink = $this->redirectMessages();
150
        // Enrol users in a course so he will receive the message.
151
        $teacher = $generator->create_user(['role' => 'editingteacher']);
152
        $generator->enrol_user($teacher->id, $this->get_course()->id);
153
        $bbformdata->coursecontentnotification = true;
154
        mod_helper::process_post_save($bbformdata);
155
        edit_module_post_actions($bbformdata, $this->course);
156
        // Now run cron.
157
        ob_start();
158
        $this->runAdhocTasks();
159
        ob_get_clean(); // Suppress output as it can fail the test.
160
        $messages = $messagesink->get_messages_by_component_and_type(
161
            component: 'core',
162
            type: 'coursecontentupdated',
163
        );
164
        $this->assertEquals(1, count($messages));
165
        $firstmessage = reset($messages);
166
        $this->assertStringContainsString('is new in', $firstmessage->smallmessage);
167
    }
168
 
169
    /**
170
     * Post save
171
     *
172
     * There was an issue when both the opening time and completion were set
173
     * and the form was saved twice.
174
     */
11 efrain 175
    public function test_process_post_save_twice_with_completion(): void {
1 efrain 176
        $this->resetAfterTest();
177
 
178
        $generator = $this->getDataGenerator();
179
        list($bbactivitycontext, $bbactivitycm, $bbactivity) =
180
            $this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
181
        // Reset some static caches used by this test after enabling the plugin.
182
        get_module_types_names(false, true);
183
 
184
        $bbformdata = $this->get_form_data_from_instance($bbactivity);
185
        $bbformdata->completionunlocked = 0;
186
        $bbformdata->completion = COMPLETION_AGGREGATION_ANY;
187
        $bbformdata->completionview = COMPLETION_VIEWED;
188
        $bbformdata->completionexpected = time();
189
        $bbformdata->openingtime = time() - 1000;
190
        $bbformdata->closing = time() + 1000;
191
        // Enrol users in a course so he will receive the message.
192
        $teacher = $generator->create_user();
193
        $generator->enrol_user($teacher->id, $this->get_course()->id, 'editingteacher');
194
        $this->setUser($teacher);
195
        // Mark the form to trigger notification.
196
        $bbformdata->coursecontentnotification = true;
197
        $bbformdata->update = false;
198
        $messagesink = $this->redirectMessages();
199
        mod_helper::process_post_save($bbformdata);
200
        edit_module_post_actions($bbformdata, $this->course);
201
        // Now run cron.
202
        ob_start();
203
        $this->runAdhocTasks();
204
        ob_get_clean(); // Suppress output as it can fail the test.
205
        $this->assertEquals(1, $messagesink->count());
206
        $firstmessage = $messagesink->get_messages()[0];
207
        $this->assertStringContainsString('is new in', $firstmessage->smallmessage);
208
        $messagesink->clear();
209
        // Do it a again, so we check we still have one event.
210
        mod_helper::process_post_save($bbformdata);
211
        // Mark the form to trigger notification.
212
        $bbformdata->update = true;
213
        edit_module_post_actions($bbformdata, $this->course);
214
        // Now run cron.
215
        ob_start();
216
        $this->runAdhocTasks();
217
        ob_get_clean(); // Suppress output as it can fail the test.
218
        $this->assertEquals(1, $messagesink->count());
219
        $firstmessage = $messagesink->get_messages()[0];
220
        $this->assertStringContainsString('has been changed', $firstmessage->smallmessage);
221
    }
222
}