Build/Test Tools: Continue eliminating randomness in tests.

See [38762]
See #37371


git-svn-id: https://develop.svn.wordpress.org/trunk@38763 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2016-10-09 01:29:04 +00:00
parent c91be6f1fe
commit b4f01bb97f
9 changed files with 110 additions and 110 deletions

View File

@ -9,7 +9,7 @@ class Tests_Actions extends WP_UnitTestCase {
function test_simple_action() { function test_simple_action() {
$a = new MockAction(); $a = new MockAction();
$tag = 'test_action'; $tag = __FUNCTION__;
add_action($tag, array(&$a, 'action')); add_action($tag, array(&$a, 'action'));
do_action($tag); do_action($tag);
@ -26,7 +26,7 @@ class Tests_Actions extends WP_UnitTestCase {
function test_remove_action() { function test_remove_action() {
$a = new MockAction(); $a = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
add_action($tag, array(&$a, 'action')); add_action($tag, array(&$a, 'action'));
do_action($tag); do_action($tag);
@ -44,8 +44,8 @@ class Tests_Actions extends WP_UnitTestCase {
} }
function test_has_action() { function test_has_action() {
$tag = rand_str(); $tag = __FUNCTION__;
$func = rand_str(); $func = __FUNCTION__ . '_func';
$this->assertFalse( has_action($tag, $func) ); $this->assertFalse( has_action($tag, $func) );
$this->assertFalse( has_action($tag) ); $this->assertFalse( has_action($tag) );
@ -61,7 +61,7 @@ class Tests_Actions extends WP_UnitTestCase {
function test_multiple_actions() { function test_multiple_actions() {
$a1 = new MockAction(); $a1 = new MockAction();
$a2 = new MockAction(); $a2 = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
// add both actions to the hook // add both actions to the hook
add_action($tag, array(&$a1, 'action')); add_action($tag, array(&$a1, 'action'));
@ -76,8 +76,8 @@ class Tests_Actions extends WP_UnitTestCase {
function test_action_args_1() { function test_action_args_1() {
$a = new MockAction(); $a = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
$val = rand_str(); $val = __FUNCTION__ . '_val';
add_action($tag, array(&$a, 'action')); add_action($tag, array(&$a, 'action'));
// call the action with a single argument // call the action with a single argument
@ -92,9 +92,9 @@ class Tests_Actions extends WP_UnitTestCase {
function test_action_args_2() { function test_action_args_2() {
$a1 = new MockAction(); $a1 = new MockAction();
$a2 = new MockAction(); $a2 = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
$val1 = rand_str(); $val1 = __FUNCTION__ . '_val1';
$val2 = rand_str(); $val2 = __FUNCTION__ . '_val2';
// a1 accepts two arguments, a2 doesn't // a1 accepts two arguments, a2 doesn't
add_action($tag, array(&$a1, 'action'), 10, 2); add_action($tag, array(&$a1, 'action'), 10, 2);
@ -125,9 +125,9 @@ class Tests_Actions extends WP_UnitTestCase {
$a1 = new MockAction(); $a1 = new MockAction();
$a2 = new MockAction(); $a2 = new MockAction();
$a3 = new MockAction(); $a3 = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
$val1 = rand_str(); $val1 = __FUNCTION__ . '_val1';
$val2 = rand_str(); $val2 = __FUNCTION__ . '_val2';
// a1 accepts two arguments, a2 doesn't, a3 accepts two arguments // a1 accepts two arguments, a2 doesn't, a3 accepts two arguments
add_action( $tag, array( &$a1, 'action' ), 10, 2 ); add_action( $tag, array( &$a1, 'action' ), 10, 2 );
@ -155,7 +155,7 @@ class Tests_Actions extends WP_UnitTestCase {
function test_action_priority() { function test_action_priority() {
$a = new MockAction(); $a = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
add_action($tag, array(&$a, 'action'), 10); add_action($tag, array(&$a, 'action'), 10);
add_action($tag, array(&$a, 'action2'), 9); add_action($tag, array(&$a, 'action2'), 9);
@ -204,8 +204,8 @@ class Tests_Actions extends WP_UnitTestCase {
function test_all_action() { function test_all_action() {
$a = new MockAction(); $a = new MockAction();
$tag1 = rand_str(); $tag1 = __FUNCTION__ . '_1';
$tag2 = rand_str(); $tag2 = __FUNCTION__ . '_2';
// add an 'all' action // add an 'all' action
add_action('all', array(&$a, 'action')); add_action('all', array(&$a, 'action'));
@ -228,7 +228,7 @@ class Tests_Actions extends WP_UnitTestCase {
function test_remove_all_action() { function test_remove_all_action() {
$a = new MockAction(); $a = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
add_action('all', array(&$a, 'action')); add_action('all', array(&$a, 'action'));
$this->assertEquals(10, has_filter('all', array(&$a, 'action'))); $this->assertEquals(10, has_filter('all', array(&$a, 'action')));
@ -249,7 +249,7 @@ class Tests_Actions extends WP_UnitTestCase {
function test_action_ref_array() { function test_action_ref_array() {
$obj = new stdClass(); $obj = new stdClass();
$a = new MockAction(); $a = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
add_action($tag, array(&$a, 'action')); add_action($tag, array(&$a, 'action'));
@ -268,17 +268,17 @@ class Tests_Actions extends WP_UnitTestCase {
function test_action_keyed_array() { function test_action_keyed_array() {
$a = new MockAction(); $a = new MockAction();
$tag = rand_str(); $tag = __FUNCTION__;
add_action($tag, array(&$a, 'action')); add_action($tag, array(&$a, 'action'));
$context = array( rand_str() => rand_str() ); $context = array( 'key1' => 'val1' );
do_action($tag, $context); do_action($tag, $context);
$args = $a->get_args(); $args = $a->get_args();
$this->assertSame($args[0][0], $context); $this->assertSame($args[0][0], $context);
$context2 = array( rand_str() => rand_str(), rand_str() => rand_str() ); $context2 = array( 'key2' => 'val2', 'key3' => 'val3' );
do_action($tag, $context2); do_action($tag, $context2);
$args = $a->get_args(); $args = $a->get_args();
@ -300,7 +300,7 @@ class Tests_Actions extends WP_UnitTestCase {
* @ticket 17817 * @ticket 17817
*/ */
function test_action_recursion() { function test_action_recursion() {
$tag = rand_str(); $tag = __FUNCTION__;
$a = new MockAction(); $a = new MockAction();
$b = new MockAction(); $b = new MockAction();
@ -327,7 +327,7 @@ class Tests_Actions extends WP_UnitTestCase {
* @ticket 17817 * @ticket 17817
*/ */
function test_action_callback_manipulation_while_running() { function test_action_callback_manipulation_while_running() {
$tag = rand_str(); $tag = __FUNCTION__;
$a = new MockAction(); $a = new MockAction();
$b = new MockAction(); $b = new MockAction();
$c = new MockAction(); $c = new MockAction();
@ -362,7 +362,7 @@ class Tests_Actions extends WP_UnitTestCase {
* https://core.trac.wordpress.org/ticket/17817#comment:52 * https://core.trac.wordpress.org/ticket/17817#comment:52
*/ */
function test_remove_anonymous_callback() { function test_remove_anonymous_callback() {
$tag = rand_str(); $tag = __FUNCTION__;
$a = new MockAction(); $a = new MockAction();
add_action( $tag, array( $a, 'action' ), 12, 1 ); add_action( $tag, array( $a, 'action' ), 12, 1 );
$this->assertTrue( has_action( $tag ) ); $this->assertTrue( has_action( $tag ) );
@ -396,7 +396,7 @@ class Tests_Actions extends WP_UnitTestCase {
*/ */
function test_array_access_of_wp_filter_global() { function test_array_access_of_wp_filter_global() {
global $wp_filter; global $wp_filter;
$tag = rand_str(); $tag = __FUNCTION__;
add_action( $tag, '__return_null', 11, 1 ); add_action( $tag, '__return_null', 11, 1 );

View File

@ -17,7 +17,7 @@ class Tests_Actions_Closures extends WP_UnitTestCase {
$this->assertSame( 10, has_action($tag, $closure) ); $this->assertSame( 10, has_action($tag, $closure) );
$context = array( rand_str(), rand_str() ); $context = array( 'val1', 'val2' );
do_action($tag, $context[0], $context[1]); do_action($tag, $context[0], $context[1]);
$this->assertSame($GLOBALS[$context[0]], $context[1]); $this->assertSame($GLOBALS[$context[0]], $context[1]);

View File

@ -154,7 +154,7 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
} }
function test_help_tabs() { function test_help_tabs() {
$tab = rand_str(); $tab = __FUNCTION__;
$tab_args = array( $tab_args = array(
'id' => $tab, 'id' => $tab,
'title' => 'Help!', 'title' => 'Help!',
@ -278,7 +278,7 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
* @ticket 25799 * @ticket 25799
*/ */
function test_options() { function test_options() {
$option = rand_str(); $option = __FUNCTION__;
$option_args = array( $option_args = array(
'label' => 'Option', 'label' => 'Option',
'default' => 10, 'default' => 10,

View File

@ -27,19 +27,19 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_miss() { function test_miss() {
$this->assertEquals(NULL, $this->cache->get(rand_str())); $this->assertEquals( NULL, $this->cache->get( 'test_miss' ) );
} }
function test_add_get() { function test_add_get() {
$key = rand_str(); $key = __FUNCTION__;
$val = rand_str(); $val = 'val';
$this->cache->add($key, $val); $this->cache->add($key, $val);
$this->assertEquals($val, $this->cache->get($key)); $this->assertEquals($val, $this->cache->get($key));
} }
function test_add_get_0() { function test_add_get_0() {
$key = rand_str(); $key = __FUNCTION__;
$val = 0; $val = 0;
// you can store zero in the cache // you can store zero in the cache
@ -48,7 +48,7 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_add_get_null() { function test_add_get_null() {
$key = rand_str(); $key = __FUNCTION__;
$val = null; $val = null;
$this->assertTrue( $this->cache->add($key, $val) ); $this->assertTrue( $this->cache->add($key, $val) );
@ -57,9 +57,9 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_add() { function test_add() {
$key = rand_str(); $key = __FUNCTION__;
$val1 = rand_str(); $val1 = 'val1';
$val2 = rand_str(); $val2 = 'val2';
// add $key to the cache // add $key to the cache
$this->assertTrue($this->cache->add($key, $val1)); $this->assertTrue($this->cache->add($key, $val1));
@ -70,9 +70,9 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_replace() { function test_replace() {
$key = rand_str(); $key = __FUNCTION__;
$val = rand_str(); $val = 'val1';
$val2 = rand_str(); $val2 = 'val2';
// memcached rejects replace() if the key does not exist // memcached rejects replace() if the key does not exist
$this->assertFalse($this->cache->replace($key, $val)); $this->assertFalse($this->cache->replace($key, $val));
@ -84,9 +84,9 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_set() { function test_set() {
$key = rand_str(); $key = __FUNCTION__;
$val1 = rand_str(); $val1 = 'val1';
$val2 = rand_str(); $val2 = 'val2';
// memcached accepts set() if the key does not exist // memcached accepts set() if the key does not exist
$this->assertTrue($this->cache->set($key, $val1)); $this->assertTrue($this->cache->set($key, $val1));
@ -102,8 +102,8 @@ class Tests_Cache extends WP_UnitTestCase {
if ( $_wp_using_ext_object_cache ) if ( $_wp_using_ext_object_cache )
return; return;
$key = rand_str(); $key = __FUNCTION__;
$val = rand_str(); $val = 'val';
$this->cache->add($key, $val); $this->cache->add($key, $val);
// item is visible to both cache objects // item is visible to both cache objects
@ -115,7 +115,7 @@ class Tests_Cache extends WP_UnitTestCase {
// Make sure objects are cloned going to and from the cache // Make sure objects are cloned going to and from the cache
function test_object_refs() { function test_object_refs() {
$key = rand_str(); $key = __FUNCTION__ . '_1';
$object_a = new stdClass; $object_a = new stdClass;
$object_a->foo = 'alpha'; $object_a->foo = 'alpha';
$this->cache->set( $key, $object_a ); $this->cache->set( $key, $object_a );
@ -125,7 +125,7 @@ class Tests_Cache extends WP_UnitTestCase {
$object_b->foo = 'charlie'; $object_b->foo = 'charlie';
$this->assertEquals( 'bravo', $object_a->foo ); $this->assertEquals( 'bravo', $object_a->foo );
$key = rand_str(); $key = __FUNCTION__ . '_2';
$object_a = new stdClass; $object_a = new stdClass;
$object_a->foo = 'alpha'; $object_a->foo = 'alpha';
$this->cache->add( $key, $object_a ); $this->cache->add( $key, $object_a );
@ -137,7 +137,7 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_incr() { function test_incr() {
$key = rand_str(); $key = __FUNCTION__;
$this->assertFalse( $this->cache->incr( $key ) ); $this->assertFalse( $this->cache->incr( $key ) );
@ -150,7 +150,7 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_wp_cache_incr() { function test_wp_cache_incr() {
$key = rand_str(); $key = __FUNCTION__;
$this->assertFalse( wp_cache_incr( $key ) ); $this->assertFalse( wp_cache_incr( $key ) );
@ -163,7 +163,7 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_decr() { function test_decr() {
$key = rand_str(); $key = __FUNCTION__;
$this->assertFalse( $this->cache->decr( $key ) ); $this->assertFalse( $this->cache->decr( $key ) );
@ -183,7 +183,7 @@ class Tests_Cache extends WP_UnitTestCase {
* @ticket 21327 * @ticket 21327
*/ */
function test_wp_cache_decr() { function test_wp_cache_decr() {
$key = rand_str(); $key = __FUNCTION__;
$this->assertFalse( wp_cache_decr( $key ) ); $this->assertFalse( wp_cache_decr( $key ) );
@ -200,8 +200,8 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_delete() { function test_delete() {
$key = rand_str(); $key = __FUNCTION__;
$val = rand_str(); $val = 'val';
// Verify set // Verify set
$this->assertTrue( $this->cache->set( $key, $val ) ); $this->assertTrue( $this->cache->set( $key, $val ) );
@ -215,8 +215,8 @@ class Tests_Cache extends WP_UnitTestCase {
} }
function test_wp_cache_delete() { function test_wp_cache_delete() {
$key = rand_str(); $key = __FUNCTION__;
$val = rand_str(); $val = 'val';
// Verify set // Verify set
$this->assertTrue( wp_cache_set( $key, $val ) ); $this->assertTrue( wp_cache_set( $key, $val ) );
@ -237,9 +237,9 @@ class Tests_Cache extends WP_UnitTestCase {
if ( ! method_exists( $this->cache, 'switch_to_blog' ) ) if ( ! method_exists( $this->cache, 'switch_to_blog' ) )
return; return;
$key = rand_str(); $key = __FUNCTION__;
$val = rand_str(); $val = 'val1';
$val2 = rand_str(); $val2 = 'val2';
if ( ! is_multisite() ) { if ( ! is_multisite() ) {
// Single site ingnores switch_to_blog(). // Single site ingnores switch_to_blog().

View File

@ -622,7 +622,7 @@ class Tests_Comment_Submission extends WP_UnitTestCase {
$data = array( $data = array(
'comment_post_ID' => $post->ID, 'comment_post_ID' => $post->ID,
'comment' => rand_str(), 'comment' => 'Comment',
'author' => rand_long_str( 255 ), 'author' => rand_long_str( 255 ),
'email' => 'comment@example.org', 'email' => 'comment@example.org',
); );
@ -642,7 +642,7 @@ class Tests_Comment_Submission extends WP_UnitTestCase {
$data = array( $data = array(
'comment_post_ID' => $post->ID, 'comment_post_ID' => $post->ID,
'comment' => rand_str(), 'comment' => 'Comment',
'author' => 'Comment Author', 'author' => 'Comment Author',
'email' => rand_long_str( 90 ) . '@example.com', 'email' => rand_long_str( 90 ) . '@example.com',
); );
@ -661,7 +661,7 @@ class Tests_Comment_Submission extends WP_UnitTestCase {
$post = self::factory()->post->create_and_get(); $post = self::factory()->post->create_and_get();
$data = array( $data = array(
'comment_post_ID' => $post->ID, 'comment_post_ID' => $post->ID,
'comment' => rand_str(), 'comment' => 'Comment',
'author' => 'Comment Author', 'author' => 'Comment Author',
'email' => 'comment@example.org', 'email' => 'comment@example.org',
'url' => rand_long_str( 201 ), 'url' => rand_long_str( 201 ),

View File

@ -127,11 +127,11 @@ class Tests_Comment extends WP_UnitTestCase {
public function test_wp_new_comment_respects_dates() { public function test_wp_new_comment_respects_dates() {
$data = array( $data = array(
'comment_post_ID' => self::$post_id, 'comment_post_ID' => self::$post_id,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
'comment_date' => '2011-01-01 10:00:00', 'comment_date' => '2011-01-01 10:00:00',
'comment_date_gmt' => '2011-01-01 10:00:00', 'comment_date_gmt' => '2011-01-01 10:00:00',
); );
@ -150,12 +150,12 @@ class Tests_Comment extends WP_UnitTestCase {
public function test_wp_new_comment_respects_author_ip() { public function test_wp_new_comment_respects_author_ip() {
$data = array( $data = array(
'comment_post_ID' => self::$post_id, 'comment_post_ID' => self::$post_id,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_IP' => '192.168.1.1', 'comment_author_IP' => '192.168.1.1',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
); );
$id = wp_new_comment( $data ); $id = wp_new_comment( $data );
@ -171,12 +171,12 @@ class Tests_Comment extends WP_UnitTestCase {
public function test_wp_new_comment_respects_author_ip_empty_string() { public function test_wp_new_comment_respects_author_ip_empty_string() {
$data = array( $data = array(
'comment_post_ID' => self::$post_id, 'comment_post_ID' => self::$post_id,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_IP' => '', 'comment_author_IP' => '',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
); );
$id = wp_new_comment( $data ); $id = wp_new_comment( $data );
@ -192,13 +192,13 @@ class Tests_Comment extends WP_UnitTestCase {
public function test_wp_new_comment_respects_comment_agent() { public function test_wp_new_comment_respects_comment_agent() {
$data = array( $data = array(
'comment_post_ID' => self::$post_id, 'comment_post_ID' => self::$post_id,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_IP' => '', 'comment_author_IP' => '',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53', 'comment_agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
); );
$id = wp_new_comment( $data ); $id = wp_new_comment( $data );
@ -214,13 +214,13 @@ class Tests_Comment extends WP_UnitTestCase {
public function test_wp_new_comment_should_trim_provided_comment_agent_to_254_chars() { public function test_wp_new_comment_should_trim_provided_comment_agent_to_254_chars() {
$data = array( $data = array(
'comment_post_ID' => self::$post_id, 'comment_post_ID' => self::$post_id,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_IP' => '', 'comment_author_IP' => '',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en; rv:1.8.1.4pre) Gecko/20070511 Camino/1.6pre', 'comment_agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en; rv:1.8.1.4pre) Gecko/20070511 Camino/1.6pre',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
); );
$id = wp_new_comment( $data ); $id = wp_new_comment( $data );
@ -236,13 +236,13 @@ class Tests_Comment extends WP_UnitTestCase {
public function test_wp_new_comment_respects_comment_agent_empty_string() { public function test_wp_new_comment_respects_comment_agent_empty_string() {
$data = array( $data = array(
'comment_post_ID' => self::$post_id, 'comment_post_ID' => self::$post_id,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_IP' => '', 'comment_author_IP' => '',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_agent' => '', 'comment_agent' => '',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
); );
$id = wp_new_comment( $data ); $id = wp_new_comment( $data );
@ -256,7 +256,7 @@ class Tests_Comment extends WP_UnitTestCase {
public function test_comment_field_lengths() { public function test_comment_field_lengths() {
$data = array( $data = array(
'comment_post_ID' => self::$post_id, 'comment_post_ID' => self::$post_id,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_type' => '', 'comment_type' => '',
@ -538,11 +538,11 @@ class Tests_Comment extends WP_UnitTestCase {
// Moderators are notified when a new comment is added. // Moderators are notified when a new comment is added.
$data = array( $data = array(
'comment_post_ID' => $post, 'comment_post_ID' => $post,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
); );
wp_new_comment( $data ); wp_new_comment( $data );
@ -588,11 +588,11 @@ class Tests_Comment extends WP_UnitTestCase {
// Post authors are notified when a new comment is added to their post. // Post authors are notified when a new comment is added to their post.
$data = array( $data = array(
'comment_post_ID' => $post, 'comment_post_ID' => $post,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
); );
wp_new_comment( $data ); wp_new_comment( $data );
@ -638,13 +638,13 @@ class Tests_Comment extends WP_UnitTestCase {
$default_data = array( $default_data = array(
'comment_post_ID' => self::$post_id, 'comment_post_ID' => self::$post_id,
'comment_author' => rand_str(), 'comment_author' => 'Comment Author',
'comment_author_IP' => '192.168.0.1', 'comment_author_IP' => '192.168.0.1',
'comment_agent' => 'WRONG_AGENT', 'comment_agent' => 'WRONG_AGENT',
'comment_author_url' => '', 'comment_author_url' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_type' => '', 'comment_type' => '',
'comment_content' => rand_str(), 'comment_content' => 'Comment',
); );
$comment_id = wp_new_comment( $default_data ); $comment_id = wp_new_comment( $default_data );

View File

@ -40,9 +40,9 @@ class Tests_Comment_GetCommentAuthorEmailLink extends WP_UnitTestCase {
public function test_all_parameters() { public function test_all_parameters() {
unset( $GLOBALS['comment'] ); unset( $GLOBALS['comment'] );
$linktext = rand_str( 10 ); $linktext = 'linktext';
$before = rand_str( 5 ); $before = 'before';
$after = rand_str( 6 ); $after = 'after';
$comment = self::factory()->comment->create_and_get( array( $comment = self::factory()->comment->create_and_get( array(
'comment_author_email' => $email = 'baz@example.org' 'comment_author_email' => $email = 'baz@example.org'
) ); ) );
@ -53,9 +53,9 @@ class Tests_Comment_GetCommentAuthorEmailLink extends WP_UnitTestCase {
} }
public function test_all_parameters_with_global_comment() { public function test_all_parameters_with_global_comment() {
$linktext = rand_str( 10 ); $linktext = 'linktext';
$before = rand_str( 5 ); $before = 'before';
$after = rand_str( 6 ); $after = 'after';
$expected = sprintf( '%1$s<a href="mailto:foo@example.org">%2$s</a>%3$s', $before, $linktext, $after ); $expected = sprintf( '%1$s<a href="mailto:foo@example.org">%2$s</a>%3$s', $before, $linktext, $after );
@ -63,19 +63,19 @@ class Tests_Comment_GetCommentAuthorEmailLink extends WP_UnitTestCase {
} }
public function test_linktext() { public function test_linktext() {
$expected = sprintf( '<a href="mailto:foo@example.org">%1$s</a>', $linktext = rand_str( 12 ) ); $expected = sprintf( '<a href="mailto:foo@example.org">%1$s</a>', $linktext = 'linktext' );
$this->assertEquals( $expected, get_comment_author_email_link( $linktext ) ); $this->assertEquals( $expected, get_comment_author_email_link( $linktext ) );
} }
public function test_before() { public function test_before() {
$expected = sprintf( '%1$s<a href="mailto:foo@example.org">foo@example.org</a>', $before = rand_str( 5 ) ); $expected = sprintf( '%1$s<a href="mailto:foo@example.org">foo@example.org</a>', $before = 'before' );
$this->assertEquals( $expected, get_comment_author_email_link( '', $before ) ); $this->assertEquals( $expected, get_comment_author_email_link( '', $before ) );
} }
public function test_after() { public function test_after() {
$expected = sprintf( '<a href="mailto:foo@example.org">foo@example.org</a>%1$s', $after = rand_str( 5 ) ); $expected = sprintf( '<a href="mailto:foo@example.org">foo@example.org</a>%1$s', $after = 'after' );
$this->assertEquals( $expected, get_comment_author_email_link( '', '', $after ) ); $this->assertEquals( $expected, get_comment_author_email_link( '', '', $after ) );
} }

View File

@ -20,13 +20,13 @@ class Tests_Cron extends WP_UnitTestCase {
function test_wp_get_schedule_empty() { function test_wp_get_schedule_empty() {
// nothing scheduled // nothing scheduled
$hook = rand_str(); $hook = __FUNCTION__;
$this->assertFalse(wp_get_schedule($hook)); $this->assertFalse(wp_get_schedule($hook));
} }
function test_schedule_event_single() { function test_schedule_event_single() {
// schedule an event and make sure it's returned by wp_next_scheduled // schedule an event and make sure it's returned by wp_next_scheduled
$hook = rand_str(); $hook = __FUNCTION__;
$timestamp = strtotime('+1 hour'); $timestamp = strtotime('+1 hour');
wp_schedule_single_event( $timestamp, $hook ); wp_schedule_single_event( $timestamp, $hook );
@ -56,7 +56,7 @@ class Tests_Cron extends WP_UnitTestCase {
function test_schedule_event() { function test_schedule_event() {
// schedule an event and make sure it's returned by wp_next_scheduled // schedule an event and make sure it's returned by wp_next_scheduled
$hook = rand_str(); $hook = __FUNCTION__;
$recur = 'hourly'; $recur = 'hourly';
$timestamp = strtotime('+1 hour'); $timestamp = strtotime('+1 hour');
@ -87,7 +87,7 @@ class Tests_Cron extends WP_UnitTestCase {
function test_unschedule_event() { function test_unschedule_event() {
// schedule an event and make sure it's returned by wp_next_scheduled // schedule an event and make sure it's returned by wp_next_scheduled
$hook = rand_str(); $hook = __FUNCTION__;
$timestamp = strtotime('+1 hour'); $timestamp = strtotime('+1 hour');
wp_schedule_single_event( $timestamp, $hook ); wp_schedule_single_event( $timestamp, $hook );
@ -99,8 +99,8 @@ class Tests_Cron extends WP_UnitTestCase {
} }
function test_clear_schedule() { function test_clear_schedule() {
$hook = rand_str(); $hook = __FUNCTION__;
$args = array(rand_str()); $args = array( 'arg1' );
// schedule several events with and without arguments // schedule several events with and without arguments
wp_schedule_single_event( strtotime('+1 hour'), $hook ); wp_schedule_single_event( strtotime('+1 hour'), $hook );
@ -125,8 +125,8 @@ class Tests_Cron extends WP_UnitTestCase {
} }
function test_clear_schedule_multiple_args() { function test_clear_schedule_multiple_args() {
$hook = rand_str(); $hook = __FUNCTION__;
$args = array(rand_str(), rand_str()); $args = array( 'arg1', 'arg2' );
// schedule several events with and without arguments // schedule several events with and without arguments
wp_schedule_single_event( strtotime('+1 hour'), $hook ); wp_schedule_single_event( strtotime('+1 hour'), $hook );
@ -154,10 +154,10 @@ class Tests_Cron extends WP_UnitTestCase {
* @ticket 10468 * @ticket 10468
*/ */
function test_clear_schedule_new_args() { function test_clear_schedule_new_args() {
$hook = rand_str(); $hook = __FUNCTION__;
$args = array(rand_str()); $args = array( 'arg1' );
$multi_hook = rand_str(); $multi_hook = __FUNCTION__ . '_multi';
$multi_args = array(rand_str(), rand_str()); $multi_args = array( 'arg2', 'arg3' );
// schedule several events with and without arguments // schedule several events with and without arguments
wp_schedule_single_event( strtotime('+1 hour'), $hook ); wp_schedule_single_event( strtotime('+1 hour'), $hook );
@ -194,8 +194,8 @@ class Tests_Cron extends WP_UnitTestCase {
*/ */
function test_duplicate_event() { function test_duplicate_event() {
// duplicate events close together should be skipped // duplicate events close together should be skipped
$hook = rand_str(); $hook = __FUNCTION__;
$args = array(rand_str()); $args = array( 'arg1' );
$ts1 = strtotime('+5 minutes'); $ts1 = strtotime('+5 minutes');
$ts2 = strtotime('+3 minutes'); $ts2 = strtotime('+3 minutes');
@ -213,8 +213,8 @@ class Tests_Cron extends WP_UnitTestCase {
*/ */
function test_not_duplicate_event() { function test_not_duplicate_event() {
// duplicate events far apart should work normally // duplicate events far apart should work normally
$hook = rand_str(); $hook = __FUNCTION__;
$args = array( rand_str() ); $args = array( 'arg1' );
$ts1 = strtotime( '+30 minutes' ); $ts1 = strtotime( '+30 minutes' );
$ts2 = strtotime( '+3 minutes' ); $ts2 = strtotime( '+3 minutes' );
@ -232,8 +232,8 @@ class Tests_Cron extends WP_UnitTestCase {
function test_not_duplicate_event_reversed() { function test_not_duplicate_event_reversed() {
// duplicate events far apart should work normally regardless of order // duplicate events far apart should work normally regardless of order
$hook = rand_str(); $hook = __FUNCTION__;
$args = array( rand_str() ); $args = array( 'arg1' );
$ts1 = strtotime( '+3 minutes' ); $ts1 = strtotime( '+3 minutes' );
$ts2 = strtotime( '+30 minutes' ); $ts2 = strtotime( '+30 minutes' );
@ -274,7 +274,7 @@ class WPTestCronRunning extends _WPEmptyBlog {
function test_run_schedule_single() { function test_run_schedule_single() {
// schedule an event, run it, and make sure the hook is called // schedule an event, run it, and make sure the hook is called
$hook = rand_str(); $hook = __FUNCTION__;
$args = array(rand_str()); $args = array(rand_str());
$timestamp = strtotime('-1 second'); $timestamp = strtotime('-1 second');
@ -300,7 +300,7 @@ class WPTestCronRunning extends _WPEmptyBlog {
function test_run_schedule_recurring() { function test_run_schedule_recurring() {
// schedule a recurring event, run it, and make sure the hook is called // schedule a recurring event, run it, and make sure the hook is called
$hook = rand_str(); $hook = __FUNCTION__;
$args = array(rand_str()); $args = array(rand_str());
$timestamp = strtotime('-1 second'); $timestamp = strtotime('-1 second');
$recur = 'hourly'; $recur = 'hourly';

View File

@ -480,7 +480,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
function test_is_current_blog_previewed() { function test_is_current_blog_previewed() {
$type = 'option'; $type = 'option';
$name = 'blogname'; $name = 'blogname';
$post_value = rand_str(); $post_value = __FUNCTION__;
$this->manager->set_post_value( $name, $post_value ); $this->manager->set_post_value( $name, $post_value );
$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) ); $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) );
$this->assertFalse( $setting->is_current_blog_previewed() ); $this->assertFalse( $setting->is_current_blog_previewed() );
@ -504,7 +504,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
$type = 'option'; $type = 'option';
$name = 'blogdescription'; $name = 'blogdescription';
$post_value = rand_str(); $post_value = __FUNCTION__;
$this->manager->set_post_value( $name, $post_value ); $this->manager->set_post_value( $name, $post_value );
$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) ); $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) );
$this->assertFalse( $setting->is_current_blog_previewed() ); $this->assertFalse( $setting->is_current_blog_previewed() );