Passed
Pull Request — master (#222)
by
unknown
01:48
created

Fixtures::getBreakoutCreateMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5
 *
6
 * Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under the
9
 * terms of the GNU Lesser General Public License as published by the Free Software
10
 * Foundation; either version 3.0 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License along
18
 * with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace BigBlueButton\Util;
22
23
use BigBlueButton\Enum\Feature;
24
use BigBlueButton\Enum\GuestPolicy;
25
use BigBlueButton\Enum\MeetingLayout;
26
use BigBlueButton\Enum\Role;
27
use BigBlueButton\Parameters\CreateMeetingParameters;
28
use BigBlueButton\Parameters\EndMeetingParameters;
29
use BigBlueButton\Parameters\JoinMeetingParameters;
30
use BigBlueButton\Parameters\UpdateRecordingsParameters;
31
use Faker\Factory as Faker;
32
33
class Fixtures
34
{
35
    public const PATH = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR;
36
37
    // LOADERS ---------------------------------------------------------------------------------------------------------
38
    public static function fromXmlFile(string $filename): \SimpleXMLElement
39
    {
40
        $uri = self::PATH . $filename;
41
42
        if (!file_exists($uri)) {
43
            throw new \RuntimeException("File '{$uri}' not found.");
44
        }
45
46
        $content = file_get_contents($uri);
47
48
        if (!$content) {
49
            throw new \RuntimeException('Content of file could not be loaded.');
50
        }
51
52
        $xml = simplexml_load_string($content);
53
54
        if (!$xml) {
0 ignored issues
show
introduced by
$xml is of type SimpleXMLElement, thus it always evaluated to true.
Loading history...
55
            throw new \RuntimeException('Content could not be converted to XML.');
56
        }
57
58
        return $xml;
59
    }
60
61
    public static function fromJsonFile(string $filename): string
62
    {
63
        $uri = self::PATH . $filename;
64
65
        if (!file_exists($uri)) {
66
            throw new \RuntimeException("File '{$uri}' not found.");
67
        }
68
69
        $content = file_get_contents($uri);
70
71
        if (!$content) {
72
            throw new \RuntimeException('Content of file could not be loaded.');
73
        }
74
75
        return $content;
76
    }
77
78
    // GENERATORS ------------------------------------------------------------------------------------------------------
79
    /**
80
     * @return array<string, mixed>
81
     */
82
    public static function generateCreateParams(): array
83
    {
84
        $faker = Faker::create();
85
86
        return [
87
            'meetingName'                            => $faker->name,
88
            'meetingId'                              => $faker->uuid,
89
            'attendeePassword'                       => $faker->password,
90
            'moderatorPassword'                      => $faker->password,
91
            'autoStartRecording'                     => $faker->boolean(50),
92
            'dialNumber'                             => $faker->phoneNumber,
93
            'voiceBridge'                            => $faker->randomNumber(5),
94
            'webVoice'                               => $faker->word,
95
            'logoutUrl'                              => $faker->url,
96
            'maxParticipants'                        => $faker->numberBetween(2, 100),
97
            'record'                                 => $faker->boolean(50),
98
            'duration'                               => $faker->numberBetween(0, 6000),
99
            'welcomeMessage'                         => $faker->sentence,
100
            'allowStartStopRecording'                => $faker->boolean(50),
101
            'moderatorOnlyMessage'                   => $faker->sentence,
102
            'webcamsOnlyForModerator'                => $faker->boolean(50),
103
            'logo'                                   => $faker->imageUrl(330, 70),
104
            'copyright'                              => $faker->text,
105
            'muteOnStart'                            => $faker->boolean(50),
106
            'lockSettingsDisableCam'                 => $faker->boolean(50),
107
            'lockSettingsDisableMic'                 => $faker->boolean(50),
108
            'lockSettingsDisablePrivateChat'         => $faker->boolean(50),
109
            'lockSettingsDisablePublicChat'          => $faker->boolean(50),
110
            'lockSettingsDisableNote'                => $faker->boolean(50),
111
            'lockSettingsHideUserList'               => $faker->boolean(50),
112
            'lockSettingsLockedLayout'               => $faker->boolean(50),
113
            'lockSettingsLockOnJoin'                 => $faker->boolean(50),
114
            'lockSettingsLockOnJoinConfigurable'     => $faker->boolean(50),
115
            'lockSettingsHideViewersCursor'          => $faker->boolean(50),
116
            'allowModsToUnmuteUsers'                 => $faker->boolean(50),
117
            'allowModsToEjectCameras'                => $faker->boolean(50),
118
            'guestPolicy'                            => $faker->randomElement(GuestPolicy::getValues()),
0 ignored issues
show
Bug introduced by
The call to Faker\Generator::randomElement() has too few arguments starting with 'b'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

118
            'guestPolicy'                            => $faker->/** @scrutinizer ignore-call */ randomElement(GuestPolicy::getValues()),

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
119
            'endWhenNoModerator'                     => $faker->boolean(50),
120
            'endWhenNoModeratorDelayInMinutes'       => $faker->numberBetween(1, 30),
121
            'meetingKeepEvents'                      => $faker->boolean(50),
122
            'learningDashboardEnabled'               => $faker->boolean(50),
123
            'virtualBackgroundsDisabled'             => $faker->boolean(50),
124
            'learningDashboardCleanupDelayInMinutes' => $faker->numberBetween(1, 30),
125
            'allowRequestsWithoutSession'            => $faker->boolean(50),
126
            'userCameraCap'                          => $faker->numberBetween(1, 5),
127
            'bannerText'                             => $faker->sentence,
128
            'bannerColor'                            => $faker->hexColor,
129
            'breakoutRoomsEnabled'                   => $faker->boolean(50),
130
            'breakoutRoomsRecord'                    => $faker->boolean(50),
131
            'breakoutRoomsPrivateChatEnabled'        => $faker->boolean(50),
132
            'meetingEndedURL'                        => $faker->url,
133
            'meetingLayout'                          => $faker->randomElement(MeetingLayout::getValues()),
134
            'meetingCameraCap'                       => $faker->numberBetween(1, 3),
135
            'meetingExpireIfNoUserJoinedInMinutes'   => $faker->numberBetween(1, 10),
136
            'meetingExpireWhenLastUserLeftInMinutes' => $faker->numberBetween(5, 15),
137
            'preUploadedPresentationOverrideDefault' => $faker->boolean,
138
            'groups'                                 => Fixtures::generateBreakoutRoomsGroups(),
139
            'disabledFeatures'                       => $faker->randomElements(Feature::getValues()),
0 ignored issues
show
Bug introduced by
The call to Faker\Generator::randomElements() has too few arguments starting with 'b'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

139
            'disabledFeatures'                       => $faker->/** @scrutinizer ignore-call */ randomElements(Feature::getValues()),

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
140
            'disabledFeaturesExclude'                => $faker->randomElements(Feature::getValues()),
141
            'meta_presenter'                         => $faker->name,
142
            'meta_endCallbackUrl'                    => $faker->url,
143
            'meta_bbb-recording-ready-url'           => $faker->url,
144
            'notifyRecordingIsOn'                    => $faker->boolean(50),
145
            'presentationUploadExternalUrl'          => $faker->url,
146
            'presentationUploadExternalDescription'  => $faker->text,
147
            'recordFullDurationMedia'                => $faker->boolean(50),
148
        ];
149
    }
150
151
    /**
152
     * @return array<int, array<string, mixed>>
153
     */
154
    public static function generateBreakoutRoomsGroups(): array
155
    {
156
        $faker = Faker::create();
157
        $br    = $faker->numberBetween(0, 8);
158
159
        $groups = [];
160
        for ($i = 0; $i <= $br; ++$i) {
161
            $groups[] = [
162
                'id'     => $faker->uuid,
163
                'name'   => $faker->name,
164
                'roster' => $faker->randomElements,
165
            ];
166
        }
167
168
        return $groups;
169
    }
170
171
    /**
172
     * @param mixed $createParams
173
     *
174
     * @return array<string, mixed>
175
     */
176
    public static function generateBreakoutCreateParams($createParams): array
177
    {
178
        $faker = Faker::create();
179
180
        return array_merge($createParams, [
181
            'isBreakout'      => true,
182
            'parentMeetingId' => $faker->uuid,
183
            'sequence'        => $faker->numberBetween(1, 8),
184
            'freeJoin'        => $faker->boolean(50),
185
        ]);
186
    }
187
188
    /**
189
     * @return array<string, mixed>
190
     */
191
    public static function generateJoinMeetingParams(): array
192
    {
193
        $faker = Faker::create();
194
195
        return [
196
            'meetingId'            => $faker->uuid,
197
            'userName'             => $faker->name,
198
            'password'             => $faker->password,
199
            'userId'               => $faker->numberBetween(1, 1000),
200
            'webVoiceConf'         => $faker->word,
201
            'creationTime'         => $faker->unixTime,
202
            'role'                 => $faker->randomElement(Role::getValues()),
0 ignored issues
show
Bug introduced by
The call to Faker\Generator::randomElement() has too few arguments starting with 'b'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

202
            'role'                 => $faker->/** @scrutinizer ignore-call */ randomElement(Role::getValues()),

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
203
            'excludeFromDashboard' => $faker->boolean,
204
            'userdata_countrycode' => $faker->countryCode,
205
            'userdata_email'       => $faker->email,
206
            'userdata_commercial'  => false,
207
        ];
208
    }
209
210
    /**
211
     * @return array<string, string>
212
     */
213
    public static function generateEndMeetingParams(): array
214
    {
215
        $faker = Faker::create();
216
217
        return [
218
            'meetingId' => $faker->uuid,
219
            'password'  => $faker->password,
220
        ];
221
    }
222
223
    /**
224
     * @return array<string, string>
225
     */
226
    public static function generateUpdateRecordingsParams(): array
227
    {
228
        $faker = Faker::create();
229
230
        return [
231
            'recordingId'    => $faker->uuid,
232
            'meta_presenter' => $faker->name,
233
        ];
234
    }
235
236
    // MOCKS -----------------------------------------------------------------------------------------------------------
237
    /**
238
     * @param array<string, mixed> $params
239
     */
240
    public static function getCreateMeetingParametersMock(array $params): CreateMeetingParameters
241
    {
242
        $createMeetingParams = new CreateMeetingParameters($params['meetingId'], $params['meetingName']);
243
244
        foreach ($params['groups'] as $group) {
245
            $createMeetingParams->addBreakoutRoomsGroup($group['id'], $group['name'], $group['roster']);
246
        }
247
248
        return $createMeetingParams
0 ignored issues
show
Deprecated Code introduced by
The function BigBlueButton\Parameters...alBackgroundsDisabled() has been deprecated: Removed in 2.5, temporarily still handled, please transition to disabledFeatures. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

248
        return /** @scrutinizer ignore-deprecated */ $createMeetingParams

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function BigBlueButton\Parameters...tBreakoutRoomsEnabled() has been deprecated: Removed in 2.5, temporarily still handled, please transition to disabledFeatures. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

248
        return /** @scrutinizer ignore-deprecated */ $createMeetingParams

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function BigBlueButton\Parameters...::setAttendeePassword() has been deprecated: Password-string replaced by an Enum\Role-constant in JoinMeetingParameters::__construct() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

248
        return /** @scrutinizer ignore-deprecated */ $createMeetingParams

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function BigBlueButton\Parameters...rningDashboardEnabled() has been deprecated: Removed in 2.5, temporarily still handled, please transition to disabledFeatures. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

248
        return /** @scrutinizer ignore-deprecated */ $createMeetingParams

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function BigBlueButton\Parameters...:setModeratorPassword() has been deprecated: Password-string replaced by an Enum\Role-constant in JoinMeetingParameters::__construct() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

248
        return /** @scrutinizer ignore-deprecated */ $createMeetingParams

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
249
            ->setAttendeePassword($params['attendeePassword'])
250
            ->setModeratorPassword($params['moderatorPassword'])
251
            ->setDialNumber($params['dialNumber'])
252
            ->setVoiceBridge($params['voiceBridge'])
253
            ->setWebVoice($params['webVoice'])
254
            ->setLogoutUrl($params['logoutUrl'])
255
            ->setMaxParticipants($params['maxParticipants'])
256
            ->setRecord($params['record'])
257
            ->setDuration($params['duration'])
258
            ->setWelcomeMessage($params['welcomeMessage'])
259
            ->setAutoStartRecording($params['autoStartRecording'])
260
            ->setAllowStartStopRecording($params['allowStartStopRecording'])
261
            ->setModeratorOnlyMessage($params['moderatorOnlyMessage'])
262
            ->setWebcamsOnlyForModerator($params['webcamsOnlyForModerator'])
263
            ->setLogo($params['logo'])
264
            ->setCopyright($params['copyright'])
265
            ->setEndCallbackUrl($params['meta_endCallbackUrl'])
266
            ->setRecordingReadyCallbackUrl($params['meta_bbb-recording-ready-url'])
267
            ->setMuteOnStart($params['muteOnStart'])
268
            ->setLockSettingsDisableCam($params['lockSettingsDisableCam'])
269
            ->setLockSettingsDisableMic($params['lockSettingsDisableMic'])
270
            ->setLockSettingsDisablePrivateChat($params['lockSettingsDisablePrivateChat'])
271
            ->setLockSettingsDisablePublicChat($params['lockSettingsDisablePublicChat'])
272
            ->setLockSettingsDisableNote($params['lockSettingsDisableNote'])
273
            ->setLockSettingsHideUserList($params['lockSettingsHideUserList'])
274
            ->setLockSettingsLockedLayout($params['lockSettingsLockedLayout'])
275
            ->setLockSettingsLockOnJoin($params['lockSettingsLockOnJoin'])
276
            ->setLockSettingsLockOnJoinConfigurable($params['lockSettingsLockOnJoinConfigurable'])
277
            ->setLockSettingsHideViewersCursor($params['lockSettingsHideViewersCursor'])
278
            ->setEndWhenNoModerator($params['endWhenNoModerator'])
279
            ->setEndWhenNoModeratorDelayInMinutes($params['endWhenNoModeratorDelayInMinutes'])
280
            ->setAllowModsToUnmuteUsers($params['allowModsToUnmuteUsers'])
281
            ->setAllowModsToEjectCameras($params['allowModsToEjectCameras'])
282
            ->setGuestPolicy($params['guestPolicy'])
283
            ->setMeetingKeepEvents($params['meetingKeepEvents'])
284
            ->setLearningDashboardEnabled($params['learningDashboardEnabled'])
285
            ->setVirtualBackgroundsDisabled($params['virtualBackgroundsDisabled'])
286
            ->setLearningDashboardCleanupDelayInMinutes($params['learningDashboardCleanupDelayInMinutes'])
287
            ->setBannerColor($params['bannerColor'])
288
            ->setBannerText($params['bannerText'])
289
            ->setBreakoutRoomsEnabled($params['breakoutRoomsEnabled'])
290
            ->setBreakoutRoomsRecord($params['breakoutRoomsRecord'])
291
            ->setBreakoutRoomsPrivateChatEnabled($params['breakoutRoomsPrivateChatEnabled'])
292
            ->setMeetingEndedURL($params['meetingEndedURL'])
293
            ->setMeetingLayout($params['meetingLayout'])
294
            ->setAllowRequestsWithoutSession($params['allowRequestsWithoutSession'])
295
            ->setUserCameraCap($params['userCameraCap'])
296
            ->setMeetingCameraCap($params['meetingCameraCap'])
297
            ->setMeetingExpireIfNoUserJoinedInMinutes($params['meetingExpireIfNoUserJoinedInMinutes'])
298
            ->setMeetingExpireWhenLastUserLeftInMinutes($params['meetingExpireWhenLastUserLeftInMinutes'])
299
            ->setPreUploadedPresentationOverrideDefault($params['preUploadedPresentationOverrideDefault'])
300
            ->setDisabledFeatures($params['disabledFeatures'])
301
            ->setDisabledFeaturesExclude($params['disabledFeaturesExclude'])
302
            ->setRecordFullDurationMedia($params['recordFullDurationMedia'])
303
            ->addMeta('presenter', $params['meta_presenter'])
304
            ->addMeta('bbb-recording-ready-url', $params['meta_bbb-recording-ready-url'])
305
            ->setNotifyRecordingIsOn($params['notifyRecordingIsOn'])
306
            ->setPresentationUploadExternalUrl($params['presentationUploadExternalUrl'])
307
            ->setPresentationUploadExternalDescription($params['presentationUploadExternalDescription'])
308
        ;
309
    }
310
311
    /**
312
     * @param mixed $params
313
     */
314
    public static function getBreakoutCreateMock($params): CreateMeetingParameters
315
    {
316
        $createMeetingParams = Fixtures::getCreateMeetingParametersMock($params);
317
318
        return $createMeetingParams
319
            ->setBreakout($params['isBreakout'])
320
            ->setParentMeetingId($params['parentMeetingId'])
321
            ->setSequence($params['sequence'])
322
            ->setFreeJoin($params['freeJoin'])
323
        ;
324
    }
325
326
    /**
327
     * @param array<string, mixed> $params
328
     */
329
    public static function getJoinMeetingMock(array $params): JoinMeetingParameters
330
    {
331
        $joinMeetingParams = new JoinMeetingParameters($params['meetingId'], $params['userName'], $params['password']);
332
333
        return $joinMeetingParams
334
            ->setUserId($params['userId'])
335
            ->setWebVoiceConf($params['webVoiceConf'])
336
            ->setCreationTime($params['creationTime'])
337
            ->addUserData('countrycode', $params['userdata_countrycode'])
338
            ->setRole($params['role'])
339
            ->addUserData('email', $params['userdata_email'])
340
            ->addUserData('commercial', $params['userdata_commercial'])
341
            ->setExcludeFromDashboard($params['excludeFromDashboard'])
342
        ;
343
    }
344
345
    /**
346
     * @param array<string, string> $params
347
     */
348
    public static function getEndMeetingMock(array $params): EndMeetingParameters
349
    {
350
        return new EndMeetingParameters($params['meetingId'], $params['password']);
351
    }
352
353
    /**
354
     * @param array<string, string> $params
355
     */
356
    public static function getUpdateRecordingsParamsMock(array $params): UpdateRecordingsParameters
357
    {
358
        $updateRecordingsParams = new UpdateRecordingsParameters($params['recordingId']);
359
360
        return $updateRecordingsParams->addMeta('presenter', $params['meta_presenter']);
361
    }
362
363
}
364