forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.php
More file actions
111 lines (94 loc) · 2.72 KB
/
basic.php
File metadata and controls
111 lines (94 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
require_once ABSPATH . 'wp-admin/includes/admin.php';
require_once ABSPATH . WPINC . '/class-IXR.php';
require_once ABSPATH . WPINC . '/class-wp-xmlrpc-server.php';
/**
* @group xmlrpc
*/
class Tests_XMLRPC_Basic extends WP_XMLRPC_UnitTestCase {
function test_enabled() {
$result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'username', 'password' ) );
$this->assertIXRError( $result );
// If disabled, 405 would result.
$this->assertEquals( 403, $result->code );
}
function test_login_pass_ok() {
$user_id = $this->make_user_by_role( 'subscriber' );
$this->assertTrue( $this->myxmlrpcserver->login_pass_ok( 'subscriber', 'subscriber' ) );
$this->assertInstanceOf( 'WP_User', $this->myxmlrpcserver->login( 'subscriber', 'subscriber' ) );
}
function test_login_pass_bad() {
$user_id = $this->make_user_by_role( 'subscriber' );
$this->assertFalse( $this->myxmlrpcserver->login_pass_ok( 'username', 'password' ) );
$this->assertFalse( $this->myxmlrpcserver->login( 'username', 'password' ) );
// The auth will still fail due to authentication blocking after the first failed attempt
$this->assertFalse( $this->myxmlrpcserver->login_pass_ok( 'subscriber', 'subscriber' ) );
}
/**
* @ticket 34336
*/
function test_multicall_invalidates_all_calls_after_invalid_call() {
$editor_id = $this->make_user_by_role( 'editor' );
$post_id = self::factory()->post->create(
array(
'post_author' => $editor_id,
)
);
$method_calls = array(
// Valid login
array(
'methodName' => 'wp.editPost',
'params' => array(
0,
'editor',
'editor',
$post_id,
array(
'title' => 'Title 1',
),
),
),
// *Invalid* login
array(
'methodName' => 'wp.editPost',
'params' => array(
0,
'editor',
'password',
$post_id,
array(
'title' => 'Title 2',
),
),
),
// Valid login
array(
'methodName' => 'wp.editPost',
'params' => array(
0,
'editor',
'editor',
$post_id,
array(
'title' => 'Title 3',
),
),
),
);
$this->myxmlrpcserver->callbacks = $this->myxmlrpcserver->methods;
$result = $this->myxmlrpcserver->multiCall( $method_calls );
$this->assertArrayNotHasKey( 'faultCode', $result[0] );
$this->assertArrayHasKey( 'faultCode', $result[1] );
$this->assertArrayHasKey( 'faultCode', $result[2] );
}
/**
* @ticket 36586
*/
function test_isStruct_on_non_numerically_indexed_array() {
$value = new IXR_Value( array( '0.0' => 100 ) );
$return = "<struct>\n";
$return .= " <member><name>0.0</name><value><int>100</int></value></member>\n";
$return .= '</struct>';
$this->assertXmlStringEqualsXmlString( $return, $value->getXML() );
}
}