diff --git tests/phpunit/includes/bootstrap.php tests/phpunit/includes/bootstrap.php
index 5d3e159685..7059a560e7 100644
|
|
|
require dirname( __FILE__ ) . '/testcase-canonical.php'; |
| 115 | 115 | require dirname( __FILE__ ) . '/exceptions.php'; |
| 116 | 116 | require dirname( __FILE__ ) . '/utils.php'; |
| 117 | 117 | require dirname( __FILE__ ) . '/spy-rest-server.php'; |
| | 118 | require dirname( __FILE__ ) . '/class-mock-passwordhash.php'; |
| | 119 | |
| | 120 | /** |
| | 121 | * Override the $wp_hasher global that contains an instance of the PasswordHash class. |
| | 122 | * |
| | 123 | * By mocking the hashing functions used for password handling, we can speed up user creation in unit tests. |
| | 124 | * |
| | 125 | * @since 5.0.0 |
| | 126 | */ |
| | 127 | $GLOBALS['wp_hasher'] = new Mock_PasswordHash(); |
| 118 | 128 | |
| 119 | 129 | /** |
| 120 | 130 | * A child class of the PHP test runner. |
diff --git tests/phpunit/includes/class-mock-passwordhash.php tests/phpunit/includes/class-mock-passwordhash.php
new file mode 100644
index 0000000000..abbb2a7c6b
|
-
|
+
|
|
| | 1 | <?php |
| | 2 | /** |
| | 3 | * Mock of the phpass class. |
| | 4 | * |
| | 5 | * @since 5.0.0 |
| | 6 | */ |
| | 7 | |
| | 8 | /** |
| | 9 | * Class Mock_PasswordHash |
| | 10 | */ |
| | 11 | class Mock_PasswordHash { |
| | 12 | function HashPassword( $password ) { |
| | 13 | // The password needs to be longer than 32 characters, so that `wp_check_password()` uses the hasher class. |
| | 14 | return 'bar_bar_bar_bar_bar_bar_bar_bar_bar_'; |
| | 15 | } |
| | 16 | |
| | 17 | function CheckPassword( $password, $stored_hash ) { |
| | 18 | return true; |
| | 19 | } |
| | 20 | } |
diff --git tests/phpunit/tests/auth.php tests/phpunit/tests/auth.php
index 5a1084fc57..825c080e02 100644
|
|
|
class Tests_Auth extends WP_UnitTestCase { |
| 16 | 16 | protected $nonce_failure_hook = 'wp_verify_nonce_failed'; |
| 17 | 17 | |
| 18 | 18 | public static function wpSetUpBeforeClass( $factory ) { |
| | 19 | /** |
| | 20 | * Set the $wp_hasher global to null. This causes the password related functions in Core to create a valid |
| | 21 | * instance of the PasswordHash class. |
| | 22 | */ |
| | 23 | $GLOBALS['wp_hasher'] = null; |
| | 24 | |
| 19 | 25 | self::$_user = $factory->user->create_and_get( |
| 20 | 26 | array( |
| 21 | 27 | 'user_login' => 'password-tests', |
| … |
… |
class Tests_Auth extends WP_UnitTestCase { |
| 28 | 34 | self::$wp_hasher = new PasswordHash( 8, true ); |
| 29 | 35 | } |
| 30 | 36 | |
| | 37 | public static function wpTearDownAfterClass() { |
| | 38 | // Set the $wp_hasher global to the test mock. |
| | 39 | $GLOBALS['wp_hasher'] = new Mock_PasswordHash(); |
| | 40 | } |
| | 41 | |
| 31 | 42 | function setUp() { |
| 32 | 43 | parent::setUp(); |
| 33 | 44 | |
diff --git tests/phpunit/tests/xmlrpc/basic.php tests/phpunit/tests/xmlrpc/basic.php
index 68c8e8f0df..d02e4b5fcd 100644
|
|
|
class Tests_XMLRPC_Basic extends WP_XMLRPC_UnitTestCase { |
| 37 | 37 | * @ticket 34336 |
| 38 | 38 | */ |
| 39 | 39 | function test_multicall_invalidates_all_calls_after_invalid_call() { |
| | 40 | /** |
| | 41 | * Set the $wp_hasher global to null. This causes the password related functions in Core to create a valid |
| | 42 | * instance of the PasswordHash class. |
| | 43 | */ |
| | 44 | $GLOBALS['wp_hasher'] = null; |
| | 45 | |
| 40 | 46 | $editor_id = $this->make_user_by_role( 'editor' ); |
| 41 | 47 | $post_id = self::factory()->post->create( |
| 42 | 48 | array( |
| … |
… |
class Tests_XMLRPC_Basic extends WP_XMLRPC_UnitTestCase { |
| 94 | 100 | $this->assertArrayHasKey( 'faultCode', $result[1] ); |
| 95 | 101 | $this->assertArrayHasKey( 'faultCode', $result[2] ); |
| 96 | 102 | |
| | 103 | // Set the $wp_hasher global to the test mock. |
| | 104 | $GLOBALS['wp_hasher'] = new Mock_PasswordHash(); |
| 97 | 105 | } |
| 98 | 106 | |
| 99 | 107 | /** |
diff --git tests/phpunit/tests/xmlrpc/wp/editProfile.php tests/phpunit/tests/xmlrpc/wp/editProfile.php
index e637016ef9..6d862ca761 100644
|
|
|
class Tests_XMLRPC_wp_editProfile extends WP_XMLRPC_UnitTestCase { |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function test_ignore_password_change() { |
| | 43 | /** |
| | 44 | * Set the $wp_hasher global to null. This causes the password related functions in Core to create a valid |
| | 45 | * instance of the PasswordHash class. |
| | 46 | */ |
| | 47 | $GLOBALS['wp_hasher'] = null; |
| | 48 | |
| 43 | 49 | $this->make_user_by_role( 'author' ); |
| 44 | 50 | $new_pass = 'newpassword'; |
| 45 | 51 | $new_data = array( 'password' => $new_pass ); |
| … |
… |
class Tests_XMLRPC_wp_editProfile extends WP_XMLRPC_UnitTestCase { |
| 52 | 58 | $auth_new = wp_authenticate( 'author', $new_pass ); |
| 53 | 59 | $this->assertInstanceOf( 'WP_User', $auth_old ); |
| 54 | 60 | $this->assertWPError( $auth_new ); |
| | 61 | |
| | 62 | // Set the $wp_hasher global to the test mock. |
| | 63 | $GLOBALS['wp_hasher'] = new Mock_PasswordHash(); |
| 55 | 64 | } |
| 56 | 65 | |
| 57 | 66 | function test_ignore_email_change() { |