Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 15... Línea 15...
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
namespace mod_bigbluebuttonbn\local;
16
namespace mod_bigbluebuttonbn\local;
Línea 17... Línea 17...
17
 
17
 
18
use backup;
18
use backup;
-
 
19
use backup_controller;
19
use backup_controller;
20
use mod_bigbluebuttonbn\broker;
20
use mod_bigbluebuttonbn\completion\custom_completion;
21
use mod_bigbluebuttonbn\completion\custom_completion;
21
use mod_bigbluebuttonbn\extension;
22
use mod_bigbluebuttonbn\extension;
22
use mod_bigbluebuttonbn\instance;
23
use mod_bigbluebuttonbn\instance;
23
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
24
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
Línea 34... Línea 35...
34
 * @copyright 2023 - present, Blindside Networks Inc
35
 * @copyright 2023 - present, Blindside Networks Inc
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @author    Laurent David (laurent@call-learning.fr)
37
 * @author    Laurent David (laurent@call-learning.fr)
37
 * @coversDefaultClass \mod_bigbluebuttonbn\extension
38
 * @coversDefaultClass \mod_bigbluebuttonbn\extension
38
 */
39
 */
39
class extension_test extends \advanced_testcase {
40
final class extension_test extends \advanced_testcase {
40
    use subplugins_test_helper_trait;
41
    use subplugins_test_helper_trait;
41
    use testcase_helper_trait;
42
    use testcase_helper_trait;
Línea 42... Línea 43...
42
 
43
 
43
    /**
44
    /**
44
     * Setup our fake plugin
45
     * Setup our fake plugin
45
     *
46
     *
46
     * @return void
47
     * @return void
47
     */
48
     */
-
 
49
    public function setUp(): void {
48
    public function setUp(): void {
50
        parent::setUp();
49
        $this->resetAfterTest(true);
51
        $this->resetAfterTest(true);
50
        $this->setup_fake_plugin('simple');
52
        $this->setup_fake_plugin('simple');
51
        $this->resetDebugging(); // We might have debugging messages issued from setup_fake_plugin here that we need to get rid of.
53
        $this->resetDebugging(); // We might have debugging messages issued from setup_fake_plugin here that we need to get rid of.
Línea 57... Línea 59...
57
     *
59
     *
58
     * @return void
60
     * @return void
59
     */
61
     */
60
    public function tearDown(): void {
62
    public function tearDown(): void {
61
        $this->uninstall_fake_plugin('simple');
63
        $this->uninstall_fake_plugin('simple');
-
 
64
        parent::tearDown();
62
    }
65
    }
Línea 63... Línea 66...
63
 
66
 
64
    /**
67
    /**
65
     * Test for the type_text provider.
68
     * Test for the type_text provider.
Línea 366... Línea 369...
366
            ],
369
            ],
367
        ];
370
        ];
368
    }
371
    }
Línea 369... Línea 372...
369
 
372
 
-
 
373
    /**
-
 
374
     * Test broker meeting_events with and without addons.
-
 
375
     * @return void
-
 
376
     * @covers \mod_bigbluebuttonbn\local\extension\broker_meeting_events_addons
-
 
377
     */
-
 
378
    public function test_broker_meeting_events_addons(): void {
-
 
379
        $this->resetAfterTest();
-
 
380
        global $DB;
-
 
381
        // Enable plugin.
-
 
382
        $this->enable_plugins(true);
-
 
383
        $this->initialise_mock_server();
-
 
384
        [$bbactivitycontext, $bbactivitycm, $bbactivity] = $this->create_instance(
-
 
385
            $this->get_course());
-
 
386
        $plugingenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
-
 
387
        $user = $this->getDataGenerator()->create_user();
-
 
388
        $this->setUser($user);
-
 
389
 
-
 
390
        // Now create a couple of events.
-
 
391
        $instance = instance::get_from_instanceid($bbactivity->id);
-
 
392
        set_config('bigbluebuttonbn_meetingevents_enabled', true);
-
 
393
        $meeting = $plugingenerator->create_meeting([
-
 
394
            'instanceid' => $instance->get_instance_id(),
-
 
395
            'groupid' => $instance->get_group_id(),
-
 
396
            'participants' => json_encode([$user->id]),
-
 
397
        ]);
-
 
398
 
-
 
399
        $events = [
-
 
400
            (object) ['name' => 'talks'],
-
 
401
            (object) ['name' => 'raisehand'],
-
 
402
            (object) ['name' => 'raisehand'],
-
 
403
        ];
-
 
404
        foreach ($events as $edesc) {
-
 
405
            $plugingenerator->add_meeting_event($user, $instance, $edesc->name, $edesc->data ?? '');
-
 
406
        }
-
 
407
        $result = $plugingenerator->send_all_events($instance);
-
 
408
        $this->assertNotEmpty($result->data);
-
 
409
        $data = json_encode($result->data);
-
 
410
        $reflection = new \ReflectionClass(broker::class);
-
 
411
        $method = $reflection->getMethod('process_extension_actions');
-
 
412
        $method->setAccessible(true);
-
 
413
        $method->invokeArgs(null, [$instance, $data]);
-
 
414
        $addondata = $DB->get_field('bbbext_simple', 'meetingevents', ['bigbluebuttonbnid' => $bbactivity->id]);
-
 
415
        $addondata = json_decode($addondata);
-
 
416
        // Check that the data is received.
-
 
417
        $this->assertEquals(json_encode($addondata), $data);
-
 
418
    }
-
 
419
 
-
 
420
 
370
    /**
421
    /**
371
     * Data provider for testing get_class_implementing
422
     * Data provider for testing get_class_implementing
372
     *
423
     *
373
     * @return array[]
424
     * @return array[]
374
     */
425
     */
375
    public function classes_implementing_class(): array {
426
    public static function classes_implementing_class(): array {
376
        return [
427
        return [
377
            'mod_instance_helper with plugin disabled' => [
428
            'mod_instance_helper with plugin disabled' => [
378
                'bbbenabled' => false,
429
                'bbbenabled' => false,
379
                'apiclass' => mod_instance_helper::class,
430
                'apiclass' => mod_instance_helper::class,
380
                'result' => [],
431
                'extensionclasses' => [],
381
            ],
432
            ],
382
            'mod_instance_helper with plugin enabled' => [
433
            'mod_instance_helper with plugin enabled' => [
383
                'bbbenabled' => true,
434
                'bbbenabled' => true,
384
                'apiclass' => mod_instance_helper::class,
435
                'apiclass' => mod_instance_helper::class,
385
                'result' => [
436
                'extensionclasses' => [
386
                    'bbbext_simple\\bigbluebuttonbn\\mod_instance_helper',
437
                    'bbbext_simple\\bigbluebuttonbn\\mod_instance_helper',
387
                ],
438
                ],
388
            ],
439
            ],
389
        ];
440
        ];
Línea 390... Línea 441...
390
    }
441
    }
-
 
442
 
-
 
443
    /**
-
 
444
     * Test the get_sorted_plugins_list
-
 
445
     * @param array $sortorders
-
 
446
     * @param array $expected
-
 
447
     * @return void
-
 
448
     * @dataProvider sorted_plugins_list_data_provider
-
 
449
     * @covers \mod_bigbluebuttonbn\extension::get_sorted_plugins_list
-
 
450
     */
-
 
451
    public function test_get_sorted_plugins_list(array $sortorders, array $expected): void {
-
 
452
        $this->resetAfterTest();
-
 
453
        // Enable plugin.
-
 
454
        $this->enable_plugins(true);
-
 
455
        // Create list of plugins we will then sort.
-
 
456
        $pluginlist = [
-
 
457
            'simpleone' => '/path/to/simpleone',
-
 
458
            'simpletwo' => '/path/to/simpletwo',
-
 
459
        ];
-
 
460
        // Set sortorder.
-
 
461
        foreach ($sortorders as $plugin => $sortorder) {
-
 
462
            set_config('sortorder', $sortorder, 'bbbext_' . $plugin);
-
 
463
        }
-
 
464
        $sortedlist = extension::get_sorted_plugins_list($pluginlist);
-
 
465
        $this->assertSame($expected, $sortedlist);
-
 
466
    }
-
 
467
 
-
 
468
    /**
-
 
469
     * Data provider for testing get_sorted_plugins_list
-
 
470
     *
-
 
471
     * @return array[]
-
 
472
     */
-
 
473
    public static function sorted_plugins_list_data_provider(): array {
-
 
474
        return [
-
 
475
            'no sortorder' => [
-
 
476
                [],
-
 
477
                ['simpleone', 'simpletwo'],
-
 
478
            ],
-
 
479
            'default sortorder' => [
-
 
480
                ['simpleone' => 0, 'simpletwo' => 1],
-
 
481
                ['simpleone', 'simpletwo'],
-
 
482
            ],
-
 
483
            'changed sortorder' => [
-
 
484
                ['simpleone' => 1, 'simpletwo' => 0],
-
 
485
                ['simpletwo', 'simpleone'],
-
 
486
            ],
-
 
487
        ];
-
 
488
    }
391
 
489
 
392
    /**
490
    /**
393
     * Enable plugins
491
     * Enable plugins
394
     *
492
     *
395
     * @param bool $bbbenabled
493
     * @param bool $bbbenabled