| | 1 | <?php |
| | 2 | |
| | 3 | class TestXMLRPCServer_wp_getComments extends WPXMLRPCServerTestCase { |
| | 4 | function test_contributor_capabilities() { |
| | 5 | wp_delete_comment( 1 ); |
| | 6 | $author_id = get_user_by( 'login', 'author' )->ID; |
| | 7 | $post = array( 'post_title' => 'Author', 'post_author' => $author_id, 'post_status' => 'publish' ); |
| | 8 | $author_post_id = wp_insert_post( $post ); |
| | 9 | |
| | 10 | $author_comment_id = wp_insert_comment( array( |
| | 11 | 'comment_post_ID' => $author_post_id, |
| | 12 | 'comment_author' => "Commenter 1", |
| | 13 | 'comment_author_url' => "http://example.com/1/", |
| | 14 | 'comment_approved' => 0, |
| | 15 | )); |
| | 16 | |
| | 17 | $editor_id = get_user_by( 'login', 'editor' )->ID; |
| | 18 | $post = array( 'post_title' => 'Editor', 'post_author' => $editor_id, 'post_status' => 'publish' ); |
| | 19 | $editor_post_id = wp_insert_post( $post ); |
| | 20 | |
| | 21 | $editor_comment_id = wp_insert_comment(array( |
| | 22 | 'comment_post_ID' => $editor_post_id, |
| | 23 | 'comment_author' => "Commenter 2", |
| | 24 | 'comment_author_url' => "http://example.com/2/", |
| | 25 | 'comment_approved' => 0, |
| | 26 | )); |
| | 27 | |
| | 28 | $result = $this->myxmlrpcserver->wp_getComments( array( 1, 'contributor', 'contributor' ) ); |
| | 29 | $this->assertNotInstanceOf( 'IXR_Error', $result ); |
| | 30 | $this->assertInternalType( 'array', $result ); |
| | 31 | |
| | 32 | $this->assertEquals( 2, count( $result ) ); |
| | 33 | |
| | 34 | $this->assertFalse( $result[0]['can_edit'] ); |
| | 35 | $this->assertFalse( $result[1]['can_edit'] ); |
| | 36 | } |
| | 37 | |
| | 38 | function test_author_capabilities() { |
| | 39 | wp_delete_comment( 1 ); |
| | 40 | $author_id = get_user_by( 'login', 'author' )->ID; |
| | 41 | $post = array( 'post_title' => 'Author', 'post_author' => $author_id, 'post_status' => 'publish' ); |
| | 42 | $author_post_id = wp_insert_post( $post ); |
| | 43 | |
| | 44 | wp_insert_comment( array( |
| | 45 | 'comment_post_ID' => $author_post_id, |
| | 46 | 'comment_author' => "Commenter 1", |
| | 47 | 'comment_author_url' => "http://example.com/1/", |
| | 48 | 'comment_approved' => 0, |
| | 49 | )); |
| | 50 | |
| | 51 | $editor_id = get_user_by( 'login', 'editor' )->ID; |
| | 52 | $post = array( 'post_title' => 'Editor', 'post_author' => $editor_id, 'post_status' => 'publish' ); |
| | 53 | $editor_post_id = wp_insert_post( $post ); |
| | 54 | |
| | 55 | wp_insert_comment(array( |
| | 56 | 'comment_post_ID' => $editor_post_id, |
| | 57 | 'comment_author' => "Commenter 2", |
| | 58 | 'comment_author_url' => "http://example.com/2/", |
| | 59 | 'comment_approved' => 0, |
| | 60 | )); |
| | 61 | |
| | 62 | $result = $this->myxmlrpcserver->wp_getComments( array( 1, 'author', 'author', array( 'post_id' => $author_post_id ) ) ); |
| | 63 | $this->assertNotInstanceOf( 'IXR_Error', $result ); |
| | 64 | $this->assertInternalType( 'array', $result ); |
| | 65 | $this->assertEquals( 1, count( $result ) ); |
| | 66 | $this->assertTrue( $result[0]['can_edit'] ); |
| | 67 | |
| | 68 | $result = $this->myxmlrpcserver->wp_getComments( array( 1, 'author', 'author', array( 'post_id' => $editor_post_id ) ) ); |
| | 69 | $this->assertNotInstanceOf( 'IXR_Error', $result ); |
| | 70 | $this->assertInternalType( 'array', $result ); |
| | 71 | $this->assertEquals( 1, count( $result ) ); |
| | 72 | $this->assertFalse( $result[0]['can_edit'] ); |
| | 73 | } |
| | 74 | |
| | 75 | function test_editor_capabilities() { |
| | 76 | wp_delete_comment( 1 ); |
| | 77 | $author_id = get_user_by( 'login', 'author' )->ID; |
| | 78 | $post = array( 'post_title' => 'Editor', 'post_author' => $author_id, 'post_status' => 'publish' ); |
| | 79 | $author_post_id = wp_insert_post( $post ); |
| | 80 | |
| | 81 | wp_insert_comment( array( |
| | 82 | 'comment_post_ID' => $author_post_id, |
| | 83 | 'comment_author' => "Commenter 1", |
| | 84 | 'comment_author_url' => "http://example.com/1/", |
| | 85 | 'comment_approved' => 0, |
| | 86 | )); |
| | 87 | |
| | 88 | $editor_id = get_user_by( 'login', 'editor' )->ID; |
| | 89 | $post = array( 'post_title' => 'Editor', 'post_author' => $editor_id, 'post_status' => 'publish' ); |
| | 90 | $editor_post_id = wp_insert_post( $post ); |
| | 91 | |
| | 92 | wp_insert_comment(array( |
| | 93 | 'comment_post_ID' => $editor_post_id, |
| | 94 | 'comment_author' => "Commenter 2", |
| | 95 | 'comment_author_url' => "http://example.com/2/", |
| | 96 | 'comment_approved' => 0, |
| | 97 | )); |
| | 98 | |
| | 99 | $result = $this->myxmlrpcserver->wp_getComments( array( 1, 'editor', 'editor' ) ); |
| | 100 | $this->assertNotInstanceOf( 'IXR_Error', $result ); |
| | 101 | $this->assertInternalType( 'array', $result ); |
| | 102 | |
| | 103 | $this->assertEquals( 2, count( $result ) ); |
| | 104 | |
| | 105 | $this->assertTrue( $result[0]['can_edit'] ); |
| | 106 | $this->assertTrue( $result[1]['can_edit'] ); |
| | 107 | } |
| | 108 | } |
| | 109 | |
| | 110 | ?> |
| | 111 | No newline at end of file |