- Timestamp:
- 10/27/2016 02:56:28 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-settings-controller.php
r38971 r38975 11 11 */ 12 12 class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase { 13 protected static $administrator; 14 15 public static function wpSetUpBeforeClass( $factory ) { 16 self::$administrator = $factory->user->create( array( 17 'role' => 'administrator', 18 ) ); 19 } 20 21 public static function wpTearDownAfterClass() { 22 self::delete_user( self::$administrator ); 23 } 13 24 14 25 public function setUp() { 15 26 parent::setUp(); 16 $this->administrator = $this->factory->user->create( array(17 'role' => 'administrator',18 ) );19 27 $this->endpoint = new WP_REST_Settings_Controller(); 20 28 } … … 38 46 39 47 public function test_get_item() { 40 wp_set_current_user( $this->administrator );48 wp_set_current_user( self::$administrator ); 41 49 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); 42 50 $response = $this->server->dispatch( $request ); … … 64 72 65 73 public function test_get_item_value_is_cast_to_type() { 66 wp_set_current_user( $this->administrator );74 wp_set_current_user( self::$administrator ); 67 75 update_option( 'posts_per_page', 'invalid_number' ); // this is cast to (int) 1 68 76 $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); … … 75 83 76 84 public function test_get_item_with_custom_setting() { 77 wp_set_current_user( $this->administrator );85 wp_set_current_user( self::$administrator ); 78 86 79 87 register_setting( 'somegroup', 'mycustomsetting', array( … … 115 123 116 124 public function test_get_item_with_filter() { 117 wp_set_current_user( $this->administrator );125 wp_set_current_user( self::$administrator ); 118 126 119 127 add_filter( 'rest_pre_get_setting', array( $this, 'get_setting_custom_callback' ), 10, 3 ); … … 156 164 157 165 public function test_update_item() { 158 wp_set_current_user( $this->administrator );166 wp_set_current_user( self::$administrator ); 159 167 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 160 168 $request->set_param( 'title', 'The new title!' ); … … 177 185 178 186 public function test_update_item_with_filter() { 179 wp_set_current_user( $this->administrator );187 wp_set_current_user( self::$administrator ); 180 188 181 189 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); … … 208 216 209 217 public function test_update_item_with_invalid_type() { 210 wp_set_current_user( $this->administrator );218 wp_set_current_user( self::$administrator ); 211 219 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 212 220 $request->set_param( 'title', array( 'rendered' => 'This should fail.' ) ); … … 221 229 update_option( 'posts_per_page', 9 ); 222 230 223 wp_set_current_user( $this->administrator );231 wp_set_current_user( self::$administrator ); 224 232 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 225 233 $request->set_param( 'posts_per_page', null ); … … 234 242 update_option( 'posts_per_page', 9 ); 235 243 236 wp_set_current_user( $this->administrator );244 wp_set_current_user( self::$administrator ); 237 245 $request = new WP_REST_Request( 'PUT', '/wp/v2/settings' ); 238 246 $request->set_param( 'default_ping_status', 'open&closed' );
Note: See TracChangeset
for help on using the changeset viewer.