From 307ba5164003cf9ae19e21edc28a2dd15d8ead28 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 26 Oct 2016 01:23:24 +0000 Subject: [PATCH] Build/Test Tools: Continue eliminating randomness in tests. See #37371 git-svn-id: https://develop.svn.wordpress.org/trunk@38938 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/adminbar.php | 4 +- tests/phpunit/tests/post/thumbnails.php | 16 ++--- tests/phpunit/tests/post/wpPostType.php | 16 ++--- tests/phpunit/tests/post/wpUniquePostSlug.php | 2 +- tests/phpunit/tests/query/conditionals.php | 2 +- tests/phpunit/tests/query/metaQuery.php | 69 +++++++++++-------- tests/phpunit/tests/user/capabilities.php | 4 +- tests/phpunit/tests/user/wpDeleteUser.php | 8 +-- tests/phpunit/tests/xmlrpc/wp/editComment.php | 2 +- tests/phpunit/tests/xmlrpc/wp/editProfile.php | 4 +- tests/phpunit/tests/xmlrpc/wp/getTerms.php | 8 +-- tests/phpunit/tests/xmlrpc/wp/getUser.php | 16 ++--- tests/phpunit/tests/xmlrpc/wp/getUsers.php | 2 +- 13 files changed, 84 insertions(+), 69 deletions(-) diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index 11880a0526..00461f8490 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -349,8 +349,8 @@ class Tests_AdminBar extends WP_UnitTestCase { $post = array( 'post_author' => self::$editor_id, 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), + 'post_content' => 'Post Content', + 'post_title' => 'Post Title', ); $id = wp_insert_post( $post ); diff --git a/tests/phpunit/tests/post/thumbnails.php b/tests/phpunit/tests/post/thumbnails.php index cc3c183f55..a597ccd165 100644 --- a/tests/phpunit/tests/post/thumbnails.php +++ b/tests/phpunit/tests/post/thumbnails.php @@ -281,8 +281,8 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { $post_id = wp_insert_post( array( 'ID' => self::$post->ID, 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), + 'post_content' => 'Post content', + 'post_title' => 'Post Title', '_thumbnail_id' => self::$attachment_id, ) ); @@ -292,8 +292,8 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { $post_id = wp_insert_post( array( 'ID' => $post_id, 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), + 'post_content' => 'Post content', + 'post_title' => 'Post Title', '_thumbnail_id' => - 1, // -1 removes post thumbnail. ) ); @@ -309,8 +309,8 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { $post_id = wp_insert_post( array( 'post_type' => 'attachment', 'post_status' => 'inherit', - 'post_content' => rand_str(), - 'post_title' => rand_str(), + 'post_content' => 'Post content', + 'post_title' => 'Post Title', 'post_mime_type' => 'audio/mpeg', 'post_parent' => 0, 'file' => DIR_TESTDATA . '/audio/test-noise.mp3', // File does not exist, but does not matter here. @@ -324,8 +324,8 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { $post_id = wp_insert_post( array( 'post_type' => 'attachment', 'post_status' => 'inherit', - 'post_content' => rand_str(), - 'post_title' => rand_str(), + 'post_content' => 'Post content', + 'post_title' => 'Post Title', 'post_mime_type' => 'image/jpeg', 'post_parent' => 0, 'file' => DIR_TESTDATA . '/images/canola.jpg', diff --git a/tests/phpunit/tests/post/wpPostType.php b/tests/phpunit/tests/post/wpPostType.php index 4d4602b27a..e9d1d71d21 100644 --- a/tests/phpunit/tests/post/wpPostType.php +++ b/tests/phpunit/tests/post/wpPostType.php @@ -13,7 +13,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { } public function test_add_supports_defaults() { - $post_type = rand_str(); + $post_type = 'cpt'; $post_type_object = new WP_Post_Type( $post_type ); $post_type_object->add_supports(); @@ -27,7 +27,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { } public function test_add_supports_custom() { - $post_type = rand_str(); + $post_type = 'cpt'; $post_type_object = new WP_Post_Type( $post_type, array( 'supports' => array( 'editor', @@ -56,7 +56,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { /* @var WP $wp */ global $wp; - $post_type = rand_str(); + $post_type = 'cpt'; $post_type_object = new WP_Post_Type( $post_type, array( 'rewrite' => false, 'query_var' => 'foobar' ) ); $post_type_object->add_rewrite_rules(); @@ -69,7 +69,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { /* @var WP $wp */ global $wp; - $post_type = rand_str(); + $post_type = 'cpt'; $post_type_object = new WP_Post_Type( $post_type, array( 'public' => true, 'rewrite' => false, @@ -92,7 +92,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { /* @var WP_Rewrite $wp_rewrite */ global $wp_rewrite; - $post_type = rand_str(); + $post_type = 'cpt'; $post_type_object = new WP_Post_Type( $post_type, array( 'public' => true, 'rewrite' => true ) ); $post_type_object->add_rewrite_rules(); @@ -106,7 +106,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { } public function test_register_meta_boxes() { - $post_type = rand_str(); + $post_type = 'cpt'; $post_type_object = new WP_Post_Type( $post_type, array( 'register_meta_box_cb' => '__return_false' ) ); $post_type_object->register_meta_boxes(); @@ -119,7 +119,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { } public function test_adds_future_post_hook() { - $post_type = rand_str(); + $post_type = 'cpt'; $post_type_object = new WP_Post_Type( $post_type ); $post_type_object->add_hooks(); $has_action = has_action( "future_$post_type", '_future_post_hook' ); @@ -133,7 +133,7 @@ class Tests_WP_Post_Type extends WP_UnitTestCase { public function test_register_taxonomies() { global $wp_post_types; - $post_type = rand_str(); + $post_type = 'cpt'; $post_type_object = new WP_Post_Type( $post_type, array( 'taxonomies' => array( 'post_tag' ) ) ); $wp_post_types[ $post_type ] = $post_type_object; diff --git a/tests/phpunit/tests/post/wpUniquePostSlug.php b/tests/phpunit/tests/post/wpUniquePostSlug.php index 62f1ad6397..536017db31 100644 --- a/tests/phpunit/tests/post/wpUniquePostSlug.php +++ b/tests/phpunit/tests/post/wpUniquePostSlug.php @@ -27,7 +27,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $post = array( 'post_author' => $author_id, 'post_status' => 'publish', - 'post_content' => rand_str(), + 'post_content' => 'Post content', 'post_title' => $post_title, ); diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 21963c7c81..a3df6d0324 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -55,7 +55,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { } function test_404() { - $this->go_to('/'.rand_str()); + $this->go_to( '/notapage' ); $this->assertQueryTrue('is_404'); } diff --git a/tests/phpunit/tests/query/metaQuery.php b/tests/phpunit/tests/query/metaQuery.php index 2a9717a0ba..ee98c3768a 100644 --- a/tests/phpunit/tests/query/metaQuery.php +++ b/tests/phpunit/tests/query/metaQuery.php @@ -390,18 +390,23 @@ class Tests_Query_MetaQuery extends WP_UnitTestCase { public function test_meta_query_relation_or() { $post_id = self::factory()->post->create(); - add_post_meta( $post_id, 'foo', rand_str() ); - add_post_meta( $post_id, 'foo', rand_str() ); + add_post_meta( $post_id, 'foo', 'foo_val_1' ); + add_post_meta( $post_id, 'foo', 'foo_val_2' ); + $post_id2 = self::factory()->post->create(); - add_post_meta( $post_id2, 'bar', 'val2' ); + add_post_meta( $post_id2, 'bar', 'bar_val_1' ); + $post_id3 = self::factory()->post->create(); - add_post_meta( $post_id3, 'baz', rand_str() ); + add_post_meta( $post_id3, 'baz', 'baz_val_1' ); + $post_id4 = self::factory()->post->create(); - add_post_meta( $post_id4, 'froo', rand_str() ); + add_post_meta( $post_id4, 'froo', 'froo_val_1' ); + $post_id5 = self::factory()->post->create(); - add_post_meta( $post_id5, 'tango', 'val2' ); + add_post_meta( $post_id5, 'tango', 'tango_val_1' ); + $post_id6 = self::factory()->post->create(); - add_post_meta( $post_id6, 'bar', 'val1' ); + add_post_meta( $post_id6, 'bar', 'bar_val_2' ); $query = new WP_Query( array( 'update_post_meta_cache' => false, @@ -413,7 +418,7 @@ class Tests_Query_MetaQuery extends WP_UnitTestCase { ), array( 'key' => 'bar', - 'value' => 'val2' + 'value' => 'bar_val_1' ), array( 'key' => 'baz' @@ -431,25 +436,31 @@ class Tests_Query_MetaQuery extends WP_UnitTestCase { public function test_meta_query_relation_and() { $post_id = self::factory()->post->create(); - add_post_meta( $post_id, 'foo', rand_str() ); - add_post_meta( $post_id, 'foo', rand_str() ); + add_post_meta( $post_id, 'foo', 'foo_val_1' ); + add_post_meta( $post_id, 'foo', 'foo_val_2' ); + $post_id2 = self::factory()->post->create(); - add_post_meta( $post_id2, 'bar', 'val2' ); - add_post_meta( $post_id2, 'foo', rand_str() ); + add_post_meta( $post_id2, 'bar', 'val_2' ); + add_post_meta( $post_id2, 'foo', 'foo_val_3' ); + $post_id3 = self::factory()->post->create(); - add_post_meta( $post_id3, 'baz', rand_str() ); + add_post_meta( $post_id3, 'baz', 'baz_val_1' ); + $post_id4 = self::factory()->post->create(); - add_post_meta( $post_id4, 'froo', rand_str() ); + add_post_meta( $post_id4, 'froo', 'froo_val_1' ); + $post_id5 = self::factory()->post->create(); - add_post_meta( $post_id5, 'tango', 'val2' ); + add_post_meta( $post_id5, 'tango', 'val_2' ); + $post_id6 = self::factory()->post->create(); add_post_meta( $post_id6, 'bar', 'val1' ); - add_post_meta( $post_id6, 'foo', rand_str() ); + add_post_meta( $post_id6, 'foo', 'foo_val_4' ); + $post_id7 = self::factory()->post->create(); - add_post_meta( $post_id7, 'foo', rand_str() ); - add_post_meta( $post_id7, 'froo', rand_str() ); - add_post_meta( $post_id7, 'baz', rand_str() ); - add_post_meta( $post_id7, 'bar', 'val2' ); + add_post_meta( $post_id7, 'foo', 'foo_val_5' ); + add_post_meta( $post_id7, 'froo', 'froo_val_2' ); + add_post_meta( $post_id7, 'baz', 'baz_val_2' ); + add_post_meta( $post_id7, 'bar', 'val_2' ); $query = new WP_Query( array( 'meta_query' => array( @@ -458,7 +469,7 @@ class Tests_Query_MetaQuery extends WP_UnitTestCase { ), array( 'key' => 'bar', - 'value' => 'val2' + 'value' => 'val_2' ), array( 'key' => 'baz' @@ -565,15 +576,19 @@ class Tests_Query_MetaQuery extends WP_UnitTestCase { */ public function test_meta_query_compare_not_exists() { $post_id = self::factory()->post->create(); - add_post_meta( $post_id, 'foo', rand_str() ); + add_post_meta( $post_id, 'foo', 'foo_val_1' ); + $post_id2 = self::factory()->post->create(); - add_post_meta( $post_id2, 'bar', rand_str() ); + add_post_meta( $post_id2, 'bar', 'bar_val_1' ); + $post_id3 = self::factory()->post->create(); - add_post_meta( $post_id3, 'bar', rand_str() ); + add_post_meta( $post_id3, 'bar', 'bar_val_2' ); + $post_id4 = self::factory()->post->create(); - add_post_meta( $post_id4, 'baz', rand_str() ); + add_post_meta( $post_id4, 'baz', 'baz_val_1' ); + $post_id5 = self::factory()->post->create(); - add_post_meta( $post_id5, 'foo', rand_str() ); + add_post_meta( $post_id5, 'foo', 'foo_val_2' ); $query = new WP_Query( array( 'meta_query' => array( @@ -1452,7 +1467,7 @@ class Tests_Query_MetaQuery extends WP_UnitTestCase { $post_id4 = self::factory()->post->create(); add_post_meta( $post_id4, 'baz', 'bar' ); $post_id5 = self::factory()->post->create(); - add_post_meta( $post_id5, 'foo', rand_str() ); + add_post_meta( $post_id5, 'foo', 'tango' ); $posts = get_posts( array( 'meta_key' => 'foo', diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index 61caa76890..42868f76ea 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -674,7 +674,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { // change the capabilites associated with a role and make sure the change is reflected in has_cap() global $wp_roles; - $role_name = rand_str(); + $role_name = 'janitor'; add_role( $role_name, 'Janitor', array('level_1'=>true) ); $this->_flush_roles(); $this->assertTrue( $wp_roles->is_role($role_name) ); @@ -714,7 +714,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { // change the capabilites associated with a role and make sure the change is reflected in has_cap() global $wp_roles; - $role_name = rand_str(); + $role_name = 'janitor'; add_role( $role_name, 'Janitor', array('level_1'=>true, 'sweep_floor'=>true, 'polish_doorknobs'=>true) ); $this->_flush_roles(); $this->assertTrue( $wp_roles->is_role($role_name) ); diff --git a/tests/phpunit/tests/user/wpDeleteUser.php b/tests/phpunit/tests/user/wpDeleteUser.php index 2e249896c9..60e7cafede 100644 --- a/tests/phpunit/tests/user/wpDeleteUser.php +++ b/tests/phpunit/tests/user/wpDeleteUser.php @@ -60,8 +60,8 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase { $post = array( 'post_author' => $user_id, 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), + 'post_content' => 'Post content', + 'post_title' => 'Post Title', 'post_type' => 'post', ); @@ -76,8 +76,8 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase { $post = array( 'post_author' => $user_id, 'post_status' => 'publish', - 'post_content' => rand_str(), - 'post_title' => rand_str(), + 'post_content' => 'Post content', + 'post_title' => 'Post Title', 'post_type' => 'nav_menu_item', ); diff --git a/tests/phpunit/tests/xmlrpc/wp/editComment.php b/tests/phpunit/tests/xmlrpc/wp/editComment.php index ad3adaaffe..b43beb6ee0 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editComment.php +++ b/tests/phpunit/tests/xmlrpc/wp/editComment.php @@ -56,7 +56,7 @@ class Tests_XMLRPC_wp_editComment extends WP_XMLRPC_UnitTestCase { 'comment_author' => 'Test commenter', 'comment_author_url' => 'http://example.com/', 'comment_author_email' => 'example@example.com', - 'comment_content' => rand_str( 100 ), + 'comment_content' => 'Comment content', 'comment_approved' => '1' ); $comment_id = wp_insert_comment( $comment_data ); diff --git a/tests/phpunit/tests/xmlrpc/wp/editProfile.php b/tests/phpunit/tests/xmlrpc/wp/editProfile.php index bb6dd47e59..b096157d1b 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editProfile.php +++ b/tests/phpunit/tests/xmlrpc/wp/editProfile.php @@ -41,7 +41,7 @@ class Tests_XMLRPC_wp_editProfile extends WP_XMLRPC_UnitTestCase { function test_ignore_password_change() { $this->make_user_by_role( 'author' ); - $new_pass = rand_str(); + $new_pass = 'newpassword'; $new_data = array( 'password' => $new_pass ); $result = $this->myxmlrpcserver->wp_editProfile( array( 1, 'author', 'author', $new_data ) ); @@ -56,7 +56,7 @@ class Tests_XMLRPC_wp_editProfile extends WP_XMLRPC_UnitTestCase { function test_ignore_email_change() { $editor_id = $this->make_user_by_role( 'editor' ); - $new_email = rand_str() . '@example.com'; + $new_email = 'notaneditor@example.com'; $new_data = array( 'email' => $new_email ); $result = $this->myxmlrpcserver->wp_editProfile( array( 1, 'editor', 'editor', $new_data ) ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getTerms.php b/tests/phpunit/tests/xmlrpc/wp/getTerms.php index 794c709d53..1673975f1f 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getTerms.php +++ b/tests/phpunit/tests/xmlrpc/wp/getTerms.php @@ -42,7 +42,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { $this->make_user_by_role( 'editor' ); // make sure there's at least one category - $cat = wp_insert_term( 'term' . rand_str() , 'category' ); + $cat = wp_insert_term( 'term_' . __FUNCTION__ , 'category' ); $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category' ) ); $this->assertNotInstanceOf( 'IXR_Error', $results ); @@ -103,8 +103,8 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { function test_term_ordering() { $this->make_user_by_role( 'editor' ); - $cat1 = wp_create_category( 'wp.getTerms_' . rand_str( 16 ) ); - $cat2 = wp_create_category( 'wp.getTerms_' . rand_str( 16 ) ); + $cat1 = wp_create_category( 'wp.getTerms_' . __FUNCTION__ . '_1' ); + $cat2 = wp_create_category( 'wp.getTerms_' . __FUNCTION__ . '_2' ); self::factory()->post->create_many( 5, array( 'post_category' => array( $cat1 ) ) ); self::factory()->post->create_many( 3, array( 'post_category' => array( $cat2 ) ) ); @@ -127,7 +127,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { function test_terms_search() { $this->make_user_by_role( 'editor' ); - $name = rand_str( 30 ); + $name = __FUNCTION__; $name_id = wp_create_category( $name ); // search by full name diff --git a/tests/phpunit/tests/xmlrpc/wp/getUser.php b/tests/phpunit/tests/xmlrpc/wp/getUser.php index 6ae6bdcd7e..acef3c6a06 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getUser.php +++ b/tests/phpunit/tests/xmlrpc/wp/getUser.php @@ -56,17 +56,17 @@ class Tests_XMLRPC_wp_getUser extends WP_XMLRPC_UnitTestCase { $registered_date = strtotime( '-1 day' ); $user_data = array( 'user_login' => 'getusertestuser', - 'user_pass' => rand_str(), - 'first_name' => rand_str(), - 'last_name' => rand_str(), - 'description' => rand_str( 100 ), + 'user_pass' => 'password', + 'first_name' => 'First', + 'last_name' => 'Last', + 'description' => 'I love WordPress', 'user_email' => 'getUserTestUser@example.com', - 'nickname' => rand_str(), - 'user_nicename' => rand_str(), - 'display_name' => rand_str(), + 'nickname' => 'nickname', + 'user_nicename' => 'nicename', + 'display_name' => 'First Last', 'user_url' => 'http://www.example.com/testuser', 'role' => 'author', - 'aim' => rand_str(), + 'aim' => 'wordpress', 'user_registered' => strftime( "%Y-%m-%d %H:%M:%S", $registered_date ) ); $user_id = wp_insert_user( $user_data ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getUsers.php b/tests/phpunit/tests/xmlrpc/wp/getUsers.php index 27a75565c7..1860fd11d3 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getUsers.php +++ b/tests/phpunit/tests/xmlrpc/wp/getUsers.php @@ -47,7 +47,7 @@ class Tests_XMLRPC_wp_getUsers extends WP_XMLRPC_UnitTestCase { if ( is_multisite() ) grant_super_admin( $administrator_id ); - $filter = array( 'role' => rand_str() ); + $filter = array( 'role' => 'invalidrole' ); $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator', $filter ) ); $this->assertInstanceOf( 'IXR_Error', $results ); $this->assertEquals( 403, $results->code );