Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 26... Línea 26...
26
 * @package   quizaccess_seb
26
 * @package   quizaccess_seb
27
 * @author    Andrew Madden <andrewmadden@catalyst-au.net>
27
 * @author    Andrew Madden <andrewmadden@catalyst-au.net>
28
 * @copyright 2020 Catalyst IT
28
 * @copyright 2020 Catalyst IT
29
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
30
 */
31
class settings_provider_test extends \advanced_testcase {
31
final class settings_provider_test extends \advanced_testcase {
32
    use \quizaccess_seb_test_helper_trait;
32
    use \quizaccess_seb_test_helper_trait;
Línea 33... Línea 33...
33
 
33
 
34
    /**
34
    /**
35
     * Mocked quiz form instance.
35
     * Mocked quiz form instance.
Línea 91... Línea 91...
91
    /**
91
    /**
92
     * Capability data for testing.
92
     * Capability data for testing.
93
     *
93
     *
94
     * @return array
94
     * @return array
95
     */
95
     */
96
    public function settings_capability_data_provider() {
96
    public static function settings_capability_data_provider(): array {
97
        $data = [];
97
        $data = [];
Línea 98... Línea 98...
98
 
98
 
99
        // Build first level SEB config settings. Any of this setting let us use SEB manual config.
99
        // Build first level SEB config settings. Any of this setting let us use SEB manual config.
100
        foreach (settings_provider::get_seb_settings_map()[settings_provider::USE_SEB_CONFIG_MANUALLY] as $name => $children) {
100
        foreach (settings_provider::get_seb_settings_map()[settings_provider::USE_SEB_CONFIG_MANUALLY] as $name => $children) {
Línea 175... Línea 175...
175
     * Test hideif rules.
175
     * Test hideif rules.
176
     */
176
     */
177
    public function test_hideifs(): void {
177
    public function test_hideifs(): void {
178
        $settinghideifs = settings_provider::get_quiz_hideifs();
178
        $settinghideifs = settings_provider::get_quiz_hideifs();
Línea 179... Línea 179...
179
 
179
 
Línea 180... Línea 180...
180
        $this->assertCount(23, $settinghideifs);
180
        $this->assertCount(25, $settinghideifs);
181
 
181
 
182
        $this->assertArrayHasKey('seb_templateid', $settinghideifs);
182
        $this->assertArrayHasKey('seb_templateid', $settinghideifs);
183
        $this->assertCount(1, $settinghideifs['seb_templateid']);
183
        $this->assertCount(1, $settinghideifs['seb_templateid']);
Línea 360... Línea 360...
360
            'seb_requiresafeexambrowser',
360
            'seb_requiresafeexambrowser',
361
            'noteq',
361
            'noteq',
362
            settings_provider::USE_SEB_CONFIG_MANUALLY
362
            settings_provider::USE_SEB_CONFIG_MANUALLY
363
        );
363
        );
Línea -... Línea 364...
-
 
364
 
-
 
365
        $this->assertArrayHasKey('seb_allowcapturecamera', $settinghideifs);
-
 
366
        $this->assertCount(1, $settinghideifs['seb_allowcapturecamera']);
-
 
367
        $this->assert_hide_if(
-
 
368
            $settinghideifs['seb_allowcapturecamera'][0],
-
 
369
            'seb_allowcapturecamera',
-
 
370
            'seb_requiresafeexambrowser',
-
 
371
            'noteq',
-
 
372
            settings_provider::USE_SEB_CONFIG_MANUALLY
-
 
373
        );
-
 
374
 
-
 
375
        $this->assertArrayHasKey('seb_allowcapturemicrophone', $settinghideifs);
-
 
376
        $this->assertCount(1, $settinghideifs['seb_allowcapturemicrophone']);
-
 
377
        $this->assert_hide_if(
-
 
378
            $settinghideifs['seb_allowcapturemicrophone'][0],
-
 
379
            'seb_allowcapturemicrophone',
-
 
380
            'seb_requiresafeexambrowser',
-
 
381
            'noteq',
-
 
382
            settings_provider::USE_SEB_CONFIG_MANUALLY
-
 
383
        );
364
 
384
 
365
        $this->assertArrayHasKey('seb_muteonstartup', $settinghideifs);
385
        $this->assertArrayHasKey('seb_muteonstartup', $settinghideifs);
366
        $this->assertCount(2, $settinghideifs['seb_muteonstartup']);
386
        $this->assertCount(2, $settinghideifs['seb_muteonstartup']);
367
        $this->assert_hide_if(
387
        $this->assert_hide_if(
368
            $settinghideifs['seb_muteonstartup'][0],
388
            $settinghideifs['seb_muteonstartup'][0],
Línea 620... Línea 640...
620
    }
640
    }
Línea 621... Línea 641...
621
 
641
 
622
    /**
642
    /**
623
     * Test SEB usage options.
643
     * Test SEB usage options.
624
     *
644
     *
625
     * @param string $settingcapability Setting capability to check manual option against.
645
     * @param string $settingcapability Setting capability to check options against.
626
     *
646
     *
627
     * @dataProvider settings_capability_data_provider
647
     * @dataProvider settings_capability_data_provider
628
     */
648
     */
629
    public function test_get_requiresafeexambrowser_options($settingcapability): void {
649
    public function test_get_requiresafeexambrowser_options($settingcapability): void {
Línea 654... Línea 674...
654
        // A new user does not have the capability to use the file manager and template.
674
        // A new user does not have the capability to use the file manager and template.
655
        $this->set_up_user_and_role();
675
        $this->set_up_user_and_role();
Línea 656... Línea 676...
656
 
676
 
Línea 657... Línea 677...
657
        $options = settings_provider::get_requiresafeexambrowser_options($this->context);
677
        $options = settings_provider::get_requiresafeexambrowser_options($this->context);
658
 
678
 
659
        $this->assertCount(2, $options);
679
        $this->assertCount(1, $options);
660
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_CONFIG_MANUALLY, $options));
680
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_CONFIG_MANUALLY, $options));
661
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_TEMPLATE, $options));
681
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_TEMPLATE, $options));
662
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_UPLOAD_CONFIG, $options));
682
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_UPLOAD_CONFIG, $options));
Línea 663... Línea 683...
663
        $this->assertTrue(array_key_exists(settings_provider::USE_SEB_CLIENT_CONFIG, $options));
