Changeset 42343 for trunk/tests/phpunit/tests/import/parser.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/import/parser.php
r41169 r42343 10 10 parent::setUp(); 11 11 12 if ( ! defined( 'WP_IMPORTING' ) ) 12 if ( ! defined( 'WP_IMPORTING' ) ) { 13 13 define( 'WP_IMPORTING', true ); 14 15 if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) 14 } 15 16 if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) { 16 17 define( 'WP_LOAD_IMPORTERS', true ); 18 } 17 19 18 20 if ( ! file_exists( DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' ) ) { … … 29 31 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML' ) as $p ) { 30 32 $parser = new $p; 31 $result = $parser->parse( $file);33 $result = $parser->parse( $file ); 32 34 $this->assertWPError( $result ); 33 35 $this->assertEquals( 'There was an error when reading this WXR file', $result->get_error_message() ); … … 54 56 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) { 55 57 $message = $p . ' failed'; 56 $parser = new $p;57 $result = $parser->parse( $file );58 $parser = new $p; 59 $result = $parser->parse( $file ); 58 60 59 61 $this->assertTrue( is_array( $result ), $message ); 60 62 $this->assertEquals( 'http://localhost/', $result['base_url'], $message ); 61 $this->assertEquals( array( 62 'author_id' => 2, 63 'author_login' => 'john', 64 'author_email' => 'johndoe@example.org', 65 'author_display_name' => 'John Doe', 66 'author_first_name' => 'John', 67 'author_last_name' => 'Doe' 68 ), $result['authors']['john'], $message ); 69 $this->assertEquals( array( 70 'term_id' => 3, 71 'category_nicename' => 'alpha', 72 'category_parent' => '', 73 'cat_name' => 'alpha', 74 'category_description' => 'The alpha category' 75 ), $result['categories'][0], $message ); 76 $this->assertEquals( array( 77 'term_id' => 22, 78 'tag_slug' => 'clippable', 79 'tag_name' => 'Clippable', 80 'tag_description' => 'The Clippable post_tag' 81 ), $result['tags'][0], $message ); 82 $this->assertEquals( array( 83 'term_id' => 40, 84 'term_taxonomy' => 'post_tax', 85 'slug' => 'bieup', 86 'term_parent' => '', 87 'term_name' => 'bieup', 88 'term_description' => 'The bieup post_tax' 89 ), $result['terms'][0], $message ); 90 91 $this->assertEquals( 2, count($result['posts']), $message ); 92 $this->assertEquals( 19, count($result['posts'][0]), $message ); 93 $this->assertEquals( 18, count($result['posts'][1]), $message ); 94 $this->assertEquals( array( 95 array( 'name' => 'alpha', 'slug' => 'alpha', 'domain' => 'category' ), 96 array( 'name' => 'Clippable', 'slug' => 'clippable', 'domain' => 'post_tag' ), 97 array( 'name' => 'bieup', 'slug' => 'bieup', 'domain' => 'post_tax' ) 98 ), $result['posts'][0]['terms'], $message ); 99 $this->assertEquals( array( 100 array( 'key' => '_wp_page_template', 'value' => 'default' ) 101 ), $result['posts'][1]['postmeta'], $message ); 63 $this->assertEquals( 64 array( 65 'author_id' => 2, 66 'author_login' => 'john', 67 'author_email' => 'johndoe@example.org', 68 'author_display_name' => 'John Doe', 69 'author_first_name' => 'John', 70 'author_last_name' => 'Doe', 71 ), $result['authors']['john'], $message 72 ); 73 $this->assertEquals( 74 array( 75 'term_id' => 3, 76 'category_nicename' => 'alpha', 77 'category_parent' => '', 78 'cat_name' => 'alpha', 79 'category_description' => 'The alpha category', 80 ), $result['categories'][0], $message 81 ); 82 $this->assertEquals( 83 array( 84 'term_id' => 22, 85 'tag_slug' => 'clippable', 86 'tag_name' => 'Clippable', 87 'tag_description' => 'The Clippable post_tag', 88 ), $result['tags'][0], $message 89 ); 90 $this->assertEquals( 91 array( 92 'term_id' => 40, 93 'term_taxonomy' => 'post_tax', 94 'slug' => 'bieup', 95 'term_parent' => '', 96 'term_name' => 'bieup', 97 'term_description' => 'The bieup post_tax', 98 ), $result['terms'][0], $message 99 ); 100 101 $this->assertEquals( 2, count( $result['posts'] ), $message ); 102 $this->assertEquals( 19, count( $result['posts'][0] ), $message ); 103 $this->assertEquals( 18, count( $result['posts'][1] ), $message ); 104 $this->assertEquals( 105 array( 106 array( 107 'name' => 'alpha', 108 'slug' => 'alpha', 109 'domain' => 'category', 110 ), 111 array( 112 'name' => 'Clippable', 113 'slug' => 'clippable', 114 'domain' => 'post_tag', 115 ), 116 array( 117 'name' => 'bieup', 118 'slug' => 'bieup', 119 'domain' => 'post_tax', 120 ), 121 ), $result['posts'][0]['terms'], $message 122 ); 123 $this->assertEquals( 124 array( 125 array( 126 'key' => '_wp_page_template', 127 'value' => 'default', 128 ), 129 ), $result['posts'][1]['postmeta'], $message 130 ); 102 131 } 103 132 } … … 108 137 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) { 109 138 $message = $p . ' failed'; 110 $parser = new $p;111 $result = $parser->parse( $file );139 $parser = new $p; 140 $result = $parser->parse( $file ); 112 141 113 142 $this->assertTrue( is_array( $result ), $message ); … … 120 149 $this->assertEquals( $result['tags'][0]['tag_name'], 'chicken', $message ); 121 150 122 $this->assertEquals( 6, count($result['posts']), $message ); 123 $this->assertEquals( 19, count($result['posts'][0]), $message ); 124 $this->assertEquals( 18, count($result['posts'][1]), $message ); 125 126 $this->assertEquals( array( 127 array( 'name' => 'Uncategorized', 'slug' => 'uncategorized', 'domain' => 'category' ) 128 ), $result['posts'][0]['terms'], $message ); 129 $this->assertEquals( array( 130 array( 'name' => 'alpha', 'slug' => 'alpha', 'domain' => 'category' ), 131 array( 'name' => 'news', 'slug' => 'news', 'domain' => 'tag' ), 132 array( 'name' => 'roar', 'slug' => 'roar', 'domain' => 'tag' ) 133 ), $result['posts'][2]['terms'], $message ); 134 $this->assertEquals( array( 135 array( 'name' => 'chicken', 'slug' => 'chicken', 'domain' => 'tag' ), 136 array( 'name' => 'child', 'slug' => 'child', 'domain' => 'category' ), 137 array( 'name' => 'face', 'slug' => 'face', 'domain' => 'tag' ) 138 ), $result['posts'][3]['terms'], $message ); 139 140 $this->assertEquals( array( 141 array( 'key' => '_wp_page_template', 'value' => 'default' ) 142 ), $result['posts'][1]['postmeta'], $message ); 151 $this->assertEquals( 6, count( $result['posts'] ), $message ); 152 $this->assertEquals( 19, count( $result['posts'][0] ), $message ); 153 $this->assertEquals( 18, count( $result['posts'][1] ), $message ); 154 155 $this->assertEquals( 156 array( 157 array( 158 'name' => 'Uncategorized', 159 'slug' => 'uncategorized', 160 'domain' => 'category', 161 ), 162 ), $result['posts'][0]['terms'], $message 163 ); 164 $this->assertEquals( 165 array( 166 array( 167 'name' => 'alpha', 168 'slug' => 'alpha', 169 'domain' => 'category', 170 ), 171 array( 172 'name' => 'news', 173 'slug' => 'news', 174 'domain' => 'tag', 175 ), 176 array( 177 'name' => 'roar', 178 'slug' => 'roar', 179 'domain' => 'tag', 180 ), 181 ), $result['posts'][2]['terms'], $message 182 ); 183 $this->assertEquals( 184 array( 185 array( 186 'name' => 'chicken', 187 'slug' => 'chicken', 188 'domain' => 'tag', 189 ), 190 array( 191 'name' => 'child', 192 'slug' => 'child', 193 'domain' => 'category', 194 ), 195 array( 196 'name' => 'face', 197 'slug' => 'face', 198 'domain' => 'tag', 199 ), 200 ), $result['posts'][3]['terms'], $message 201 ); 202 203 $this->assertEquals( 204 array( 205 array( 206 'key' => '_wp_page_template', 207 'value' => 'default', 208 ), 209 ), $result['posts'][1]['postmeta'], $message 210 ); 143 211 } 144 212 } … … 153 221 $file = DIR_TESTDATA . '/export/crazy-cdata-escaped.xml'; 154 222 155 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {223 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) { 156 224 $message = 'Parser ' . $p; 157 $parser = new $p;158 $result = $parser->parse( $file );225 $parser = new $p; 226 $result = $parser->parse( $file ); 159 227 160 228 $post = $result['posts'][0]; … … 162 230 foreach ( $post['postmeta'] as $meta ) { 163 231 switch ( $meta['key'] ) { 164 case 'Plain string': $value = 'Foo'; break; 165 case 'Closing CDATA': $value = ']]>'; break; 166 case 'Alot of CDATA': $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; break; 167 default: $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p ); 232 case 'Plain string': 233 $value = 'Foo'; 234 break; 235 case 'Closing CDATA': 236 $value = ']]>'; 237 break; 238 case 'Alot of CDATA': 239 $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; 240 break; 241 default: 242 $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p ); 168 243 } 169 244 $this->assertEquals( $value, $meta['value'], $message ); … … 186 261 foreach ( $post['postmeta'] as $meta ) { 187 262 switch ( $meta['key'] ) { 188 case 'Plain string': $value = 'Foo'; break; 189 case 'Closing CDATA': $value = ']]>'; break; 190 case 'Alot of CDATA': $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; break; 191 default: $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p ); 263 case 'Plain string': 264 $value = 'Foo'; 265 break; 266 case 'Closing CDATA': 267 $value = ']]>'; 268 break; 269 case 'Alot of CDATA': 270 $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; 271 break; 272 default: 273 $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p ); 192 274 } 193 275 $this->assertEquals( $value, $meta['value'] );
Note: See TracChangeset
for help on using the changeset viewer.