wordpress-develop/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
Sergey Biryukov 5bad4e7f8d Code Modernization: Use explicit visibility for class property declarations.
Using `var` or only `static` to declare a class property is PHP 4 code.

This updates the codebase to use explicit visibility modifiers introduced in PHP 5.

Props jrf.
Fixes #51557. See #22234.

git-svn-id: https://develop.svn.wordpress.org/trunk@49184 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-17 16:24:35 +00:00

70 lines
2.3 KiB
PHP

<?php
/**
* @group xmlrpc
*/
class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase {
protected static $post_id;
public $attachment_data;
public $attachment_id;
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$post_id = $factory->post->create();
}
function setUp() {
parent::setUp();
add_theme_support( 'post-thumbnails' );
$filename = ( DIR_TESTDATA . '/images/waffles.jpg' );
$contents = file_get_contents( $filename );
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
$this->attachment_id = $this->_make_attachment( $upload, self::$post_id );
$this->attachment_data = get_post( $this->attachment_id, ARRAY_A );
set_post_thumbnail( self::$post_id, $this->attachment_id );
}
function tearDown() {
remove_theme_support( 'post-thumbnails' );
$this->remove_added_uploads();
parent::tearDown();
}
function test_invalid_username_password() {
$result = $this->myxmlrpcserver->wp_getMediaItem( array( 1, 'username', 'password', 0 ) );
$this->assertIXRError( $result );
$this->assertSame( 403, $result->code );
}
function test_valid_media_item() {
$this->make_user_by_role( 'author' );
$fields = array( 'post' );
$result = $this->myxmlrpcserver->wp_getMediaItem( array( 1, 'author', 'author', $this->attachment_id, $fields ) );
$this->assertNotIXRError( $result );
// Check data types.
$this->assertInternalType( 'string', $result['attachment_id'] );
$this->assertInternalType( 'int', $result['parent'] );
$this->assertInternalType( 'string', $result['title'] );
$this->assertInstanceOf( 'IXR_Date', $result['date_created_gmt'] );
$this->assertInternalType( 'string', $result['caption'] );
$this->assertInternalType( 'string', $result['description'] );
$this->assertInternalType( 'string', $result['link'] );
$this->assertInternalType( 'string', $result['thumbnail'] );
$this->assertInternalType( 'array', $result['metadata'] );
// Check expected values.
$this->assertStringMatchesFormat( '%d', $result['attachment_id'] );
$this->assertSame( $this->attachment_data['post_title'], $result['title'] );
$this->assertSame( wp_get_attachment_url( $this->attachment_id ), $result['link'] );
$this->assertSame( wp_get_attachment_thumb_url( $this->attachment_id ), $result['thumbnail'] );
}
}