Build/Test tools: Fix the Travis CI build for the 4.0 branch.

Among other fixes, this backports [29860], [29869], [29954], [30160], [30530].

Fixes #46646


git-svn-id: https://develop.svn.wordpress.org/branches/4.0@45013 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2019-03-26 00:45:57 +00:00
parent 239c1aaa46
commit 358ddc9710
16 changed files with 47 additions and 413 deletions

View File

@ -25,7 +25,7 @@
"grunt-jsvalidate": "~0.2.2",
"grunt-legacy-util": "^0.2.0",
"grunt-patch-wordpress": "~0.2.1",
"grunt-sass": "~0.14.0",
"grunt-sass": "~0.16.0",
"matchdep": "~0.3.0"
}
}

View File

@ -25,4 +25,7 @@
<logging>
<log type="junit" target="tests/phpunit/build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
<php>
<const name="WP_RUN_CORE_TESTS" value="1" />
</php>
</phpunit>

View File

@ -37,11 +37,51 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
ini_set('display_errors', 1 );
$this->factory = new WP_UnitTest_Factory;
$this->clean_up_global_scope();
/*
* When running core tests, ensure that post types and taxonomies
* are reset for each test. We skip this step for non-core tests,
* given the large number of plugins that register post types and
* taxonomies at 'init'.
*/
if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
$this->reset_post_types();
$this->reset_taxonomies();
}
$this->start_transaction();
$this->expectDeprecated();
add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
}
/**
* Unregister existing post types and register defaults.
*
* Run before each test in order to clean up the global scope, in case
* a test forgets to unregister a post type on its own, or fails before
* it has a chance to do so.
*/
protected function reset_post_types() {
foreach ( get_post_types() as $pt ) {
_unregister_post_type( $pt );
}
create_initial_post_types();
}
/**
* Unregister existing taxonomies and register defaults.
*
* Run before each test in order to clean up the global scope, in case
* a test forgets to unregister a taxonomy on its own, or fails before
* it has a chance to do so.
*/
protected function reset_taxonomies() {
foreach ( get_taxonomies() as $tax ) {
_unregister_taxonomy( $tax );
}
create_initial_taxonomies();
}
function tearDown() {
global $wpdb, $wp_query, $post;
$this->expectedDeprecated();

View File

@ -25,4 +25,7 @@
<group>ajax</group>
</exclude>
</groups>
<php>
<const name="WP_RUN_CORE_TESTS" value="1" />
</php>
</phpunit>

View File

@ -41,21 +41,6 @@ class Tests_Canonical_HTTPS extends Tests_Canonical {
}
/**
* @ticket 27954
*/
public function test_http_request_with_https_home() {
add_filter( 'home_url', array( $this, 'set_https' ) );
$redirect = redirect_canonical( $this->http, false );
$this->assertEquals( $redirect, $this->https );
remove_filter( 'home_url', array( $this, 'set_https' ) );
}
/**
* @ticket 27954
*/

View File

@ -35,20 +35,6 @@ class Tests_Formatting_SanitizeTitleWithDashes extends WP_UnitTestCase {
$this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
}
/**
* @ticket 10823
*/
function test_strips_entities() {
$this->assertEquals("no-entities-here", sanitize_title_with_dashes("No &nbsp; Entities &ndash; Here &amp;"));
$this->assertEquals("one-two", sanitize_title_with_dashes("One &amp; Two", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One &#123; Two;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One & Two;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One Two™;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One &&amp; Two;", '', 'save'));
$this->assertEquals("onetwo", sanitize_title_with_dashes("One&Two", '', 'save'));
$this->assertEquals("onetwo-test", sanitize_title_with_dashes("One&Two Test;", '', 'save'));
}
function test_replaces_nbsp() {
$this->assertEquals("dont-break-the-space", sanitize_title_with_dashes("don't break the space", '', 'save'));
}

View File

@ -9,14 +9,6 @@ class Tests_Formatting_SanitizeUser extends WP_UnitTestCase {
$expected = is_multisite() ? 'captain awesome' : 'Captain Awesome';
$this->assertEquals($expected, sanitize_user($input));
}
/**
* @ticket 10823
*/
function test_strips_entities() {
$this->assertEquals("ATT", sanitize_user("AT&amp;T"));
$this->assertEquals("ATT Test;", sanitize_user("AT&amp;T Test;"));
$this->assertEquals("AT&T Test;", sanitize_user("AT&T Test;"));
}
function test_strips_percent_encoded_octets() {
$expected = is_multisite() ? 'franois' : 'Franois';
$this->assertEquals( $expected, sanitize_user( "Fran%c3%a7ois" ) );

View File

@ -131,37 +131,6 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\\fg.png' ), 'Tripple slashed not removed' );
}
/**
* @ticket 9930
*/
function test_is_serialized() {
$cases = array(
serialize(null),
serialize(true),
serialize(false),
serialize(-25),
serialize(25),
serialize(1.1),
serialize(2.1E+200),
serialize('this string will be serialized'),
serialize("a\nb"),
serialize(array()),
serialize(array(1,1,2,3,5,8,13)),
serialize( (object)array('test' => true, '3', 4) )
);
foreach ( $cases as $case )
$this->assertTrue( is_serialized($case), "Serialized data: $case" );
$not_serialized = array(
'a string',
'garbage:a:0:garbage;',
'b:4;',
's:4:test;'
);
foreach ( $not_serialized as $case )
$this->assertFalse( is_serialized($case), "Test data: $case" );
}
/**
* @group add_query_arg
*/

View File

@ -71,40 +71,6 @@ class Tests_Mail extends WP_UnitTestCase {
$this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0);
}
/**
* @ticket 15448
*/
function test_wp_mail_plain_and_html() {
$to = 'user@example.com';
$subject = 'Test email with plain text and html versions';
$messages = array( 'text/plain' => 'Here is some plain text.',
'text/html' =>'<html><head></head><body>Here is the HTML ;-)<body></html>' );
wp_mail( $to, $subject, $messages );
preg_match( '/boundary="(.*)"/', $GLOBALS['phpmailer']->mock_sent[0]['header'], $matches);
$boundry = $matches[1];
$body = '--' . $boundry . '
Content-Type: text/plain; charset = "UTF-8"
Content-Transfer-Encoding: 8bit
Here is some plain text.
--' . $boundry . '
Content-Type: text/html; charset = "UTF-8"
Content-Transfer-Encoding: 8bit
<html><head></head><body>Here is the HTML ;-)<body></html>
--' . $boundry . '--
';
// We need some better assertions here but these test the behaviour for now.
$this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
}
/**
* @ticket 17305
*/

View File

@ -739,61 +739,6 @@ class Tests_Post extends WP_UnitTestCase {
$this->assertEquals( $post->post_title, $title );
}
/**
* @ticket 19373
*/
function test_insert_programmatic_without_current_user_success() {
$this->_unset_current_user();
register_taxonomy( 'test_tax', 'post' );
$title = rand_str();
$post_data = array(
'post_author' => $this->author_id,
'post_status' => 'public',
'post_content' => rand_str(),
'post_title' => $title,
'tax_input' => array(
'test_tax' => array( 'term', 'term2', 'term3' )
)
);
// with sanitize set to false
$insert_post_id = wp_insert_post( $post_data, true, false );
$post = get_post( $insert_post_id );
$this->assertEquals( $post->post_author, $this->author_id );
$this->assertEquals( $post->post_title, $title );
$terms = wp_get_object_terms( $insert_post_id, 'test_tax' );
$this->assertTrue( ( is_array( $terms ) && count( $terms ) == 3 ) );
}
/**
* @ticket 19373
*/
function test_insert_programmatic_without_current_user_fail() {
$this->_unset_current_user();
register_taxonomy( 'test_tax', 'post' );
$title = rand_str();
$post_data = array(
// post_author not set
'post_status' => 'public',
'post_content' => rand_str(),
'post_title' => $title,
'tax_input' => array(
'test_tax' => array( 'term', 'term2', 'term3' )
)
);
// with sanitize set to false
$insert_post_id = wp_insert_post( $post_data, true, false );
// should error because no default user exists and no post author is passed in
$this->assertInstanceOf( 'WP_Error', $insert_post_id );
$this->assertEquals( 'empty_author', $insert_post_id->get_error_code() );
}
/**
* @ticket 24803
*/

View File

@ -90,106 +90,6 @@ EOF;
$this->assertEquals( $expected, $post->post_content );
}
/**
* make sure unbalanced tags are fixed when they span a --more-- tag
* @ticket 6297
*/
function test_post_content_unbalanced_more() {
$content = <<<EOF
<em>some text<!--more-->
that's continued after the jump</em>
EOF;
$expected = <<<EOF
<em>some text</em><!--more-->
that's continued after the jump
EOF;
$id = $this->factory->post->create( array( 'post_content' => $content ) );
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
/**
* make sure unbalanced tags are fixed when they span a --nextpage-- tag
* @ticket 6297
*/
function test_post_content_unbalanced_nextpage() {
$content = <<<EOF
<em>some text<!--nextpage-->
that's continued after the jump</em>
EOF;
$expected = <<<EOF
<em>some text</em><!--nextpage-->
that's continued after the jump
EOF;
$id = $this->factory->post->create( array( 'post_content' => $content ) );
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
/**
* make sure unbalanced tags are fixed when they span both --more-- and --nextpage-- tags (in that order)
* @ticket 6297
*/
function test_post_content_unbalanced_more_nextpage() {
$content = <<<EOF
<em>some text<!--more-->
that's continued after the jump</em>
<!--nextpage-->
<p>and the next page
<!--nextpage-->
breaks the graf</p>
EOF;
$expected = <<<EOF
<em>some text</em><!--more-->
that's continued after the jump
<!--nextpage-->
<p>and the next page
</p><!--nextpage-->
breaks the graf
EOF;
$id = $this->factory->post->create( array( 'post_content' => $content ) );
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
/**
* make sure unbalanced tags are fixed when they span both --nextpage-- and --more-- tags (in that order)
* @ticket 6297
*/
function test_post_content_unbalanced_nextpage_more() {
$content = <<<EOF
<em>some text<!--nextpage-->
that's continued after the jump</em>
<!--more-->
<p>and the next page
<!--nextpage-->
breaks the graf</p>
EOF;
$expected = <<<EOF
<em>some text</em><!--nextpage-->
that's continued after the jump
<!--more-->
<p>and the next page
</p><!--nextpage-->
breaks the graf
EOF;
$id = $this->factory->post->create( array( 'post_content' => $content ) );
$post = get_post($id);
$this->assertEquals( $expected, $post->post_content );
}
// make sure unbalanced tags are untouched when the balance option is off
function test_post_content_nobalance_nextpage_more() {

View File

@ -343,35 +343,4 @@ class Tests_List_Pages extends WP_UnitTestCase {
$this->AssertEquals( $expected['exclude'], $actual );
}
/**
* @ticket 27326
*/
function test_wp_list_page_combo_exclude_depth() {
$args = array(
'echo' => false,
'exclude' => '3',
'depth' => 3
);
$expected['exclude_depth'] = '<li class="pagenav">Pages<ul><li class="page_item page-item-1 page_item_has_children"><a href="' . get_permalink( 1 ) . '">Parent 1</a>
<ul class=\'children\'>
<li class="page_item page-item-4"><a href="' . get_permalink( 4 ) . '">Child 1</a></li>
<li class="page_item page-item-5"><a href="' . get_permalink( 5 ) . '">Child 2</a></li>
<li class="page_item page-item-6"><a href="' . get_permalink( 6 ) . '">Child 3</a></li>
</ul>
</li>
<li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a>
<ul class=\'children\'>
<li class="page_item page-item-7"><a href="' . get_permalink( 7 ) . '">Child 1</a></li>
<li class="page_item page-item-8"><a href="' . get_permalink( 8 ) . '">Child 2</a></li>
<li class="page_item page-item-9"><a href="' . get_permalink( 9 ) . '">Child 3</a></li>
</ul>
</li>
<li class="page_item page-item-10"><a href="' . get_permalink( 10 ) . '">Child 1</a></li>
<li class="page_item page-item-11"><a href="' . get_permalink( 11 ) . '">Child 2</a></li>
<li class="page_item page-item-12"><a href="' . get_permalink( 12 ) . '">Child 3</a></li>
</ul></li>';
$actual = wp_list_pages( $args );
$this->AssertEquals( $expected['exclude_depth'], $actual );
}
}

View File

@ -278,30 +278,6 @@ class Tests_Query_Results extends WP_UnitTestCase {
$this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) );
}
/**
* @ticket 18897
*/
function test_query_offset_and_paged() {
$posts = $this->q->query('paged=2&offset=3');
$expected = array (
0 => 'many-trackbacks',
1 => 'one-trackback',
2 => 'comment-test',
3 => 'lorem-ipsum',
4 => 'cat-c',
5 => 'cat-b',
6 => 'cat-a',
7 => 'cats-a-and-c',
8 => 'cats-b-and-c',
9 => 'cats-a-and-b',
);
$this->assertCount( 10, $posts );
$this->assertTrue( $this->q->is_paged() );
$this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) );
}
/**
* @ticket 11056
*/