683
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_CLIENT_CONFIG, $options));
664
        $this->assertTrue(array_key_exists(settings_provider::USE_SEB_NO, $options));
684
        $this->assertTrue(array_key_exists(settings_provider::USE_SEB_NO, $options));
-
 
685
 
-
 
686
        assign_capability($settingcapability, CAP_ALLOW, $this->roleid, $this->context->id);
-
 
687
        $options = settings_provider::get_requiresafeexambrowser_options($this->context);
-
 
688
        $this->assertCount(1, $options);
-
 
689
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_CONFIG_MANUALLY, $options));
-
 
690
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_TEMPLATE, $options));
-
 
691
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_UPLOAD_CONFIG, $options));
-
 
692
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_CLIENT_CONFIG, $options));
-
 
693
        $this->assertTrue(array_key_exists(settings_provider::USE_SEB_NO, $options));
-
 
694
 
-
 
695
        assign_capability('quizaccess/seb:manage_seb_configuremanually', CAP_ALLOW, $this->roleid, $this->context->id);
-
 
696
        $options = settings_provider::get_requiresafeexambrowser_options($this->context);
-
 
697
        $this->assertCount(2, $options);
-
 
698
        $this->assertTrue(array_key_exists(settings_provider::USE_SEB_CONFIG_MANUALLY, $options));
-
 
699
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_TEMPLATE, $options));
-
 
700
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_UPLOAD_CONFIG, $options));
-
 
701
        $this->assertFalse(array_key_exists(settings_provider::USE_SEB_CLIENT_CONFIG, $options));
-
 
702
        $this->assertTrue(array_key_exists(settings_provider::USE_SEB_NO, $options));
665
 
703
 
666
        assign_capability($settingcapability, CAP_ALLOW, $this->roleid, $this->context->id);
704
        assign_capability('quizaccess/seb:manage_seb_usesebclientconfig', CAP_ALLOW, $this->roleid, $this->context->id);
