Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 59... Línea 59...
59
    }
59
    }
Línea 60... Línea 60...
60
 
60
 
61
    /**
61
    /**
62
     * Test that config is generated immediately prior to saving quiz settings.
62
     * Test that config is generated immediately prior to saving quiz settings.
63
     */
63
     */
64
    public function test_config_is_created_from_quiz_settings() {
64
    public function test_config_is_created_from_quiz_settings(): void {
65
        // Test settings to populate the in the object.
65
        // Test settings to populate the in the object.
66
        $settings = $this->get_test_settings([
66
        $settings = $this->get_test_settings([
67
            'quizid' => $this->quiz->id,
67
            'quizid' => $this->quiz->id,
68
            'cmid' => $this->quiz->cmid,
68
            'cmid' => $this->quiz->cmid,
Línea 93... Línea 93...
93
    }
93
    }
Línea 94... Línea 94...
94
 
94
 
95
    /**
95
    /**
96
     * Test that config string gets updated from quiz settings.
96
     * Test that config string gets updated from quiz settings.
97
     */
97
     */
98
    public function test_config_is_updated_from_quiz_settings() {
98
    public function test_config_is_updated_from_quiz_settings(): void {
99
        // Test settings to populate the in the object.
99
        // Test settings to populate the in the object.
100
        $settings = $this->get_test_settings([
100
        $settings = $this->get_test_settings([
101
            'quizid' => $this->quiz->id,
101
            'quizid' => $this->quiz->id,
102
            'cmid' => $this->quiz->cmid,
102
            'cmid' => $this->quiz->cmid,
Línea 143... Línea 143...
143
    }
143
    }
Línea 144... Línea 144...
144
 
144
 
145
    /**
145
    /**
146
     * Test that config key is generated immediately prior to saving quiz settings.
146
     * Test that config key is generated immediately prior to saving quiz settings.
147
     */
147
     */
148
    public function test_config_key_is_created_from_quiz_settings() {
148
    public function test_config_key_is_created_from_quiz_settings(): void {
Línea 149... Línea 149...
149
        $settings = $this->get_test_settings();
149
        $settings = $this->get_test_settings();
150
 
150
 
151
        $quizsettings = new seb_quiz_settings(0, $settings);
151
        $quizsettings = new seb_quiz_settings(0, $settings);
Línea 156... Línea 156...
156
    }
156
    }
Línea 157... Línea 157...
157
 
157
 
158
    /**
158
    /**
159
     * Test that config key is generated immediately prior to saving quiz settings.
159
     * Test that config key is generated immediately prior to saving quiz settings.
160
     */
160
     */
161
    public function test_config_key_is_updated_from_quiz_settings() {
161
    public function test_config_key_is_updated_from_quiz_settings(): void {
Línea 162... Línea 162...
162
        $settings = $this->get_test_settings();
162
        $settings = $this->get_test_settings();
163
 
163
 
164
        $quizsettings = new seb_quiz_settings(0, $settings);
164
        $quizsettings = new seb_quiz_settings(0, $settings);
Línea 178... Línea 178...
178
     * @param \stdClass $settings Quiz settings
178
     * @param \stdClass $settings Quiz settings
179
     * @param string $expectedxml SEB Config XML.
179
     * @param string $expectedxml SEB Config XML.
180
     *
180
     *
181
     * @dataProvider filter_rules_provider
181
     * @dataProvider filter_rules_provider
182
     */
182
     */
183
    public function test_filter_rules_added_to_config(\stdClass $settings, string $expectedxml) {
183
    public function test_filter_rules_added_to_config(\stdClass $settings, string $expectedxml): void {
184
        $quizsettings = new seb_quiz_settings(0, $settings);
184
        $quizsettings = new seb_quiz_settings(0, $settings);
185
        $config = $quizsettings->get_config();
185
        $config = $quizsettings->get_config();
186
        $this->assertEquals($expectedxml, $config);
186
        $this->assertEquals($expectedxml, $config);
187
    }
187
    }
Línea 188... Línea 188...
188
 
188
 
189
    /**
189
    /**
190
     * Test that browser keys are validated and retrieved as an array instead of string.
190
     * Test that browser keys are validated and retrieved as an array instead of string.
191
     */
191
     */
192
    public function test_browser_exam_keys_are_retrieved_as_array() {
192
    public function test_browser_exam_keys_are_retrieved_as_array(): void {
193
        $quizsettings = new seb_quiz_settings();
193
        $quizsettings = new seb_quiz_settings();
194
        $quizsettings->set('allowedbrowserexamkeys', "one two,three\nfour");
194
        $quizsettings->set('allowedbrowserexamkeys', "one two,three\nfour");
195
        $retrievedkeys = $quizsettings->get('allowedbrowserexamkeys');
195
        $retrievedkeys = $quizsettings->get('allowedbrowserexamkeys');
196
        $this->assertEquals(['one', 'two', 'three', 'four'], $retrievedkeys);
196
        $this->assertEquals(['one', 'two', 'three', 'four'], $retrievedkeys);
Línea 202... Línea 202...
202
     * @param string $bek Browser Exam Key.
202
     * @param string $bek Browser Exam Key.
203
     * @param string $expectederrorstring Expected error.
203
     * @param string $expectederrorstring Expected error.
204
     *
204
     *
205
     * @dataProvider bad_browser_exam_key_provider
205
     * @dataProvider bad_browser_exam_key_provider
206
     */
206
     */
207
    public function test_browser_exam_keys_validation_errors($bek, $expectederrorstring) {
207
    public function test_browser_exam_keys_validation_errors($bek, $expectederrorstring): void {
208
        $quizsettings = new seb_quiz_settings();
208
        $quizsettings = new seb_quiz_settings();
209
        $quizsettings->set('allowedbrowserexamkeys', $bek);
209
        $quizsettings->set('allowedbrowserexamkeys', $bek);
210
        $quizsettings->validate();
210
        $quizsettings->validate();
211
        $errors = $quizsettings->get_errors();
211
        $errors = $quizsettings->get_errors();
212
        $this->assertContainsEquals($expectederrorstring, $errors);
212
        $this->assertContainsEquals($expectederrorstring, $errors);
213
    }
213
    }
Línea 214... Línea 214...
214
 
214
 
215
    /**
215
    /**
216
     * Test that uploaded seb file gets converted to config string.
216
     * Test that uploaded seb file gets converted to config string.
217
     */
217
     */
218
    public function test_config_file_uploaded_converted_to_config() {
218
    public function test_config_file_uploaded_converted_to_config(): void {
219
        $url = new \moodle_url("/mod/quiz/view.php", ['id' => $this->quiz->cmid]);
219
        $url = new \moodle_url("/mod/quiz/view.php", ['id' => $this->quiz->cmid]);
220
        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
220
        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
221
                . "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
221
                . "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
222
                . "<plist version=\"1.0\"><dict><key>hashedQuitPassword</key><string>hashedpassword</string>"
222
                . "<plist version=\"1.0\"><dict><key>hashedQuitPassword</key><string>hashedpassword</string>"
Línea 231... Línea 231...
231
    }
231
    }
Línea 232... Línea 232...
232
 
232
 
233
    /**
233
    /**
234
     * Test test_no_config_file_uploaded
234
     * Test test_no_config_file_uploaded
235
     */
235
     */
236
    public function test_no_config_file_uploaded() {
236
    public function test_no_config_file_uploaded(): void {
237
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
237
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
238
        $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
238
        $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
239
        $cmid = $quizsettings->get('cmid');
239
        $cmid = $quizsettings->get('cmid');
240
        $this->expectException(\moodle_exception::class);
240
        $this->expectException(\moodle_exception::class);
Línea 272... Línea 272...
272
    }
272
    }
Línea 273... Línea 273...
273
 
273
 
274
    /**
274
    /**
275
     * Test using USE_SEB_TEMPLATE and have it override settings from the template when they are set.
275
     * Test using USE_SEB_TEMPLATE and have it override settings from the template when they are set.
276
     */
276
     */
277
    public function test_using_seb_template_override_settings_when_they_set_in_template() {
277
    public function test_using_seb_template_override_settings_when_they_set_in_template(): void {
278
        $xml = $this->get_config_xml(true, 'password');
278
        $xml = $this->get_config_xml(true, 'password');
Línea 279... Línea 279...
279
        $template = $this->create_template($xml);
279
        $template = $this->create_template($xml);
280
 
280
 
Línea 311... Línea 311...
311
    }
311
    }
Línea 312... Línea 312...
312
 
312
 
313
    /**
313
    /**
314
     * Test using USE_SEB_TEMPLATE and have it override settings from the template when they are not set.
314
     * Test using USE_SEB_TEMPLATE and have it override settings from the template when they are not set.
315
     */
315
     */
316
    public function test_using_seb_template_override_settings_when_not_set_in_template() {
316
    public function test_using_seb_template_override_settings_when_not_set_in_template(): void {
317
        $xml = $this->get_config_xml();
317
        $xml = $this->get_config_xml();
Línea 318... Línea 318...
318
        $template = $this->create_template($xml);
318
        $template = $this->create_template($xml);
319
 
319
 
Línea 344... Línea 344...
344
    }
344
    }
Línea 345... Línea 345...
345
 
345
 
346
    /**
346
    /**
347
     * Test using USE_SEB_UPLOAD_CONFIG and use settings from the file if they are set.
347
     * Test using USE_SEB_UPLOAD_CONFIG and use settings from the file if they are set.
348
     */
348
     */
349
    public function test_using_own_config_settings_are_not_overridden_if_set() {
349
    public function test_using_own_config_settings_are_not_overridden_if_set(): void {
350
        $xml = $this->get_config_xml(true, 'password');
350
        $xml = $this->get_config_xml(true, 'password');
Línea 351... Línea 351...
351
        $this->create_module_test_file($xml, $this->quiz->cmid);
351
        $this->create_module_test_file($xml, $this->quiz->cmid);
352
 
352
 
Línea 381... Línea 381...
381
    }
381
    }
Línea 382... Línea 382...
382
 
382
 
383
    /**
383
    /**
384
     * Test using USE_SEB_UPLOAD_CONFIG and use settings from the file if they are not set.
384
     * Test using USE_SEB_UPLOAD_CONFIG and use settings from the file if they are not set.
385
     */
385
     */
386
    public function test_using_own_config_settings_are_not_overridden_if_not_set() {
386
    public function test_using_own_config_settings_are_not_overridden_if_not_set(): void {
387
        $xml = $this->get_config_xml();
387
        $xml = $this->get_config_xml();
Línea 388... Línea 388...
388
        $this->create_module_test_file($xml, $this->quiz->cmid);
388
        $this->create_module_test_file($xml, $this->quiz->cmid);
389
 
389
 
Línea 416... Línea 416...
416
    }
416
    }
Línea 417... Línea 417...
417
 
417
 
418
    /**
418
    /**
419
     * Test using USE_SEB_TEMPLATE populates the linkquitseb setting if a quitURL is found.
419
     * Test using USE_SEB_TEMPLATE populates the linkquitseb setting if a quitURL is found.
420
     */
420
     */
421
    public function test_template_has_quit_url_set() {
421
    public function test_template_has_quit_url_set(): void {
422
        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
422
        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
423
            . "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
423
            . "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
424
            . "<plist version=\"1.0\"><dict><key>hashedQuitPassword</key><string>hashedpassword</string>"
424
            . "<plist version=\"1.0\"><dict><key>hashedQuitPassword</key><string>hashedpassword</string>"
425
            . "<key>allowWlan</key><false/><key>quitURL</key><string>http://seb.quit.url</string>"
425
            . "<key>allowWlan</key><false/><key>quitURL</key><string>http://seb.quit.url</string>"
Línea 439... Línea 439...
439
    }
439
    }
Línea 440... Línea 440...
440
 
440
 
441
    /**
441
    /**
442
     * Test using USE_SEB_UPLOAD_CONFIG populates the linkquitseb setting if a quitURL is found.
442
     * Test using USE_SEB_UPLOAD_CONFIG populates the linkquitseb setting if a quitURL is found.
443
     */
443
     */
444
    public function test_config_file_uploaded_has_quit_url_set() {
444
    public function test_config_file_uploaded_has_quit_url_set(): void {
445
        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
445
        $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
446
            . "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
446
            . "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
447
            . "<plist version=\"1.0\"><dict><key>hashedQuitPassword</key><string>hashedpassword</string>"
447
            . "<plist version=\"1.0\"><dict><key>hashedQuitPassword</key><string>hashedpassword</string>"
448
            . "<key>allowWlan</key><false/><key>quitURL</key><string>http://seb.quit.url</string>"
448
            . "<key>allowWlan</key><false/><key>quitURL</key><string>http://seb.quit.url</string>"
Línea 460... Línea 460...
460
    }
460
    }
Línea 461... Línea 461...
461
 
461
 
462
    /**
462
    /**
463
     * Test template id set correctly.
463
     * Test template id set correctly.
464
     */
464
     */
465
    public function test_templateid_set_correctly_when_save_settings() {
465
    public function test_templateid_set_correctly_when_save_settings(): void {
466
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
466
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
Línea 467... Línea 467...
467
        $this->assertEquals(0, $quizsettings->get('templateid'));
467
        $this->assertEquals(0, $quizsettings->get('templateid'));
468
 
468
 
Línea 695... Línea 695...
695
    }
695
    }
Línea 696... Línea 696...
696
 
696
 
697
    /**
697
    /**
698
     * Test that config and config key are null when expected.
698
     * Test that config and config key are null when expected.
699
     */
699
     */
700
    public function test_generates_config_values_as_null_when_expected() {
700
    public function test_generates_config_values_as_null_when_expected(): void {
701
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
701
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
702
        $this->assertNotNull($quizsettings->get_config());
702
        $this->assertNotNull($quizsettings->get_config());
Línea 703... Línea 703...
703
        $this->assertNotNull($quizsettings->get_config_key());
703
        $this->assertNotNull($quizsettings->get_config_key());
Línea 731... Línea 731...
731
    }
731
    }
Línea 732... Línea 732...
732
 
732
 
733
    /**
733
    /**
734
     * Test that quizsettings cache exists after creation.
734
     * Test that quizsettings cache exists after creation.
735
     */
735
     */
736
    public function test_quizsettings_cache_exists_after_creation() {
736
    public function test_quizsettings_cache_exists_after_creation(): void {
737
        $expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
737
        $expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
738
        $this->assertEquals($expected->to_record(), \cache::make('quizaccess_seb', 'quizsettings')->get($this->quiz->id));
738
        $this->assertEquals($expected->to_record(), \cache::make('quizaccess_seb', 'quizsettings')->get($this->quiz->id));
Línea 739... Línea 739...
739
    }
739
    }
740
 
740
 
741
    /**
741
    /**
742
     * Test that quizsettings cache gets deleted after deletion.
742
     * Test that quizsettings cache gets deleted after deletion.
743
     */
743
     */
Línea 744... Línea 744...
744
    public function test_quizsettings_cache_purged_after_deletion() {
744
    public function test_quizsettings_cache_purged_after_deletion(): void {
745
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'quizsettings')->get($this->quiz->id));
745
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'quizsettings')->get($this->quiz->id));
Línea 751... Línea 751...
751
    }
751
    }
Línea 752... Línea 752...
752
 
752
 
753
    /**
753
    /**
754
     * Test that we can get seb_quiz_settings by quiz id.
754
     * Test that we can get seb_quiz_settings by quiz id.
755
     */
755
     */
756
    public function test_get_quiz_settings_by_quiz_id() {
756
    public function test_get_quiz_settings_by_quiz_id(): void {
Línea 757... Línea 757...
757
        $expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
757
        $expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
Línea 758... Línea 758...
758
 
758
 
Línea 771... Línea 771...
771
    }
771
    }
Línea 772... Línea 772...
772
 
772
 
773
    /**
773
    /**
774
     * Test that SEB config cache exists after creation of the quiz.
774
     * Test that SEB config cache exists after creation of the quiz.
775
     */
775
     */
776
    public function test_config_cache_exists_after_creation() {
776
    public function test_config_cache_exists_after_creation(): void {
777
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'config')->get($this->quiz->id));
777
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'config')->get($this->quiz->id));
Línea 778... Línea 778...
778
    }
778
    }
779
 
779
 
780
    /**
780
    /**
781
     * Test that SEB config cache gets deleted after deletion.
781
     * Test that SEB config cache gets deleted after deletion.
782
     */
782
     */
Línea 783... Línea 783...
783
    public function test_config_cache_purged_after_deletion() {
783
    public function test_config_cache_purged_after_deletion(): void {
784
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'config')->get($this->quiz->id));
784
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'config')->get($this->quiz->id));
Línea 790... Línea 790...
790
    }
790
    }
