Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 52... Línea 52...
52
    /**
52
    /**
53
     * Files can be created from strings.
53
     * Files can be created from strings.
54
     *
54
     *
55
     * @covers ::create_file_from_string
55
     * @covers ::create_file_from_string
56
     */
56
     */
57
    public function test_create_file_from_string() {
57
    public function test_create_file_from_string(): void {
58
        global $DB;
58
        global $DB;
Línea 59... Línea 59...
59
 
59
 
Línea 60... Línea 60...
60
        $this->resetAfterTest(true);
60
        $this->resetAfterTest(true);
Línea 125... Línea 125...
125
    /**
125
    /**
126
     * Local files can be added to the filepool
126
     * Local files can be added to the filepool
127
     *
127
     *
128
     * @covers ::create_file_from_pathname
128
     * @covers ::create_file_from_pathname
129
     */
129
     */
130
    public function test_create_file_from_pathname() {
130
    public function test_create_file_from_pathname(): void {
131
        global $CFG, $DB;
131
        global $CFG, $DB;
Línea 132... Línea 132...
132
 
132
 
Línea 133... Línea 133...
133
        $this->resetAfterTest(true);
133
        $this->resetAfterTest(true);
Línea 207... Línea 207...
207
    /**
207
    /**
208
     * Tests get get file.
208
     * Tests get get file.
209
     *
209
     *
210
     * @covers ::get_file
210
     * @covers ::get_file
211
     */
211
     */
212
    public function test_get_file() {
212
    public function test_get_file(): stored_file {
213
        global $CFG;
213
        global $CFG;
Línea 214... Línea 214...
214
 
214
 
Línea 215... Línea 215...
215
        $this->resetAfterTest(false);
215
        $this->resetAfterTest(false);
Línea 247... Línea 247...
247
     *
247
     *
248
     * @param stored_file $file
248
     * @param stored_file $file
249
     * @depends test_get_file
249
     * @depends test_get_file
250
     * @covers ::get_file_preview
250
     * @covers ::get_file_preview
251
     */
251
     */
252
    public function test_get_file_preview(stored_file $file) {
252
    public function test_get_file_preview(stored_file $file): void {
253
        global $CFG;
253
        global $CFG;
Línea 254... Línea 254...
254
 
254
 
255
        $this->resetAfterTest();
255
        $this->resetAfterTest();
Línea 270... Línea 270...
270
    /**
270
    /**
271
     * Tests for get_file_preview without an image.
271
     * Tests for get_file_preview without an image.
272
     *
272
     *
273
     * @covers ::get_file_preview
273
     * @covers ::get_file_preview
274
     */
274
     */
275
    public function test_get_file_preview_nonimage() {
275
    public function test_get_file_preview_nonimage(): void {
276
        $this->resetAfterTest(true);
276
        $this->resetAfterTest(true);
277
        $syscontext = \context_system::instance();
277
        $syscontext = \context_system::instance();
278
        $filerecord = array(
278
        $filerecord = array(
279
            'contextid' => $syscontext->id,
279
            'contextid' => $syscontext->id,
280
            'component' => 'core',
280
            'component' => 'core',
Línea 297... Línea 297...
297
     * Make sure renaming is working
297
     * Make sure renaming is working
298
     *
298
     *
299
     * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
299
     * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
300
     * @covers \stored_file::rename
300
     * @covers \stored_file::rename
301
     */
301
     */
302
    public function test_file_renaming() {
302
    public function test_file_renaming(): void {
303
        global $CFG;
303
        global $CFG;
Línea 304... Línea 304...
304
 
304
 
305
        $this->resetAfterTest();
305
        $this->resetAfterTest();
306
        $fs = get_file_storage();
306
        $fs = get_file_storage();
Línea 343... Línea 343...
343
     * Create file from reference tests
343
     * Create file from reference tests
344
     *
344
     *
345
     * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
345
     * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
346
     * @covers ::create_file_from_reference
346
     * @covers ::create_file_from_reference
347
     */
347
     */
348
    public function test_create_file_from_reference() {
348
    public function test_create_file_from_reference(): void {
349
        global $CFG, $DB;
349
        global $CFG, $DB;
Línea 350... Línea 350...
350
 
350
 
351
        $this->resetAfterTest();
351
        $this->resetAfterTest();
352
        // Create user.
352
        // Create user.
Línea 429... Línea 429...
429
     * Create file from reference tests
429
     * Create file from reference tests
430
     *
430
     *
431
     * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
431
     * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
432
     * @covers ::create_file_from_reference
432
     * @covers ::create_file_from_reference
433
     */
433
     */
434
    public function test_create_file_from_reference_with_content_hash() {
434
    public function test_create_file_from_reference_with_content_hash(): void {
435
        global $CFG, $DB;
435
        global $CFG, $DB;
Línea 436... Línea 436...
436
 
436
 
437
        $this->resetAfterTest();
437
        $this->resetAfterTest();
438
        // Create user.
438
        // Create user.
Línea 538... Línea 538...
538
    /**
538
    /**
539
     * Tests for get_area_files
539
     * Tests for get_area_files
540
     *
540
     *
541
     * @covers ::get_area_files
541
     * @covers ::get_area_files
542
     */
542
     */
543
    public function test_get_area_files() {
543
    public function test_get_area_files(): void {
544
        $user = $this->setup_three_private_files();
544
        $user = $this->setup_three_private_files();
545
        $fs = get_file_storage();
545
        $fs = get_file_storage();
Línea 546... Línea 546...
546
 
546
 
547
        // Get area files with default options.
547
        // Get area files with default options.
Línea 598... Línea 598...
598
    /**
598
    /**
599
     * Tests for get_area_tree
599
     * Tests for get_area_tree
600
     *
600
     *
601
     * @covers ::get_area_tree
601
     * @covers ::get_area_tree
602
     */
602
     */
603
    public function test_get_area_tree() {
603
    public function test_get_area_tree(): void {
604
        $user = $this->setup_three_private_files();
604
        $user = $this->setup_three_private_files();
605
        $fs = get_file_storage();
605
        $fs = get_file_storage();
Línea 606... Línea 606...
606
 
606
 
607
        // Get area files with default options.
607
        // Get area files with default options.
Línea 657... Línea 657...
657
    /**
657
    /**
658
     * Tests for get_file_by_id
658
     * Tests for get_file_by_id
659
     *
659
     *
660
     * @covers ::get_file_by_id
660
     * @covers ::get_file_by_id
661
     */
661
     */
662
    public function test_get_file_by_id() {
662
    public function test_get_file_by_id(): void {
663
        $user = $this->setup_three_private_files();
663
        $user = $this->setup_three_private_files();
664
        $fs = get_file_storage();
664
        $fs = get_file_storage();
Línea 665... Línea 665...
665
 
665
 
Línea 678... Línea 678...
678
    /**
678
    /**
679
     * Tests for get_file_by_hash
679
     * Tests for get_file_by_hash
680
     *
680
     *
681
     * @covers ::get_file_by_hash
681
     * @covers ::get_file_by_hash
682
     */
682
     */
683
    public function test_get_file_by_hash() {
683
    public function test_get_file_by_hash(): void {
684
        $user = $this->setup_three_private_files();
684
        $user = $this->setup_three_private_files();
685
        $fs = get_file_storage();
685
        $fs = get_file_storage();
Línea 686... Línea 686...
686
 
686
 
687
        $areafiles = $fs->get_area_files($user->ctxid, 'user', 'private');
687
        $areafiles = $fs->get_area_files($user->ctxid, 'user', 'private');
Línea 698... Línea 698...
698
    /**
698
    /**
699
     * Tests for get_external_files
699
     * Tests for get_external_files
700
     *
700
     *
701
     * @covers ::get_external_files
701
     * @covers ::get_external_files
702
     */
702
     */
703
    public function test_get_external_files() {
703
    public function test_get_external_files(): void {
704
        $user = $this->setup_three_private_files();
704
        $user = $this->setup_three_private_files();
705
        $fs = get_file_storage();
705
        $fs = get_file_storage();
Línea 706... Línea 706...
706
 
706
 
707
        $repos = repository::get_instances(array('type'=>'user'));
707
        $repos = repository::get_instances(array('type'=>'user'));
Línea 765... Línea 765...
765
    /**
765
    /**
766
     * Tests for create_directory with a negative contextid.
766
     * Tests for create_directory with a negative contextid.
767
     *
767
     *
768
     * @covers ::create_directory
768
     * @covers ::create_directory
769
     */
769
     */
770
    public function test_create_directory_contextid_negative() {
770
    public function test_create_directory_contextid_negative(): void {
771
        $fs = get_file_storage();
771
        $fs = get_file_storage();
Línea 772... Línea 772...
772
 
772
 
773
        $this->expectException('file_exception');
773
        $this->expectException('file_exception');
774
        $fs->create_directory(-1, 'core', 'unittest', 0, '/');
774
        $fs->create_directory(-1, 'core', 'unittest', 0, '/');
Línea 777... Línea 777...
777
    /**
777
    /**
778
     * Tests for create_directory with an invalid contextid.
778
     * Tests for create_directory with an invalid contextid.
779
     *
779
     *
780
     * @covers ::create_directory
780
     * @covers ::create_directory
781
     */
781
     */
782
    public function test_create_directory_contextid_invalid() {
782
    public function test_create_directory_contextid_invalid(): void {
783
        $fs = get_file_storage();
783
        $fs = get_file_storage();
Línea 784... Línea 784...
784
 
784
 
785
        $this->expectException('file_exception');
785
        $this->expectException('file_exception');
786
        $fs->create_directory('not an int', 'core', 'unittest', 0, '/');
786
        $fs->create_directory('not an int', 'core', 'unittest', 0, '/');
Línea 789... Línea 789...
789
    /**
789
    /**
790
     * Tests for create_directory with an invalid component.
790
     * Tests for create_directory with an invalid component.
791
     *
791
     *
792
     * @covers ::create_directory
792
     * @covers ::create_directory
793
     */
793
     */
794
    public function test_create_directory_component_invalid() {
794
    public function test_create_directory_component_invalid(): void {
795
        $fs = get_file_storage();
795
        $fs = get_file_storage();
796
        $syscontext = \context_system::instance();
796
        $syscontext = \context_system::instance();
Línea 797... Línea 797...
797
 
797
 
798
        $this->expectException('file_exception');
798
        $this->expectException('file_exception');
Línea 802... Línea 802...
802
    /**
802
    /**
803
     * Tests for create_directory with an invalid filearea.
803
     * Tests for create_directory with an invalid filearea.
804
     *
804
     *
805
     * @covers ::create_directory
805
     * @covers ::create_directory
806
     */
806
     */
807
    public function test_create_directory_filearea_invalid() {
807
    public function test_create_directory_filearea_invalid(): void {
808
        $fs = get_file_storage();
808
        $fs = get_file_storage();
809
        $syscontext = \context_system::instance();
809
        $syscontext = \context_system::instance();
Línea 810... Línea 810...
810
 
810
 
811
        $this->expectException('file_exception');
811
        $this->expectException('file_exception');
Línea 815... Línea 815...
815
    /**
815
    /**
816
     * Tests for create_directory with a negative itemid
816
     * Tests for create_directory with a negative itemid
817
     *
817
     *
818
     * @covers ::create_directory
818
     * @covers ::create_directory
819
     */
819
     */
820
    public function test_create_directory_itemid_negative() {
820
    public function test_create_directory_itemid_negative(): void {
821
        $fs = get_file_storage();
821
        $fs = get_file_storage();
822
        $syscontext = \context_system::instance();
822
        $syscontext = \context_system::instance();
Línea 823... Línea 823...
823
 
823
 
824
        $this->expectException('file_exception');
824
        $this->expectException('file_exception');
Línea 828... Línea 828...
828
    /**
828
    /**
829
     * Tests for create_directory with an invalid itemid
829
     * Tests for create_directory with an invalid itemid
830
     *
830
     *
831
     * @covers ::create_directory
831
     * @covers ::create_directory
832
     */
832
     */
833
    public function test_create_directory_itemid_invalid() {
833
    public function test_create_directory_itemid_invalid(): void {
834
        $fs = get_file_storage();
834
        $fs = get_file_storage();
835
        $syscontext = \context_system::instance();
835
        $syscontext = \context_system::instance();
Línea 836... Línea 836...
836
 
836
 
837
        $this->expectException('file_exception');
837
        $this->expectException('file_exception');
Línea 841... Línea 841...
841
    /**
841
    /**
842
     * Tests for create_directory with an invalid filepath
842
     * Tests for create_directory with an invalid filepath
843
     *
843
     *
844
     * @covers ::create_directory
844
     * @covers ::create_directory
845
     */
845
     */
846
    public function test_create_directory_filepath_invalid() {
846
    public function test_create_directory_filepath_invalid(): void {
847
        $fs = get_file_storage();
847
        $fs = get_file_storage();
848
        $syscontext = \context_system::instance();
848
        $syscontext = \context_system::instance();
Línea 849... Línea 849...
849
 
849
 
850
        $this->expectException('file_exception');
850
        $this->expectException('file_exception');
Línea 854... Línea 854...
854
    /**
854
    /**
855
     * Tests for get_directory_files.
855
     * Tests for get_directory_files.
856
     *
856
     *
857
     * @covers ::get_directory_files
857
     * @covers ::get_directory_files
858
     */
858
     */
859
    public function test_get_directory_files() {
859
    public function test_get_directory_files(): void {
860
        $user = $this->setup_three_private_files();
860
        $user = $this->setup_three_private_files();
861
        $fs = get_file_storage();
861
        $fs = get_file_storage();
Línea 862... Línea 862...
862
 
862
 
863
        $dir = $fs->create_directory($user->ctxid, 'user', 'private', 0, '/testsubdir/');
863
        $dir = $fs->create_directory($user->ctxid, 'user', 'private', 0, '/testsubdir/');
Línea 916... Línea 916...
916
    /**
916
    /**
917
     * Tests for search_references.
917
     * Tests for search_references.
918
     *
918
     *
919
     * @covers ::search_references
919
     * @covers ::search_references
920
     */
920
     */
921
    public function test_search_references() {
921
    public function test_search_references(): void {
922
        $user = $this->setup_three_private_files();
922
        $user = $this->setup_three_private_files();
923
        $fs = get_file_storage();
923
        $fs = get_file_storage();
924
        $repos = repository::get_instances(array('type'=>'user'));
924
        $repos = repository::get_instances(array('type'=>'user'));
925
        $repo = reset($repos);
925
        $repo = reset($repos);
Línea 993... Línea 993...
993
    /**
993
    /**
994
     * Tests for delete_area_files.
994
     * Tests for delete_area_files.
995
     *
995
     *
996
     * @covers ::delete_area_files
996
     * @covers ::delete_area_files
997
     */
997
     */
998
    public function test_delete_area_files() {
998
    public function test_delete_area_files(): void {
999
        $user = $this->setup_three_private_files();
999
        $user = $this->setup_three_private_files();
1000
        $fs = get_file_storage();
1000
        $fs = get_file_storage();
Línea 1001... Línea 1001...
1001
 
1001
 
1002
        // Get area files with default options.
1002
        // Get area files with default options.
Línea 1013... Línea 1013...
1013
    /**
1013
    /**
1014
     * Tests for delete_area_files using an itemid.
1014
     * Tests for delete_area_files using an itemid.
1015
     *
1015
     *
1016
     * @covers ::delete_area_files
1016
     * @covers ::delete_area_files
1017
     */
1017
     */
1018
    public function test_delete_area_files_itemid() {
1018
    public function test_delete_area_files_itemid(): void {
1019
        $user = $this->setup_three_private_files();
1019
        $user = $this->setup_three_private_files();
1020
        $fs = get_file_storage();
1020
        $fs = get_file_storage();
Línea 1021... Línea 1021...
1021
 
1021
 
1022
        // Get area files with default options.
1022
        // Get area files with default options.
Línea 1032... Línea 1032...
1032
    /**
1032
    /**
1033
     * Tests for delete_area_files_select.
1033
     * Tests for delete_area_files_select.
1034
     *
1034
     *
1035
     * @covers ::delete_area_files_select
1035
     * @covers ::delete_area_files_select
1036
     */
1036
     */
1037
    public function test_delete_area_files_select() {
1037
    public function test_delete_area_files_select(): void {
1038
        $user = $this->setup_three_private_files();
1038
        $user = $this->setup_three_private_files();
1039
        $fs = get_file_storage();
1039
        $fs = get_file_storage();
Línea 1040... Línea 1040...
1040
 
1040
 
1041
        // Get area files with default options.
1041
        // Get area files with default options.
Línea 1052... Línea 1052...
1052
    /**
1052
    /**
1053
     * Tests for delete_component_files.
1053
     * Tests for delete_component_files.
1054
     *
1054
     *
1055
     * @covers ::delete_component_files
1055
     * @covers ::delete_component_files
1056
     */
1056
     */
1057
    public function test_delete_component_files() {
1057
    public function test_delete_component_files(): void {
1058
        $user = $this->setup_three_private_files();
1058
        $user = $this->setup_three_private_files();
1059
        $fs = get_file_storage();
1059
        $fs = get_file_storage();
Línea 1060... Línea 1060...
1060
 
1060
 
1061
        $areafiles = $fs->get_area_files($user->ctxid, 'user', 'private');
1061
        $areafiles = $fs->get_area_files($user->ctxid, 'user', 'private');
Línea 1068... Línea 1068...
1068
    /**
1068
    /**
1069
     * Tests for create_file_from_url.
1069
     * Tests for create_file_from_url.
1070
     *
1070
     *
1071
     * @covers ::create_file_from_url
1071
     * @covers ::create_file_from_url
1072
     */
1072
     */
1073
    public function test_create_file_from_url() {
1073
    public function test_create_file_from_url(): void {
1074
        $this->resetAfterTest(true);
1074
        $this->resetAfterTest(true);
Línea 1075... Línea 1075...
1075
 
1075
 
1076
        $syscontext = \context_system::instance();
1076
        $syscontext = \context_system::instance();
1077
        $filerecord = array(
1077
        $filerecord = array(
Línea 1103... Línea 1103...
1103
    /**
1103
    /**
1104
     * Tests for cron.
1104
     * Tests for cron.
1105
     *
1105
     *
1106
     * @covers ::cron
1106
     * @covers ::cron
1107
     */
1107
     */
1108
    public function test_cron() {
1108
    public function test_cron(): void {
1109
        $this->resetAfterTest(true);
1109
        $this->resetAfterTest(true);
Línea 1110... Línea 1110...
1110
 
1110
 
1111
        // Note: this is only testing DB compatibility atm, rather than
1111
        // Note: this is only testing DB compatibility atm, rather than
1112
        // that work is done.
1112
        // that work is done.
Línea 1119... Línea 1119...
1119
    /**
1119
    /**
1120
     * Tests for is_area_empty.
1120
     * Tests for is_area_empty.
1121
     *
1121
     *
1122
     * @covers ::is_area_empty
1122
     * @covers ::is_area_empty
1123
     */
1123
     */
1124
    public function test_is_area_empty() {
1124
    public function test_is_area_empty(): void {
1125
        $user = $this->setup_three_private_files();
1125
        $user = $this->setup_three_private_files();
1126
        $fs = get_file_storage();
1126
        $fs = get_file_storage();
Línea 1127... Línea 1127...
1127
 
1127
 
Línea 1136... Línea 1136...
1136
    /**
1136
    /**
1137
     * Tests for move_area_files_to_new_context.
1137
     * Tests for move_area_files_to_new_context.
1138
     *
1138
     *
1139
     * @covers ::move_area_files_to_new_context
1139
     * @covers ::move_area_files_to_new_context
1140
     */
1140
     */
1141
    public function test_move_area_files_to_new_context() {
1141
    public function test_move_area_files_to_new_context(): void {
1142
        $this->resetAfterTest(true);
1142
        $this->resetAfterTest(true);
Línea 1143... Línea 1143...
1143
 
1143
 
1144
        // Create a course with a page resource.
1144
        // Create a course with a page resource.
1145
        $course = $this->getDataGenerator()->create_course();
1145
        $course = $this->getDataGenerator()->create_course();
Línea 1190... Línea 1190...
1190
    /**
1190
    /**
1191
     * Tests for convert_image.
1191
     * Tests for convert_image.
1192
     *
1192
     *
1193
     * @covers ::convert_image
1193
     * @covers ::convert_image
1194
     */
1194
     */
1195
    public function test_convert_image() {
1195
    public function test_convert_image(): void {
1196
        global $CFG;
1196
        global $CFG;
Línea 1197... Línea 1197...
1197
 
1197
 
Línea 1198... Línea 1198...
1198
        $this->resetAfterTest(false);
1198
        $this->resetAfterTest(false);
Línea 1223... Línea 1223...
1223
    /**
1223
    /**
1224
     * Tests for convert_image with a PNG.
1224
     * Tests for convert_image with a PNG.
1225
     *
1225
     *
1226
     * @covers ::convert_image
1226
     * @covers ::convert_image
1227
     */
1227
     */
1228
    public function test_convert_image_png() {
1228
    public function test_convert_image_png(): void {
1229
        global $CFG;
1229
        global $CFG;
Línea 1230... Línea 1230...
1230
 
1230
 
Línea 1231... Línea 1231...
1231
        $this->resetAfterTest(false);
1231
        $this->resetAfterTest(false);
Línea 1302... Línea 1302...
1302
    }
1302
    }
Línea 1303... Línea 1303...
1303
 
1303
 
1304
    /**
1304
    /**
1305
     * @covers ::create_file_from_storedfile
1305
     * @covers ::create_file_from_storedfile
1306
     */
1306
     */
1307
    public function test_create_file_from_storedfile_file_invalid() {
1307
    public function test_create_file_from_storedfile_file_invalid(): void {
Línea 1308... Línea 1308...
1308
        $this->resetAfterTest(true);
1308
        $this->resetAfterTest(true);
Línea 1309... Línea 1309...
1309
 
1309
 
Línea 1317... Línea 1317...
1317
    }
1317
    }
Línea 1318... Línea 1318...
1318
 
1318
 
1319
    /**
1319
    /**
1320
     * @covers ::create_file_from_storedfile
1320
     * @covers ::create_file_from_storedfile
1321
     */
1321
     */
1322
    public function test_create_file_from_storedfile_contextid_invalid() {
1322
    public function test_create_file_from_storedfile_contextid_invalid(): void {
Línea 1323... Línea 1323...
1323
        $this->resetAfterTest(true);
1323
        $this->resetAfterTest(true);
Línea 1324... Línea 1324...
1324
 
1324
 
Línea 1337... Línea 1337...
1337
    }
1337
    }
Línea 1338... Línea 1338...
1338
 
1338
 
1339
    /**
1339
    /**
1340
     * @covers ::create_file_from_storedfile
1340
     * @covers ::create_file_from_storedfile
1341
     */
1341
     */
1342
    public function test_create_file_from_storedfile_component_invalid() {
1342
    public function test_create_file_from_storedfile_component_invalid(): void {
Línea 1343... Línea 1343...
1343
        $this->resetAfterTest(true);
1343
        $this->resetAfterTest(true);
Línea 1344... Línea 1344...
1344
 
1344
 
Línea 1357... Línea 1357...
1357
    }
1357
    }
Línea 1358... Línea 1358...
1358
 
1358
 
1359
    /**
1359
    /**
1360
     * @covers ::create_file_from_storedfile
1360
     * @covers ::create_file_from_storedfile
1361
     */
1361
     */
1362
    public function test_create_file_from_storedfile_filearea_invalid() {
1362
    public function test_create_file_from_storedfile_filearea_invalid(): void {
Línea 1363... Línea 1363...
1363
        $this->resetAfterTest(true);
1363
        $this->resetAfterTest(true);
Línea 1364... Línea 1364...
1364
 
1364
 
Línea 1377... Línea 1377...
1377
    }
1377
    }
Línea 1378... Línea 1378...
1378
 
1378
 
1379
    /**
1379
    /**
1380
     * @covers ::create_file_from_storedfile
1380
     * @covers ::create_file_from_storedfile
1381
     */
1381
     */
1382
    public function test_create_file_from_storedfile_itemid_invalid() {
1382
    public function test_create_file_from_storedfile_itemid_invalid(): void {
Línea 1383... Línea 1383...
1383
        $this->resetAfterTest(true);
1383
        $this->resetAfterTest(true);
Línea 1384... Línea 1384...
1384
 
1384
 
Línea 1397... Línea 1397...
1397
    }
1397
    }
Línea 1398... Línea 1398...
1398
 
1398
 
1399
    /**
1399
    /**
1400
     * @covers ::create_file_from_storedfile
1400
     * @covers ::create_file_from_storedfile
1401
     */
1401
     */
1402
    public function test_create_file_from_storedfile_filepath_invalid() {
1402
    public function test_create_file_from_storedfile_filepath_invalid(): void {
Línea 1403... Línea 1403...
1403
        $this->resetAfterTest(true);
1403
        $this->resetAfterTest(true);
Línea 1404... Línea 1404...
1404
 
1404
 
Línea 1417... Línea 1417...
1417
    }
1417
    }
Línea 1418... Línea 1418...
1418
 
1418
 
1419
    /**
1419
    /**
1420
     * @covers ::create_file_from_storedfile
1420
     * @covers ::create_file_from_storedfile
1421
     */
1421
     */
1422
    public function test_create_file_from_storedfile_filename_invalid() {
1422
    public function test_create_file_from_storedfile_filename_invalid(): void {
Línea 1423... Línea 1423...
1423
        $this->resetAfterTest(true);
1423
        $this->resetAfterTest(true);
Línea 1424... Línea 1424...
1424
 
1424
 
Línea 1436... Línea 1436...
1436
    }
1436
    }
Línea 1437... Línea 1437...
1437
 
1437
 
1438
    /**
1438
    /**
1439
     * @covers ::create_file_from_storedfile
1439
     * @covers ::create_file_from_storedfile
1440
     */
1440
     */
1441
    public function test_create_file_from_storedfile_timecreated_invalid() {
1441
    public function test_create_file_from_storedfile_timecreated_invalid(): void {
Línea 1442... Línea 1442...
1442
        $this->resetAfterTest(true);
1442
        $this->resetAfterTest(true);
Línea 1443... Línea 1443...
1443
 
1443
 
Línea 1456... Línea 1456...
1456
    }
1456
    }
Línea 1457... Línea 1457...
1457
 
1457
 
1458
    /**
1458
    /**
1459
     * @covers ::create_file_from_storedfile
1459
     * @covers ::create_file_from_storedfile
1460
     */
1460
     */
1461
    public function test_create_file_from_storedfile_timemodified_invalid() {
1461
    public function test_create_file_from_storedfile_timemodified_invalid(): void {
Línea 1462... Línea 1462...
1462
        $this->resetAfterTest(true);
1462
        $this->resetAfterTest(true);
Línea 1463... Línea 1463...
1463
 
1463
 
Línea 1476... Línea 1476...
1476
    }
1476
    }
Línea 1477... Línea 1477...
1477
 
1477
 
1478
    /**
1478
    /**
1479
     * @covers ::create_file_from_storedfile
1479
     * @covers ::create_file_from_storedfile
1480
     */
1480
     */
1481
    public function test_create_file_from_storedfile_duplicate() {
1481
    public function test_create_file_from_storedfile_duplicate(): void {
Línea 1482... Línea 1482...
1482
        $this->resetAfterTest(true);
1482
        $this->resetAfterTest(true);
Línea 1483... Línea 1483...
1483
 
1483
 
Línea 1496... Línea 1496...
1496
    /**
1496
    /**
1497
     * Tests for create_file_from_storedfile.
1497
     * Tests for create_file_from_storedfile.
1498
     *
1498
     *
1499
     * @covers ::create_file_from_storedfile
1499
     * @covers ::create_file_from_storedfile
1500
     */
1500
     */
1501
    public function test_create_file_from_storedfile() {
1501
    public function test_create_file_from_storedfile(): void {
1502
        $this->resetAfterTest(true);
1502
        $this->resetAfterTest(true);
Línea 1503... Línea 1503...
1503
 
1503
 
Línea 1504... Línea 1504...
1504
        $syscontext = \context_system::instance();
1504
        $syscontext = \context_system::instance();
Línea 1533... Línea 1533...
1533
    }
1533
    }
Línea 1534... Línea 1534...
1534
 
1534
 
1535
    /**
1535
    /**
1536
     * @covers ::create_file_from_string
1536
     * @covers ::create_file_from_string
1537
     */
1537
     */
1538
    public function test_create_file_from_string_contextid_invalid() {
1538
    public function test_create_file_from_string_contextid_invalid(): void {
Línea 1539... Línea 1539...
1539
        $this->resetAfterTest(true);
1539
        $this->resetAfterTest(true);
1540
 
1540
 
Línea 1549... Línea 1549...
1549
    }
1549
    }
Línea 1550... Línea 1550...
1550
 
1550
 
1551
    /**
1551
    /**
1552
     * @covers ::create_file_from_string
1552
     * @covers ::create_file_from_string
1553
     */
1553
     */
1554
    public function test_create_file_from_string_component_invalid() {
1554
    public function test_create_file_from_string_component_invalid(): void {
Línea 1555... Línea 1555...
1555
        $this->resetAfterTest(true);
1555
        $this->resetAfterTest(true);
1556
 
1556
 
Línea 1565... Línea 1565...
1565
    }
1565
    }
Línea 1566... Línea 1566...
1566
 
1566
 
1567
    /**
1567
    /**
1568
     * @covers ::create_file_from_string
1568
     * @covers ::create_file_from_string
1569
     */
1569
     */
1570
    public function test_create_file_from_string_filearea_invalid() {
1570
    public function test_create_file_from_string_filearea_invalid(): void {
Línea 1571... Línea 1571...
1571
        $this->resetAfterTest(true);
1571
        $this->resetAfterTest(true);
1572
 
1572
 
Línea 1581... Línea 1581...
1581
    }
1581
    }
Línea 1582... Línea 1582...
1582
 
1582
 
1583
    /**
1583
    /**
1584
     * @covers ::create_file_from_string
1584
     * @covers ::create_file_from_string
1585
     */
1585
     */
1586
    public function test_create_file_from_string_itemid_invalid() {
1586
    public function test_create_file_from_string_itemid_invalid(): void {
Línea 1587... Línea 1587...
1587
        $this->resetAfterTest(true);
1587
        $this->resetAfterTest(true);
1588
 
1588
 
Línea 1597... Línea 1597...
1597
    }
1597
    }
Línea 1598... Línea 1598...
1598
 
1598
 
1599
    /**
1599
    /**
1600
     * @covers ::create_file_from_string
1600
     * @covers ::create_file_from_string
1601
     */
1601
     */
1602
    public function test_create_file_from_string_filepath_invalid() {
1602
    public function test_create_file_from_string_filepath_invalid(): void {
Línea 1603... Línea 1603...
1603
        $this->resetAfterTest(true);
1603
        $this->resetAfterTest(true);
1604
 
1604
 
Línea 1613... Línea 1613...
1613
    }
1613
    }
Línea 1614... Línea 1614...
1614
 
1614
 
1615
    /**
1615
    /**
1616
     * @covers ::create_file_from_string
1616
     * @covers ::create_file_from_string
1617
     */
1617
     */
1618
    public function test_create_file_from_string_filename_invalid() {
1618
    public function test_create_file_from_string_filename_invalid(): void {
Línea 1619... Línea 1619...
1619
        $this->resetAfterTest(true);
1619
        $this->resetAfterTest(true);
1620
 
1620
 
Línea 1629... Línea 1629...
1629
    }
1629
    }
Línea 1630... Línea 1630...
1630
 
1630
 
1631
    /**
1631
    /**
1632
     * @covers ::create_file_from_string
1632
     * @covers ::create_file_from_string
1633
     */
1633
     */
1634
    public function test_create_file_from_string_timecreated_invalid() {
1634
    public function test_create_file_from_string_timecreated_invalid(): void {
Línea 1635... Línea 1635...
1635
        $this->resetAfterTest(true);
1635
        $this->resetAfterTest(true);
1636
 
1636
 
Línea 1645... Línea 1645...
1645
    }
1645
    }
Línea 1646... Línea 1646...
1646
 
1646
 
1647
    /**
1647
    /**
1648
     * @covers ::create_file_from_string
1648
     * @covers ::create_file_from_string
1649
     */
1649
     */
1650
    public function test_create_file_from_string_timemodified_invalid() {
1650
    public function test_create_file_from_string_timemodified_invalid(): void {
Línea 1651... Línea 1651...
1651
        $this->resetAfterTest(true);
1651
        $this->resetAfterTest(true);
1652
 
1652
 
Línea 1662... Línea 1662...
1662
 
1662
 
1663
    /**
1663
    /**
1664
     * Tests for create_file_from_string with a duplicate string.
1664
     * Tests for create_file_from_string with a duplicate string.
1665
     * @covers ::create_file_from_string
1665
     * @covers ::create_file_from_string
1666
     */
1666
     */
1667
    public function test_create_file_from_string_duplicate() {
1667
    public function test_create_file_from_string_duplicate(): void {
Línea 1668... Línea 1668...
1668
        $this->resetAfterTest(true);
1668
        $this->resetAfterTest(true);
1669
 
1669
 
Línea 1678... Línea 1678...
1678
    }
1678
    }
Línea 1679... Línea 1679...
1679
 
1679
 
1680
    /**
1680
    /**
1681
     * @covers ::create_file_from_pathname
1681
     * @covers ::create_file_from_pathname
1682
     */
1682
     */
1683
    public function test_create_file_from_pathname_contextid_invalid() {
1683
    public function test_create_file_from_pathname_contextid_invalid(): void {
1684
        global $CFG;
1684
        global $CFG;
Línea 1685... Línea 1685...
1685
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
1685
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
Línea 1697... Línea 1697...
1697
    }
1697
    }
Línea 1698... Línea 1698...
1698
 
1698
 
1699
    /**
1699
    /**
1700
     * @covers ::create_file_from_pathname
1700
     * @covers ::create_file_from_pathname
1701
     */
1701
     */
1702
    public function test_create_file_from_pathname_component_invalid() {
1702
    public function test_create_file_from_pathname_component_invalid(): void {
1703
        global $CFG;
1703
        global $CFG;
Línea 1704... Línea 1704...
1704
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
1704
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
Línea 1716... Línea 1716...
1716
    }
1716
    }
Línea 1717... Línea 1717...
1717
 
1717
 
1718
    /**
1718
    /**
1719
     * @covers ::create_file_from_pathname
1719
     * @covers ::create_file_from_pathname
1720
     */
1720
     */
1721
    public function test_create_file_from_pathname_filearea_invalid() {
1721
    public function test_create_file_from_pathname_filearea_invalid(): void {
1722
        global $CFG;
1722
        global $CFG;
Línea 1723... Línea 1723...
1723
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
1723
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
Línea 1735... Línea 1735...
1735
    }
1735
    }
Línea 1736... Línea 1736...
1736
 
1736
 
1737
    /**
1737
    /**
1738
     * @covers ::create_file_from_pathname
1738
     * @covers ::create_file_from_pathname
1739
     */
1739
     */
1740
    public function test_create_file_from_pathname_itemid_invalid() {
1740
    public function test_create_file_from_pathname_itemid_invalid(): void {
1741
        global $CFG;
1741
        global $CFG;
Línea 1742... Línea 1742...
1742
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
1742
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
Línea 1754... Línea 1754...
1754
    }
1754
    }
Línea 1755... Línea 1755...
1755
 
1755
 
1756
    /**
1756
    /**
1757
     * @covers ::create_file_from_pathname
1757
     * @covers ::create_file_from_pathname
1758
     */
1758
     */
1759
    public function test_create_file_from_pathname_filepath_invalid() {
1759
    public function test_create_file_from_pathname_filepath_invalid(): void {
1760
        global $CFG;
1760
        global $CFG;
Línea 1761... Línea 1761...
1761
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
1761
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
Línea 1773... Línea 1773...
1773
    }
1773
    }
Línea 1774... Línea 1774...
1774
 
1774
 
1775
    /**
1775
    /**
1776
     * @covers ::create_file_from_pathname
1776
     * @covers ::create_file_from_pathname
1777
     */
1777
     */
1778
    public function test_create_file_from_pathname_filename_invalid() {
1778
    public function test_create_file_from_pathname_filename_invalid(): void {
1779
        global $CFG;
1779
        global $CFG;
Línea 1780... Línea 1780...
1780
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
1780
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
Línea 1792... Línea 1792...
1792
    }
1792
    }
Línea 1793... Línea 1793...
1793
 
1793
 
1794
    /**
1794
    /**
1795
     * @covers ::create_file_from_pathname
1795
     * @covers ::create_file_from_pathname
1796
     */
1796
     */
1797
    public function test_create_file_from_pathname_timecreated_invalid() {
1797
    public function test_create_file_from_pathname_timecreated_invalid(): void {
1798
        global $CFG;
1798
        global $CFG;
Línea 1799... Línea 1799...
1799
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
1799
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
Línea 1811... Línea 1811...
1811
    }
1811
    }
Línea 1812... Línea 1812...
1812
 
1812
 
1813
    /**
1813
    /**
1814
     * @covers ::create_file_from_pathname
1814
     * @covers ::create_file_from_pathname
1815
     */
1815
     */
1816
    public function test_create_file_from_pathname_timemodified_invalid() {
1816
    public function test_create_file_from_pathname_timemodified_invalid(): void {
1817
        global $CFG;
1817
        global $CFG;
Línea 1818... Línea 1818...
1818
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
1818
        $path = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
Línea 1830... Línea 1830...
1830
    }
1830
    }
Línea 1831... Línea 1831...
1831
 
1831
 
1832
    /**
1832
    /**
1833
     * @covers ::create_file_from_pathname
1833
     * @covers ::create_file_from_pathname
1834
     */
1834
     */
1835
    public function test_create_file_from_pathname_duplicate_file() {
1835
    public function test_create_file_from_pathname_duplicate_file(): void {
1836
        global $CFG;
1836
        global $CFG;
Línea 1837... Línea 1837...
1837
        $this->resetAfterTest(true);
1837
        $this->resetAfterTest(true);
Línea 1853... Línea 1853...
1853
    /**
1853
    /**
1854
     * Calling \stored_file::delete_reference() on a non-reference file throws coding_exception
1854
     * Calling \stored_file::delete_reference() on a non-reference file throws coding_exception
1855
     *
1855
     *
1856
     * @covers \stored_file::delete_reference
1856
     * @covers \stored_file::delete_reference
1857
     */
1857
     */
1858
    public function test_delete_reference_on_nonreference() {
1858
    public function test_delete_reference_on_nonreference(): void {
Línea 1859... Línea 1859...
1859
 
1859
 
1860
        $this->resetAfterTest(true);
1860
        $this->resetAfterTest(true);
1861
        $user = $this->setup_three_private_files();
1861
        $user = $this->setup_three_private_files();
1862
        $fs = get_file_storage();
1862
        $fs = get_file_storage();
Línea 1882... Línea 1882...
1882
     * Calling \stored_file::delete_reference() on a reference file does not affect other
1882
     * Calling \stored_file::delete_reference() on a reference file does not affect other
1883
     * symlinks to the same original
1883
     * symlinks to the same original
1884
     *
1884
     *
1885
     * @covers \stored_file::delete_reference
1885
     * @covers \stored_file::delete_reference
1886
     */
1886
     */
1887
    public function test_delete_reference_one_symlink_does_not_rule_them_all() {
1887
    public function test_delete_reference_one_symlink_does_not_rule_them_all(): void {
Línea 1888... Línea 1888...
1888
 
1888
 
1889
        $this->resetAfterTest(true);
1889
        $this->resetAfterTest(true);
1890
        $user = $this->setup_three_private_files();
1890
        $user = $this->setup_three_private_files();
1891
        $fs = get_file_storage();
1891
        $fs = get_file_storage();
Línea 1945... Línea 1945...
1945
    /**
1945
    /**
1946
     * Make sure that when internal file is updated all references to it are
1946
     * Make sure that when internal file is updated all references to it are
1947
     * updated immediately. When it is deleted, the references are converted
1947
     * updated immediately. When it is deleted, the references are converted
1948
     * to true copies.
1948
     * to true copies.
1949
     */
1949
     */
1950
    public function test_update_reference_internal() {
1950
    public function test_update_reference_internal(): void {
1951
        purge_all_caches();
1951
        purge_all_caches();
1952
        $this->resetAfterTest(true);
1952
        $this->resetAfterTest(true);
1953
        $user = $this->setup_three_private_files();
1953
        $user = $this->setup_three_private_files();
1954
        $fs = get_file_storage();
1954
        $fs = get_file_storage();
1955
        $repos = repository::get_instances(array('type' => 'user'));
1955
        $repos = repository::get_instances(array('type' => 'user'));
Línea 2052... Línea 2052...
2052
    /**
2052
    /**
2053
     * Tests for get_unused_filename.
2053
     * Tests for get_unused_filename.
2054
     *
2054
     *
2055
     * @covers ::get_unused_filename
2055
     * @covers ::get_unused_filename
2056
     */
2056
     */
2057
    public function test_get_unused_filename() {
2057
    public function test_get_unused_filename(): void {
2058
        global $USER;
2058
        global $USER;
2059
        $this->resetAfterTest(true);
2059
        $this->resetAfterTest(true);
Línea 2060... Línea 2060...
2060
 
2060
 
2061
        $fs = get_file_storage();
2061
        $fs = get_file_storage();
Línea 2120... Línea 2120...
2120
     * Test that mimetype_from_file returns appropriate output when the
2120
     * Test that mimetype_from_file returns appropriate output when the
2121
     * file could not be found.
2121
     * file could not be found.
2122
     *
2122
     *
2123
     * @covers ::mimetype
2123
     * @covers ::mimetype
2124
     */
2124
     */
2125
    public function test_mimetype_not_found() {
2125
    public function test_mimetype_not_found(): void {
2126
        $mimetype = \file_storage::mimetype('/path/to/nonexistent/file');
2126
        $mimetype = \file_storage::mimetype('/path/to/nonexistent/file');
2127
        $this->assertEquals('document/unknown', $mimetype);
2127
        $this->assertEquals('document/unknown', $mimetype);
2128
    }
2128
    }
Línea 2129... Línea 2129...
2129
 
2129
 
Línea 2163... Línea 2163...
2163
     * Test that mimetype_from_file returns appropriate output when the
2163
     * Test that mimetype_from_file returns appropriate output when the
2164
     * file could not be found.
2164
     * file could not be found.
2165
     *
2165
     *
2166
     * @covers ::mimetype_from_file
2166
     * @covers ::mimetype_from_file
2167
     */
2167
     */
2168
    public function test_mimetype_from_file_not_found() {
2168
    public function test_mimetype_from_file_not_found(): void {
2169
        $mimetype = \file_storage::mimetype_from_file('/path/to/nonexistent/file');
2169
        $mimetype = \file_storage::mimetype_from_file('/path/to/nonexistent/file');
2170
        $this->assertEquals('document/unknown', $mimetype);
2170
        $this->assertEquals('document/unknown', $mimetype);
2171
    }
2171
    }
Línea 2172... Línea 2172...
2172
 
2172