667
        $options = settings_provider::get_requiresafeexambrowser_options($this->context);
705
        $options = settings_provider::get_requiresafeexambrowser_options($this->context);
668
        $this->assertCount(3, $options);
706
        $this->assertCount(3, $options);
669
        $this->assertTrue(array_key_exists(settings_provider::USE_SEB_CONFIG_MANUALLY, $options));
707
        $this->assertTrue(array_key_exists(settings_provider::USE_SEB_CONFIG_MANUALLY, $options));
Línea 909... Línea 947...
909
        $this->resetAfterTest();
947
        $this->resetAfterTest();
Línea 910... Línea 948...
910
 
948
 
911
        $user = $this->getDataGenerator()->create_user();
949
        $user = $this->getDataGenerator()->create_user();
Línea 912... Línea 950...
912
        $this->setUser($user);
950
        $this->setUser($user);
913
 
951
 
914
        $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
952
        $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb'));
915
        $itemid = $this->create_test_draftarea_file($xml);
953
        $itemid = $this->create_test_draftarea_file($xml);
Línea 916... Línea 954...
916
        $file = settings_provider::get_current_user_draft_file($itemid);
954
        $file = settings_provider::get_current_user_draft_file($itemid);
Línea 927... Línea 965...
927
        $this->course = $this->getDataGenerator()->create_course();
965
        $this->course = $this->getDataGenerator()->create_course();
928
        $this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
966
        $this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
929
        $this->context = \context_module::instance($this->quiz->cmid);
967
        $this->context = \context_module::instance($this->quiz->cmid);
930
        $this->set_up_user_and_role();
968
        $this->set_up_user_and_role();
Línea 931... Línea 969...
931
 
969
 
Línea 932... Línea 970...
932
        $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
970
        $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb'));
Línea 933... Línea 971...
933
 
971
 
Línea 949... Línea 987...
949
        $this->course = $this->getDataGenerator()->create_course();
987
        $this->course = $this->getDataGenerator()->create_course();
950
        $this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
988
        $this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
951
        $this->context = \context_module::instance($this->quiz->cmid);
989
        $this->context = \context_module::instance($this->quiz->cmid);
952
        $this->set_up_user_and_role();
990
        $this->set_up_user_and_role();
Línea 953... Línea 991...
953
 
991
 
954
        $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
992
        $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb'));
Línea 955... Línea 993...
955
        $draftitemid = $this->create_test_draftarea_file($xml);
993
        $draftitemid = $this->create_test_draftarea_file($xml);
Línea 956... Línea 994...
956
 
994
 
Línea 978... Línea 1016...
978
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
1016
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
979
        $this->context = \context_module::instance($this->quiz->cmid);
1017
        $this->context = \context_module::instance($this->quiz->cmid);
Línea 980... Línea 1018...
980
 
1018
 
Línea 981... Línea 1019...
981
        $this->set_up_user_and_role();
1019
        $this->set_up_user_and_role();
982
 
1020
 
Línea 983... Línea 1021...
983
        $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
1021
        $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb'));
984
        $draftitemid = $this->create_test_draftarea_file($xml);
1022
        $draftitemid = $this->create_test_draftarea_file($xml);
985
 
1023
 
Línea 1132... Línea 1170...
1132
 
1170
 
Línea 1133... Línea 1171...
1133
        $this->set_up_user_and_role();
1171
        $this->set_up_user_and_role();
Línea -... Línea 1172...
-
 
1172
 
-
 
1173
        $this->assertFalse(settings_provider::can_configure_manually($this->context));
-
 
1174
 
1134
 
1175
        assign_capability('quizaccess/seb:manage_seb_configuremanually', CAP_ALLOW, $this->roleid, $this->context->id);
1135
        $this->assertFalse(settings_provider::can_configure_manually($this->context));
1176
        $this->assertFalse(settings_provider::can_configure_manually($this->context));
1136
 
1177
 
Línea 1137... Línea 1178...
1137
        assign_capability($settingcapability, CAP_ALLOW, $this->roleid, $this->context->id);
1178
        assign_capability($settingcapability, CAP_ALLOW, $this->roleid, $this->context->id);
