mirror of
git://develop.git.wordpress.org/
synced 2025-03-21 12:29:53 +01:00
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
This commit is contained in:
parent
76a89c2f72
commit
5b5d358a57
@ -214,7 +214,6 @@ tests_reset__SERVER();
|
||||
define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
|
||||
define( 'DIR_TESTDATA', __DIR__ . '/../data' );
|
||||
define( 'DIR_TESTROOT', realpath( dirname( __DIR__ ) ) );
|
||||
define( 'IMPORTER_PLUGIN_FOR_TESTS', DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' );
|
||||
|
||||
define( 'WP_LANG_DIR', realpath( DIR_TESTDATA . '/languages' ) );
|
||||
|
||||
|
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
abstract class WP_Import_UnitTestCase extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Require the WordPress Importer plugin.
|
||||
*
|
||||
* Fails the test if the plugin is not installed.
|
||||
*/
|
||||
protected function require_importer() {
|
||||
if ( ! file_exists( IMPORTER_PLUGIN_FOR_TESTS ) ) {
|
||||
$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' );
|
||||
}
|
||||
require_once IMPORTER_PLUGIN_FOR_TESTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a WXR file.
|
||||
*
|
||||
* The $users parameter provides information on how users specified in the import
|
||||
* file should be imported. Each key is a user login name and indicates if the user
|
||||
* should be mapped to an existing user, created as a new user with a particular login
|
||||
* or imported with the information held in the WXR file. An example of this:
|
||||
*
|
||||
* <code>
|
||||
* $users = array(
|
||||
* 'alice' => 1, // alice will be mapped to user ID 1.
|
||||
* 'bob' => 'john', // bob will be transformed into john.
|
||||
* 'eve' => false // eve will be imported as is.
|
||||
* );</code>
|
||||
*
|
||||
* @param string $filename Full path of the file to import
|
||||
* @param array $users User import settings
|
||||
* @param bool $fetch_files Whether or not do download remote attachments
|
||||
*/
|
||||
protected function _import_wp( $filename, $users = array(), $fetch_files = true ) {
|
||||
$this->require_importer();
|
||||
|
||||
$importer = new WP_Import();
|
||||
$file = realpath( $filename );
|
||||
|
||||
$this->assertNotEmpty( $file, 'Path to import file is empty.' );
|
||||
$this->assertTrue( is_file( $file ), 'Import file is not a file.' );
|
||||
|
||||
$authors = array();
|
||||
$mapping = array();
|
||||
$new = array();
|
||||
$i = 0;
|
||||
|
||||
// Each user is either mapped to a given ID, mapped to a new user
|
||||
// with given login or imported using details in WXR file.
|
||||
foreach ( $users as $user => $map ) {
|
||||
$authors[ $i ] = $user;
|
||||
if ( is_int( $map ) ) {
|
||||
$mapping[ $i ] = $map;
|
||||
} elseif ( is_string( $map ) ) {
|
||||
$new[ $i ] = $map;
|
||||
}
|
||||
|
||||
++$i;
|
||||
}
|
||||
|
||||
$_POST = array(
|
||||
'imported_authors' => $authors,
|
||||
'user_map' => $mapping,
|
||||
'user_new' => $new,
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$importer->fetch_attachments = $fetch_files;
|
||||
$importer->import( $file );
|
||||
ob_end_clean();
|
||||
|
||||
$_POST = array();
|
||||
}
|
||||
}
|
@ -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( 'local@host.null', $admin->user_email );
|
||||
$editor = get_user_by( 'login', 'editor' );
|
||||
$this->assertSame( 'editor', $editor->user_login );
|
||||
$this->assertSame( 'editor@example.org', $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( 'author@example.org', $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( 'local@host.null', $admin->user_email );
|
||||
$editor = get_user_by( 'login', 'editor' );
|
||||
$this->assertSame( 'editor', $editor->user_login );
|
||||
$this->assertSame( 'editor@example.org', $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( 'author@example.org', $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 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
|
||||
);
|
||||
$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 );
|
||||
}
|
||||
}
|
||||
|
@ -1,341 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/base.php';
|
||||
|
||||
/**
|
||||
* @group import
|
||||
*/
|
||||
class Tests_Import_Parser extends WP_Import_UnitTestCase {
|
||||
public function set_up() {
|
||||
parent::set_up();
|
||||
|
||||
if ( ! defined( 'WP_IMPORTING' ) ) {
|
||||
define( 'WP_IMPORTING', true );
|
||||
}
|
||||
|
||||
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
|
||||
define( 'WP_LOAD_IMPORTERS', true );
|
||||
}
|
||||
|
||||
$this->require_importer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers WXR_Parser_SimpleXML::parse
|
||||
* @covers WXR_Parser_XML::parse
|
||||
*/
|
||||
public function test_malformed_wxr() {
|
||||
if ( PHP_VERSION_ID >= 80400 ) {
|
||||
$this->markTestSkipped( 'The Importer plugin is not ready for PHP 8.4 yet. This skip should be removed once it is.' );
|
||||
}
|
||||
|
||||
$file = DIR_TESTDATA . '/export/malformed.xml';
|
||||
|
||||
// Regex based parser cannot detect malformed XML.
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML' ) as $p ) {
|
||||
$parser = new $p();
|
||||
$result = $parser->parse( $file );
|
||||
$this->assertWPError( $result );
|
||||
$this->assertSame( 'There was an error when reading this WXR file', $result->get_error_message() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers WXR_Parser_SimpleXML::parse
|
||||
* @covers WXR_Parser_XML::parse
|
||||
* @covers WXR_Parser_Regex::parse
|
||||
*/
|
||||
public function test_invalid_wxr() {
|
||||
if ( PHP_VERSION_ID >= 80400 ) {
|
||||
$this->markTestSkipped( 'The Importer plugin is not ready for PHP 8.4 yet. This skip should be removed once it is.' );
|
||||
}
|
||||
|
||||
$f1 = DIR_TESTDATA . '/export/missing-version-tag.xml';
|
||||
$f2 = DIR_TESTDATA . '/export/invalid-version-tag.xml';
|
||||
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
|
||||
foreach ( array( $f1, $f2 ) as $file ) {
|
||||
$parser = new $p();
|
||||
$result = $parser->parse( $file );
|
||||
$this->assertWPError( $result );
|
||||
$this->assertSame( 'This does not appear to be a WXR file, missing/invalid WXR version number', $result->get_error_message() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers WXR_Parser_SimpleXML::parse
|
||||
* @covers WXR_Parser_XML::parse
|
||||
* @covers WXR_Parser_Regex::parse
|
||||
*/
|
||||
public function test_wxr_version_1_1() {
|
||||
if ( PHP_VERSION_ID >= 80400 ) {
|
||||
$this->markTestSkipped( 'The Importer plugin is not ready for PHP 8.4 yet. This skip should be removed once it is.' );
|
||||
}
|
||||
|
||||
$file = DIR_TESTDATA . '/export/valid-wxr-1.1.xml';
|
||||
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
|
||||
$message = $p . ' failed';
|
||||
$parser = new $p();
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
$this->assertIsArray( $result, $message );
|
||||
$this->assertSame( 'http://localhost/', $result['base_url'], $message );
|
||||
$this->assertEqualSetsWithIndex(
|
||||
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->assertEqualSetsWithIndex(
|
||||
array(
|
||||
'term_id' => 3,
|
||||
'category_nicename' => 'alpha',
|
||||
'category_parent' => '',
|
||||
'cat_name' => 'alpha',
|
||||
'category_description' => 'The alpha category',
|
||||
),
|
||||
$result['categories'][0],
|
||||
$message
|
||||
);
|
||||
$this->assertEqualSetsWithIndex(
|
||||
array(
|
||||
'term_id' => 22,
|
||||
'tag_slug' => 'clippable',
|
||||
'tag_name' => 'Clippable',
|
||||
'tag_description' => 'The Clippable post_tag',
|
||||
),
|
||||
$result['tags'][0],
|
||||
$message
|
||||
);
|
||||
$this->assertEqualSetsWithIndex(
|
||||
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->assertCount( 2, $result['posts'], $message );
|
||||
$this->assertCount( 19, $result['posts'][0], $message );
|
||||
$this->assertCount( 18, $result['posts'][1], $message );
|
||||
$this->assertEqualSetsWithIndex(
|
||||
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->assertSame(
|
||||
array(
|
||||
array(
|
||||
'key' => '_wp_page_template',
|
||||
'value' => 'default',
|
||||
),
|
||||
),
|
||||
$result['posts'][1]['postmeta'],
|
||||
$message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers WXR_Parser_SimpleXML::parse
|
||||
* @covers WXR_Parser_XML::parse
|
||||
* @covers WXR_Parser_Regex::parse
|
||||
*/
|
||||
public function test_wxr_version_1_0() {
|
||||
if ( PHP_VERSION_ID >= 80400 ) {
|
||||
$this->markTestSkipped( 'The Importer plugin is not ready for PHP 8.4 yet. This skip should be removed once it is.' );
|
||||
}
|
||||
|
||||
$file = DIR_TESTDATA . '/export/valid-wxr-1.0.xml';
|
||||
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
|
||||
$message = $p . ' failed';
|
||||
$parser = new $p();
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
$this->assertIsArray( $result, $message );
|
||||
$this->assertSame( 'http://localhost/', $result['base_url'], $message );
|
||||
$this->assertSame( $result['categories'][0]['category_nicename'], 'alpha', $message );
|
||||
$this->assertSame( $result['categories'][0]['cat_name'], 'alpha', $message );
|
||||
$this->assertSame( $result['categories'][0]['category_parent'], '', $message );
|
||||
$this->assertSame( $result['categories'][0]['category_description'], 'The alpha category', $message );
|
||||
$this->assertSame( $result['tags'][0]['tag_slug'], 'chicken', $message );
|
||||
$this->assertSame( $result['tags'][0]['tag_name'], 'chicken', $message );
|
||||
|
||||
$this->assertCount( 6, $result['posts'], $message );
|
||||
$this->assertCount( 19, $result['posts'][0], $message );
|
||||
$this->assertCount( 18, $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->assertSame(
|
||||
array(
|
||||
array(
|
||||
'key' => '_wp_page_template',
|
||||
'value' => 'default',
|
||||
),
|
||||
),
|
||||
$result['posts'][1]['postmeta'],
|
||||
$message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the WXR parser's ability to correctly retrieve content from CDATA
|
||||
* sections that contain escaped closing tags ("]]>" -> "]]]]><![CDATA[>").
|
||||
*
|
||||
* @link https://core.trac.wordpress.org/ticket/15203
|
||||
*
|
||||
* @covers WXR_Parser_SimpleXML::parse
|
||||
* @covers WXR_Parser_XML::parse
|
||||
* @covers WXR_Parser_Regex::parse
|
||||
*/
|
||||
public function test_escaped_cdata_closing_sequence() {
|
||||
if ( PHP_VERSION_ID >= 80400 ) {
|
||||
$this->markTestSkipped( 'The Importer plugin is not ready for PHP 8.4 yet. This skip should be removed once it is.' );
|
||||
}
|
||||
|
||||
$file = DIR_TESTDATA . '/export/crazy-cdata-escaped.xml';
|
||||
|
||||
foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML', 'WXR_Parser_Regex' ) as $p ) {
|
||||
$message = 'Parser ' . $p;
|
||||
$parser = new $p();
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
$post = $result['posts'][0];
|
||||
$this->assertSame( '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( sprintf( 'Unknown postmeta (%1$s) was parsed out by %2$s.', $meta['key'], $p ) );
|
||||
}
|
||||
$this->assertSame( $value, $meta['value'], $message );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the regex parser can still parse invalid CDATA blocks (i.e. those
|
||||
* with "]]>" unescaped within a CDATA section).
|
||||
*
|
||||
* @covers WXR_Parser_Regex::parse
|
||||
*/
|
||||
public function test_unescaped_cdata_closing_sequence() {
|
||||
$file = DIR_TESTDATA . '/export/crazy-cdata.xml';
|
||||
|
||||
$parser = new WXR_Parser_Regex();
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
$post = $result['posts'][0];
|
||||
$this->assertSame( '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( sprintf( 'Unknown postmeta (%1$s) was parsed out by %2$s.', $meta['key'], $p ) );
|
||||
}
|
||||
$this->assertSame( $value, $meta['value'] );
|
||||
}
|
||||
}
|
||||
|
||||
// Tags in CDATA #11574.
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/base.php';
|
||||
|
||||
/**
|
||||
* @group import
|
||||
*
|
||||
* @covers WP_Import::import
|
||||
*/
|
||||
class Tests_Import_Postmeta extends WP_Import_UnitTestCase {
|
||||
public function set_up() {
|
||||
parent::set_up();
|
||||
|
||||
if ( ! defined( 'WP_IMPORTING' ) ) {
|
||||
define( 'WP_IMPORTING', true );
|
||||
}
|
||||
|
||||
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
|
||||
define( 'WP_LOAD_IMPORTERS', true );
|
||||
}
|
||||
|
||||
$this->require_importer();
|
||||
}
|
||||
|
||||
public function test_serialized_postmeta_no_cdata() {
|
||||
$this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-no-cdata.xml', array( 'johncoswell' => 'john' ) );
|
||||
$expected['special_post_title'] = 'A special title';
|
||||
$expected['is_calendar'] = '';
|
||||
$this->assertSame( $expected, get_post_meta( 122, 'post-options', true ) );
|
||||
}
|
||||
|
||||
public function test_utw_postmeta() {
|
||||
$this->_import_wp( DIR_TESTDATA . '/export/test-utw-post-meta-import.xml', array( 'johncoswell' => 'john' ) );
|
||||
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'album';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'apple';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'art';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'artwork';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'dead-tracks';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'ipod';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'itunes';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'javascript';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'lyrics';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'script';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'tracks';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'windows-scripting-host';
|
||||
$expected[] = $classy;
|
||||
$classy = new StdClass();
|
||||
$classy->tag = 'wscript';
|
||||
$expected[] = $classy;
|
||||
|
||||
$this->assertEqualSets( $expected, get_post_meta( 150, 'test', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 9633
|
||||
*/
|
||||
public function test_serialized_postmeta_with_cdata() {
|
||||
$this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) );
|
||||
|
||||
// HTML in the CDATA should work with old WordPress version.
|
||||
$this->assertSame( '<pre>some html</pre>', get_post_meta( 10, 'contains-html', true ) );
|
||||
// Serialised will only work with 3.0 onwards.
|
||||
$expected['special_post_title'] = 'A special title';
|
||||
$expected['is_calendar'] = '';
|
||||
$this->assertSame( $expected, get_post_meta( 10, 'post-options', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 11574
|
||||
*/
|
||||
public function test_serialized_postmeta_with_evil_stuff_in_cdata() {
|
||||
$this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) );
|
||||
// Evil content in the CDATA.
|
||||
$this->assertSame( '<wp:meta_value>evil</wp:meta_value>', get_post_meta( 10, 'evil', true ) );
|
||||
}
|
||||
}
|
@ -26,8 +26,6 @@ wp_cli( `config set WP_DEVELOPMENT_MODE ${process.env.LOCAL_WP_DEVELOPMENT_MODE}
|
||||
// Move wp-config.php to the base directory, so it doesn't get mixed up in the src or build directories.
|
||||
renameSync( `${process.env.LOCAL_DIR}/wp-config.php`, 'wp-config.php' );
|
||||
|
||||
install_wp_importer();
|
||||
|
||||
// Read in wp-tests-config-sample.php, edit it to work with our config, then write it to wp-tests-config.php.
|
||||
const testConfig = readFileSync( 'wp-tests-config-sample.php', 'utf8' )
|
||||
.replace( 'youremptytestdbnamehere', 'wordpress_develop_tests' )
|
||||
@ -57,14 +55,3 @@ function wp_cli( cmd ) {
|
||||
|
||||
execSync( `docker compose ${composeFiles} run --quiet-pull --rm cli ${cmd} --path=/var/www/${process.env.LOCAL_DIR}`, { stdio: 'inherit' } );
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the WordPress Importer plugin for use in tests.
|
||||
*/
|
||||
function install_wp_importer() {
|
||||
const testPluginDirectory = 'tests/phpunit/data/plugins/wordpress-importer';
|
||||
const composeFiles = local_env_utils.get_compose_files();
|
||||
|
||||
execSync( `docker compose ${composeFiles} exec -T php rm -rf ${testPluginDirectory}`, { stdio: 'inherit' } );
|
||||
execSync( `docker compose ${composeFiles} exec -T php git clone https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user