PageRenderTime 21ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/xmlrpc/wp/getOptions.php

https://gitlab.com/Blueprint-Marketing/wordpress-unit-tests
PHP | 211 lines | 137 code | 64 blank | 10 comment | 0 complexity | 4935babb3411116ce9b3b3ae8555fa3c MD5 | raw file
  1. <?php
  2. /**
  3. * @group xmlrpc
  4. */
  5. class Tests_XMLRPC_wp_getOptions extends WP_XMLRPC_UnitTestCase {
  6. function test_invalid_username_password() {
  7. $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'username', 'password' ) );
  8. $this->assertInstanceOf( 'IXR_Error', $result );
  9. $this->assertEquals( 403, $result->code );
  10. }
  11. function test_valid_username_password() {
  12. $this->make_user_by_role( 'subscriber' );
  13. $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) );
  14. $this->assertInternalType( 'array', $result );
  15. $this->assertEquals( 'WordPress', $result['software_name']['value'] );
  16. }
  17. function test_option_value() {
  18. $this->make_user_by_role( 'administrator' );
  19. $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'administrator', 'administrator', 'default_comment_status' ) );
  20. $this->assertInternalType( 'array', $result );
  21. $this->assertEquals( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
  22. $this->assertFalse( $result['default_comment_status']['readonly'] );
  23. }
  24. /**
  25. * @ticket 20201
  26. */
  27. function test_option_values_subscriber() {
  28. global $wp_version;
  29. $this->make_user_by_role( 'subscriber' );
  30. $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) );
  31. $this->assertInternalType( 'array', $result );
  32. // Read Only options
  33. $this->assertEquals( 'WordPress', $result['software_name']['value'] );
  34. $this->assertTrue( $result['software_name']['readonly'] );
  35. $this->assertEquals( $wp_version, $result['software_version']['value'] );
  36. $this->assertTrue( $result['software_version']['readonly'] );
  37. $this->assertEquals( get_site_url(), $result['blog_url']['value'] );
  38. $this->assertTrue( $result['blog_url']['readonly'] );
  39. $this->assertEquals( wp_login_url(), $result['login_url']['value'] );
  40. $this->assertTrue( $result['login_url']['readonly'] );
  41. $this->assertEquals( get_admin_url(), $result['admin_url']['value'] );
  42. $this->assertTrue( $result['admin_url']['readonly'] );
  43. $this->assertEquals( get_option( 'image_default_link_type' ), $result['image_default_link_type']['value'] );
  44. $this->assertTrue( $result['image_default_link_type']['readonly'] );
  45. $this->assertEquals( get_option( 'image_default_size' ), $result['image_default_size']['value'] );
  46. $this->assertTrue( $result['image_default_size']['readonly'] );
  47. $this->assertEquals( get_option( 'image_default_align' ), $result['image_default_align']['value'] );
  48. $this->assertTrue( $result['image_default_align']['readonly'] );
  49. $this->assertEquals( get_template(), $result['template']['value'] );
  50. $this->assertTrue( $result['template']['readonly'] );
  51. $this->assertEquals( get_stylesheet(), $result['stylesheet']['value'] );
  52. $this->assertTrue( $result['stylesheet']['readonly'] );
  53. $this->assertEquals( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] );
  54. $this->assertTrue( $result['post_thumbnail']['readonly'] );
  55. // Updatable options
  56. $this->assertEquals( get_option( 'gmt_offset' ), $result['time_zone']['value'] );
  57. $this->assertTrue( $result['time_zone']['readonly'] );
  58. $this->assertEquals( get_option( 'blogname' ), $result['blog_title']['value'] );
  59. $this->assertTrue( $result['blog_title']['readonly'] );
  60. $this->assertEquals( get_option( 'blogdescription' ), $result['blog_tagline']['value'] );
  61. $this->assertTrue( $result['blog_tagline']['readonly'] );
  62. $this->assertEquals( get_option( 'date_format' ), $result['date_format']['value'] );
  63. $this->assertTrue( $result['date_format']['readonly'] );
  64. $this->assertEquals( get_option( 'time_format' ), $result['time_format']['value'] );
  65. $this->assertTrue( $result['time_format']['readonly'] );
  66. $this->assertEquals( get_option( 'users_can_register' ), $result['users_can_register']['value'] );
  67. $this->assertTrue( $result['users_can_register']['readonly'] );
  68. $this->assertEquals( get_option( 'thumbnail_size_w' ), $result['thumbnail_size_w']['value'] );
  69. $this->assertTrue( $result['thumbnail_size_w']['readonly'] );
  70. $this->assertEquals( get_option( 'thumbnail_size_h' ), $result['thumbnail_size_h']['value'] );
  71. $this->assertTrue( $result['thumbnail_size_h']['readonly'] );
  72. $this->assertEquals( get_option( 'thumbnail_crop' ), $result['thumbnail_crop']['value'] );
  73. $this->assertTrue( $result['thumbnail_crop']['readonly'] );
  74. $this->assertEquals( get_option( 'medium_size_w' ), $result['medium_size_w']['value'] );
  75. $this->assertTrue( $result['medium_size_w']['readonly'] );
  76. $this->assertEquals( get_option( 'medium_size_h' ), $result['medium_size_h']['value'] );
  77. $this->assertTrue( $result['medium_size_h']['readonly'] );
  78. $this->assertEquals( get_option( 'large_size_w' ), $result['large_size_w']['value'] );
  79. $this->assertTrue( $result['large_size_w']['readonly'] );
  80. $this->assertEquals( get_option( 'large_size_h' ), $result['large_size_h']['value'] );
  81. $this->assertTrue( $result['large_size_h']['readonly'] );
  82. $this->assertEquals( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
  83. $this->assertTrue( $result['default_comment_status']['readonly'] );
  84. $this->assertEquals( get_option( 'default_ping_status' ), $result['default_ping_status']['value'] );
  85. $this->assertTrue( $result['default_ping_status']['readonly'] );
  86. }
  87. function test_option_values_admin() {
  88. global $wp_version;
  89. $this->make_user_by_role( 'administrator' );
  90. $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'administrator', 'administrator' ) );
  91. $this->assertInternalType( 'array', $result );
  92. // Read Only options
  93. $this->assertEquals( 'WordPress', $result['software_name']['value'] );
  94. $this->assertTrue( $result['software_name']['readonly'] );
  95. $this->assertEquals( $wp_version, $result['software_version']['value'] );
  96. $this->assertTrue( $result['software_version']['readonly'] );
  97. $this->assertEquals( get_site_url(), $result['blog_url']['value'] );
  98. $this->assertTrue( $result['blog_url']['readonly'] );
  99. $this->assertEquals( wp_login_url(), $result['login_url']['value'] );
  100. $this->assertTrue( $result['login_url']['readonly'] );
  101. $this->assertEquals( get_admin_url(), $result['admin_url']['value'] );
  102. $this->assertTrue( $result['admin_url']['readonly'] );
  103. $this->assertEquals( get_option( 'image_default_link_type' ), $result['image_default_link_type']['value'] );
  104. $this->assertTrue( $result['image_default_link_type']['readonly'] );
  105. $this->assertEquals( get_option( 'image_default_size' ), $result['image_default_size']['value'] );
  106. $this->assertTrue( $result['image_default_size']['readonly'] );
  107. $this->assertEquals( get_option( 'image_default_align' ), $result['image_default_align']['value'] );
  108. $this->assertTrue( $result['image_default_align']['readonly'] );
  109. $this->assertEquals( get_template(), $result['template']['value'] );
  110. $this->assertTrue( $result['template']['readonly'] );
  111. $this->assertEquals( get_stylesheet(), $result['stylesheet']['value'] );
  112. $this->assertTrue( $result['stylesheet']['readonly'] );
  113. $this->assertEquals( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] );
  114. $this->assertTrue( $result['post_thumbnail']['readonly'] );
  115. // Updatable options
  116. $this->assertEquals( get_option( 'gmt_offset' ), $result['time_zone']['value'] );
  117. $this->assertFalse( $result['time_zone']['readonly'] );
  118. $this->assertEquals( get_option( 'blogname' ), $result['blog_title']['value'] );
  119. $this->assertFalse( $result['blog_title']['readonly'] );
  120. $this->assertEquals( get_option( 'blogdescription' ), $result['blog_tagline']['value'] );
  121. $this->assertFalse( $result['blog_tagline']['readonly'] );
  122. $this->assertEquals( get_option( 'date_format' ), $result['date_format']['value'] );
  123. $this->assertFalse( $result['date_format']['readonly'] );
  124. $this->assertEquals( get_option( 'time_format' ), $result['time_format']['value'] );
  125. $this->assertFalse( $result['time_format']['readonly'] );
  126. $this->assertEquals( get_option( 'users_can_register' ), $result['users_can_register']['value'] );
  127. $this->assertFalse( $result['users_can_register']['readonly'] );
  128. $this->assertEquals( get_option( 'thumbnail_size_w' ), $result['thumbnail_size_w']['value'] );
  129. $this->assertFalse( $result['thumbnail_size_w']['readonly'] );
  130. $this->assertEquals( get_option( 'thumbnail_size_h' ), $result['thumbnail_size_h']['value'] );
  131. $this->assertFalse( $result['thumbnail_size_h']['readonly'] );
  132. $this->assertEquals( get_option( 'thumbnail_crop' ), $result['thumbnail_crop']['value'] );
  133. $this->assertFalse( $result['thumbnail_crop']['readonly'] );
  134. $this->assertEquals( get_option( 'medium_size_w' ), $result['medium_size_w']['value'] );
  135. $this->assertFalse( $result['medium_size_w']['readonly'] );
  136. $this->assertEquals( get_option( 'medium_size_h' ), $result['medium_size_h']['value'] );
  137. $this->assertFalse( $result['medium_size_h']['readonly'] );
  138. $this->assertEquals( get_option( 'large_size_w' ), $result['large_size_w']['value'] );
  139. $this->assertFalse( $result['large_size_w']['readonly'] );
  140. $this->assertEquals( get_option( 'large_size_h' ), $result['large_size_h']['value'] );
  141. $this->assertFalse( $result['large_size_h']['readonly'] );
  142. $this->assertEquals( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
  143. $this->assertFalse( $result['default_comment_status']['readonly'] );
  144. $this->assertEquals( get_option( 'default_ping_status' ), $result['default_ping_status']['value'] );
  145. $this->assertFalse( $result['default_ping_status']['readonly'] );
  146. }
  147. }