Línea 1192... Línea 1233...
1192
        $this->course = $this->getDataGenerator()->create_course();
1233
        $this->course = $this->getDataGenerator()->create_course();
1193
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
1234
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
1194
        $this->context = \context_module::instance($this->quiz->cmid);
1235
        $this->context = \context_module::instance($this->quiz->cmid);
Línea 1195... Línea 1236...
1195
 
1236
 
1196
        // Save file.
1237
        // Save file.
1197
        $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
1238
        $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb'));
1198
        $draftitemid = $this->create_test_draftarea_file($xml);
1239
        $draftitemid = $this->create_test_draftarea_file($xml);
1199
        settings_provider::save_filemanager_sebconfigfile_draftarea($draftitemid, $this->quiz->cmid);
1240
        settings_provider::save_filemanager_sebconfigfile_draftarea($draftitemid, $this->quiz->cmid);
1200
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
1241
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
1201
        $settings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
1242
        $settings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
Línea 1226... Línea 1267...
1226
 
1267
 
Línea 1227... Línea 1268...
1227
        $this->assertFalse(settings_provider::is_conflicting_permissions($this->context));
1268
        $this->assertFalse(settings_provider::is_conflicting_permissions($this->context));
Línea -... Línea 1269...
-
 
1269
 
-
 
1270
        $this->set_up_user_and_role();
-
 
1271
 
-
 
1272
        $this->assertTrue(settings_provider::is_conflicting_permissions($this->context));
-
 
1273
 
1228
 
1274
        assign_capability('quizaccess/seb:manage_seb_configuremanually', CAP_ALLOW, $this->roleid, $this->context->id);
1229
        $this->set_up_user_and_role();
1275
        $this->assertTrue(settings_provider::is_conflicting_permissions($this->context));
1230
 
1276
 
Línea 1231... Línea 1277...
1231
        assign_capability($settingcapability, CAP_ALLOW, $this->roleid, $this->context->id);
1277
        assign_capability($settingcapability, CAP_ALLOW, $this->roleid, $this->context->id);
Línea 1291... Línea 1337...
1291
        $allsettings->seb_regexallowed = 18;
1337
        $allsettings->seb_regexallowed = 18;
1292
        $allsettings->seb_expressionsblocked = 19;
1338
        $allsettings->seb_expressionsblocked = 19;
1293
        $allsettings->seb_regexblocked = 20;
1339
        $allsettings->seb_regexblocked = 20;
1294
        $allsettings->seb_templateid = 21;
1340
        $allsettings->seb_templateid = 21;
1295
        $allsettings->seb_allowedbrowserexamkeys = 22;
1341
        $allsettings->seb_allowedbrowserexamkeys = 22;
-
 
1342
        $allsettings->seb_allowcapturecamera = 23;
-
 
1343
        $allsettings->seb_allowcapturemicrophone = 24;
Línea 1296... Línea 1344...
1296
 
1344
 
1297
        return $allsettings;
1345
        return $allsettings;
Línea 1298... Línea 1346...
1298
    }
1346
    }
Línea 1394... Línea 1442...
1394
                    'seb_showwificontrol' => [],
1442
                    'seb_showwificontrol' => [],
1395
                ],
1443
                ],
1396
                'seb_enableaudiocontrol' => [
1444
                'seb_enableaudiocontrol' => [
1397
                    'seb_muteonstartup' => [],
1445
                    'seb_muteonstartup' => [],
1398
                ],
1446
                ],
-
 
1447
                'seb_allowcapturecamera' => [],
-
 
1448
                'seb_allowcapturemicrophone' => [],
1399
                'seb_allowspellchecking' => [],
1449
                'seb_allowspellchecking' => [],
1400
                'seb_activateurlfiltering' => [
1450
                'seb_activateurlfiltering' => [
1401
                    'seb_filterembeddedcontent' => [],
1451
                    'seb_filterembeddedcontent' => [],
1402
                    'seb_expressionsallowed' => [],
1452
                    'seb_expressionsallowed' => [],
1403
                    'seb_regexallowed' => [],
1453
                    'seb_regexallowed' => [],