- Timestamp:
- 07/11/2020 08:32:19 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php
r48118 r48437 57 57 58 58 /** 59 * Dynamic block with boolean attributes block name. 60 * 61 * @since 5.5.0 62 * 63 * @var string 64 */ 65 protected static $dynamic_block_with_boolean_attributes_block_name = 'core/dynamic-block-with-boolean-attributes'; 66 67 /** 59 68 * Test API user's ID. 60 69 * … … 128 137 $this->register_post_context_test_block(); 129 138 $this->register_non_dynamic_block(); 139 $this->register_dynamic_block_with_boolean_attributes(); 130 140 parent::setUp(); 131 141 } … … 140 150 WP_Block_Type_Registry::get_instance()->unregister( self::$context_block_name ); 141 151 WP_Block_Type_Registry::get_instance()->unregister( self::$non_dynamic_block_name ); 152 WP_Block_Type_Registry::get_instance()->unregister( self::$dynamic_block_with_boolean_attributes_block_name ); 142 153 parent::tearDown(); 143 154 } … … 197 208 198 209 /** 210 * Registers the dynamic with boolean attributes block name. 211 * 212 * @since 5.5.0 213 */ 214 protected function register_dynamic_block_with_boolean_attributes() { 215 register_block_type( 216 self::$dynamic_block_with_boolean_attributes_block_name, 217 array( 218 'attributes' => array( 219 'boolean_true_attribute' => array( 220 'type' => 'boolean', 221 'default' => true, 222 ), 223 'boolean_false_attribute' => array( 224 'type' => 'boolean', 225 'default' => false, 226 ), 227 ), 228 'render_callback' => array( $this, 'render_test_block' ), 229 ) 230 ); 231 } 232 233 /** 199 234 * Test render callback. 200 235 * … … 524 559 525 560 /** 561 * @ticket 50620 562 */ 563 public function test_get_sanitized_attributes_for_dynamic_block_with_boolean_attributes() { 564 wp_set_current_user( self::$user_id ); 565 566 $request = new WP_REST_Request( 'GET', self::$rest_api_route . self::$dynamic_block_with_boolean_attributes_block_name ); 567 568 $attributes = array( 569 'boolean_true_attribute' => 'true', 570 'boolean_false_attribute' => 'false', 571 ); 572 573 $expected = array( 574 'boolean_true_attribute' => true, 575 'boolean_false_attribute' => false, 576 ); 577 578 $request->set_param( 'context', 'edit' ); 579 $request->set_param( 'attributes', $attributes ); 580 $response = rest_get_server()->dispatch( $request ); 581 $this->assertEquals( 200, $response->get_status() ); 582 $data = $response->get_data(); 583 584 $this->assertSame( $expected, json_decode( $data['rendered'], true ) ); 585 } 586 587 /** 526 588 * Get item schema. 527 589 *
Note: See TracChangeset
for help on using the changeset viewer.