Make WordPress Core

Ticket #42904: 42904.patch

File 42904.patch, 4.4 KB (added by Frank Klein, 7 years ago)
  • tests/phpunit/includes/bootstrap.php

    diff --git tests/phpunit/includes/bootstrap.php tests/phpunit/includes/bootstrap.php
    index 5d3e159685..7059a560e7 100644
    require dirname( __FILE__ ) . '/testcase-canonical.php'; 
    115115require dirname( __FILE__ ) . '/exceptions.php';
    116116require dirname( __FILE__ ) . '/utils.php';
    117117require dirname( __FILE__ ) . '/spy-rest-server.php';
     118require 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();
    118128
    119129/**
    120130 * A child class of the PHP test runner.
  • new file tests/phpunit/includes/class-mock-passwordhash.php

    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 */
     11class 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}
  • tests/phpunit/tests/auth.php

    diff --git tests/phpunit/tests/auth.php tests/phpunit/tests/auth.php
    index 5a1084fc57..825c080e02 100644
    class Tests_Auth extends WP_UnitTestCase { 
    1616        protected $nonce_failure_hook = 'wp_verify_nonce_failed';
    1717
    1818        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
    1925                self::$_user = $factory->user->create_and_get(
    2026                        array(
    2127                                'user_login' => 'password-tests',
    class Tests_Auth extends WP_UnitTestCase { 
    2834                self::$wp_hasher = new PasswordHash( 8, true );
    2935        }
    3036
     37        public static function wpTearDownAfterClass() {
     38                // Set the $wp_hasher global to the test mock.
     39                $GLOBALS['wp_hasher'] = new Mock_PasswordHash();
     40        }
     41
    3142        function setUp() {
    3243                parent::setUp();
    3344
  • tests/phpunit/tests/xmlrpc/basic.php

    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 { 
    3737         * @ticket 34336
    3838         */
    3939        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
    4046                $editor_id = $this->make_user_by_role( 'editor' );
    4147                $post_id   = self::factory()->post->create(
    4248                        array(
    class Tests_XMLRPC_Basic extends WP_XMLRPC_UnitTestCase { 
    94100                $this->assertArrayHasKey( 'faultCode', $result[1] );
    95101                $this->assertArrayHasKey( 'faultCode', $result[2] );
    96102
     103                // Set the $wp_hasher global to the test mock.
     104                $GLOBALS['wp_hasher'] = new Mock_PasswordHash();
    97105        }
    98106
    99107        /**
  • tests/phpunit/tests/xmlrpc/wp/editProfile.php

    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 { 
    4040        }
    4141
    4242        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
    4349                $this->make_user_by_role( 'author' );
    4450                $new_pass = 'newpassword';
    4551                $new_data = array( 'password' => $new_pass );
    class Tests_XMLRPC_wp_editProfile extends WP_XMLRPC_UnitTestCase { 
    5258                $auth_new = wp_authenticate( 'author', $new_pass );
    5359                $this->assertInstanceOf( 'WP_User', $auth_old );
    5460                $this->assertWPError( $auth_new );
     61
     62                // Set the $wp_hasher global to the test mock.
     63                $GLOBALS['wp_hasher'] = new Mock_PasswordHash();
    5564        }
    5665
    5766        function test_ignore_email_change() {