Files
wordpress-develop/tests/phpunit/tests/xmlrpc/wp/getOptions.php
T
Sergey Biryukov bca693b190 Build/Test Tools: Replace assertInternalType() usage in unit tests.
The `assertInternalType()` and `assertNotInternalType()` methods are deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

* `assertIsArray()`
* `assertIsBool()`
* `assertIsFloat()`
* `assertIsInt()`
* `assertIsNumeric()`
* `assertIsObject()`
* `assertIsResource()`
* `assertIsString()`
* `assertIsScalar()`
* `assertIsCallable()`
* `assertIsIterable()`
* `assertIsNotArray()`
* `assertIsNotBool()`
* `assertIsNotFloat()`
* `assertIsNotInt()`
* `assertIsNotNumeric()`
* `assertIsNotObject()`
* `assertIsNotResource()`
* `assertIsNotString()`
* `assertIsNotScalar()`
* `assertIsNotCallable()`
* `assertIsNotIterable()`

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods are now added to the `WP_UnitTestCase` class for PHPUnit < 7.5.

Props pbearne, jrf, dd32, SergeyBiryukov.
Fixes #53491. See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51331 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-05 17:21:53 +00:00

212 lines
9.2 KiB
PHP

<?php
/**
* @group xmlrpc
*/
class Tests_XMLRPC_wp_getOptions extends WP_XMLRPC_UnitTestCase {
function test_invalid_username_password() {
$result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'username', 'password' ) );
$this->assertIXRError( $result );
$this->assertSame( 403, $result->code );
}
function test_valid_username_password() {
$this->make_user_by_role( 'subscriber' );
$result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) );
$this->assertIsArray( $result );
$this->assertSame( 'WordPress', $result['software_name']['value'] );
}
function test_option_value() {
$this->make_user_by_role( 'administrator' );
$result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'administrator', 'administrator', 'default_comment_status' ) );
$this->assertIsArray( $result );
$this->assertSame( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
$this->assertFalse( $result['default_comment_status']['readonly'] );
}
/**
* @ticket 20201
*/
function test_option_values_subscriber() {
global $wp_version;
$this->make_user_by_role( 'subscriber' );
$result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) );
$this->assertIsArray( $result );
// Read-only options.
$this->assertSame( 'WordPress', $result['software_name']['value'] );
$this->assertTrue( $result['software_name']['readonly'] );
$this->assertSame( $wp_version, $result['software_version']['value'] );
$this->assertTrue( $result['software_version']['readonly'] );
$this->assertSame( get_site_url(), $result['blog_url']['value'] );
$this->assertTrue( $result['blog_url']['readonly'] );
$this->assertSame( wp_login_url(), $result['login_url']['value'] );
$this->assertTrue( $result['login_url']['readonly'] );
$this->assertSame( get_admin_url(), $result['admin_url']['value'] );
$this->assertTrue( $result['admin_url']['readonly'] );
$this->assertSame( get_option( 'image_default_link_type' ), $result['image_default_link_type']['value'] );
$this->assertTrue( $result['image_default_link_type']['readonly'] );
$this->assertSame( get_option( 'image_default_size' ), $result['image_default_size']['value'] );
$this->assertTrue( $result['image_default_size']['readonly'] );
$this->assertSame( get_option( 'image_default_align' ), $result['image_default_align']['value'] );
$this->assertTrue( $result['image_default_align']['readonly'] );
$this->assertSame( get_template(), $result['template']['value'] );
$this->assertTrue( $result['template']['readonly'] );
$this->assertSame( get_stylesheet(), $result['stylesheet']['value'] );
$this->assertTrue( $result['stylesheet']['readonly'] );
$this->assertSame( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] );
$this->assertTrue( $result['post_thumbnail']['readonly'] );
// Updatable options.
$this->assertSame( get_option( 'gmt_offset' ), $result['time_zone']['value'] );
$this->assertTrue( $result['time_zone']['readonly'] );
$this->assertSame( get_option( 'blogname' ), $result['blog_title']['value'] );
$this->assertTrue( $result['blog_title']['readonly'] );
$this->assertSame( get_option( 'blogdescription' ), $result['blog_tagline']['value'] );
$this->assertTrue( $result['blog_tagline']['readonly'] );
$this->assertSame( get_option( 'date_format' ), $result['date_format']['value'] );
$this->assertTrue( $result['date_format']['readonly'] );
$this->assertSame( get_option( 'time_format' ), $result['time_format']['value'] );
$this->assertTrue( $result['time_format']['readonly'] );
$this->assertSame( get_option( 'users_can_register' ), $result['users_can_register']['value'] );
$this->assertTrue( $result['users_can_register']['readonly'] );
$this->assertSame( get_option( 'thumbnail_size_w' ), $result['thumbnail_size_w']['value'] );
$this->assertTrue( $result['thumbnail_size_w']['readonly'] );
$this->assertSame( get_option( 'thumbnail_size_h' ), $result['thumbnail_size_h']['value'] );
$this->assertTrue( $result['thumbnail_size_h']['readonly'] );
$this->assertSame( get_option( 'thumbnail_crop' ), $result['thumbnail_crop']['value'] );
$this->assertTrue( $result['thumbnail_crop']['readonly'] );
$this->assertSame( get_option( 'medium_size_w' ), $result['medium_size_w']['value'] );
$this->assertTrue( $result['medium_size_w']['readonly'] );
$this->assertSame( get_option( 'medium_size_h' ), $result['medium_size_h']['value'] );
$this->assertTrue( $result['medium_size_h']['readonly'] );
$this->assertSame( get_option( 'large_size_w' ), $result['large_size_w']['value'] );
$this->assertTrue( $result['large_size_w']['readonly'] );
$this->assertSame( get_option( 'large_size_h' ), $result['large_size_h']['value'] );
$this->assertTrue( $result['large_size_h']['readonly'] );
$this->assertSame( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
$this->assertTrue( $result['default_comment_status']['readonly'] );
$this->assertSame( get_option( 'default_ping_status' ), $result['default_ping_status']['value'] );
$this->assertTrue( $result['default_ping_status']['readonly'] );
}
function test_option_values_admin() {
global $wp_version;
$this->make_user_by_role( 'administrator' );
$result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'administrator', 'administrator' ) );
$this->assertIsArray( $result );
// Read-only options.
$this->assertSame( 'WordPress', $result['software_name']['value'] );
$this->assertTrue( $result['software_name']['readonly'] );
$this->assertSame( $wp_version, $result['software_version']['value'] );
$this->assertTrue( $result['software_version']['readonly'] );
$this->assertSame( get_site_url(), $result['blog_url']['value'] );
$this->assertTrue( $result['blog_url']['readonly'] );
$this->assertSame( wp_login_url(), $result['login_url']['value'] );
$this->assertTrue( $result['login_url']['readonly'] );
$this->assertSame( get_admin_url(), $result['admin_url']['value'] );
$this->assertTrue( $result['admin_url']['readonly'] );
$this->assertSame( get_option( 'image_default_link_type' ), $result['image_default_link_type']['value'] );
$this->assertTrue( $result['image_default_link_type']['readonly'] );
$this->assertSame( get_option( 'image_default_size' ), $result['image_default_size']['value'] );
$this->assertTrue( $result['image_default_size']['readonly'] );
$this->assertSame( get_option( 'image_default_align' ), $result['image_default_align']['value'] );
$this->assertTrue( $result['image_default_align']['readonly'] );
$this->assertSame( get_template(), $result['template']['value'] );
$this->assertTrue( $result['template']['readonly'] );
$this->assertSame( get_stylesheet(), $result['stylesheet']['value'] );
$this->assertTrue( $result['stylesheet']['readonly'] );
$this->assertSame( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] );
$this->assertTrue( $result['post_thumbnail']['readonly'] );
// Updatable options.
$this->assertSame( get_option( 'gmt_offset' ), $result['time_zone']['value'] );
$this->assertFalse( $result['time_zone']['readonly'] );
$this->assertSame( get_option( 'blogname' ), $result['blog_title']['value'] );
$this->assertFalse( $result['blog_title']['readonly'] );
$this->assertSame( get_option( 'blogdescription' ), $result['blog_tagline']['value'] );
$this->assertFalse( $result['blog_tagline']['readonly'] );
$this->assertSame( get_option( 'date_format' ), $result['date_format']['value'] );
$this->assertFalse( $result['date_format']['readonly'] );
$this->assertSame( get_option( 'time_format' ), $result['time_format']['value'] );
$this->assertFalse( $result['time_format']['readonly'] );
$this->assertSame( get_option( 'users_can_register' ), $result['users_can_register']['value'] );
$this->assertFalse( $result['users_can_register']['readonly'] );
$this->assertSame( get_option( 'thumbnail_size_w' ), $result['thumbnail_size_w']['value'] );
$this->assertFalse( $result['thumbnail_size_w']['readonly'] );
$this->assertSame( get_option( 'thumbnail_size_h' ), $result['thumbnail_size_h']['value'] );
$this->assertFalse( $result['thumbnail_size_h']['readonly'] );
$this->assertSame( get_option( 'thumbnail_crop' ), $result['thumbnail_crop']['value'] );
$this->assertFalse( $result['thumbnail_crop']['readonly'] );
$this->assertSame( get_option( 'medium_size_w' ), $result['medium_size_w']['value'] );
$this->assertFalse( $result['medium_size_w']['readonly'] );
$this->assertSame( get_option( 'medium_size_h' ), $result['medium_size_h']['value'] );
$this->assertFalse( $result['medium_size_h']['readonly'] );
$this->assertSame( get_option( 'large_size_w' ), $result['large_size_w']['value'] );
$this->assertFalse( $result['large_size_w']['readonly'] );
$this->assertSame( get_option( 'large_size_h' ), $result['large_size_h']['value'] );
$this->assertFalse( $result['large_size_h']['readonly'] );
$this->assertSame( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
$this->assertFalse( $result['default_comment_status']['readonly'] );
$this->assertSame( get_option( 'default_ping_status' ), $result['default_ping_status']['value'] );
$this->assertFalse( $result['default_ping_status']['readonly'] );
}
}