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
This commit is contained in:
John Blackbourn 2016-10-26 01:23:24 +00:00
parent 1f49a4c0cf
commit 307ba51640
13 changed files with 84 additions and 69 deletions

View File

@ -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 );

View File

@ -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',

View File

@ -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;

View File

@ -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,
);

View File

@ -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');
}

View File

@ -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',

View File

@ -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) );

View File

@ -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',
);

View File

@ -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 );

View File

@ -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 ) );

View File

@ -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

View File

@ -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 );

View File

@ -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 );