123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- /**
- * @group xmlrpc
- */
- class Tests_XMLRPC_mw_getPost extends WP_XMLRPC_UnitTestCase {
- protected static $post_id;
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$post_id = $factory->post->create(
- array(
- 'post_author' => $factory->user->create(
- array(
- 'user_login' => 'author',
- 'user_pass' => 'author',
- 'role' => 'author',
- )
- ),
- 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', strtotime( '+1 day' ) ),
- )
- );
- }
- function test_invalid_username_password() {
- $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'username', 'password' ) );
- $this->assertIXRError( $result );
- $this->assertSame( 403, $result->code );
- }
- function test_incapable_user() {
- $this->make_user_by_role( 'subscriber' );
- $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'subscriber', 'subscriber' ) );
- $this->assertIXRError( $result );
- $this->assertSame( 401, $result->code );
- }
- /**
- * @ticket 20336
- */
- function test_invalid_postid() {
- $result = $this->myxmlrpcserver->mw_getPost( array( 9999, 'author', 'author' ) );
- $this->assertIXRError( $result );
- $this->assertSame( 404, $result->code );
- }
- function test_valid_post() {
- add_theme_support( 'post-thumbnails' );
- $fields = array( 'post' );
- $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) );
- $this->assertNotIXRError( $result );
- // Check data types.
- $this->assertInternalType( 'string', $result['userid'] );
- $this->assertInternalType( 'int', $result['postid'] );
- $this->assertInternalType( 'string', $result['description'] );
- $this->assertInternalType( 'string', $result['title'] );
- $this->assertInternalType( 'string', $result['link'] );
- $this->assertInternalType( 'string', $result['permaLink'] );
- $this->assertInternalType( 'array', $result['categories'] );
- $this->assertInternalType( 'string', $result['mt_excerpt'] );
- $this->assertInternalType( 'string', $result['mt_text_more'] );
- $this->assertInternalType( 'string', $result['wp_more_text'] );
- $this->assertInternalType( 'int', $result['mt_allow_comments'] );
- $this->assertInternalType( 'int', $result['mt_allow_pings'] );
- $this->assertInternalType( 'string', $result['mt_keywords'] );
- $this->assertInternalType( 'string', $result['wp_slug'] );
- $this->assertInternalType( 'string', $result['wp_password'] );
- $this->assertInternalType( 'string', $result['wp_author_id'] );
- $this->assertInternalType( 'string', $result['wp_author_display_name'] );
- $this->assertInternalType( 'string', $result['post_status'] );
- $this->assertInternalType( 'array', $result['custom_fields'] );
- $this->assertInternalType( 'string', $result['wp_post_format'] );
- $this->assertInternalType( 'bool', $result['sticky'] );
- $post_data = get_post( self::$post_id );
- // Check expected values.
- $this->assertStringMatchesFormat( '%d', $result['userid'] );
- $this->assertSame( $post_data->post_title, $result['title'] );
- $this->assertSame( 'publish', $result['post_status'] );
- $this->assertStringMatchesFormat( '%d', $result['wp_author_id'] );
- $this->assertSame( $post_data->post_excerpt, $result['mt_excerpt'] );
- $this->assertSame( url_to_postid( $result['link'] ), self::$post_id );
- $this->assertSame( 0, $result['wp_post_thumbnail'] );
- remove_theme_support( 'post-thumbnails' );
- }
- function test_post_thumbnail() {
- add_theme_support( 'post-thumbnails' );
- // Create attachment.
- $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' );
- $attachment_id = self::factory()->attachment->create_upload_object( $filename );
- set_post_thumbnail( self::$post_id, $attachment_id );
- $fields = array( 'post' );
- $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) );
- $this->assertNotIXRError( $result );
- $this->assertInternalType( 'int', $result['wp_post_thumbnail'] );
- $this->assertSame( $attachment_id, $result['wp_post_thumbnail'] );
- remove_theme_support( 'post-thumbnails' );
- }
- function test_date() {
- $fields = array( 'post' );
- $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) );
- $this->assertNotIXRError( $result );
- $this->assertInstanceOf( 'IXR_Date', $result['dateCreated'] );
- $this->assertInstanceOf( 'IXR_Date', $result['date_created_gmt'] );
- $this->assertInstanceOf( 'IXR_Date', $result['date_modified'] );
- $this->assertInstanceOf( 'IXR_Date', $result['date_modified_gmt'] );
- $post_data = get_post( self::$post_id );
- $this->assertSame( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() );
- $this->assertSame( strtotime( $post_data->post_date ), $result['date_modified']->getTimestamp() );
- $post_date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) );
- $post_modified_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) );
- $this->assertSame( $post_date_gmt, $result['date_created_gmt']->getTimestamp() );
- $this->assertSame( $post_modified_gmt, $result['date_modified_gmt']->getTimestamp() );
- }
- }
|