Skip to content

Commit c09bdc5

Browse files
committed
Tests: Unregister block types in REST_Block_Type_Controller_Test
Test methods that register new block types should unregister them as well. Otherwise, the state leaks into later tests.
1 parent a336e41 commit c09bdc5

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎tests/phpunit/tests/rest-api/rest-block-type-controller.php‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public static function wpTearDownAfterClass() {
6262
self::delete_user( self::$admin_id );
6363
self::delete_user( self::$subscriber_id );
6464
unregister_block_type( 'fake/test' );
65-
unregister_block_type( 'fake/invalid' );
66-
unregister_block_type( 'fake/false' );
6765
}
6866

6967
/**
@@ -138,6 +136,7 @@ public function test_get_item_with_styles() {
138136
wp_set_current_user( self::$admin_id );
139137
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_name );
140138
$response = rest_get_server()->dispatch( $request );
139+
unregister_block_type( $block_name );
141140
$data = $response->get_data();
142141
$this->assertSameSets( array( $block_styles ), $data['styles'] );
143142
}
@@ -166,6 +165,7 @@ public function test_get_item_with_styles_merge() {
166165
wp_set_current_user( self::$admin_id );
167166
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_name );
168167
$response = rest_get_server()->dispatch( $request );
168+
unregister_block_type( $block_name );
169169
$data = $response->get_data();
170170
$expected = array(
171171
array(
@@ -232,6 +232,7 @@ public function test_get_item_invalid() {
232232
wp_set_current_user( self::$admin_id );
233233
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type );
234234
$response = rest_get_server()->dispatch( $request );
235+
unregister_block_type( $block_type );
235236
$data = $response->get_data();
236237
$this->assertSame( $block_type, $data['name'] );
237238
$this->assertSame( '1', $data['title'] );
@@ -311,6 +312,7 @@ public function test_get_item_defaults() {
311312
wp_set_current_user( self::$admin_id );
312313
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type );
313314
$response = rest_get_server()->dispatch( $request );
315+
unregister_block_type( $block_type );
314316
$data = $response->get_data();
315317
$this->assertSame( $block_type, $data['name'] );
316318
$this->assertSame( '', $data['title'] );
@@ -368,6 +370,7 @@ public function test_get_item_deprecated() {
368370
wp_set_current_user( self::$admin_id );
369371
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type );
370372
$response = rest_get_server()->dispatch( $request );
373+
unregister_block_type( $block_type );
371374
$data = $response->get_data();
372375
$this->assertSameSets(
373376
array( 'hello_world' ),
@@ -438,6 +441,7 @@ public function test_get_item_deprecated_with_arrays() {
438441
wp_set_current_user( self::$admin_id );
439442
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type );
440443
$response = rest_get_server()->dispatch( $request );
444+
unregister_block_type( $block_type );
441445
$data = $response->get_data();
442446
$this->assertSameSets(
443447
$settings['editor_script'],
@@ -525,6 +529,7 @@ public function test_get_variation() {
525529
wp_set_current_user( self::$admin_id );
526530
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type );
527531
$response = rest_get_server()->dispatch( $request );
532+
unregister_block_type( $block_type );
528533
$data = $response->get_data();
529534
$this->assertSame( $block_type, $data['name'] );
530535
$this->assertArrayHasKey( 'variations', $data );
@@ -868,6 +873,7 @@ public function test_variation_callback() {
868873
wp_set_current_user( self::$admin_id );
869874
$request = new WP_REST_Request( 'GET', '/wp/v2/block-types/' . $block_type );
870875
$response = rest_get_server()->dispatch( $request );
876+
unregister_block_type( $block_type );
871877
$data = $response->get_data();
872878
$this->assertSameSets( $this->mock_variation_callback(), $data['variations'] );
873879
}

0 commit comments

Comments
 (0)