Changeset 407 in tests for wp-testcase/test_import_wp.php
- Timestamp:
- 08/04/2011 08:38:26 PM (15 years ago)
- File:
-
- 1 edited
-
wp-testcase/test_import_wp.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-testcase/test_import_wp.php
r366 r407 6 6 7 7 // _nuke_main_tables style function on tearDown? (Should this be part of _WPEmptyBlog tearDown?) 8 8 9 9 class WXRParserTest extends WPTestCase { 10 10 function setUp() { … … 13 13 if ( ! defined( 'WP_IMPORTING' ) ) 14 14 define( 'WP_IMPORTING', true ); 15 15 16 16 if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) 17 define( 'WP_LOAD_IMPORTERS', true ); 17 define( 'WP_LOAD_IMPORTERS', true ); 18 18 19 19 require_once DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php'; … … 23 23 parent::tearDown(); 24 24 } 25 25 26 26 function test_malformed_wxr() { 27 27 $file = DIR_TESTDATA . '/export/malformed.xml'; 28 28 29 29 // regex based parser cannot detect malformed XML 30 30 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML' ) as $p ) { … … 32 32 $result = $parser->parse($file); 33 33 $this->assertTrue( is_wp_error( $result ) ); 34 $this->assertEquals( 'There was an error when reading this WXR file', $result->get_error_message() ); 35 } 36 } 34 $this->assertEquals( 'There was an error when reading this WXR file', $result->get_error_message() ); 35 } 36 } 37 37 38 38 function test_invalid_wxr() { 39 39 $f1 = DIR_TESTDATA . '/export/missing-version-tag.xml'; 40 40 $f2 = DIR_TESTDATA . '/export/invalid-version-tag.xml'; 41 41 42 42 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) { 43 43 foreach ( array( $f1, $f2 ) as $file ) { 44 44 $parser = new $p; 45 $result = $parser->parse( $file ); 45 $result = $parser->parse( $file ); 46 46 $this->assertTrue( is_wp_error( $result ) ); 47 $this->assertEquals( 'This does not appear to be a WXR file, missing/invalid WXR version number', $result->get_error_message() ); 47 $this->assertEquals( 'This does not appear to be a WXR file, missing/invalid WXR version number', $result->get_error_message() ); 48 48 } 49 } 50 } 51 49 } 50 } 51 52 52 function test_wxr_version_1_1() { 53 53 $file = DIR_TESTDATA . '/export/valid-wxr-1.1.xml'; 54 54 55 55 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) { 56 56 $message = $p . ' failed'; 57 57 $parser = new $p; 58 $result = $parser->parse( $file ); 59 60 $this->assertTrue( is_array( $result ), $message ); 58 $result = $parser->parse( $file ); 59 60 $this->assertTrue( is_array( $result ), $message ); 61 61 $this->assertEquals( 'http://localhost/', $result['base_url'], $message ); 62 $this->assertEquals( array( 62 $this->assertEquals( array( 63 63 'author_id' => 2, 64 64 'author_login' => 'john', … … 73 73 'category_parent' => '', 74 74 'cat_name' => 'alpha', 75 'category_description' => 'The alpha category' 75 'category_description' => 'The alpha category' 76 76 ), $result['categories'][0], $message ); 77 77 $this->assertEquals( array( … … 79 79 'tag_slug' => 'clippable', 80 80 'tag_name' => 'Clippable', 81 'tag_description' => 'The Clippable post_tag' 81 'tag_description' => 'The Clippable post_tag' 82 82 ), $result['tags'][0], $message ); 83 83 $this->assertEquals( array( … … 85 85 'term_taxonomy' => 'post_tax', 86 86 'slug' => 'bieup', 87 'term_parent' => '', 87 'term_parent' => '', 88 88 'term_name' => 'bieup', 89 'term_description' => 'The bieup post_tax' 90 ), $result['terms'][0], $message ); 89 'term_description' => 'The bieup post_tax' 90 ), $result['terms'][0], $message ); 91 91 92 92 $this->assertEquals( 2, count($result['posts']), $message ); … … 100 100 $this->assertEquals( array( 101 101 array( 'key' => '_wp_page_template', 'value' => 'default' ) 102 ), $result['posts'][1]['postmeta'], $message ); 102 ), $result['posts'][1]['postmeta'], $message ); 103 103 } 104 104 } 105 105 106 106 function test_wxr_version_1_0() { 107 107 $file = DIR_TESTDATA . '/export/valid-wxr-1.0.xml'; 108 108 109 109 foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) { 110 110 $message = $p . ' failed'; 111 111 $parser = new $p; 112 112 $result = $parser->parse( $file ); 113 114 $this->assertTrue( is_array( $result ), $message ); 113 114 $this->assertTrue( is_array( $result ), $message ); 115 115 $this->assertEquals( 'http://localhost/', $result['base_url'], $message ); 116 116 $this->assertEquals( $result['categories'][0]['category_nicename'], 'alpha', $message ); … … 119 119 $this->assertEquals( $result['categories'][0]['category_description'], 'The alpha category', $message ); 120 120 $this->assertEquals( $result['tags'][0]['tag_slug'], 'chicken', $message ); 121 $this->assertEquals( $result['tags'][0]['tag_name'], 'chicken', $message ); 121 $this->assertEquals( $result['tags'][0]['tag_name'], 'chicken', $message ); 122 122 123 123 $this->assertEquals( 6, count($result['posts']), $message ); … … 144 144 } 145 145 } 146 146 147 147 // tags in CDATA #11574 148 148 } … … 154 154 if ( ! defined( 'WP_IMPORTING' ) ) 155 155 define( 'WP_IMPORTING', true ); 156 156 157 157 if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) 158 158 define( 'WP_LOAD_IMPORTERS', true ); 159 159 160 160 require_once DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php'; 161 161 … … 178 178 wp_delete_user( $user->ID ); 179 179 } 180 180 181 181 function test_small_import() { 182 182 global $wpdb; 183 183 184 $authors = array( 'admin' => false, 'editor' => false, 'author' => false ); 184 $authors = array( 'admin' => false, 'editor' => false, 'author' => false ); 185 185 $this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors ); 186 186 … … 335 335 $this->assertEquals( 1, count($cats) ); 336 336 } 337 337 338 338 function test_double_import() { 339 339 $authors = array( 'admin' => false, 'editor' => false, 'author' => false ); … … 379 379 function setUp() { 380 380 parent::setUp(); 381 381 382 382 if ( ! defined( 'WP_IMPORTING' ) ) 383 383 define( 'WP_IMPORTING', true ); 384 384 385 385 if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) 386 386 define( 'WP_LOAD_IMPORTERS', true ); 387 387 388 388 require_once DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php'; 389 389 } … … 392 392 parent::tearDown(); 393 393 } 394 394 395 395 function test_serialized_postmeta_no_cdata() { 396 $this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-no-cdata.xml', array( 'johncoswell' => false ) ); 396 $this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-no-cdata.xml', array( 'johncoswell' => false ) ); 397 397 $expected['special_post_title'] = 'A special title'; 398 $expected['is_calendar'] = ''; 398 $expected['is_calendar'] = ''; 399 399 $this->assertEquals( $expected, get_post_meta( 122, 'post-options', true ) ); 400 400 } 401 401 402 402 function test_utw_postmeta() { 403 403 $this->_import_wp( DIR_TESTDATA . '/export/test-utw-post-meta-import.xml', array( 'johncoswell' => false ) ); … … 414 414 $classy = new StdClass(); 415 415 $classy->tag = "artwork"; 416 $expected[] = $classy; 416 $expected[] = $classy; 417 417 $classy = new StdClass(); 418 418 $classy->tag = "dead-tracks"; 419 $expected[] = $classy; 419 $expected[] = $classy; 420 420 $classy = new StdClass(); 421 421 $classy->tag = "ipod"; … … 429 429 $classy = new StdClass(); 430 430 $classy->tag = "lyrics"; 431 $expected[] = $classy; 431 $expected[] = $classy; 432 432 $classy = new StdClass(); 433 433 $classy->tag = "script"; 434 $expected[] = $classy; 434 $expected[] = $classy; 435 435 $classy = new StdClass(); 436 436 $classy->tag = "tracks"; 437 $expected[] = $classy; 437 $expected[] = $classy; 438 438 $classy = new StdClass(); 439 439 $classy->tag = "windows-scripting-host"; 440 $expected[] = $classy; 440 $expected[] = $classy; 441 441 $classy = new StdClass(); 442 442 $classy->tag = "wscript"; 443 $expected[] = $classy; 444 443 $expected[] = $classy; 444 445 445 $this->assertEquals( $expected, get_post_meta( 150, 'test', true ) ); 446 446 } … … 469 469 470 470 //HTML in the CDATA should work with old WordPress version 471 $this->assertEquals( '<pre>some html</pre>', get_post_meta( 10, 'contains-html', true ) ); 471 $this->assertEquals( '<pre>some html</pre>', get_post_meta( 10, 'contains-html', true ) ); 472 472 //Serialised will only work with 3.0 onwards. 473 473 $expected["special_post_title"] = "A special title"; 474 474 $expected["is_calendar"] = ""; 475 $this->assertEquals( $expected, get_post_meta( 10, 'post-options', true ) ); 475 $this->assertEquals( $expected, get_post_meta( 10, 'post-options', true ) ); 476 476 } 477 477
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)