- Timestamp:
- 03/07/2024 02:10:31 PM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php
r57366 r57790 48 48 public static function wpTearDownAfterClass() { 49 49 wp_delete_post( self::$post->ID ); 50 } 51 52 /** 53 * Tear down after each test. 54 * 55 * @since 6.5.0 56 */ 57 public function tear_down() { 58 if ( has_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' ) ) { 59 remove_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes', 10 ); 60 } 61 if ( WP_Block_Type_Registry::get_instance()->is_registered( 'tests/block' ) ) { 62 unregister_block_type( 'tests/hooked-block' ); 63 } 64 65 parent::tear_down(); 50 66 } 51 67 … … 912 928 $this->assertEmpty( $prepared->post_content, 'The content was not correct in the prepared template part.' ); 913 929 } 930 931 /** 932 * @ticket 60671 933 * 934 * @covers WP_REST_Templates_Controller::prepare_item_for_database 935 * @covers inject_ignored_hooked_blocks_metadata_attributes 936 */ 937 public function test_prepare_item_for_database_injects_hooked_block() { 938 register_block_type( 939 'tests/hooked-block', 940 array( 941 'block_hooks' => array( 942 'tests/anchor-block' => 'after', 943 ), 944 ) 945 ); 946 947 add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes', 10, 2 ); 948 949 $endpoint = new WP_REST_Templates_Controller( 'wp_template_part' ); 950 951 $prepare_item_for_database = new ReflectionMethod( $endpoint, 'prepare_item_for_database' ); 952 $prepare_item_for_database->setAccessible( true ); 953 954 $body_params = array( 955 'title' => 'Untitled Template Part', 956 'slug' => 'untitled-template-part', 957 'content' => '<!-- wp:tests/anchor-block -->Hello<!-- /wp:tests/anchor-block -->', 958 ); 959 960 $request = new WP_REST_Request( 'POST', '/wp/v2/template-parts' ); 961 $request->set_body_params( $body_params ); 962 963 $prepared = $prepare_item_for_database->invoke( $endpoint, $request ); 964 $this->assertSame( 965 '<!-- wp:tests/anchor-block {"metadata":{"ignoredHookedBlocks":["tests/hooked-block"]}} -->Hello<!-- /wp:tests/anchor-block -->', 966 $prepared->post_content, 967 'The hooked block was not injected into the anchor block\'s ignoredHookedBlocks metadata.' 968 ); 969 } 914 970 }
Note: See TracChangeset
for help on using the changeset viewer.