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:
Gary Pendergast
2017-11-30 23:09:33 +00:00
parent ec6a089f98
commit 8f95800d52
1103 changed files with 105978 additions and 78184 deletions
+51 -26
View File
@@ -9,11 +9,13 @@ class Tests_Import_Import 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 );
}
add_filter( 'import_allow_create_users', '__return_true' );
@@ -25,8 +27,9 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
global $wpdb;
// crude but effective: make sure there's no residual data in the main tables
foreach ( array('posts', 'postmeta', 'comments', 'terms', 'term_taxonomy', 'term_relationships', 'users', 'usermeta') as $table)
$wpdb->query("DELETE FROM {$wpdb->$table}");
foreach ( array( 'posts', 'postmeta', 'comments', 'terms', 'term_taxonomy', 'term_relationships', 'users', 'usermeta' ) as $table ) {
$wpdb->query( "DELETE FROM {$wpdb->$table}" );
}
}
function tearDown() {
@@ -38,7 +41,11 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
function test_small_import() {
global $wpdb;
$authors = array( 'admin' => false, 'editor' => false, 'author' => false );
$authors = array(
'admin' => false,
'editor' => false,
'author' => false,
);
$this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors );
// ensure that authors were imported correctly
@@ -61,7 +68,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$this->assertEquals( 3, wp_count_terms( 'post_tag' ) );
$foo = get_term_by( 'slug', 'foo', 'category' );
$this->assertEquals( 0, $foo->parent );
$bar = get_term_by( 'slug', 'bar', 'category' );
$bar = get_term_by( 'slug', 'bar', 'category' );
$foo_bar = get_term_by( 'slug', 'foo-bar', 'category' );
$this->assertEquals( $bar->term_id, $foo_bar->parent );
@@ -75,8 +82,15 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$comment_count = wp_count_comments();
$this->assertEquals( 1, $comment_count->total_comments );
$posts = get_posts( array( 'numberposts' => 20, 'post_type' => 'any', 'post_status' => 'any', 'orderby' => 'ID' ) );
$this->assertEquals( 11, count($posts) );
$posts = get_posts(
array(
'numberposts' => 20,
'post_type' => 'any',
'post_status' => 'any',
'orderby' => 'ID',
)
);
$this->assertEquals( 11, count( $posts ) );
$post = $posts[0];
$this->assertEquals( 'Many Categories', $post->post_title );
@@ -86,7 +100,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$this->assertEquals( 'publish', $post->post_status );
$this->assertEquals( 0, $post->post_parent );
$cats = wp_get_post_categories( $post->ID );
$this->assertEquals( 27, count($cats) );
$this->assertEquals( 27, count( $cats ) );
$post = $posts[1];
$this->assertEquals( 'Non-standard post format', $post->post_title );
@@ -96,7 +110,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$this->assertEquals( 'publish', $post->post_status );
$this->assertEquals( 0, $post->post_parent );
$cats = wp_get_post_categories( $post->ID );
$this->assertEquals( 1, count($cats) );
$this->assertEquals( 1, count( $cats ) );
$this->assertTrue( has_post_format( 'aside', $post->ID ) );
$post = $posts[2];
@@ -107,7 +121,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$this->assertEquals( 'publish', $post->post_status );
$this->assertEquals( 0, $post->post_parent );
$cats = wp_get_post_categories( $post->ID, array( 'fields' => 'all' ) );
$this->assertEquals( 1, count($cats) );
$this->assertEquals( 1, count( $cats ) );
$this->assertEquals( 'foo', $cats[0]->slug );
$post = $posts[3];
@@ -118,7 +132,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$this->assertEquals( 'publish', $post->post_status );
$this->assertEquals( 0, $post->post_parent );
$cats = wp_get_post_categories( $post->ID, array( 'fields' => 'all' ) );
$this->assertEquals( 1, count($cats) );
$this->assertEquals( 1, count( $cats ) );
$this->assertEquals( 'foo-bar', $cats[0]->slug );
$post = $posts[4];
@@ -129,9 +143,9 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$this->assertEquals( 'private', $post->post_status );
$this->assertEquals( 0, $post->post_parent );
$cats = wp_get_post_categories( $post->ID );
$this->assertEquals( 1, count($cats) );
$this->assertEquals( 1, count( $cats ) );
$tags = wp_get_post_tags( $post->ID );
$this->assertEquals( 3, count($tags) );
$this->assertEquals( 3, count( $tags ) );
$this->assertEquals( 'tag1', $tags[0]->slug );
$this->assertEquals( 'tag2', $tags[1]->slug );
$this->assertEquals( 'tag3', $tags[2]->slug );
@@ -189,11 +203,15 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$this->assertEquals( 'publish', $post->post_status );
$this->assertEquals( 0, $post->post_parent );
$cats = wp_get_post_categories( $post->ID );
$this->assertEquals( 1, count($cats) );
$this->assertEquals( 1, count( $cats ) );
}
function test_double_import() {
$authors = array( 'admin' => false, 'editor' => false, 'author' => false );
$authors = array(
'admin' => false,
'editor' => false,
'author' => false,
);
$this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors );
$this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors );
@@ -215,7 +233,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$this->assertEquals( 3, wp_count_terms( 'post_tag' ) );
$foo = get_term_by( 'slug', 'foo', 'category' );
$this->assertEquals( 0, $foo->parent );
$bar = get_term_by( 'slug', 'bar', 'category' );
$bar = get_term_by( 'slug', 'bar', 'category' );
$foo_bar = get_term_by( 'slug', 'foo-bar', 'category' );
$this->assertEquals( $bar->term_id, $foo_bar->parent );
@@ -232,20 +250,22 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
function test_ordering_of_importers() {
global $wp_importers;
$_wp_importers = $wp_importers; // Preserve global state
$wp_importers = array(
$wp_importers = array(
'xyz1' => array( 'xyz1' ),
'XYZ2' => array( 'XYZ2' ),
'abc2' => array( 'abc2' ),
'ABC1' => array( 'ABC1' ),
'def1' => array( 'def1' ),
);
$this->assertEquals( array(
'ABC1' => array( 'ABC1' ),
'abc2' => array( 'abc2' ),
'def1' => array( 'def1' ),
'xyz1' => array( 'xyz1' ),
'XYZ2' => array( 'XYZ2' ),
), get_importers() );
$this->assertEquals(
array(
'ABC1' => array( 'ABC1' ),
'abc2' => array( 'abc2' ),
'def1' => array( 'def1' ),
'xyz1' => array( 'xyz1' ),
'XYZ2' => array( 'XYZ2' ),
), get_importers()
);
$wp_importers = $_wp_importers; // Restore global state
}
@@ -264,7 +284,12 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
$tag1 = get_term_by( 'slug', 'tag1', 'post_tag' );
$this->assertSame( "foo\'bar", $tag1->name );
$posts = get_posts( array( 'post_type' => 'any', 'post_status' => 'any' ) );
$posts = get_posts(
array(
'post_type' => 'any',
'post_status' => 'any',
)
);
$this->assertSame( 'Slashes aren\\\'t \"cool\"', $posts[0]->post_content );
}