mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -9,11 +9,13 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
if ( ! defined( 'WP_IMPORTING' ) )
|
||||
if ( ! defined( 'WP_IMPORTING' ) ) {
|
||||
define( 'WP_IMPORTING', true );
|
||||
}
|
||||
|
||||
if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
|
||||
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
|
||||
define( 'WP_LOAD_IMPORTERS', true );
|
||||
}
|
||||
|
||||
if ( ! file_exists( DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' ) ) {
|
||||
$this->fail( 'This test requires the WordPress Importer plugin to be installed in the test suite. See: https://make.wordpress.org/core/handbook/contribute/git/#unit-tests' );
|
||||
@@ -28,7 +30,7 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
|
||||
// regex based parser cannot detect malformed XML
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML' ) as $p ) {
|
||||
$parser = new $p;
|
||||
$result = $parser->parse($file);
|
||||
$result = $parser->parse( $file );
|
||||
$this->assertWPError( $result );
|
||||
$this->assertEquals( 'There was an error when reading this WXR file', $result->get_error_message() );
|
||||
}
|
||||
@@ -53,52 +55,79 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
|
||||
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
|
||||
$message = $p . ' failed';
|
||||
$parser = new $p;
|
||||
$result = $parser->parse( $file );
|
||||
$parser = new $p;
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
$this->assertTrue( is_array( $result ), $message );
|
||||
$this->assertEquals( 'http://localhost/', $result['base_url'], $message );
|
||||
$this->assertEquals( array(
|
||||
'author_id' => 2,
|
||||
'author_login' => 'john',
|
||||
'author_email' => 'johndoe@example.org',
|
||||
'author_display_name' => 'John Doe',
|
||||
'author_first_name' => 'John',
|
||||
'author_last_name' => 'Doe'
|
||||
), $result['authors']['john'], $message );
|
||||
$this->assertEquals( array(
|
||||
'term_id' => 3,
|
||||
'category_nicename' => 'alpha',
|
||||
'category_parent' => '',
|
||||
'cat_name' => 'alpha',
|
||||
'category_description' => 'The alpha category'
|
||||
), $result['categories'][0], $message );
|
||||
$this->assertEquals( array(
|
||||
'term_id' => 22,
|
||||
'tag_slug' => 'clippable',
|
||||
'tag_name' => 'Clippable',
|
||||
'tag_description' => 'The Clippable post_tag'
|
||||
), $result['tags'][0], $message );
|
||||
$this->assertEquals( array(
|
||||
'term_id' => 40,
|
||||
'term_taxonomy' => 'post_tax',
|
||||
'slug' => 'bieup',
|
||||
'term_parent' => '',
|
||||
'term_name' => 'bieup',
|
||||
'term_description' => 'The bieup post_tax'
|
||||
), $result['terms'][0], $message );
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'author_id' => 2,
|
||||
'author_login' => 'john',
|
||||
'author_email' => 'johndoe@example.org',
|
||||
'author_display_name' => 'John Doe',
|
||||
'author_first_name' => 'John',
|
||||
'author_last_name' => 'Doe',
|
||||
), $result['authors']['john'], $message
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'term_id' => 3,
|
||||
'category_nicename' => 'alpha',
|
||||
'category_parent' => '',
|
||||
'cat_name' => 'alpha',
|
||||
'category_description' => 'The alpha category',
|
||||
), $result['categories'][0], $message
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'term_id' => 22,
|
||||
'tag_slug' => 'clippable',
|
||||
'tag_name' => 'Clippable',
|
||||
'tag_description' => 'The Clippable post_tag',
|
||||
), $result['tags'][0], $message
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'term_id' => 40,
|
||||
'term_taxonomy' => 'post_tax',
|
||||
'slug' => 'bieup',
|
||||
'term_parent' => '',
|
||||
'term_name' => 'bieup',
|
||||
'term_description' => 'The bieup post_tax',
|
||||
), $result['terms'][0], $message
|
||||
);
|
||||
|
||||
$this->assertEquals( 2, count($result['posts']), $message );
|
||||
$this->assertEquals( 19, count($result['posts'][0]), $message );
|
||||
$this->assertEquals( 18, count($result['posts'][1]), $message );
|
||||
$this->assertEquals( array(
|
||||
array( 'name' => 'alpha', 'slug' => 'alpha', 'domain' => 'category' ),
|
||||
array( 'name' => 'Clippable', 'slug' => 'clippable', 'domain' => 'post_tag' ),
|
||||
array( 'name' => 'bieup', 'slug' => 'bieup', 'domain' => 'post_tax' )
|
||||
), $result['posts'][0]['terms'], $message );
|
||||
$this->assertEquals( array(
|
||||
array( 'key' => '_wp_page_template', 'value' => 'default' )
|
||||
), $result['posts'][1]['postmeta'], $message );
|
||||
$this->assertEquals( 2, count( $result['posts'] ), $message );
|
||||
$this->assertEquals( 19, count( $result['posts'][0] ), $message );
|
||||
$this->assertEquals( 18, count( $result['posts'][1] ), $message );
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
'name' => 'alpha',
|
||||
'slug' => 'alpha',
|
||||
'domain' => 'category',
|
||||
),
|
||||
array(
|
||||
'name' => 'Clippable',
|
||||
'slug' => 'clippable',
|
||||
'domain' => 'post_tag',
|
||||
),
|
||||
array(
|
||||
'name' => 'bieup',
|
||||
'slug' => 'bieup',
|
||||
'domain' => 'post_tax',
|
||||
),
|
||||
), $result['posts'][0]['terms'], $message
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
'key' => '_wp_page_template',
|
||||
'value' => 'default',
|
||||
),
|
||||
), $result['posts'][1]['postmeta'], $message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +136,8 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
|
||||
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
|
||||
$message = $p . ' failed';
|
||||
$parser = new $p;
|
||||
$result = $parser->parse( $file );
|
||||
$parser = new $p;
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
$this->assertTrue( is_array( $result ), $message );
|
||||
$this->assertEquals( 'http://localhost/', $result['base_url'], $message );
|
||||
@@ -119,27 +148,66 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
|
||||
$this->assertEquals( $result['tags'][0]['tag_slug'], 'chicken', $message );
|
||||
$this->assertEquals( $result['tags'][0]['tag_name'], 'chicken', $message );
|
||||
|
||||
$this->assertEquals( 6, count($result['posts']), $message );
|
||||
$this->assertEquals( 19, count($result['posts'][0]), $message );
|
||||
$this->assertEquals( 18, count($result['posts'][1]), $message );
|
||||
$this->assertEquals( 6, count( $result['posts'] ), $message );
|
||||
$this->assertEquals( 19, count( $result['posts'][0] ), $message );
|
||||
$this->assertEquals( 18, count( $result['posts'][1] ), $message );
|
||||
|
||||
$this->assertEquals( array(
|
||||
array( 'name' => 'Uncategorized', 'slug' => 'uncategorized', 'domain' => 'category' )
|
||||
), $result['posts'][0]['terms'], $message );
|
||||
$this->assertEquals( array(
|
||||
array( 'name' => 'alpha', 'slug' => 'alpha', 'domain' => 'category' ),
|
||||
array( 'name' => 'news', 'slug' => 'news', 'domain' => 'tag' ),
|
||||
array( 'name' => 'roar', 'slug' => 'roar', 'domain' => 'tag' )
|
||||
), $result['posts'][2]['terms'], $message );
|
||||
$this->assertEquals( array(
|
||||
array( 'name' => 'chicken', 'slug' => 'chicken', 'domain' => 'tag' ),
|
||||
array( 'name' => 'child', 'slug' => 'child', 'domain' => 'category' ),
|
||||
array( 'name' => 'face', 'slug' => 'face', 'domain' => 'tag' )
|
||||
), $result['posts'][3]['terms'], $message );
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
'name' => 'Uncategorized',
|
||||
'slug' => 'uncategorized',
|
||||
'domain' => 'category',
|
||||
),
|
||||
), $result['posts'][0]['terms'], $message
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
'name' => 'alpha',
|
||||
'slug' => 'alpha',
|
||||
'domain' => 'category',
|
||||
),
|
||||
array(
|
||||
'name' => 'news',
|
||||
'slug' => 'news',
|
||||
'domain' => 'tag',
|
||||
),
|
||||
array(
|
||||
'name' => 'roar',
|
||||
'slug' => 'roar',
|
||||
'domain' => 'tag',
|
||||
),
|
||||
), $result['posts'][2]['terms'], $message
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
'name' => 'chicken',
|
||||
'slug' => 'chicken',
|
||||
'domain' => 'tag',
|
||||
),
|
||||
array(
|
||||
'name' => 'child',
|
||||
'slug' => 'child',
|
||||
'domain' => 'category',
|
||||
),
|
||||
array(
|
||||
'name' => 'face',
|
||||
'slug' => 'face',
|
||||
'domain' => 'tag',
|
||||
),
|
||||
), $result['posts'][3]['terms'], $message
|
||||
);
|
||||
|
||||
$this->assertEquals( array(
|
||||
array( 'key' => '_wp_page_template', 'value' => 'default' )
|
||||
), $result['posts'][1]['postmeta'], $message );
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
'key' => '_wp_page_template',
|
||||
'value' => 'default',
|
||||
),
|
||||
), $result['posts'][1]['postmeta'], $message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,19 +220,26 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
|
||||
function test_escaped_cdata_closing_sequence() {
|
||||
$file = DIR_TESTDATA . '/export/crazy-cdata-escaped.xml';
|
||||
|
||||
foreach( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
|
||||
$message = 'Parser ' . $p;
|
||||
$parser = new $p;
|
||||
$result = $parser->parse( $file );
|
||||
$parser = new $p;
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
$post = $result['posts'][0];
|
||||
$this->assertEquals( 'Content with nested <![CDATA[ tags ]]> :)', $post['post_content'], $message );
|
||||
foreach ( $post['postmeta'] as $meta ) {
|
||||
switch ( $meta['key'] ) {
|
||||
case 'Plain string': $value = 'Foo'; break;
|
||||
case 'Closing CDATA': $value = ']]>'; break;
|
||||
case 'Alot of CDATA': $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; break;
|
||||
default: $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
|
||||
case 'Plain string':
|
||||
$value = 'Foo';
|
||||
break;
|
||||
case 'Closing CDATA':
|
||||
$value = ']]>';
|
||||
break;
|
||||
case 'Alot of CDATA':
|
||||
$value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>';
|
||||
break;
|
||||
default:
|
||||
$this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
|
||||
}
|
||||
$this->assertEquals( $value, $meta['value'], $message );
|
||||
}
|
||||
@@ -185,10 +260,17 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase {
|
||||
$this->assertEquals( 'Content with nested <![CDATA[ tags ]]> :)', $post['post_content'] );
|
||||
foreach ( $post['postmeta'] as $meta ) {
|
||||
switch ( $meta['key'] ) {
|
||||
case 'Plain string': $value = 'Foo'; break;
|
||||
case 'Closing CDATA': $value = ']]>'; break;
|
||||
case 'Alot of CDATA': $value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>'; break;
|
||||
default: $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
|
||||
case 'Plain string':
|
||||
$value = 'Foo';
|
||||
break;
|
||||
case 'Closing CDATA':
|
||||
$value = ']]>';
|
||||
break;
|
||||
case 'Alot of CDATA':
|
||||
$value = 'This has <![CDATA[ opening and ]]> closing <![CDATA[ tags like this: ]]>';
|
||||
break;
|
||||
default:
|
||||
$this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
|
||||
}
|
||||
$this->assertEquals( $value, $meta['value'] );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user