Línea 791... Línea 791...
791
 
791
 
792
    /**
792
    /**
793
     * Test that we can get SEB config by quiz id.
793
     * Test that we can get SEB config by quiz id.
794
     */
794
     */
795
    public function test_get_config_by_quiz_id() {
795
    public function test_get_config_by_quiz_id(): void {
796
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
796
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
Línea 797... Línea 797...
797
        $expected = $quizsettings->get_config();
797
        $expected = $quizsettings->get_config();
Línea 811... Línea 811...
811
    }
811
    }
Línea 812... Línea 812...
812
 
812
 
813
    /**
813
    /**
814
     * Test that SEB config key cache exists after creation of the quiz.
814
     * Test that SEB config key cache exists after creation of the quiz.
815
     */
815
     */
816
    public function test_config_key_cache_exists_after_creation() {
816
    public function test_config_key_cache_exists_after_creation(): void {
817
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'configkey')->get($this->quiz->id));
817
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'configkey')->get($this->quiz->id));
Línea 818... Línea 818...
818
    }
818
    }
819
 
819
 
820
    /**
820
    /**
821
     * Test that SEB config key cache gets deleted after deletion.
821
     * Test that SEB config key cache gets deleted after deletion.
822
     */
822
     */
Línea 823... Línea 823...
823
    public function test_config_key_cache_purged_after_deletion() {
823
    public function test_config_key_cache_purged_after_deletion(): void {
824
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'configkey')->get($this->quiz->id));
824
        $this->assertNotEmpty(\cache::make('quizaccess_seb', 'configkey')->get($this->quiz->id));
Línea 830... Línea 830...
830
    }
830
    }
Línea 831... Línea 831...
831
 
831
 
832
    /**
832
    /**
833
     * Test that we can get SEB config key by quiz id.
833
     * Test that we can get SEB config key by quiz id.
834
     */
834
     */
835
    public function test_get_config_key_by_quiz_id() {
835
    public function test_get_config_key_by_quiz_id(): void {
836
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
836
        $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
Línea 837... Línea 837...
837
        $expected = $quizsettings->get_config_key();
837
        $expected = $quizsettings->get_config_key();