Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 106... Línea 106...
106
 
106
 
107
    /**
107
    /**
108
     * Ensure that the file system is not clonable.
108
     * Ensure that the file system is not clonable.
109
     *
109
     *
110
     */
110
     */
111
    public function test_not_cloneable() {
111
    public function test_not_cloneable(): void {
112
        $reflection = new \ReflectionClass('file_system');
112
        $reflection = new \ReflectionClass('file_system');
113
        $this->assertFalse($reflection->isCloneable());
113
        $this->assertFalse($reflection->isCloneable());
Línea 114... Línea 114...
114
    }
114
    }
115
 
115
 
116
    /**
116
    /**
117
     * Ensure that the filedir file_system extension is used by default.
117
     * Ensure that the filedir file_system extension is used by default.
118
     *
118
     *
119
     */
119
     */
Línea 120... Línea 120...
120
    public function test_default_class() {
120
    public function test_default_class(): void {
121
        $this->resetAfterTest();
121
        $this->resetAfterTest();
122
 
122
 
Línea 132... Línea 132...
132
 
132
 
133
    /**
133
    /**
134
     * Ensure that the specified file_system extension class is used.
134
     * Ensure that the specified file_system extension class is used.
135
     *
135
     *
136
     */
136
     */
137
    public function test_supplied_class() {
137
    public function test_supplied_class(): void {
138
        global $CFG;
138
        global $CFG;
Línea 139... Línea 139...
139
        $this->resetAfterTest();
139
        $this->resetAfterTest();
140
 
140
 
Línea 154... Línea 154...
154
    /**
154
    /**
155
     * Test that the readfile function outputs content to disk.
155
     * Test that the readfile function outputs content to disk.
156
     *
156
     *
157
     * @covers ::readfile
157
     * @covers ::readfile
158
     */
158
     */
159
    public function test_readfile_remote() {
159
    public function test_readfile_remote(): void {
160
        global $CFG;
160
        global $CFG;
Línea 161... Línea 161...
161
 
161
 
162
        // Mock the filesystem.
162
        // Mock the filesystem.
163
        $filecontent = 'example content';
163
        $filecontent = 'example content';
Línea 187... Línea 187...
187
    /**
187
    /**
188
     * Test that the readfile function outputs content to disk.
188
     * Test that the readfile function outputs content to disk.
189
     *
189
     *
190
     * @covers ::readfile
190
     * @covers ::readfile
191
     */
191
     */
192
    public function test_readfile_local() {
192
    public function test_readfile_local(): void {
193
        global $CFG;
193
        global $CFG;
Línea 194... Línea 194...
194
 
194
 
195
        // Mock the filesystem.
195
        // Mock the filesystem.
196
        $filecontent = 'example content';
196
        $filecontent = 'example content';
Línea 225... Línea 225...
225
     * @param   array   $args The additional args to pass to get_local_path_from_storedfile
225
     * @param   array   $args The additional args to pass to get_local_path_from_storedfile
226
     * @param   bool    $fetch Whether the combination of args should have caused a fetch
226
     * @param   bool    $fetch Whether the combination of args should have caused a fetch
227
     *
227
     *
228
     * @covers ::get_local_path_from_storedfile
228
     * @covers ::get_local_path_from_storedfile
229
     */
229
     */
230
    public function test_get_local_path_from_storedfile($args, $fetch) {
230
    public function test_get_local_path_from_storedfile($args, $fetch): void {
231
        $filepath = '/path/to/file';
231
        $filepath = '/path/to/file';
232
        $filecontent = 'example content';
232
        $filecontent = 'example content';
Línea 233... Línea 233...
233
 
233
 
234
        // Get the filesystem mock.
234
        // Get the filesystem mock.
Línea 252... Línea 252...
252
     * simply calls get_local_path_from_storedfile without requiring a
252
     * simply calls get_local_path_from_storedfile without requiring a
253
     * fetch.
253
     * fetch.
254
     *
254
     *
255
     * @covers ::get_remote_path_from_storedfile
255
     * @covers ::get_remote_path_from_storedfile
256
     */
256
     */
257
    public function test_get_remote_path_from_storedfile() {
257
    public function test_get_remote_path_from_storedfile(): void {
258
        $filepath = '/path/to/file';
258
        $filepath = '/path/to/file';
259
        $filecontent = 'example content';
259
        $filecontent = 'example content';
Línea 260... Línea 260...
260
 
260
 
261
        $fs = $this->get_testable_mock([
261
        $fs = $this->get_testable_mock([
Línea 282... Línea 282...
282
     *
282
     *
283
     * Fetching the file is optional.
283
     * Fetching the file is optional.
284
     *
284
     *
285
     * @covers ::is_file_readable_locally_by_hash
285
     * @covers ::is_file_readable_locally_by_hash
286
     */
286
     */
287
    public function test_is_file_readable_locally_by_hash() {
287
    public function test_is_file_readable_locally_by_hash(): void {
288
        $filecontent = 'example content';
288
        $filecontent = 'example content';
289
        $contenthash = \file_storage::hash_from_string($filecontent);
289
        $contenthash = \file_storage::hash_from_string($filecontent);
290
        $filepath = __FILE__;
290
        $filepath = __FILE__;
Línea 291... Línea 291...
291
 
291
 
Línea 303... Línea 303...
303
    /**
303
    /**
304
     * Test the stock implementation of is_file_readable_locally_by_hash with an empty file.
304
     * Test the stock implementation of is_file_readable_locally_by_hash with an empty file.
305
     *
305
     *
306
     * @covers ::is_file_readable_locally_by_hash
306
     * @covers ::is_file_readable_locally_by_hash
307
     */
307
     */
308
    public function test_is_file_readable_locally_by_hash_empty() {
308
    public function test_is_file_readable_locally_by_hash_empty(): void {
309
        $filecontent = '';
309
        $filecontent = '';
310
        $contenthash = \file_storage::hash_from_string($filecontent);
310
        $contenthash = \file_storage::hash_from_string($filecontent);
Línea 311... Línea 311...
311
 
311
 
312
        $fs = $this->get_testable_mock([
312
        $fs = $this->get_testable_mock([
Línea 322... Línea 322...
322
    /**
322
    /**
323
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
323
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
324
     *
324
     *
325
     * @covers ::is_file_readable_remotely_by_hash
325
     * @covers ::is_file_readable_remotely_by_hash
326
     */
326
     */
327
    public function test_is_file_readable_remotely_by_hash() {
327
    public function test_is_file_readable_remotely_by_hash(): void {
328
        $filecontent = 'example content';
328
        $filecontent = 'example content';
329
        $contenthash = \file_storage::hash_from_string($filecontent);
329
        $contenthash = \file_storage::hash_from_string($filecontent);
Línea 330... Línea 330...
330
 
330
 
331
        $fs = $this->get_testable_mock([
331
        $fs = $this->get_testable_mock([
Línea 342... Línea 342...
342
    /**
342
    /**
343
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
343
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
344
     *
344
     *
345
     * @covers ::is_file_readable_remotely_by_hash
345
     * @covers ::is_file_readable_remotely_by_hash
346
     */
346
     */
347
    public function test_is_file_readable_remotely_by_hash_empty() {
347
    public function test_is_file_readable_remotely_by_hash_empty(): void {
348
        $filecontent = '';
348
        $filecontent = '';
349
        $contenthash = \file_storage::hash_from_string($filecontent);
349
        $contenthash = \file_storage::hash_from_string($filecontent);
Línea 350... Línea 350...
350
 
350
 
351
        $fs = $this->get_testable_mock([
351
        $fs = $this->get_testable_mock([
Línea 361... Línea 361...
361
    /**
361
    /**
362
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
362
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
363
     *
363
     *
364
     * @covers ::is_file_readable_remotely_by_hash
364
     * @covers ::is_file_readable_remotely_by_hash
365
     */
365
     */
366
    public function test_is_file_readable_remotely_by_hash_not_found() {
366
    public function test_is_file_readable_remotely_by_hash_not_found(): void {
367
        $filecontent = 'example content';
367
        $filecontent = 'example content';
368
        $contenthash = \file_storage::hash_from_string($filecontent);
368
        $contenthash = \file_storage::hash_from_string($filecontent);
Línea 369... Línea 369...
369
 
369
 
370
        $fs = $this->get_testable_mock([
370
        $fs = $this->get_testable_mock([
Línea 381... Línea 381...
381
    /**
381
    /**
382
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
382
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
383
     *
383
     *
384
     * @covers ::is_file_readable_remotely_by_storedfile
384
     * @covers ::is_file_readable_remotely_by_storedfile
385
     */
385
     */
386
    public function test_is_file_readable_remotely_by_storedfile() {
386
    public function test_is_file_readable_remotely_by_storedfile(): void {
387
        $file = $this->get_stored_file('example content');
387
        $file = $this->get_stored_file('example content');
Línea 388... Línea 388...
388
 
388
 
389
        $fs = $this->get_testable_mock([
389
        $fs = $this->get_testable_mock([
390
            'get_remote_path_from_storedfile',
390
            'get_remote_path_from_storedfile',
Línea 399... Línea 399...
399
    /**
399
    /**
400
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
400
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
401
     *
401
     *
402
     * @covers ::is_file_readable_remotely_by_storedfile
402
     * @covers ::is_file_readable_remotely_by_storedfile
403
     */
403
     */
404
    public function test_is_file_readable_remotely_by_storedfile_empty() {
404
    public function test_is_file_readable_remotely_by_storedfile_empty(): void {
405
        $fs = $this->get_testable_mock([
405
        $fs = $this->get_testable_mock([
406
            'get_remote_path_from_storedfile',
406
            'get_remote_path_from_storedfile',
407
        ]);
407
        ]);
Línea 408... Línea 408...
408
 
408
 
Línea 416... Línea 416...
416
    /**
416
    /**
417
     * Test the stock implementation of is_file_readable_locally_by_storedfile with an empty file.
417
     * Test the stock implementation of is_file_readable_locally_by_storedfile with an empty file.
418
     *
418
     *
419
     * @covers ::is_file_readable_locally_by_storedfile
419
     * @covers ::is_file_readable_locally_by_storedfile
420
     */
420
     */
421
    public function test_is_file_readable_locally_by_storedfile_empty() {
421
    public function test_is_file_readable_locally_by_storedfile_empty(): void {
422
        $fs = $this->get_testable_mock([
422
        $fs = $this->get_testable_mock([
423
            'get_local_path_from_storedfile',
423
            'get_local_path_from_storedfile',
424
        ]);
424
        ]);
Línea 425... Línea 425...
425
 
425
 
Línea 433... Línea 433...
433
    /**
433
    /**
434
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
434
     * Test the stock implementation of is_file_readable_remotely_by_storedfile with a valid file.
435
     *
435
     *
436
     * @covers ::is_file_readable_locally_by_storedfile
436
     * @covers ::is_file_readable_locally_by_storedfile
437
     */
437
     */
438
    public function test_is_file_readable_remotely_by_storedfile_not_found() {
438
    public function test_is_file_readable_remotely_by_storedfile_not_found(): void {
439
        $file = $this->get_stored_file('example content');
439
        $file = $this->get_stored_file('example content');
Línea 440... Línea 440...
440
 
440
 
441
        $fs = $this->get_testable_mock([
441
        $fs = $this->get_testable_mock([
442
            'get_remote_path_from_storedfile',
442
            'get_remote_path_from_storedfile',
Línea 451... Línea 451...
451
    /**
451
    /**
452
     * Test the stock implementation of is_file_readable_locally_by_storedfile with a valid file.
452
     * Test the stock implementation of is_file_readable_locally_by_storedfile with a valid file.
453
     *
453
     *
454
     * @covers ::is_file_readable_locally_by_storedfile
454
     * @covers ::is_file_readable_locally_by_storedfile
455
     */
455
     */
456
    public function test_is_file_readable_locally_by_storedfile_unreadable() {
456
    public function test_is_file_readable_locally_by_storedfile_unreadable(): void {
457
        $fs = $this->get_testable_mock([
457
        $fs = $this->get_testable_mock([
458
            'get_local_path_from_storedfile',
458
            'get_local_path_from_storedfile',
459
        ]);
459
        ]);
460
        $file = $this->get_stored_file('example content');
460
        $file = $this->get_stored_file('example content');
Línea 469... Línea 469...
469
    /**
469
    /**
470
     * Test the stock implementation of is_file_readable_locally_by_storedfile with a valid file should pass fetch.
470
     * Test the stock implementation of is_file_readable_locally_by_storedfile with a valid file should pass fetch.
471
     *
471
     *
472
     * @covers ::is_file_readable_locally_by_storedfile
472
     * @covers ::is_file_readable_locally_by_storedfile
473
     */
473
     */
474
    public function test_is_file_readable_locally_by_storedfile_passes_fetch() {
474
    public function test_is_file_readable_locally_by_storedfile_passes_fetch(): void {
475
        $fs = $this->get_testable_mock([
475
        $fs = $this->get_testable_mock([
476
            'get_local_path_from_storedfile',
476
            'get_local_path_from_storedfile',
477
        ]);
477
        ]);
478
        $file = $this->get_stored_file('example content');
478
        $file = $this->get_stored_file('example content');
Línea 487... Línea 487...
487
    /**
487
    /**
488
     * Ensure that is_file_removable returns correctly for an empty file.
488
     * Ensure that is_file_removable returns correctly for an empty file.
489
     *
489
     *
490
     * @covers ::is_file_removable
490
     * @covers ::is_file_removable
491
     */
491
     */
492
    public function test_is_file_removable_empty() {
492
    public function test_is_file_removable_empty(): void {
493
        $filecontent = '';
493
        $filecontent = '';
494
        $contenthash = \file_storage::hash_from_string($filecontent);
494
        $contenthash = \file_storage::hash_from_string($filecontent);
Línea 495... Línea 495...
495
 
495
 
496
        $method = new \ReflectionMethod(file_system::class, 'is_file_removable');
496
        $method = new \ReflectionMethod(file_system::class, 'is_file_removable');
Línea 501... Línea 501...
501
    /**
501
    /**
502
     * Ensure that is_file_removable returns false if the file is still in use.
502
     * Ensure that is_file_removable returns false if the file is still in use.
503
     *
503
     *
504
     * @covers ::is_file_removable
504
     * @covers ::is_file_removable
505
     */
505
     */
506
    public function test_is_file_removable_in_use() {
506
    public function test_is_file_removable_in_use(): void {
507
        $this->resetAfterTest();
507
        $this->resetAfterTest();
508
        global $DB;
508
        global $DB;
Línea 509... Línea 509...
509
 
509
 
510
        $filecontent = 'example content';
510
        $filecontent = 'example content';
Línea 524... Línea 524...
524
    /**
524
    /**
525
     * Ensure that is_file_removable returns false if the file is not in use.
525
     * Ensure that is_file_removable returns false if the file is not in use.
526
     *
526
     *
527
     * @covers ::is_file_removable
527
     * @covers ::is_file_removable
528
     */
528
     */
529
    public function test_is_file_removable_not_in_use() {
529
    public function test_is_file_removable_not_in_use(): void {
530
        $this->resetAfterTest();
530
        $this->resetAfterTest();
531
        global $DB;
531
        global $DB;
Línea 532... Línea 532...
532
 
532
 
533
        $filecontent = 'example content';
533
        $filecontent = 'example content';
Línea 547... Línea 547...
547
    /**
547
    /**
548
     * Test the stock implementation of get_content.
548
     * Test the stock implementation of get_content.
549
     *
549
     *
550
     * @covers ::get_content
550
     * @covers ::get_content
551
     */
551
     */
552
    public function test_get_content() {
552
    public function test_get_content(): void {
553
        global $CFG;
553
        global $CFG;
Línea 554... Línea 554...
554
 
554
 
555
        // Mock the filesystem.
555
        // Mock the filesystem.
556
        $filecontent = 'example content';
556
        $filecontent = 'example content';
Línea 572... Línea 572...
572
    /**
572
    /**
573
     * Test the stock implementation of get_content.
573
     * Test the stock implementation of get_content.
574
     *
574
     *
575
     * @covers ::get_content
575
     * @covers ::get_content
576
     */
576
     */
577
    public function test_get_content_empty() {
577
    public function test_get_content_empty(): void {
578
        global $CFG;
578
        global $CFG;
Línea 579... Línea 579...
579
 
579
 
580
        $filecontent = '';
580
        $filecontent = '';
Línea 595... Línea 595...
595
     * Ensure that the list_files function requires a local copy of the
595
     * Ensure that the list_files function requires a local copy of the
596
     * file, and passes the path to the packer.
596
     * file, and passes the path to the packer.
597
     *
597
     *
598
     * @covers ::list_files
598
     * @covers ::list_files
599
     */
599
     */
600
    public function test_list_files() {
600
    public function test_list_files(): void {
601
        $filecontent = 'example content';
601
        $filecontent = 'example content';
602
        $file = $this->get_stored_file($filecontent);
602
        $file = $this->get_stored_file($filecontent);
603
        $filepath = __FILE__;
603
        $filepath = __FILE__;
604
        $expectedresult = (object) [];
604
        $expectedresult = (object) [];
Línea 627... Línea 627...
627
     * Ensure that the extract_to_pathname function requires a local copy of the
627
     * Ensure that the extract_to_pathname function requires a local copy of the
628
     * file, and passes the path to the packer.
628
     * file, and passes the path to the packer.
629
     *
629
     *
630
     * @covers ::extract_to_pathname
630
     * @covers ::extract_to_pathname
631
     */
631
     */
632
    public function test_extract_to_pathname() {
632
    public function test_extract_to_pathname(): void {
633
        $filecontent = 'example content';
633
        $filecontent = 'example content';
634
        $file = $this->get_stored_file($filecontent);
634
        $file = $this->get_stored_file($filecontent);
635
        $filepath = __FILE__;
635
        $filepath = __FILE__;
636
        $expectedresult = (object) [];
636
        $expectedresult = (object) [];
637
        $outputpath = '/path/to/output';
637
        $outputpath = '/path/to/output';
Línea 660... Línea 660...
660
     * Ensure that the extract_to_storage function requires a local copy of the
660
     * Ensure that the extract_to_storage function requires a local copy of the
661
     * file, and passes the path to the packer.
661
     * file, and passes the path to the packer.
662
     *
662
     *
663
     * @covers ::extract_to_storage
663
     * @covers ::extract_to_storage
664
     */
664
     */
665
    public function test_extract_to_storage() {
665
    public function test_extract_to_storage(): void {
666
        $filecontent = 'example content';
666
        $filecontent = 'example content';
667
        $file = $this->get_stored_file($filecontent);
667
        $file = $this->get_stored_file($filecontent);
668
        $filepath = __FILE__;
668
        $filepath = __FILE__;
669
        $expectedresult = (object) [];
669
        $expectedresult = (object) [];
670
        $outputpath = '/path/to/output';
670
        $outputpath = '/path/to/output';
Línea 701... Línea 701...
701
    /**
701
    /**
702
     * Ensure that the add_storedfile_to_archive function requires a local copy of the
702
     * Ensure that the add_storedfile_to_archive function requires a local copy of the
703
     * file, and passes the path to the archive.
703
     * file, and passes the path to the archive.
704
     *
704
     *
705
     */
705
     */
706
    public function test_add_storedfile_to_archive_directory() {
706
    public function test_add_storedfile_to_archive_directory(): void {
707
        $file = $this->get_stored_file('', '.');
707
        $file = $this->get_stored_file('', '.');
708
        $archivepath = 'example';
708
        $archivepath = 'example';
709
        $expectedresult = (object) [];
709
        $expectedresult = (object) [];
Línea 710... Línea 710...
710
 
710
 
Línea 737... Línea 737...
737
    /**
737
    /**
738
     * Ensure that the add_storedfile_to_archive function requires a local copy of the
738
     * Ensure that the add_storedfile_to_archive function requires a local copy of the
739
     * file, and passes the path to the archive.
739
     * file, and passes the path to the archive.
740
     *
740
     *
741
     */
741
     */
742
    public function test_add_storedfile_to_archive_file() {
742
    public function test_add_storedfile_to_archive_file(): void {
743
        $file = $this->get_stored_file('example content');
743
        $file = $this->get_stored_file('example content');
744
        $filepath = __LINE__;
744
        $filepath = __LINE__;
745
        $archivepath = 'example';
745
        $archivepath = 'example';
746
        $expectedresult = (object) [];
746
        $expectedresult = (object) [];
Línea 778... Línea 778...
778
     * Ensure that the add_to_curl_request function requires a local copy of the
778
     * Ensure that the add_to_curl_request function requires a local copy of the
779
     * file, and passes the path to curl_file_create.
779
     * file, and passes the path to curl_file_create.
780
     *
780
     *
781
     * @covers ::add_to_curl_request
781
     * @covers ::add_to_curl_request
782
     */
782
     */
783
    public function test_add_to_curl_request() {
783
    public function test_add_to_curl_request(): void {
784
        $file = $this->get_stored_file('example content');
784
        $file = $this->get_stored_file('example content');
785
        $filepath = __FILE__;
785
        $filepath = __FILE__;
786
        $archivepath = 'example';
786
        $archivepath = 'example';
787
        $key = 'myfile';
787
        $key = 'myfile';
Línea 802... Línea 802...
802
     * Ensure that test_get_imageinfo_not_image returns false if the file
802
     * Ensure that test_get_imageinfo_not_image returns false if the file
803
     * passed was deemed to not be an image.
803
     * passed was deemed to not be an image.
804
     *
804
     *
805
     * @covers ::get_imageinfo
805
     * @covers ::get_imageinfo
806
     */
806
     */
807
    public function test_get_imageinfo_not_image() {
807
    public function test_get_imageinfo_not_image(): void {
808
        $filecontent = 'example content';
808
        $filecontent = 'example content';
809
        $file = $this->get_stored_file($filecontent);
809
        $file = $this->get_stored_file($filecontent);
Línea 810... Línea 810...
810
 
810
 
811
        $fs = $this->get_testable_mock([
811
        $fs = $this->get_testable_mock([
Línea 823... Línea 823...
823
    /**
823
    /**
824
     * Ensure that test_get_imageinfo_not_image returns imageinfo.
824
     * Ensure that test_get_imageinfo_not_image returns imageinfo.
825
     *
825
     *
826
     * @covers ::get_imageinfo
826
     * @covers ::get_imageinfo
827
     */
827
     */
828
    public function test_get_imageinfo() {
828
    public function test_get_imageinfo(): void {
829
        $filepath = '/path/to/file';
829
        $filepath = '/path/to/file';
830
        $filecontent = 'example content';
830
        $filecontent = 'example content';
831
        $expectedresult = (object) [];
831
        $expectedresult = (object) [];
832
        $file = $this->get_stored_file($filecontent);
832
        $file = $this->get_stored_file($filecontent);
Línea 859... Línea 859...
859
     * Ensure that is_image_from_storedfile always returns false for an
859
     * Ensure that is_image_from_storedfile always returns false for an
860
     * empty file size.
860
     * empty file size.
861
     *
861
     *
862
     * @covers ::is_image_from_storedfile
862
     * @covers ::is_image_from_storedfile
863
     */
863
     */
864
    public function test_is_image_empty_filesize() {
864
    public function test_is_image_empty_filesize(): void {
865
        $filecontent = 'example content';
865
        $filecontent = 'example content';
866
        $file = $this->get_stored_file($filecontent, null, ['get_filesize']);
866
        $file = $this->get_stored_file($filecontent, null, ['get_filesize']);
Línea 867... Línea 867...
867
 
867
 
868
        $file->expects($this->once())
868
        $file->expects($this->once())
Línea 880... Línea 880...
880
     * @dataProvider is_image_from_storedfile_provider
880
     * @dataProvider is_image_from_storedfile_provider
881
     * @param   string  $mimetype Mimetype to test
881
     * @param   string  $mimetype Mimetype to test
882
     * @param   bool    $isimage Whether this mimetype should be detected as an image
882
     * @param   bool    $isimage Whether this mimetype should be detected as an image
883
     * @covers ::is_image_from_storedfile
883
     * @covers ::is_image_from_storedfile
884
     */
884
     */
885
    public function test_is_image_from_storedfile_mimetype($mimetype, $isimage) {
885
    public function test_is_image_from_storedfile_mimetype($mimetype, $isimage): void {
886
        $filecontent = 'example content';
886
        $filecontent = 'example content';
887
        $file = $this->get_stored_file($filecontent, null, ['get_mimetype']);
887
        $file = $this->get_stored_file($filecontent, null, ['get_mimetype']);
Línea 888... Línea 888...
888
 
888
 
889
        $file->expects($this->once())
889
        $file->expects($this->once())
Línea 898... Línea 898...
898
     * Test that get_imageinfo_from_path returns an appropriate response
898
     * Test that get_imageinfo_from_path returns an appropriate response
899
     * for an image.
899
     * for an image.
900
     *
900
     *
901
     * @covers ::get_imageinfo_from_path
901
     * @covers ::get_imageinfo_from_path
902
     */
902
     */
903
    public function test_get_imageinfo_from_path() {
903
    public function test_get_imageinfo_from_path(): void {
904
        $filepath = __DIR__ . "/fixtures/testimage.jpg";
904
        $filepath = __DIR__ . "/fixtures/testimage.jpg";
Línea 905... Línea 905...
905
 
905
 
906
        // Get the filesystem mock.
906
        // Get the filesystem mock.
Línea 919... Línea 919...
919
     * Test that get_imageinfo_from_path returns an appropriate response
919
     * Test that get_imageinfo_from_path returns an appropriate response
920
     * for a file which is not an image.
920
     * for a file which is not an image.
921
     *
921
     *
922
     * @covers ::get_imageinfo_from_path
922
     * @covers ::get_imageinfo_from_path
923
     */
923
     */
924
    public function test_get_imageinfo_from_path_no_image() {
924
    public function test_get_imageinfo_from_path_no_image(): void {
925
        $filepath = __FILE__;
925
        $filepath = __FILE__;
Línea 926... Línea 926...
926
 
926
 
927
        // Get the filesystem mock.
927
        // Get the filesystem mock.
Línea 935... Línea 935...
935
 
935
 
936
    /**
936
    /**
937
     * Test that get_imageinfo_from_path returns an appropriate response
937
     * Test that get_imageinfo_from_path returns an appropriate response
938
     * for an svg image with viewbox attribute.
938
     * for an svg image with viewbox attribute.
939
     */
939
     */
940
    public function test_get_imageinfo_from_path_svg_viewbox() {
940
    public function test_get_imageinfo_from_path_svg_viewbox(): void {
Línea 941... Línea 941...
941
        $filepath = __DIR__ . '/fixtures/testimage_viewbox.svg';
941
        $filepath = __DIR__ . '/fixtures/testimage_viewbox.svg';
942
 
942
 
Línea 956... Línea 956...
956
 
956
 
957
    /**
957
    /**
958
     * Test that get_imageinfo_from_path returns an appropriate response
958
     * Test that get_imageinfo_from_path returns an appropriate response
959
     * for an svg image with width and height attributes.
959
     * for an svg image with width and height attributes.
960
     */
960
     */
961
    public function test_get_imageinfo_from_path_svg_with_width_height() {
961
    public function test_get_imageinfo_from_path_svg_with_width_height(): void {
Línea 962... Línea 962...
962
        $filepath = __DIR__ . '/fixtures/testimage_width_height.svg';
962
        $filepath = __DIR__ . '/fixtures/testimage_width_height.svg';
963
 
963
 
Línea 977... Línea 977...
977
 
977
 
978
    /**
978
    /**
979
     * Test that get_imageinfo_from_path returns an appropriate response
979
     * Test that get_imageinfo_from_path returns an appropriate response
980
     * for an svg image without attributes.
980
     * for an svg image without attributes.
981
     */
981
     */
982
    public function test_get_imageinfo_from_path_svg_without_attribute() {
982
    public function test_get_imageinfo_from_path_svg_without_attribute(): void {
Línea 983... Línea 983...
983
        $filepath = __DIR__ . '/fixtures/testimage.svg';
983
        $filepath = __DIR__ . '/fixtures/testimage.svg';
984
 
984
 
Línea 998... Línea 998...
998
 
998
 
999
    /**
999
    /**
1000
     * Test that get_imageinfo_from_path returns an appropriate response
1000
     * Test that get_imageinfo_from_path returns an appropriate response
1001
     * for a file which is not an correct svg.
1001
     * for a file which is not an correct svg.
1002
     */
1002
     */
1003
    public function test_get_imageinfo_from_path_svg_invalid() {
1003
    public function test_get_imageinfo_from_path_svg_invalid(): void {
Línea 1004... Línea 1004...
1004
        $filepath = __DIR__ . '/fixtures/testimage_error.svg';
1004
        $filepath = __DIR__ . '/fixtures/testimage_error.svg';
1005
 
1005
 
Línea 1015... Línea 1015...
1015
    /**
1015
    /**
1016
     * Ensure that get_content_file_handle returns a valid file handle.
1016
     * Ensure that get_content_file_handle returns a valid file handle.
1017
     *
1017
     *
1018
     * @covers ::get_content_file_handle
1018
     * @covers ::get_content_file_handle
1019
     */
1019
     */
1020
    public function test_get_content_file_handle_default() {
1020
    public function test_get_content_file_handle_default(): void {
1021
        $filecontent = 'example content';
1021
        $filecontent = 'example content';
1022
        $file = $this->get_stored_file($filecontent);
1022
        $file = $this->get_stored_file($filecontent);
Línea 1023... Línea 1023...
1023
 
1023
 
1024
        $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']);
1024
        $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']);
Línea 1035... Línea 1035...
1035
    /**
1035
    /**
1036
     * Ensure that get_content_file_handle returns a valid file handle for a gz file.
1036
     * Ensure that get_content_file_handle returns a valid file handle for a gz file.
1037
     *
1037
     *
1038
     * @covers ::get_content_file_handle
1038
     * @covers ::get_content_file_handle
1039
     */
1039
     */
1040
    public function test_get_content_file_handle_gz() {
1040
    public function test_get_content_file_handle_gz(): void {
1041
        $filecontent = 'example content';
1041
        $filecontent = 'example content';
1042
        $file = $this->get_stored_file($filecontent);
1042
        $file = $this->get_stored_file($filecontent);
Línea 1043... Línea 1043...
1043
 
1043
 
1044
        $fs = $this->get_testable_mock(['get_local_path_from_storedfile']);
1044
        $fs = $this->get_testable_mock(['get_local_path_from_storedfile']);
Línea 1054... Línea 1054...
1054
    /**
1054
    /**
1055
     * Ensure that get_content_file_handle returns an exception when calling for a invalid file handle type.
1055
     * Ensure that get_content_file_handle returns an exception when calling for a invalid file handle type.
1056
     *
1056
     *
1057
     * @covers ::get_content_file_handle
1057
     * @covers ::get_content_file_handle
1058
     */
1058
     */
1059
    public function test_get_content_file_handle_invalid() {
1059
    public function test_get_content_file_handle_invalid(): void {
1060
        $filecontent = 'example content';
1060
        $filecontent = 'example content';
1061
        $file = $this->get_stored_file($filecontent);
1061
        $file = $this->get_stored_file($filecontent);
Línea 1062... Línea 1062...
1062
 
1062
 
1063
        $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']);
1063
        $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']);
Línea 1091... Línea 1091...
1091
     * Test that mimetype_from_hash returns the correct mimetype with
1091
     * Test that mimetype_from_hash returns the correct mimetype with
1092
     * a file whose filename suggests mimetype.
1092
     * a file whose filename suggests mimetype.
1093
     *
1093
     *
1094
     * @covers ::mimetype_from_hash
1094
     * @covers ::mimetype_from_hash
1095
     */
1095
     */
1096
    public function test_mimetype_from_hash_using_filename() {
1096
    public function test_mimetype_from_hash_using_filename(): void {
1097
        $filepath = '/path/to/file/not/currently/on/disk';
1097
        $filepath = '/path/to/file/not/currently/on/disk';
1098
        $filecontent = 'example content';
1098
        $filecontent = 'example content';
1099
        $filename = 'test.jpg';
1099
        $filename = 'test.jpg';
1100
        $contenthash = \file_storage::hash_from_string($filecontent);
1100
        $contenthash = \file_storage::hash_from_string($filecontent);
Línea 1110... Línea 1110...
1110
     * Test that mimetype_from_hash returns the correct mimetype with
1110
     * Test that mimetype_from_hash returns the correct mimetype with
1111
     * a locally available file whose filename does not suggest mimetype.
1111
     * a locally available file whose filename does not suggest mimetype.
1112
     *
1112
     *
1113
     * @covers ::mimetype_from_hash
1113
     * @covers ::mimetype_from_hash
1114
     */
1114
     */
1115
    public function test_mimetype_from_hash_using_file_content() {
1115
    public function test_mimetype_from_hash_using_file_content(): void {
1116
        $filecontent = 'example content';
1116
        $filecontent = 'example content';
1117
        $contenthash = \file_storage::hash_from_string($filecontent);
1117
        $contenthash = \file_storage::hash_from_string($filecontent);
1118
        $filename = 'example';
1118
        $filename = 'example';
Línea 1119... Línea 1119...
1119
 
1119
 
Línea 1129... Línea 1129...
1129
     * Test that mimetype_from_hash returns the correct mimetype with
1129
     * Test that mimetype_from_hash returns the correct mimetype with
1130
     * a remotely available file whose filename does not suggest mimetype.
1130
     * a remotely available file whose filename does not suggest mimetype.
1131
     *
1131
     *
1132
     * @covers ::mimetype_from_hash
1132
     * @covers ::mimetype_from_hash
1133
     */
1133
     */
1134
    public function test_mimetype_from_hash_using_file_content_remote() {
1134
    public function test_mimetype_from_hash_using_file_content_remote(): void {
1135
        $filepath = '/path/to/file/not/currently/on/disk';
1135
        $filepath = '/path/to/file/not/currently/on/disk';
1136
        $filecontent = 'example content';
1136
        $filecontent = 'example content';
1137
        $contenthash = \file_storage::hash_from_string($filecontent);
1137
        $contenthash = \file_storage::hash_from_string($filecontent);
1138
        $filename = 'example';
1138
        $filename = 'example';
Línea 1157... Línea 1157...
1157
     * Test that mimetype_from_storedfile returns the correct mimetype with
1157
     * Test that mimetype_from_storedfile returns the correct mimetype with
1158
     * a file whose filename suggests mimetype.
1158
     * a file whose filename suggests mimetype.
1159
     *
1159
     *
1160
     * @covers ::mimetype_from_storedfile
1160
     * @covers ::mimetype_from_storedfile
1161
     */
1161
     */
1162
    public function test_mimetype_from_storedfile_empty() {
1162
    public function test_mimetype_from_storedfile_empty(): void {
1163
        $file = $this->get_stored_file('');
1163
        $file = $this->get_stored_file('');
Línea 1164... Línea 1164...
1164
 
1164
 
1165
        $fs = $this->get_testable_mock();
1165
        $fs = $this->get_testable_mock();
1166
        $result = $fs->mimetype_from_storedfile($file);
1166
        $result = $fs->mimetype_from_storedfile($file);
Línea 1171... Línea 1171...
1171
     * Test that mimetype_from_storedfile returns the correct mimetype with
1171
     * Test that mimetype_from_storedfile returns the correct mimetype with
1172
     * a file whose filename suggests mimetype.
1172
     * a file whose filename suggests mimetype.
1173
     *
1173
     *
1174
     * @covers ::mimetype_from_storedfile
1174
     * @covers ::mimetype_from_storedfile
1175
     */
1175
     */
1176
    public function test_mimetype_from_storedfile_using_filename() {
1176
    public function test_mimetype_from_storedfile_using_filename(): void {
1177
        $filepath = '/path/to/file/not/currently/on/disk';
1177
        $filepath = '/path/to/file/not/currently/on/disk';
1178
        $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']);
1178
        $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']);
1179
        $fs->method('get_remote_path_from_storedfile')->willReturn($filepath);
1179
        $fs->method('get_remote_path_from_storedfile')->willReturn($filepath);
Línea 1180... Línea 1180...
1180
 
1180
 
Línea 1188... Línea 1188...
1188
     * Test that mimetype_from_storedfile returns the correct mimetype with
1188
     * Test that mimetype_from_storedfile returns the correct mimetype with
1189
     * a locally available file whose filename does not suggest mimetype.
1189
     * a locally available file whose filename does not suggest mimetype.
1190
     *
1190
     *
1191
     * @covers ::mimetype_from_storedfile
1191
     * @covers ::mimetype_from_storedfile
1192
     */
1192
     */
1193
    public function test_mimetype_from_storedfile_using_file_content() {
1193
    public function test_mimetype_from_storedfile_using_file_content(): void {
1194
        $filepath = __DIR__ . "/fixtures/testimage.jpg";
1194
        $filepath = __DIR__ . "/fixtures/testimage.jpg";
1195
        $fs = $this->get_testable_mock(['get_local_path_from_hash']);
1195
        $fs = $this->get_testable_mock(['get_local_path_from_hash']);
1196
        $fs->method('get_local_path_from_hash')->willReturn($filepath);
1196
        $fs->method('get_local_path_from_hash')->willReturn($filepath);
Línea 1197... Línea 1197...
1197
 
1197
 
Línea 1205... Línea 1205...
1205
     * Test that mimetype_from_storedfile returns the correct mimetype with
1205
     * Test that mimetype_from_storedfile returns the correct mimetype with
1206
     * a remotely available file whose filename does not suggest mimetype.
1206
     * a remotely available file whose filename does not suggest mimetype.
1207
     *
1207
     *
1208
     * @covers ::mimetype_from_storedfile
1208
     * @covers ::mimetype_from_storedfile
1209
     */
1209
     */
1210
    public function test_mimetype_from_storedfile_using_file_content_remote() {
1210
    public function test_mimetype_from_storedfile_using_file_content_remote(): void {
1211
        $filepath = __DIR__ . "/fixtures/testimage.jpg";
1211
        $filepath = __DIR__ . "/fixtures/testimage.jpg";
Línea 1212... Línea 1212...
1212
 
1212
 
1213
        $fs = $this->get_testable_mock([
1213
        $fs = $this->get_testable_mock([
1214
            'is_file_readable_locally_by_hash',
1214
            'is_file_readable_locally_by_hash',