View File

@ -307,16 +307,6 @@ EOF;
$this->assertEquals( $test_string, shortcode_unautop( wpautop( $test_string ) ) );
}
/**
* @ticket 14050
*/
function test_multiple_shortcode_unautop() {
// a blank line is added at the end, so test with it already there
$test_string = "[footag]\n[footag]\n";
$actual = shortcode_unautop( wpautop( $test_string ) );
$this->assertEquals( $test_string, $actual );
}
/**
* @ticket 10326
*/

View File

@ -33,22 +33,6 @@ class Tests_Taxonomy extends WP_UnitTestCase {
}
}
function test_get_the_taxonomies() {
$post_id = $this->factory->post->create();
$taxes = get_the_taxonomies( $post_id );
$this->assertNotEmpty( $taxes );
$this->assertEquals( array( 'category' ), array_keys( $taxes ) );
$id = $this->factory->tag->create();
wp_set_post_tags( $post_id, array( $id ) );
$taxes = get_the_taxonomies( $post_id );
$this->assertNotEmpty( $taxes );
$this->assertCount( 2, $taxes );
$this->assertEquals( array( 'category', 'post_tag' ), array_keys( $taxes ) );
}
function test_the_taxonomies() {
$post_id = $this->factory->post->create();
@ -134,54 +118,6 @@ class Tests_Taxonomy extends WP_UnitTestCase {
$this->assertInstanceOf( 'WP_Error', register_taxonomy( 'abcdefghijklmnopqrstuvwxyz0123456789', 'post', array() ) );
}
/**
* @ticket 11058
*/
function test_registering_taxonomies_to_object_types() {
// Create a taxonomy to test with
$tax = 'test_tax';
$this->assertFalse( taxonomy_exists($tax) );
register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) );
// Create a post type to test with
$post_type = 'test_cpt';
$this->assertFalse( get_post_type( $post_type ) );
$this->assertObjectHasAttribute( 'name', register_post_type( $post_type ) );
// Core taxonomy, core post type
$this->assertTrue( unregister_taxonomy_for_object_type( 'category', 'post' ) );
$this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'post' ) );
$this->assertTrue( register_taxonomy_for_object_type( 'category', 'post' ) );
// Core taxonomy, non-core post type
$this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) );
$this->assertTrue( unregister_taxonomy_for_object_type( 'category', $post_type ) );
$this->assertFalse( unregister_taxonomy_for_object_type( 'category', $post_type ) );
$this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) );
// Core taxonomies, non-post object types
$this->assertFalse( register_taxonomy_for_object_type( 'category', 'user' ) );
$this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'user' ) );
// Non-core taxonomy, core post type
$this->assertTrue( unregister_taxonomy_for_object_type( $tax, 'post' ) );
$this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'post' ) );
$this->assertTrue( register_taxonomy_for_object_type( $tax, 'post' ) );
// Non-core taxonomy, non-core post type
$this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) );
$this->assertTrue( unregister_taxonomy_for_object_type( $tax, $post_type ) );
$this->assertFalse( unregister_taxonomy_for_object_type( $tax, $post_type ) );
$this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) );
// Non-core taxonomies, non-post object types
$this->assertFalse( register_taxonomy_for_object_type( $tax, 'user' ) );
$this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) );
unset($GLOBALS['wp_taxonomies'][$tax]);
_unregister_post_type( $post_type );
}
/**
* @ticket 25706
*/

View File

@ -29,30 +29,4 @@ class Tests_XMLRPC_wp_uploadFile extends WP_XMLRPC_UnitTestCase {
$this->assertInternalType( 'string', $result['type'] );
}
/**
* @ticket 21292
*/
function test_network_limit() {
$this->make_user_by_role( 'editor' );
update_option( 'blog_upload_space', 0.1 );
// create attachment
$filename = ( DIR_TESTDATA . '/images/canola.jpg' );
$contents = file_get_contents( $filename );
$data = array(
'name' => 'canola.jpg',
'type' => 'image/jpeg',
'bits' => $contents
);
$result = $this->myxmlrpcserver->mw_newMediaObject( array( 0, 'editor', 'editor', $data ) );
// Only multisite should have a limit
if ( is_multisite() )
$this->assertInstanceOf( 'IXR_Error', $result );
else
$this->assertNotInstanceOf( 'IXR_Error', $result );
}
}