@@ -15,24 +15,23 @@ protected function setUp(): void {
15
15
}
16
16
}
17
17
18
- /**
19
- * @before
18
+ /**
19
+ * @before
20
20
*
21
21
* TODO: Run each test in a fresh Playground instance instead of sharing the global
22
22
* state like this.
23
- */
24
- public function clean_up_uploads (): void
25
- {
26
- $ files = glob ( '/wordpress/wp-content/uploads/* ' );
27
- foreach ( $ files as $ file ) {
28
- if ( is_dir ( $ file ) ) {
29
- array_map ( 'unlink ' , glob ( "$ file/*.* " ) );
30
- rmdir ( $ file );
31
- } else {
32
- unlink ( $ file );
33
- }
34
- }
35
- }
23
+ */
24
+ public function clean_up_uploads (): void {
25
+ $ files = glob ( '/wordpress/wp-content/uploads/* ' );
26
+ foreach ( $ files as $ file ) {
27
+ if ( is_dir ( $ file ) ) {
28
+ array_map ( 'unlink ' , glob ( "$ file/*.* " ) );
29
+ rmdir ( $ file );
30
+ } else {
31
+ unlink ( $ file );
32
+ }
33
+ }
34
+ }
36
35
37
36
public function test_import_simple_wxr () {
38
37
$ import = data_liberation_import ( __DIR__ . '/wxr/small-export.xml ' );
@@ -44,7 +43,7 @@ public function test_frontloading() {
44
43
$ wxr_path = __DIR__ . '/wxr/frontloading-1-attachment.xml ' ;
45
44
$ importer = WP_Stream_Importer::create_for_wxr_file ( $ wxr_path );
46
45
$ this ->skip_to_stage ( $ importer , WP_Stream_Importer::STAGE_FRONTLOAD_ASSETS );
47
- while ( $ importer ->next_step () ) {
46
+ while ( $ importer ->next_step () ) {
48
47
// noop
49
48
}
50
49
$ files = glob ( '/wordpress/wp-content/uploads/* ' );
@@ -57,17 +56,17 @@ public function test_resume_frontloading() {
57
56
$ importer = WP_Stream_Importer::create_for_wxr_file ( $ wxr_path );
58
57
$ this ->skip_to_stage ( $ importer , WP_Stream_Importer::STAGE_FRONTLOAD_ASSETS );
59
58
60
- $ progress_url = null ;
59
+ $ progress_url = null ;
61
60
$ progress_value = null ;
62
- for ( $ i = 0 ; $ i < 20 ; ++$ i ) {
61
+ for ( $ i = 0 ; $ i < 20 ; ++$ i ) {
63
62
$ importer ->next_step ();
64
63
$ progress = $ importer ->get_frontloading_progress ();
65
- if ( count ( $ progress ) === 0 ) {
64
+ if ( count ( $ progress ) === 0 ) {
66
65
continue ;
67
66
}
68
- $ progress_url = array_keys ( $ progress )[0 ];
67
+ $ progress_url = array_keys ( $ progress )[0 ];
69
68
$ progress_value = array_values ( $ progress )[0 ];
70
- if ( null === $ progress_value ['received ' ] ) {
69
+ if ( null === $ progress_value ['received ' ] ) {
71
70
continue ;
72
71
}
73
72
break ;
@@ -78,22 +77,22 @@ public function test_resume_frontloading() {
78
77
$ this ->assertEquals ( 'https://wpthemetestdata.files.wordpress.com/2008/06/canola2.jpg ' , $ progress_url );
79
78
$ this ->assertGreaterThan ( 0 , $ progress_value ['total ' ] );
80
79
81
- $ cursor = $ importer ->get_reentrancy_cursor ();
82
- $ importer = WP_Stream_Importer::create_for_wxr_file ( $ wxr_path , [] , $ cursor );
80
+ $ cursor = $ importer ->get_reentrancy_cursor ();
81
+ $ importer = WP_Stream_Importer::create_for_wxr_file ( $ wxr_path , array () , $ cursor );
83
82
// Rewind back to the entity we were on.
84
83
$ this ->assertTrue ( $ importer ->next_step () );
85
84
86
85
// Restart the download of the same entity – from scratch.
87
- $ progress_value = [] ;
88
- for ( $ i = 0 ; $ i < 20 ; ++$ i ) {
86
+ $ progress_value = array () ;
87
+ for ( $ i = 0 ; $ i < 20 ; ++$ i ) {
89
88
$ importer ->next_step ();
90
89
$ progress = $ importer ->get_frontloading_progress ();
91
- if ( count ( $ progress ) === 0 ) {
90
+ if ( count ( $ progress ) === 0 ) {
92
91
continue ;
93
92
}
94
- $ progress_url = array_keys ( $ progress )[0 ];
93
+ $ progress_url = array_keys ( $ progress )[0 ];
95
94
$ progress_value = array_values ( $ progress )[0 ];
96
- if ( null === $ progress_value ['received ' ] ) {
95
+ if ( null === $ progress_value ['received ' ] ) {
97
96
continue ;
98
97
}
99
98
break ;
@@ -105,17 +104,17 @@ public function test_resume_frontloading() {
105
104
}
106
105
107
106
/**
108
- *
107
+ * Test resume entity import.
109
108
*/
110
109
public function test_resume_entity_import () {
111
110
$ wxr_path = __DIR__ . '/wxr/entities-options-and-posts.xml ' ;
112
111
$ importer = WP_Stream_Importer::create_for_wxr_file ( $ wxr_path );
113
112
$ this ->skip_to_stage ( $ importer , WP_Stream_Importer::STAGE_IMPORT_ENTITIES );
114
113
115
- for ( $ i = 0 ; $ i < 11 ; ++$ i ) {
114
+ for ( $ i = 0 ; $ i < 11 ; ++$ i ) {
116
115
$ this ->assertTrue ( $ importer ->next_step () );
117
- $ cursor = $ importer ->get_reentrancy_cursor ();
118
- $ importer = WP_Stream_Importer::create_for_wxr_file ( $ wxr_path , [] , $ cursor );
116
+ $ cursor = $ importer ->get_reentrancy_cursor ();
117
+ $ importer = WP_Stream_Importer::create_for_wxr_file ( $ wxr_path , array () , $ cursor );
119
118
// Rewind back to the entity we were on.
120
119
// Note this means we may attempt to insert it twice. It's
121
120
// the importer's job to detect that and skip the duplicate
@@ -125,6 +124,18 @@ public function test_resume_entity_import() {
125
124
$ this ->assertFalse ( $ importer ->next_step () );
126
125
}
127
126
127
+ public function test_sort_categories () {
128
+ $ wxr_path = __DIR__ . '/wxr/mixed-categories.xml ' ;
129
+ $ importer = WP_Stream_Importer::create_for_wxr_file ( $ wxr_path );
130
+ $ this ->skip_to_stage ( $ importer , WP_Stream_Importer::STAGE_TOPOLOGICAL_SORT );
131
+
132
+ while ( $ importer ->next_step () ) {
133
+ if ( $ importer ->get_next_stage () === WP_Stream_Importer::STAGE_FRONTLOAD_ASSETS ) {
134
+ break ;
135
+ }
136
+ }
137
+ }
138
+
128
139
private function skip_to_stage ( WP_Stream_Importer $ importer , string $ stage ) {
129
140
do {
130
141
while ( $ importer ->next_step () ) {
0 commit comments