Make WordPress Core


Ignore:
Timestamp:
06/07/2022 02:44:00 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Move the tests for individual pluggable functions into their own directory.

This aims to make the tests more discoverable and easier to expand.

Follow-up to [50790], [53473], [53477].

See #55652.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/pluggable.php

    r53477 r53478  
    339339                return $signatures;
    340340        }
    341 
    342         /**
    343          * @ticket 28020
    344          */
    345         public function test_get_user_by_should_return_same_instance_as_wp_get_current_user() {
    346                 // Create a test user.
    347                 $new_user = self::factory()->user->create( array( 'role' => 'subscriber' ) );
    348 
    349                 // Set the test user as the current user.
    350                 $current_user = wp_set_current_user( $new_user );
    351 
    352                 // Get the test user using get_user_by().
    353                 $from_get_user_by = get_user_by( 'id', $new_user );
    354 
    355                 $this->assertSame( $current_user, $from_get_user_by );
    356         }
    357 
    358         /**
    359          * Tests that wp_rand() returns zero when `$min` and `$max` are zero.
    360          *
    361          * @ticket 55194
    362          * @dataProvider data_wp_rand_should_return_zero_when_min_and_max_are_zero
    363          * @covers ::wp_rand
    364          *
    365          * @param mixed $min Lower limit for the generated number.
    366          * @param mixed $max Upper limit for the generated number.
    367          */
    368         public function test_wp_rand_should_return_zero_when_min_and_max_are_zero( $min, $max ) {
    369                 $this->assertSame( 0, wp_rand( $min, $max ) );
    370         }
    371 
    372         /**
    373          * Data provider.
    374          *
    375          * @return array
    376          */
    377         public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() {
    378                 return array(
    379                         'min and max as 0'      => array(
    380                                 'min' => 0,
    381                                 'max' => 0,
    382                         ),
    383                         'min and max as 0.0'    => array(
    384                                 'min' => 0.0,
    385                                 'max' => 0.0,
    386                         ),
    387                         'min as null, max as 0' => array(
    388                                 'min' => null,
    389                                 'max' => 0,
    390                         ),
    391                 );
    392         }
    393 
    394         /**
    395          * Tests that wp_rand() returns a positive integer for both positive and negative input.
    396          *
    397          * @ticket 55194
    398          * @dataProvider data_wp_rand_should_return_a_positive_integer
    399          * @covers ::wp_rand
    400          *
    401          * @param int $min Lower limit for the generated number.
    402          * @param int $max Upper limit for the generated number.
    403          */
    404         public function test_wp_rand_should_return_a_positive_integer( $min, $max ) {
    405                 $this->assertGreaterThan(
    406                         0,
    407                         wp_rand( $min, $max ),
    408                         'The value was not greater than 0'
    409                 );
    410 
    411                 $this->assertLessThan(
    412                         100,
    413                         wp_rand( $min, $max ),
    414                         'The value was not less than 100'
    415                 );
    416         }
    417 
    418         /**
    419          * Data provider.
    420          *
    421          * @return array
    422          */
    423         public function data_wp_rand_should_return_a_positive_integer() {
    424                 return array(
    425                         '1 and 99'       => array(
    426                                 'min' => 1,
    427                                 'max' => 99,
    428                         ),
    429                         '-1 and 99'      => array(
    430                                 'min' => -1,
    431                                 'max' => 99,
    432                         ),
    433                         '1 and -99'      => array(
    434                                 'min' => 1,
    435                                 'max' => -99,
    436                         ),
    437                         '-1 and -99'     => array(
    438                                 'min' => -1,
    439                                 'max' => -99,
    440                         ),
    441                         '1.0 and 99.0'   => array(
    442                                 'min' => 1.0,
    443                                 'max' => 99.0,
    444                         ),
    445                         '-1.0 and -99.0' => array(
    446                                 'min' => -1.0,
    447                                 'max' => -99.0,
    448                         ),
    449                 );
    450         }
    451341}
Note: See TracChangeset for help on using the changeset viewer.