From 358ddc9710320c0247d17f850ad2ef32bc6cca0b Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 26 Mar 2019 00:45:57 +0000 Subject: [PATCH] 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 --- package.json | 2 +- phpunit.xml.dist | 3 + tests/phpunit/includes/testcase.php | 40 +++++++ tests/phpunit/multisite.xml | 3 + tests/phpunit/tests/canonical/https.php | 15 --- .../formatting/SanitizeTitleWithDashes.php | 14 --- .../phpunit/tests/formatting/SanitizeUser.php | 8 -- tests/phpunit/tests/functions.php | 31 ------ tests/phpunit/tests/mail.php | 34 ------ tests/phpunit/tests/post.php | 55 ---------- tests/phpunit/tests/post/filtering.php | 100 ------------------ tests/phpunit/tests/post/listPages.php | 31 ------ tests/phpunit/tests/query/results.php | 24 ----- tests/phpunit/tests/shortcode.php | 10 -- tests/phpunit/tests/taxonomy.php | 64 ----------- tests/phpunit/tests/xmlrpc/wp/uploadFile.php | 26 ----- 16 files changed, 47 insertions(+), 413 deletions(-) diff --git a/package.json b/package.json index d7d067ab87..2fc4f8fa39 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2178ce2e42..abf5f00059 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -25,4 +25,7 @@ + + + diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index a7f1275921..4b9bd85b7d 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -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(); diff --git a/tests/phpunit/multisite.xml b/tests/phpunit/multisite.xml index d4361a5467..b2a2633cc6 100644 --- a/tests/phpunit/multisite.xml +++ b/tests/phpunit/multisite.xml @@ -25,4 +25,7 @@ ajax + + + diff --git a/tests/phpunit/tests/canonical/https.php b/tests/phpunit/tests/canonical/https.php index 2d354f6040..84a85f6577 100644 --- a/tests/phpunit/tests/canonical/https.php +++ b/tests/phpunit/tests/canonical/https.php @@ -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 */ diff --git a/tests/phpunit/tests/formatting/SanitizeTitleWithDashes.php b/tests/phpunit/tests/formatting/SanitizeTitleWithDashes.php index 53931bd173..1b9d5d7239 100644 --- a/tests/phpunit/tests/formatting/SanitizeTitleWithDashes.php +++ b/tests/phpunit/tests/formatting/SanitizeTitleWithDashes.php @@ -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   Entities – Here &")); - $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 & 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("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')); } diff --git a/tests/phpunit/tests/formatting/SanitizeUser.php b/tests/phpunit/tests/formatting/SanitizeUser.php index 3f7f03b34a..2cf808df37 100644 --- a/tests/phpunit/tests/formatting/SanitizeUser.php +++ b/tests/phpunit/tests/formatting/SanitizeUser.php @@ -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&T")); - $this->assertEquals("ATT Test;", sanitize_user("AT&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" ) ); diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 6d7f972cf3..445e11365e 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -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 */ diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php index 441a29787b..2ca73dd1ec 100644 --- a/tests/phpunit/tests/mail.php +++ b/tests/phpunit/tests/mail.php @@ -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' =>'Here is the 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 - -Here is the 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 */ diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 134742e3bf..25ae94bf49 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -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 */ diff --git a/tests/phpunit/tests/post/filtering.php b/tests/phpunit/tests/post/filtering.php index fff1b20304..57c4ed7b72 100644 --- a/tests/phpunit/tests/post/filtering.php +++ b/tests/phpunit/tests/post/filtering.php @@ -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 = <<some text -that's continued after the jump -EOF; - - $expected = <<some text -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 = <<some text -that's continued after the jump -EOF; - - $expected = <<some text -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 = <<some text -that's continued after the jump - -

and the next page - -breaks the graf

-EOF; - - $expected = <<some text -that's continued after the jump - -

and the next page -

-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 = <<some text -that's continued after the jump - -

and the next page - -breaks the graf

-EOF; - - $expected = <<some text -that's continued after the jump - -

and the next page -

-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() { diff --git a/tests/phpunit/tests/post/listPages.php b/tests/phpunit/tests/post/listPages.php index fa4a375902..faf494a5a5 100644 --- a/tests/phpunit/tests/post/listPages.php +++ b/tests/phpunit/tests/post/listPages.php @@ -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'] = ''; - $actual = wp_list_pages( $args ); - $this->AssertEquals( $expected['exclude_depth'], $actual ); - } - } diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index 9a3e89d264..8119e5559b 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -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 */ diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index 27c8ffb42d..160c957a9d 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -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 */ diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 6d9cc117cc..41eb655fdb 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -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 */ diff --git a/tests/phpunit/tests/xmlrpc/wp/uploadFile.php b/tests/phpunit/tests/xmlrpc/wp/uploadFile.php index 44f3fb749d..0e3e7a8f19 100644 --- a/tests/phpunit/tests/xmlrpc/wp/uploadFile.php +++ b/tests/phpunit/tests/xmlrpc/wp/uploadFile.php @@ -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 ); - } - }