- Timestamp:
- 06/22/2021 09:23:19 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
r51021 r51208 259 259 $this->assertSame( 500, $response->status ); 260 260 $this->assertWPError( $response->as_error() ); 261 } 262 263 /** 264 * @covers WP_REST_Pattern_Directory_Controller::get_items 265 * 266 * @since 5.8.0 267 */ 268 public function test_get_items_prepare_filter() { 269 wp_set_current_user( self::$contributor_id ); 270 self::mock_successful_response( 'browse-all', true ); 271 272 // Test that filter changes uncached values. 273 add_filter( 274 'rest_prepare_block_pattern', 275 function( $response ) { 276 return 'initial value'; 277 } 278 ); 279 280 $request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' ); 281 $response = rest_do_request( $request ); 282 $patterns = $response->get_data(); 283 284 $this->assertSame( 'initial value', $patterns[0] ); 285 286 // Test that filter changes cached values (the previous request primed the cache). 287 add_filter( 288 'rest_prepare_block_pattern', 289 function( $response ) { 290 return 'modified the cache'; 291 }, 292 11 293 ); 294 295 // Test that the filter works against cached values. 296 $request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' ); 297 $response = rest_do_request( $request ); 298 $patterns = $response->get_data(); 299 300 $this->assertSame( 'modified the cache', $patterns[0] ); 261 301 } 262 302
Note: See TracChangeset
for help on using the changeset viewer.