@@ -43,14 +43,7 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile extends WP_UnitTestC
4343 */
4444 public static $ exports_dir ;
4545
46- /**
47- * Create fixtures that are shared by multiple test cases.
48- *
49- * @since 5.2.0
50- *
51- * @param WP_UnitTest_Factory $factory The base factory object.
52- */
53- public static function wpSetUpBeforeClass ( WP_UnitTest_Factory $ factory ) {
46+ public static function setUpBeforeClass () {
5447 self ::$ export_request_id = wp_create_user_request ( 'export-requester@example.com ' , 'export_personal_data ' );
5548 self ::$ exports_dir = wp_privacy_exports_dir ();
5649 }
@@ -98,63 +91,6 @@ public function tearDown() {
9891 parent ::tearDown ();
9992 }
10093
101- /**
102- * Stores the name of the export zip file to check the file is actually created.
103- *
104- * @since 5.2.0
105- *
106- * @param string $archive_name Created export zip file path.
107- */
108- public function action_wp_privacy_personal_data_export_file_created ( $ archive_name ) {
109- $ this ->export_file_name = $ archive_name ;
110- }
111-
112- /**
113- * Removes the privacy exports directory, including files and subdirectories.
114- *
115- * Ignores hidden files and has upper limit of nested levels, because of `list_files()`.
116- *
117- * @since 5.2.0
118- *
119- * @return bool Whether the privacy exports directory was removed.
120- */
121- private function remove_exports_dir () {
122- /**
123- * The `$exports_dir` will be a file after the `test_detect_cannot_create_folder()` test method, or,
124- * if an incorrect value is returned to the `wp_privacy_exports_dir` filter.
125- */
126- if ( is_file ( untrailingslashit ( self ::$ exports_dir ) ) ) {
127- wp_delete_file ( untrailingslashit ( self ::$ exports_dir ) );
128-
129- return ! is_file ( untrailingslashit ( self ::$ exports_dir ) );
130- }
131-
132- if ( ! is_dir ( self ::$ exports_dir ) ) {
133- return true ;
134- }
135-
136- chmod ( self ::$ exports_dir , 0755 );
137-
138- $ files = list_files ( self ::$ exports_dir );
139-
140- // Delete files first, then delete subdirectories.
141- foreach ( $ files as $ file ) {
142- if ( is_file ( $ file ) ) {
143- wp_delete_file ( $ file );
144- }
145- }
146-
147- foreach ( $ files as $ file ) {
148- if ( is_dir ( $ file ) ) {
149- rmdir ( $ file );
150- }
151- }
152-
153- rmdir ( self ::$ exports_dir );
154-
155- return ! is_dir ( self ::$ exports_dir );
156- }
157-
15894 /**
15995 * When a remove request ID is passed to the export function an error should be displayed.
16096 *
@@ -215,17 +151,15 @@ public function test_detect_cannot_create_folder() {
215151
216152 /**
217153 * @dataProvider dataInvalidExportDataGrouped
154+ *
155+ * @param mixed $groups '_export_data_grouped' post meta value.
156+ * @param string $type Expected groups data type.
218157 */
219158 public function test_invalid_export_data_grouped_type_error ( $ groups , $ type ) {
220159 update_post_meta ( self ::$ export_request_id , '_export_data_grouped ' , $ groups );
221160
222161 $ this ->expectException ( 'WPDieException ' );
223- $ this ->expectOutputString (
224- sprintf (
225- '{"success":false,"data":"Warning: array_merge(): Expected parameter 2 to be an array, %s given."} ' ,
226- $ type
227- )
228- );
162+ $ this ->expectOutputString ( '{"success":false,"data":"Warning: array_merge(): Expected parameter 2 to be an array, ' . $ type . ' given."} ' );
229163
230164 wp_privacy_generate_personal_data_export_file ( self ::$ export_request_id );
231165 }
@@ -321,7 +255,6 @@ public function test_can_succeed() {
321255 * Test the export JSON file has all the expected parts.
322256 *
323257 * @dataProvider dataExportContents
324- * @ticket 49029
325258 */
326259 public function test_json_contents ( $ export_data_grouped ) {
327260 $ report_dir = $ this ->setup_export_contents_test ( $ export_data_grouped );
@@ -699,4 +632,61 @@ public function dataExportContents() {
699632 ),
700633 );
701634 }
635+
636+ /**
637+ * Stores the name of the export zip file to check the file is actually created.
638+ *
639+ * @since 5.2.0
640+ *
641+ * @param string $archive_name Created export zip file path.
642+ */
643+ public function action_wp_privacy_personal_data_export_file_created ( $ archive_name ) {
644+ $ this ->export_file_name = $ archive_name ;
645+ }
646+
647+ /**
648+ * Removes the privacy exports directory, including files and subdirectories.
649+ *
650+ * Ignores hidden files and has upper limit of nested levels, because of `list_files()`.
651+ *
652+ * @since 5.2.0
653+ *
654+ * @return bool Whether the privacy exports directory was removed.
655+ */
656+ private function remove_exports_dir () {
657+ /**
658+ * The `$exports_dir` will be a file after the `test_detect_cannot_create_folder()` test method, or,
659+ * if an incorrect value is returned to the `wp_privacy_exports_dir` filter.
660+ */
661+ if ( is_file ( untrailingslashit ( self ::$ exports_dir ) ) ) {
662+ wp_delete_file ( untrailingslashit ( self ::$ exports_dir ) );
663+
664+ return ! is_file ( untrailingslashit ( self ::$ exports_dir ) );
665+ }
666+
667+ if ( ! is_dir ( self ::$ exports_dir ) ) {
668+ return true ;
669+ }
670+
671+ chmod ( self ::$ exports_dir , 0755 );
672+
673+ $ files = list_files ( self ::$ exports_dir );
674+
675+ // Delete files first, then delete subdirectories.
676+ foreach ( $ files as $ file ) {
677+ if ( is_file ( $ file ) ) {
678+ wp_delete_file ( $ file );
679+ }
680+ }
681+
682+ foreach ( $ files as $ file ) {
683+ if ( is_dir ( $ file ) ) {
684+ rmdir ( $ file );
685+ }
686+ }
687+
688+ rmdir ( self ::$ exports_dir );
689+
690+ return ! is_dir ( self ::$ exports_dir );
691+ }
702692}
0 commit comments