diff --git tests/phpunit/includes/testcase-xmlrpc.php tests/phpunit/includes/testcase-xmlrpc.php
index bf0f22a..5f80e83 100644
|
|
include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); |
5 | 5 | |
6 | 6 | class WP_XMLRPC_UnitTestCase extends WP_UnitTestCase { |
7 | 7 | protected $myxmlrpcserver; |
| 8 | protected $username; |
| 9 | protected $password; |
| 10 | protected $role; |
| 11 | protected $user_id; |
| 12 | protected $mocked_auth = false; |
8 | 13 | |
9 | 14 | function setUp() { |
10 | 15 | parent::setUp(); |
11 | 16 | |
12 | 17 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
13 | 18 | |
| 19 | add_filter( 'authenticate', array( $this, 'mock_authenticate' ), 10, 3 ); |
14 | 20 | $this->myxmlrpcserver = new wp_xmlrpc_server(); |
15 | 21 | } |
16 | 22 | |
17 | 23 | function tearDown() { |
| 24 | remove_filter( 'authenticate', array( $this, 'mock_authenticate' ), 10, 3 ); |
| 25 | |
| 26 | if ( $this->mocked_auth ) { |
| 27 | add_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); |
| 28 | add_filter( 'authenticate', 'wp_authenticate_spam_check', 99 ); |
| 29 | } |
| 30 | |
18 | 31 | remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
19 | 32 | $this->remove_added_uploads(); |
20 | 33 | |
21 | 34 | parent::tearDown(); |
22 | 35 | } |
23 | 36 | |
| 37 | public function mock_authenticate( $user, $username, $password ) { |
| 38 | if ( $username === $this->username && $password === $this->password ) { |
| 39 | $user = new WP_User( $this->user_id ); |
| 40 | |
| 41 | // Don't let WP do its native authentication checks. |
| 42 | remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); |
| 43 | remove_filter( 'authenticate', 'wp_authenticate_spam_check', 99 ); |
| 44 | |
| 45 | $this->mocked_auth = true; |
| 46 | } |
| 47 | |
| 48 | return $user; |
| 49 | } |
| 50 | |
24 | 51 | protected function make_user_by_role( $role ) { |
25 | | return $this->factory->user->create( array( |
| 52 | $this->user_id = $this->factory->user->create( array( |
26 | 53 | 'user_login' => $role, |
27 | 54 | 'user_pass' => $role, |
28 | 55 | 'role' => $role |
29 | 56 | )); |
| 57 | |
| 58 | $this->username = $role; |
| 59 | $this->password = $role; |
| 60 | $this->role = $role; |
| 61 | |
| 62 | return $this->user_id; |
30 | 63 | } |
31 | 64 | } |