Registration::test_validate_passwords PHP Method

test_validate_passwords() public method

    public function test_validate_passwords()
    {
        global $_POST;
        // Test for correct stage
        $content = array('errors' => new WP_Error());
        $_POST['stage'] = '';
        \Pressbooks\Registration\validate_passwords($content);
        $this->assertEquals('', $content['errors']->get_error_message('password_1'));
        // Test for empty password field
        $content = array('errors' => new WP_Error());
        $_POST['stage'] = 'validate-user-signup';
        // Validation stage
        $_POST['password_1'] = '';
        // Empty password
        $_POST['password_2'] = 'barrel aquiline abolish belabour';
        // Legitimate password
        \Pressbooks\Registration\validate_passwords($content);
        $this->assertEquals('You have to enter a password.', $content['errors']->get_error_message('password_1'));
        // Test for password mismatch
        $content = array('errors' => new WP_Error());
        $_POST['stage'] = 'validate-user-signup';
        // Validation stage
        $_POST['password_1'] = 'colloquy glint tendril choler';
        // Legitimate password
        $_POST['password_2'] = 'barrel aquiline abolish belabour';
        // Legitimate password that doesn't match
        \Pressbooks\Registration\validate_passwords($content);
        $this->assertEquals('Passwords do not match.', $content['errors']->get_error_message('password_1'));
    }