forked from WordPress/wordpress-develop
/
deleteTerm.php
75 lines (60 loc) · 2.45 KB
/
deleteTerm.php
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
<?php
/**
* @group xmlrpc
*/
class Tests_XMLRPC_wp_deleteTerm extends WP_XMLRPC_UnitTestCase {
protected static $term_id;
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$term_id = $factory->term->create(
array(
'taxonomy' => 'category',
)
);
}
function test_invalid_username_password() {
$result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'username', 'password', 'category', 0 ) );
$this->assertIXRError( $result );
$this->assertEquals( 403, $result->code );
}
function test_empty_taxonomy() {
$this->make_user_by_role( 'subscriber' );
$result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', '', 0 ) );
$this->assertIXRError( $result );
$this->assertEquals( 403, $result->code );
$this->assertEquals( __( 'Invalid taxonomy.' ), $result->message );
}
function test_invalid_taxonomy() {
$this->make_user_by_role( 'subscriber' );
$result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'not_existing', 0 ) );
$this->assertIXRError( $result );
$this->assertEquals( 403, $result->code );
$this->assertEquals( __( 'Invalid taxonomy.' ), $result->message );
}
function test_incapable_user() {
$this->make_user_by_role( 'subscriber' );
$result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'category', self::$term_id ) );
$this->assertIXRError( $result );
$this->assertEquals( 401, $result->code );
$this->assertEquals( __( 'Sorry, you are not allowed to delete this term.' ), $result->message );
}
function test_empty_term() {
$this->make_user_by_role( 'editor' );
$result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', '' ) );
$this->assertIXRError( $result );
$this->assertEquals( 500, $result->code );
$this->assertEquals( __( 'Empty Term.' ), $result->message );
}
function test_invalid_term() {
$this->make_user_by_role( 'editor' );
$result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', 9999 ) );
$this->assertIXRError( $result );
$this->assertEquals( 404, $result->code );
$this->assertEquals( __( 'Invalid term ID.' ), $result->message );
}
function test_term_deleted() {
$this->make_user_by_role( 'editor' );
$result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', self::$term_id ) );
$this->assertNotIXRError( $result );
$this->assertIsBool( $result );
}
}