mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import: Remove Importer plugin related unit tests.
The WordPress Importer plugin has been maintained separately in a repository on GitHub since 2016. However, the unit tests were left in wordpress-develop due to the lack of a CI setup on GitHub. With GitHub Actions set up for the plugin repository, these tests are now running in two locations. Because they are more relevant to the plugin itself, the tests have been synced, will run weekly through a `schedule` event, and are now being removed from wordpress-develop. The only remaining test method in the `import` group covers `get_importers()`, which is a function maintained in WordPress Core itself. Props frank-klein, netweb, dd32, peterwilsoncc, azaozz, desrosj, swissspidy. Fixes #42668. git-svn-id: https://develop.svn.wordpress.org/trunk@59769 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
desrosj
committed
Feb 6, 2025
1 parent
76a89c2
commit 5b5d358
Showing
6 changed files
with
1 addition
and
798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,249 +1,9 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/base.php'; | ||
|
||
/** | ||
* @group import | ||
*/ | ||
class Tests_Import_Import extends WP_Import_UnitTestCase { | ||
public function set_up() { | ||
global $wpdb; | ||
|
||
parent::set_up(); | ||
|
||
if ( ! defined( 'WP_IMPORTING' ) ) { | ||
define( 'WP_IMPORTING', true ); | ||
} | ||
|
||
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) { | ||
define( 'WP_LOAD_IMPORTERS', true ); | ||
} | ||
|
||
add_filter( 'import_allow_create_users', '__return_true' ); | ||
|
||
$this->require_importer(); | ||
|
||
// 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}" ); | ||
} | ||
} | ||
|
||
/** | ||
* @covers WP_Import::import | ||
*/ | ||
public function test_small_import() { | ||
global $wpdb; | ||
|
||
$authors = array( | ||
'admin' => false, | ||
'editor' => false, | ||
'author' => false, | ||
); | ||
$this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors ); | ||
|
||
// Ensure that authors were imported correctly. | ||
$user_count = count_users(); | ||
$this->assertSame( 3, $user_count['total_users'] ); | ||
$admin = get_user_by( 'login', 'admin' ); | ||
$this->assertSame( 'admin', $admin->user_login ); | ||
$this->assertSame( '[email protected]', $admin->user_email ); | ||
$editor = get_user_by( 'login', 'editor' ); | ||
$this->assertSame( 'editor', $editor->user_login ); | ||
$this->assertSame( '[email protected]', $editor->user_email ); | ||
$this->assertSame( 'FirstName', $editor->user_firstname ); | ||
$this->assertSame( 'LastName', $editor->user_lastname ); | ||
$author = get_user_by( 'login', 'author' ); | ||
$this->assertSame( 'author', $author->user_login ); | ||
$this->assertSame( '[email protected]', $author->user_email ); | ||
|
||
// Check that terms were imported correctly. | ||
$this->assertSame( '30', wp_count_terms( array( 'taxonomy' => 'category' ) ) ); | ||
$this->assertSame( '3', wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) ); | ||
$foo = get_term_by( 'slug', 'foo', 'category' ); | ||
$this->assertSame( 0, $foo->parent ); | ||
$bar = get_term_by( 'slug', 'bar', 'category' ); | ||
$foo_bar = get_term_by( 'slug', 'foo-bar', 'category' ); | ||
$this->assertSame( $bar->term_id, $foo_bar->parent ); | ||
|
||
// Check that posts/pages were imported correctly. | ||
$post_count = wp_count_posts( 'post' ); | ||
$this->assertSame( '5', $post_count->publish ); | ||
$this->assertSame( '1', $post_count->private ); | ||
$page_count = wp_count_posts( 'page' ); | ||
$this->assertSame( '4', $page_count->publish ); | ||
$this->assertSame( '1', $page_count->draft ); | ||
$comment_count = wp_count_comments(); | ||
$this->assertSame( 1, $comment_count->total_comments ); | ||
|
||
$posts = get_posts( | ||
array( | ||
'numberposts' => 20, | ||
'post_type' => 'any', | ||
'post_status' => 'any', | ||
'orderby' => 'ID', | ||
) | ||
); | ||
$this->assertCount( 11, $posts ); | ||
|
||
$post = $posts[0]; | ||
$this->assertSame( 'Many Categories', $post->post_title ); | ||
$this->assertSame( 'many-categories', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'post', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$cats = wp_get_post_categories( $post->ID ); | ||
$this->assertCount( 27, $cats ); | ||
|
||
$post = $posts[1]; | ||
$this->assertSame( 'Non-standard post format', $post->post_title ); | ||
$this->assertSame( 'non-standard-post-format', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'post', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$cats = wp_get_post_categories( $post->ID ); | ||
$this->assertCount( 1, $cats ); | ||
$this->assertTrue( has_post_format( 'aside', $post->ID ) ); | ||
|
||
$post = $posts[2]; | ||
$this->assertSame( 'Top-level Foo', $post->post_title ); | ||
$this->assertSame( 'top-level-foo', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'post', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$cats = wp_get_post_categories( $post->ID, array( 'fields' => 'all' ) ); | ||
$this->assertCount( 1, $cats ); | ||
$this->assertSame( 'foo', $cats[0]->slug ); | ||
|
||
$post = $posts[3]; | ||
$this->assertSame( 'Foo-child', $post->post_title ); | ||
$this->assertSame( 'foo-child', $post->post_name ); | ||
$this->assertEquals( $editor->ID, $post->post_author ); | ||
$this->assertSame( 'post', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$cats = wp_get_post_categories( $post->ID, array( 'fields' => 'all' ) ); | ||
$this->assertCount( 1, $cats ); | ||
$this->assertSame( 'foo-bar', $cats[0]->slug ); | ||
|
||
$post = $posts[4]; | ||
$this->assertSame( 'Private Post', $post->post_title ); | ||
$this->assertSame( 'private-post', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'post', $post->post_type ); | ||
$this->assertSame( 'private', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$cats = wp_get_post_categories( $post->ID ); | ||
$this->assertCount( 1, $cats ); | ||
$tags = wp_get_post_tags( $post->ID ); | ||
$this->assertCount( 3, $tags ); | ||
$this->assertSame( 'tag1', $tags[0]->slug ); | ||
$this->assertSame( 'tag2', $tags[1]->slug ); | ||
$this->assertSame( 'tag3', $tags[2]->slug ); | ||
|
||
$post = $posts[5]; | ||
$this->assertSame( '1-col page', $post->post_title ); | ||
$this->assertSame( '1-col-page', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'page', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$this->assertSame( 'onecolumn-page.php', get_post_meta( $post->ID, '_wp_page_template', true ) ); | ||
|
||
$post = $posts[6]; | ||
$this->assertSame( 'Draft Page', $post->post_title ); | ||
$this->assertSame( '', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'page', $post->post_type ); | ||
$this->assertSame( 'draft', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$this->assertSame( 'default', get_post_meta( $post->ID, '_wp_page_template', true ) ); | ||
|
||
$post = $posts[7]; | ||
$this->assertSame( 'Parent Page', $post->post_title ); | ||
$this->assertSame( 'parent-page', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'page', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$this->assertSame( 'default', get_post_meta( $post->ID, '_wp_page_template', true ) ); | ||
|
||
$post = $posts[8]; | ||
$this->assertSame( 'Child Page', $post->post_title ); | ||
$this->assertSame( 'child-page', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'page', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( $posts[7]->ID, $post->post_parent ); | ||
$this->assertSame( 'default', get_post_meta( $post->ID, '_wp_page_template', true ) ); | ||
|
||
$post = $posts[9]; | ||
$this->assertSame( 'Sample Page', $post->post_title ); | ||
$this->assertSame( 'sample-page', $post->post_name ); | ||
$this->assertEquals( $admin->ID, $post->post_author ); | ||
$this->assertSame( 'page', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$this->assertSame( 'default', get_post_meta( $post->ID, '_wp_page_template', true ) ); | ||
|
||
$post = $posts[10]; | ||
$this->assertSame( 'Hello world!', $post->post_title ); | ||
$this->assertSame( 'hello-world', $post->post_name ); | ||
$this->assertEquals( $author->ID, $post->post_author ); | ||
$this->assertSame( 'post', $post->post_type ); | ||
$this->assertSame( 'publish', $post->post_status ); | ||
$this->assertSame( 0, $post->post_parent ); | ||
$cats = wp_get_post_categories( $post->ID ); | ||
$this->assertCount( 1, $cats ); | ||
} | ||
|
||
/** | ||
* @covers WP_Import::import | ||
*/ | ||
public function test_double_import() { | ||
$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 ); | ||
|
||
$user_count = count_users(); | ||
$this->assertSame( 3, $user_count['total_users'] ); | ||
$admin = get_user_by( 'login', 'admin' ); | ||
$this->assertSame( 'admin', $admin->user_login ); | ||
$this->assertSame( '[email protected]', $admin->user_email ); | ||
$editor = get_user_by( 'login', 'editor' ); | ||
$this->assertSame( 'editor', $editor->user_login ); | ||
$this->assertSame( '[email protected]', $editor->user_email ); | ||
$this->assertSame( 'FirstName', $editor->user_firstname ); | ||
$this->assertSame( 'LastName', $editor->user_lastname ); | ||
$author = get_user_by( 'login', 'author' ); | ||
$this->assertSame( 'author', $author->user_login ); | ||
$this->assertSame( '[email protected]', $author->user_email ); | ||
|
||
$this->assertSame( '30', wp_count_terms( array( 'taxonomy' => 'category' ) ) ); | ||
$this->assertSame( '3', wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) ); | ||
$foo = get_term_by( 'slug', 'foo', 'category' ); | ||
$this->assertSame( 0, $foo->parent ); | ||
$bar = get_term_by( 'slug', 'bar', 'category' ); | ||
$foo_bar = get_term_by( 'slug', 'foo-bar', 'category' ); | ||
$this->assertSame( $bar->term_id, $foo_bar->parent ); | ||
|
||
$post_count = wp_count_posts( 'post' ); | ||
$this->assertSame( '5', $post_count->publish ); | ||
$this->assertSame( '1', $post_count->private ); | ||
$page_count = wp_count_posts( 'page' ); | ||
$this->assertSame( '4', $page_count->publish ); | ||
$this->assertSame( '1', $page_count->draft ); | ||
$comment_count = wp_count_comments(); | ||
$this->assertSame( 1, $comment_count->total_comments ); | ||
} | ||
|
||
class Tests_Import_Import extends WP_UnitTestCase { | ||
/** | ||
* @covers ::get_importers | ||
*/ | ||
|
@@ -269,30 +29,4 @@ public function test_ordering_of_importers() { | |
); | ||
$wp_importers = $_wp_importers; // Restore global state. | ||
} | ||
|
||
/** | ||
* @ticket 21007 | ||
* | ||
* @covers WP_Import::import | ||
*/ | ||
public function test_slashes_should_not_be_stripped() { | ||
global $wpdb; | ||
|
||
$authors = array( 'admin' => false ); | ||
$this->_import_wp( DIR_TESTDATA . '/export/slashes.xml', $authors ); | ||
|
||
$alpha = get_term_by( 'slug', 'alpha', 'category' ); | ||
$this->assertSame( 'a \"great\" category', $alpha->name ); | ||
|
||
$tag1 = get_term_by( 'slug', 'tag1', 'post_tag' ); | ||
$this->assertSame( "foo\'bar", $tag1->name ); | ||
|
||
$posts = get_posts( | ||
array( | ||
'post_type' => 'any', | ||
'post_status' => 'any', | ||
) | ||
); | ||
$this->assertSame( 'Slashes aren\\\'t \"cool\"', $posts[0]->post_content ); | ||
} | ||
} |
Oops, something went wrong.