diff --git a/tests/phpunit/tests/pluggable.php b/tests/phpunit/tests/pluggable.php index 48a169e1e7..7bf32f66f5 100644 --- a/tests/phpunit/tests/pluggable.php +++ b/tests/phpunit/tests/pluggable.php @@ -338,114 +338,4 @@ class Tests_Pluggable extends WP_UnitTestCase { return $signatures; } - - /** - * @ticket 28020 - */ - public function test_get_user_by_should_return_same_instance_as_wp_get_current_user() { - // Create a test user. - $new_user = self::factory()->user->create( array( 'role' => 'subscriber' ) ); - - // Set the test user as the current user. - $current_user = wp_set_current_user( $new_user ); - - // Get the test user using get_user_by(). - $from_get_user_by = get_user_by( 'id', $new_user ); - - $this->assertSame( $current_user, $from_get_user_by ); - } - - /** - * Tests that wp_rand() returns zero when `$min` and `$max` are zero. - * - * @ticket 55194 - * @dataProvider data_wp_rand_should_return_zero_when_min_and_max_are_zero - * @covers ::wp_rand - * - * @param mixed $min Lower limit for the generated number. - * @param mixed $max Upper limit for the generated number. - */ - public function test_wp_rand_should_return_zero_when_min_and_max_are_zero( $min, $max ) { - $this->assertSame( 0, wp_rand( $min, $max ) ); - } - - /** - * Data provider. - * - * @return array - */ - public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() { - return array( - 'min and max as 0' => array( - 'min' => 0, - 'max' => 0, - ), - 'min and max as 0.0' => array( - 'min' => 0.0, - 'max' => 0.0, - ), - 'min as null, max as 0' => array( - 'min' => null, - 'max' => 0, - ), - ); - } - - /** - * Tests that wp_rand() returns a positive integer for both positive and negative input. - * - * @ticket 55194 - * @dataProvider data_wp_rand_should_return_a_positive_integer - * @covers ::wp_rand - * - * @param int $min Lower limit for the generated number. - * @param int $max Upper limit for the generated number. - */ - public function test_wp_rand_should_return_a_positive_integer( $min, $max ) { - $this->assertGreaterThan( - 0, - wp_rand( $min, $max ), - 'The value was not greater than 0' - ); - - $this->assertLessThan( - 100, - wp_rand( $min, $max ), - 'The value was not less than 100' - ); - } - - /** - * Data provider. - * - * @return array - */ - public function data_wp_rand_should_return_a_positive_integer() { - return array( - '1 and 99' => array( - 'min' => 1, - 'max' => 99, - ), - '-1 and 99' => array( - 'min' => -1, - 'max' => 99, - ), - '1 and -99' => array( - 'min' => 1, - 'max' => -99, - ), - '-1 and -99' => array( - 'min' => -1, - 'max' => -99, - ), - '1.0 and 99.0' => array( - 'min' => 1.0, - 'max' => 99.0, - ), - '-1.0 and -99.0' => array( - 'min' => -1.0, - 'max' => -99.0, - ), - ); - } } diff --git a/tests/phpunit/tests/pluggable/getUserBy.php b/tests/phpunit/tests/pluggable/getUserBy.php new file mode 100644 index 0000000000..96ae8a1b5f --- /dev/null +++ b/tests/phpunit/tests/pluggable/getUserBy.php @@ -0,0 +1,24 @@ +user->create( array( 'role' => 'subscriber' ) ); + + // Set the test user as the current user. + $current_user = wp_set_current_user( $new_user ); + + // Get the test user using get_user_by(). + $from_get_user_by = get_user_by( 'id', $new_user ); + + $this->assertSame( $current_user, $from_get_user_by ); + } +} diff --git a/tests/phpunit/tests/pluggable/wpRand.php b/tests/phpunit/tests/pluggable/wpRand.php new file mode 100644 index 0000000000..f3092ca41b --- /dev/null +++ b/tests/phpunit/tests/pluggable/wpRand.php @@ -0,0 +1,100 @@ +assertGreaterThan( + 0, + wp_rand( $min, $max ), + 'The value was not greater than 0' + ); + + $this->assertLessThan( + 100, + wp_rand( $min, $max ), + 'The value was not less than 100' + ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_wp_rand_should_return_a_positive_integer() { + return array( + '1 and 99' => array( + 'min' => 1, + 'max' => 99, + ), + '-1 and 99' => array( + 'min' => -1, + 'max' => 99, + ), + '1 and -99' => array( + 'min' => 1, + 'max' => -99, + ), + '-1 and -99' => array( + 'min' => -1, + 'max' => -99, + ), + '1.0 and 99.0' => array( + 'min' => 1.0, + 'max' => 99.0, + ), + '-1.0 and -99.0' => array( + 'min' => -1.0, + 'max' => -99.0, + ), + ); + } + + /** + * Tests that wp_rand() returns zero when `$min` and `$max` are zero. + * + * @ticket 55194 + * @dataProvider data_wp_rand_should_return_zero_when_min_and_max_are_zero + * + * @param mixed $min Lower limit for the generated number. + * @param mixed $max Upper limit for the generated number. + */ + public function test_wp_rand_should_return_zero_when_min_and_max_are_zero( $min, $max ) { + $this->assertSame( 0, wp_rand( $min, $max ) ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() { + return array( + 'min and max as 0' => array( + 'min' => 0, + 'max' => 0, + ), + 'min and max as 0.0' => array( + 'min' => 0.0, + 'max' => 0.0, + ), + 'min as null, max as 0' => array( + 'min' => null, + 'max' => 0, + ), + ); + } +}