Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 44... Línea 44...
44
     *
44
     *
45
     * @dataProvider export_data_provider
45
     * @dataProvider export_data_provider
46
     * @param   \stdClass  $data Data
46
     * @param   \stdClass  $data Data
47
     * @covers ::export_data
47
     * @covers ::export_data
48
     */
48
     */
49
    public function test_export_data($data) {
49
    public function test_export_data($data): void {
50
        $context = \context_system::instance();
50
        $context = \context_system::instance();
51
        $subcontext = [];
51
        $subcontext = [];
Línea 52... Línea 52...
52
 
52
 
53
        $writer = $this->get_writer_instance()
53
        $writer = $this->get_writer_instance()
Línea 69... Línea 69...
69
     *
69
     *
70
     * @dataProvider export_data_provider
70
     * @dataProvider export_data_provider
71
     * @param   \stdClass  $data Data
71
     * @param   \stdClass  $data Data
72
     * @covers ::export_data
72
     * @covers ::export_data
73
     */
73
     */
74
    public function test_export_data_different_context($data) {
74
    public function test_export_data_different_context($data): void {
75
        $context = \context_user::instance(\core_user::get_user_by_username('admin')->id);
75
        $context = \context_user::instance(\core_user::get_user_by_username('admin')->id);
76
        $subcontext = ['sub', 'context'];
76
        $subcontext = ['sub', 'context'];
Línea 77... Línea 77...
77
 
77
 
78
        $writer = $this->get_writer_instance()
78
        $writer = $this->get_writer_instance()
Línea 92... Línea 92...
92
    /**
92
    /**
93
     * Test that exported is saved within the correct directory locations.
93
     * Test that exported is saved within the correct directory locations.
94
     *
94
     *
95
     * @covers ::export_data
95
     * @covers ::export_data
96
     */
96
     */
97
    public function test_export_data_writes_to_multiple_context() {
97
    public function test_export_data_writes_to_multiple_context(): void {
98
        $subcontext = ['sub', 'context'];
98
        $subcontext = ['sub', 'context'];
Línea 99... Línea 99...
99
 
99
 
100
        $systemcontext = \context_system::instance();
100
        $systemcontext = \context_system::instance();
101
        $systemdata = (object) [
101
        $systemdata = (object) [
Línea 136... Línea 136...
136
    /**
136
    /**
137
     * Test that multiple writes to the same location cause the latest version to be written.
137
     * Test that multiple writes to the same location cause the latest version to be written.
138
     *
138
     *
139
     * @covers ::export_data
139
     * @covers ::export_data
140
     */
140
     */
141
    public function test_export_data_multiple_writes_same_context() {
141
    public function test_export_data_multiple_writes_same_context(): void {
142
        $subcontext = ['sub', 'context'];
142
        $subcontext = ['sub', 'context'];
Línea 143... Línea 143...
143
 
143
 
144
        $systemcontext = \context_system::instance();
144
        $systemcontext = \context_system::instance();
145
        $originaldata = (object) [
145
        $originaldata = (object) [
Línea 192... Línea 192...
192
     * @param   string  $key Key
192
     * @param   string  $key Key
193
     * @param   string  $value Value
193
     * @param   string  $value Value
194
     * @param   string  $description Description
194
     * @param   string  $description Description
195
     * @covers ::export_metadata
195
     * @covers ::export_metadata
196
     */
196
     */
197
    public function test_export_metadata($key, $value, $description) {
197
    public function test_export_metadata($key, $value, $description): void {
198
        $context = \context_system::instance();
198
        $context = \context_system::instance();
199
        $subcontext = ['a', 'b', 'c'];
199
        $subcontext = ['a', 'b', 'c'];
Línea 200... Línea 200...
200
 
200
 
201
        $writer = $this->get_writer_instance()
201
        $writer = $this->get_writer_instance()
Línea 217... Línea 217...
217
    /**
217
    /**
218
     * Test that metadata can be set additively.
218
     * Test that metadata can be set additively.
219
     *
219
     *
220
     * @covers ::export_metadata
220
     * @covers ::export_metadata
221
     */
221
     */
222
    public function test_export_metadata_additive() {
222
    public function test_export_metadata_additive(): void {
223
        $context = \context_system::instance();
223
        $context = \context_system::instance();
224
        $subcontext = [];
224
        $subcontext = [];
Línea 225... Línea 225...
225
 
225
 
Línea 253... Línea 253...
253
    /**
253
    /**
254
     * Test that metadata can be set additively.
254
     * Test that metadata can be set additively.
255
     *
255
     *
256
     * @covers ::export_metadata
256
     * @covers ::export_metadata
257
     */
257
     */
258
    public function test_export_metadata_to_multiple_contexts() {
258
    public function test_export_metadata_to_multiple_contexts(): void {
259
        $systemcontext = \context_system::instance();
259
        $systemcontext = \context_system::instance();
260
        $usercontext = \context_user::instance(\core_user::get_user_by_username('admin')->id);
260
        $usercontext = \context_user::instance(\core_user::get_user_by_username('admin')->id);
261
        $subcontext = [];
261
        $subcontext = [];
Línea 262... Línea 262...
262
 
262
 
Línea 331... Línea 331...
331
    /**
331
    /**
332
     * Exporting a single stored_file should cause that file to be output in the files directory.
332
     * Exporting a single stored_file should cause that file to be output in the files directory.
333
     *
333
     *
334
     * @covers ::export_area_files
334
     * @covers ::export_area_files
335
     */
335
     */
336
    public function test_export_area_files() {
336
    public function test_export_area_files(): void {
337
        $this->resetAfterTest();
337
        $this->resetAfterTest();
338
        $context = \context_system::instance();
338
        $context = \context_system::instance();
339
        $fs = get_file_storage();
339
        $fs = get_file_storage();
Línea 340... Línea 340...
340
 
340
 
Línea 437... Línea 437...
437
     * @param   string  $filename File name
437
     * @param   string  $filename File name
438
     * @param   string  $content Content
438
     * @param   string  $content Content
439
     *
439
     *
440
     * @covers ::export_file
440
     * @covers ::export_file
441
     */
441
     */
442
    public function test_export_file($filearea, $itemid, $filepath, $filename, $content) {
442
    public function test_export_file($filearea, $itemid, $filepath, $filename, $content): void {
443
        $this->resetAfterTest();
443
        $this->resetAfterTest();
444
        $context = \context_system::instance();
444
        $context = \context_system::instance();
445
        $filenamepath = '/' . $filearea . '/' . ($itemid ? '_' . $itemid : '') . $filepath . $filename;
445
        $filenamepath = '/' . $filearea . '/' . ($itemid ? '_' . $itemid : '') . $filepath . $filename;
Línea 446... Línea 446...
446
 
446
 
Línea 534... Línea 534...
534
     * @param   string      $key Key
534
     * @param   string      $key Key
535
     * @param   string      $value Value
535
     * @param   string      $value Value
536
     * @param   string      $desc Description
536
     * @param   string      $desc Description
537
     * @covers ::export_user_preference
537
     * @covers ::export_user_preference
538
     */
538
     */
539
    public function test_export_user_preference_context_user($component, $key, $value, $desc) {
539
    public function test_export_user_preference_context_user($component, $key, $value, $desc): void {
540
        $admin = \core_user::get_user_by_username('admin');
540
        $admin = \core_user::get_user_by_username('admin');
Línea 541... Línea 541...
541
 
541
 
Línea 542... Línea 542...
542
        $writer = $this->get_writer_instance();
542
        $writer = $this->get_writer_instance();
Línea 567... Línea 567...
567
     * @param   string      $key Key
567
     * @param   string      $key Key
568
     * @param   string      $value Value
568
     * @param   string      $value Value
569
     * @param   string      $desc Description
569
     * @param   string      $desc Description
570
     * @covers ::export_user_preference
570
     * @covers ::export_user_preference
571
     */
571
     */
572
    public function test_export_user_preference_context_coursecat($component, $key, $value, $desc) {
572
    public function test_export_user_preference_context_coursecat($component, $key, $value, $desc): void {
573
        global $DB;
573
        global $DB;
Línea 574... Línea 574...
574
 
574
 
575
        $categories = $DB->get_records('course_categories');
575
        $categories = $DB->get_records('course_categories');
Línea 601... Línea 601...
601
     * @param   string      $key Key
601
     * @param   string      $key Key
602
     * @param   string      $value Value
602
     * @param   string      $value Value
603
     * @param   string      $desc Description
603
     * @param   string      $desc Description
604
     * @covers ::export_user_preference
604
     * @covers ::export_user_preference
605
     */
605
     */
606
    public function test_export_user_preference_context_course($component, $key, $value, $desc) {
606
    public function test_export_user_preference_context_course($component, $key, $value, $desc): void {
607
        global $DB;
607
        global $DB;
Línea 608... Línea 608...
608
 
608
 
Línea 609... Línea 609...
609
        $this->resetAfterTest();
609
        $this->resetAfterTest();
Línea 636... Línea 636...
636
     * @param   string      $key Key
636
     * @param   string      $key Key
637
     * @param   string      $value Value
637
     * @param   string      $value Value
638
     * @param   string      $desc Description
638
     * @param   string      $desc Description
639
     * @covers ::export_user_preference
639
     * @covers ::export_user_preference
640
     */
640
     */
641
    public function test_export_user_preference_context_module($component, $key, $value, $desc) {
641
    public function test_export_user_preference_context_module($component, $key, $value, $desc): void {
642
        global $DB;
642
        global $DB;
Línea 643... Línea 643...
643
 
643
 
Línea 644... Línea 644...
644
        $this->resetAfterTest();
644
        $this->resetAfterTest();
Línea 672... Línea 672...
672
     * @param   string      $key Key
672
     * @param   string      $key Key
673
     * @param   string      $value Value
673
     * @param   string      $value Value
674
     * @param   string      $desc Description
674
     * @param   string      $desc Description
675
     * @covers ::export_user_preference
675
     * @covers ::export_user_preference
676
     */
676
     */
677
    public function test_export_user_preference_context_block($component, $key, $value, $desc) {
677
    public function test_export_user_preference_context_block($component, $key, $value, $desc): void {
678
        global $DB;
678
        global $DB;
Línea 679... Línea 679...
679
 
679
 
680
        $blocks = $DB->get_records('block_instances');
680
        $blocks = $DB->get_records('block_instances');
Línea 703... Línea 703...
703
     * same parent context should generate two different context paths and export
703
     * same parent context should generate two different context paths and export
704
     * files.
704
     * files.
705
     *
705
     *
706
     * @covers ::export_user_preference
706
     * @covers ::export_user_preference
707
     */
707
     */
708
    public function test_export_user_preference_context_block_multiple_instances() {
708
    public function test_export_user_preference_context_block_multiple_instances(): void {
709
        $this->resetAfterTest();
709
        $this->resetAfterTest();
Línea 710... Línea 710...
710
 
710
 
711
        $generator = $this->getDataGenerator();
711
        $generator = $this->getDataGenerator();
712
        $course = $generator->create_course();
712
        $course = $generator->create_course();
Línea 765... Línea 765...
765
     * @param   string      $value Value
765
     * @param   string      $value Value
766
     * @param   string      $desc Description
766
     * @param   string      $desc Description
767
     *
767
     *
768
     * @covers ::export_user_preference
768
     * @covers ::export_user_preference
769
     */
769
     */
770
    public function test_export_user_preference_context_system($component, $key, $value, $desc) {
770
    public function test_export_user_preference_context_system($component, $key, $value, $desc): void {
771
        $context = \context_system::instance();
771
        $context = \context_system::instance();
772
        $writer = $this->get_writer_instance()
772
        $writer = $this->get_writer_instance()
773
            ->set_context($context)
773
            ->set_context($context)
774
            ->export_user_preference($component, $key, $value, $desc);
774
            ->export_user_preference($component, $key, $value, $desc);
Línea 789... Línea 789...
789
    /**
789
    /**
790
     * User preferences can be exported against the system.
790
     * User preferences can be exported against the system.
791
     *
791
     *
792
     * @covers ::export_user_preference
792
     * @covers ::export_user_preference
793
     */
793
     */
794
    public function test_export_multiple_user_preference_context_system() {
794
    public function test_export_multiple_user_preference_context_system(): void {
795
        $context = \context_system::instance();
795
        $context = \context_system::instance();
796
        $writer = $this->get_writer_instance();
796
        $writer = $this->get_writer_instance();
797
        $component = 'core_privacy';
797
        $component = 'core_privacy';
Línea 798... Línea 798...
798
 
798
 
Línea 823... Línea 823...
823
    /**
823
    /**
824
     * User preferences can be exported against the system.
824
     * User preferences can be exported against the system.
825
     *
825
     *
826
     * @covers ::export_user_preference
826
     * @covers ::export_user_preference
827
     */
827
     */
828
    public function test_export_user_preference_replace() {
828
    public function test_export_user_preference_replace(): void {
829
        $context = \context_system::instance();
829
        $context = \context_system::instance();
830
        $writer = $this->get_writer_instance();
830
        $writer = $this->get_writer_instance();
831
        $component = 'core_privacy';
831
        $component = 'core_privacy';
832
        $key = 'key';
832
        $key = 'key';
Línea 886... Línea 886...
886
     *
886
     *
887
     * @dataProvider unescaped_unicode_export_provider
887
     * @dataProvider unescaped_unicode_export_provider
888
     * @param string $text
888
     * @param string $text
889
     * @covers ::export_data
889
     * @covers ::export_data
890
     */
890
     */
891
    public function test_export_data_unescaped_unicode($text) {
891
    public function test_export_data_unescaped_unicode($text): void {
892
        $context = \context_system::instance();
892
        $context = \context_system::instance();
893
        $subcontext = [];
893
        $subcontext = [];
894
        $data = (object) ['key' => $text];
894
        $data = (object) ['key' => $text];
Línea 895... Línea 895...
895
 
895
 
Línea 913... Línea 913...
913
     *
913
     *
914
     * @dataProvider unescaped_unicode_export_provider
914
     * @dataProvider unescaped_unicode_export_provider
915
     * @param string $text
915
     * @param string $text
916
     * @covers ::export_metadata
916
     * @covers ::export_metadata
917
     */
917
     */
918
    public function test_export_metadata_unescaped_unicode($text) {
918
    public function test_export_metadata_unescaped_unicode($text): void {
919
        $context = \context_system::instance();
919
        $context = \context_system::instance();
920
        $subcontext = ['a', 'b', 'c'];
920
        $subcontext = ['a', 'b', 'c'];
Línea 921... Línea 921...
921
 
921
 
922
        $writer = $this->get_writer_instance()
922
        $writer = $this->get_writer_instance()
Línea 941... Línea 941...
941
     *
941
     *
942
     * @dataProvider unescaped_unicode_export_provider
942
     * @dataProvider unescaped_unicode_export_provider
943
     * @param string $text
943
     * @param string $text
944
     * @covers ::export_related_data
944
     * @covers ::export_related_data
945
     */
945
     */
946
    public function test_export_related_data_unescaped_unicode($text) {
946
    public function test_export_related_data_unescaped_unicode($text): void {
947
        $context = \context_system::instance();
947
        $context = \context_system::instance();
948
        $subcontext = [];
948
        $subcontext = [];
949
        $data = (object) ['key' => $text];
949
        $data = (object) ['key' => $text];
Línea 950... Línea 950...
950
 
950
 
Línea 966... Línea 966...
966
    /**
966
    /**
967
     * Test that exported related data name is properly cleaned
967
     * Test that exported related data name is properly cleaned
968
     *
968
     *
969
     * @covers ::export_related_data
969
     * @covers ::export_related_data
970
     */
970
     */
971
    public function test_export_related_data_clean_name() {
971
    public function test_export_related_data_clean_name(): void {
972
        $context = \context_system::instance();
972
        $context = \context_system::instance();
973
        $subcontext = [];
973
        $subcontext = [];
974
        $data = (object) ['foo' => 'bar'];
974
        $data = (object) ['foo' => 'bar'];
Línea 975... Línea 975...
975
 
975
 
Línea 996... Línea 996...
996
     *
996
     *
997
     * @dataProvider unescaped_unicode_export_provider
997
     * @dataProvider unescaped_unicode_export_provider
998
     * @param string $text
998
     * @param string $text
999
     * @covers ::export_user_preference
999
     * @covers ::export_user_preference
1000
     */
1000
     */
1001
    public function test_export_user_preference_unescaped_unicode($text) {
1001
    public function test_export_user_preference_unescaped_unicode($text): void {
1002
        $context = \context_system::instance();
1002
        $context = \context_system::instance();
1003
        $component = 'core_privacy';
1003
        $component = 'core_privacy';
Línea 1004... Línea 1004...
1004
 
1004
 
1005
        $writer = $this->get_writer_instance()
1005
        $writer = $this->get_writer_instance()
Línea 1033... Línea 1033...
1033
    /**
1033
    /**
1034
     * Test that exported data subcontext is properly cleaned
1034
     * Test that exported data subcontext is properly cleaned
1035
     *
1035
     *
1036
     * @covers ::export_data
1036
     * @covers ::export_data
1037
     */
1037
     */
1038
    public function test_export_data_clean_subcontext() {
1038
    public function test_export_data_clean_subcontext(): void {
1039
        $context = \context_system::instance();
1039
        $context = \context_system::instance();
1040
        $subcontext = ['Something/weird', 'More/bad:>', 'Bad&chars:>'];
1040
        $subcontext = ['Something/weird', 'More/bad:>', 'Bad&chars:>'];
1041
        $data = (object) ['foo' => 'bar'];
1041
        $data = (object) ['foo' => 'bar'];
Línea 1042... Línea 1042...
1042
 
1042
 
Línea 1062... Línea 1062...
1062
     * @param string $expected
1062
     * @param string $expected
1063
     * @param string $text
1063
     * @param string $text
1064
     *
1064
     *
1065
     * @covers ::export_data
1065
     * @covers ::export_data
1066
     */
1066
     */
1067
    public function test_export_data_long_filename($longtext, $expected, $text) {
1067
    public function test_export_data_long_filename($longtext, $expected, $text): void {
1068
        $context = \context_system::instance();
1068
        $context = \context_system::instance();
1069
        $subcontext = [$longtext];
1069
        $subcontext = [$longtext];
1070
        $data = (object) ['key' => $text];
1070
        $data = (object) ['key' => $text];
Línea 1071... Línea 1071...
1071
 
1071
 
Línea 1094... Línea 1094...
1094
     * @param string $expected
1094
     * @param string $expected
1095
     * @param string $text
1095
     * @param string $text
1096
     *
1096
     *
1097
     * @covers ::export_related_data
1097
     * @covers ::export_related_data
1098
     */
1098
     */
1099
    public function test_export_related_data_long_filename($longtext, $expected, $text) {
1099
    public function test_export_related_data_long_filename($longtext, $expected, $text): void {
1100
        $context = \context_system::instance();
1100
        $context = \context_system::instance();
1101
        $subcontext = [$longtext];
1101
        $subcontext = [$longtext];
1102
        $data = (object) ['key' => $text];
1102
        $data = (object) ['key' => $text];
Línea 1103... Línea 1103...
1103
 
1103
 
Línea 1124... Línea 1124...
1124
     * @dataProvider long_filename_provider
1124
     * @dataProvider long_filename_provider
1125
     * @param string $longtext
1125
     * @param string $longtext
1126
     * @param string $expected
1126
     * @param string $expected
1127
     * @param string $text
1127
     * @param string $text
1128
     */
1128
     */
1129
    public function test_export_metadata_long_filename($longtext, $expected, $text) {
1129
    public function test_export_metadata_long_filename($longtext, $expected, $text): void {
1130
        $context = \context_system::instance();
1130
        $context = \context_system::instance();
1131
        $subcontext = [$longtext];
1131
        $subcontext = [$longtext];
1132
        $data = (object) ['key' => $text];
1132
        $data = (object) ['key' => $text];
Línea 1133... Línea 1133...
1133
 
1133
 
Línea 1156... Línea 1156...
1156
     * @dataProvider long_filename_provider
1156
     * @dataProvider long_filename_provider
1157
     * @param string $longtext
1157
     * @param string $longtext
1158
     * @param string $expected
1158
     * @param string $expected
1159
     * @param string $text
1159
     * @param string $text
1160
     */
1160
     */
1161
    public function test_export_user_preference_long_filename($longtext, $expected, $text) {
1161
    public function test_export_user_preference_long_filename($longtext, $expected, $text): void {
1162
        $this->resetAfterTest();
1162
        $this->resetAfterTest();
Línea 1163... Línea 1163...
1163
 
1163
 
1164
        if (!array_key_exists('json', core_filetypes::get_types())) {
1164
        if (!array_key_exists('json', core_filetypes::get_types())) {
1165
            // Add json as mime type to avoid lose the extension when shortening filenames.
1165
            // Add json as mime type to avoid lose the extension when shortening filenames.
Línea 1271... Línea 1271...
1271
     * @param int $itemid Which item those files belong to.
1271
     * @param int $itemid Which item those files belong to.
1272
     * @param string $input Raw text as stored in the database.
1272
     * @param string $input Raw text as stored in the database.
1273
     * @param string $expectedoutput Expected output of URL rewriting.
1273
     * @param string $expectedoutput Expected output of URL rewriting.
1274
     * @covers ::rewrite_pluginfile_urls
1274
     * @covers ::rewrite_pluginfile_urls
1275
     */
1275
     */
1276
    public function test_rewrite_pluginfile_urls($filearea, $itemid, $input, $expectedoutput) {
1276
    public function test_rewrite_pluginfile_urls($filearea, $itemid, $input, $expectedoutput): void {
Línea 1277... Línea 1277...
1277
 
1277
 
1278
        $writer = $this->get_writer_instance();
1278
        $writer = $this->get_writer_instance();
Línea 1279... Línea 1279...
1279
        $writer->set_context(\context_system::instance());
1279
        $writer->set_context(\context_system::instance());
Línea 1321... Línea 1321...
1321
                '<a href="System _.1/_files/post_content/_9889/embedded/docs/muhehe.exe">Click here!</a>',
1321
                '<a href="System _.1/_files/post_content/_9889/embedded/docs/muhehe.exe">Click here!</a>',
1322
            ],
1322
            ],
1323
        ];
1323
        ];
1324
    }
1324
    }
Línea 1325... Línea 1325...
1325
 
1325
 
1326
    public function test_export_html_functions() {
1326
    public function test_export_html_functions(): void {
Línea 1327... Línea 1327...
1327
        $this->resetAfterTest();
1327
        $this->resetAfterTest();
Línea 1328... Línea 1328...
1328
 
1328