Skip to content

Commit

Permalink
Merge upstream changes to test files from wordpress-develop (#181)
Browse files Browse the repository at this point in the history
* Merge missing change from https://core.trac.wordpress.org/changeset/47122.

* Merge changes from https://core.trac.wordpress.org/changeset/48840/.

* Merge changes from https://core.trac.wordpress.org/changeset/49033.

* Merge changes from https://core.trac.wordpress.org/changeset/53864.

* Merge changes from https://core.trac.wordpress.org/changeset/54402.

* Merge changes from https://core.trac.wordpress.org/changeset/56738.

* Add a weekly schedule.

---------

Co-authored-by: desrosj <[email protected]>
Co-authored-by: swissspidy <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2025
1 parent c693419 commit 90f7db9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
branches:
- master
pull_request:
schedule:
- cron: '0 0 * * 1'
# Allow manually triggering the workflow.
workflow_dispatch:

Expand Down
19 changes: 12 additions & 7 deletions phpunit/tests/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function set_up() {
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 ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DELETE FROM {$wpdb->$table}" );
}
}
Expand All @@ -33,6 +32,9 @@ public function tear_down() {
parent::tear_down();
}

/**
* @covers WP_Import::import
*/
public function test_small_import() {
global $wpdb;

Expand All @@ -59,8 +61,8 @@ public function test_small_import() {
$this->assertSame( '[email protected]', $author->user_email );

// Check that terms were imported correctly.
$this->assertSame( '30', wp_count_terms( 'category' ) );
$this->assertSame( '3', wp_count_terms( 'post_tag' ) );
$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' );
Expand Down Expand Up @@ -201,6 +203,9 @@ public function test_small_import() {
$this->assertCount( 1, $cats );
}

/**
* @covers WP_Import::import
*/
public function test_double_import() {
$authors = array(
'admin' => false,
Expand All @@ -224,8 +229,8 @@ public function test_double_import() {
$this->assertSame( 'author', $author->user_login );
$this->assertSame( '[email protected]', $author->user_email );

$this->assertSame( '30', wp_count_terms( 'category' ) );
$this->assertSame( '3', wp_count_terms( 'post_tag' ) );
$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' );
Expand All @@ -244,6 +249,8 @@ public function test_double_import() {

/**
* @ticket 21007
*
* @covers WP_Import::import
*/
public function test_slashes_should_not_be_stripped() {
global $wpdb;
Expand Down Expand Up @@ -291,6 +298,4 @@ public function test_fetch_remote_file_php81_deprecation() {
'The WP Error object did not contain the expected error'
);
}

// function test_menu_import
}
39 changes: 32 additions & 7 deletions phpunit/tests/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public function set_up() {
}
}

/**
* @covers WXR_Parser_SimpleXML::parse
* @covers WXR_Parser_XML::parse
*/
public function test_malformed_wxr() {
$file = DIR_TESTDATA_WP_IMPORTER . '/malformed.xml';

Expand All @@ -30,6 +34,11 @@ public function test_malformed_wxr() {
}
}

/**
* @covers WXR_Parser_SimpleXML::parse
* @covers WXR_Parser_XML::parse
* @covers WXR_Parser_Regex::parse
*/
public function test_invalid_wxr() {
$f1 = DIR_TESTDATA_WP_IMPORTER . '/missing-version-tag.xml';
$f2 = DIR_TESTDATA_WP_IMPORTER . '/invalid-version-tag.xml';
Expand All @@ -44,6 +53,11 @@ public function test_invalid_wxr() {
}
}

/**
* @covers WXR_Parser_SimpleXML::parse
* @covers WXR_Parser_XML::parse
* @covers WXR_Parser_Regex::parse
*/
public function test_wxr_version_1_1() {
$file = DIR_TESTDATA_WP_IMPORTER . '/valid-wxr-1.1.xml';

Expand All @@ -54,7 +68,7 @@ public function test_wxr_version_1_1() {

$this->assertIsArray( $result, $message );
$this->assertSame( 'http://localhost/', $result['base_url'], $message );
$this->assertEquals(
$this->assertEqualSetsWithIndex(
array(
'author_id' => 2,
'author_login' => 'john',
Expand All @@ -66,7 +80,7 @@ public function test_wxr_version_1_1() {
$result['authors']['john'],
$message
);
$this->assertEquals(
$this->assertEqualSetsWithIndex(
array(
'term_id' => 3,
'category_nicename' => 'alpha',
Expand All @@ -77,7 +91,7 @@ public function test_wxr_version_1_1() {
$result['categories'][0],
$message
);
$this->assertEquals(
$this->assertEqualSetsWithIndex(
array(
'term_id' => 22,
'tag_slug' => 'clippable',
Expand All @@ -87,7 +101,7 @@ public function test_wxr_version_1_1() {
$result['tags'][0],
$message
);
$this->assertEquals(
$this->assertEqualSetsWithIndex(
array(
'term_id' => 40,
'term_taxonomy' => 'post_tax',
Expand All @@ -103,7 +117,7 @@ public function test_wxr_version_1_1() {
$this->assertCount( 2, $result['posts'], $message );
$this->assertCount( 19, $result['posts'][0], $message );
$this->assertCount( 18, $result['posts'][1], $message );
$this->assertEquals(
$this->assertEqualSetsWithIndex(
array(
array(
'name' => 'alpha',
Expand Down Expand Up @@ -137,6 +151,11 @@ public function test_wxr_version_1_1() {
}
}

/**
* @covers WXR_Parser_SimpleXML::parse
* @covers WXR_Parser_XML::parse
* @covers WXR_Parser_Regex::parse
*/
public function test_wxr_version_1_0() {
$file = DIR_TESTDATA_WP_IMPORTER . '/valid-wxr-1.0.xml';

Expand Down Expand Up @@ -267,6 +286,10 @@ public function test_varied_taxonomy_term_spacing() {
* 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() {
$file = DIR_TESTDATA_WP_IMPORTER . '/crazy-cdata-escaped.xml';
Expand All @@ -290,7 +313,7 @@ public function test_escaped_cdata_closing_sequence() {
$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->fail( sprintf( 'Unknown postmeta (%1$s) was parsed out by %2$s.', $meta['key'], $p ) );
}
$this->assertSame( $value, $meta['value'], $message );
}
Expand All @@ -300,6 +323,8 @@ public function test_escaped_cdata_closing_sequence() {
/**
* 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_WP_IMPORTER . '/crazy-cdata.xml';
Expand All @@ -321,7 +346,7 @@ public function test_unescaped_cdata_closing_sequence() {
$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->fail( sprintf( 'Unknown postmeta (%1$s) was parsed out by %2$s.', $meta['key'], $p ) );
}
$this->assertSame( $value, $meta['value'] );
}
Expand Down
4 changes: 3 additions & 1 deletion phpunit/tests/postmeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/**
* @group import
* @group post-meta
*
* @covers WP_Import::import
*/
class Tests_Import_Postmeta extends WP_Import_UnitTestCase {
public function set_up() {
Expand Down Expand Up @@ -69,7 +71,7 @@ public function test_utw_postmeta() {
$classy->tag = 'wscript';
$expected[] = $classy;

$this->assertEquals( $expected, get_post_meta( 150, 'test', true ) );
$this->assertEqualSetsWithIndex( $expected, get_post_meta( 150, 'test', true ) );
}

/**
Expand Down

0 comments on commit 90f7db9

Please sign in to comment.