Changeset 44261 for trunk/tests/phpunit/tests/blocks/render.php
- Timestamp:
- 12/17/2018 04:50:48 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43884,43888
- Property svn:mergeinfo changed
-
trunk/tests/phpunit/tests/blocks/render.php
r44226 r44261 47 47 $registry->unregister( 'core/test' ); 48 48 } 49 if ( $registry->is_registered( 'core/dynamic' ) ) { 50 $registry->unregister( 'core/dynamic' ); 51 } 49 52 } 50 53 … … 76 79 $block_filtered_content = preg_replace( "/\n{2,}/", "\n", $block_filtered_content ); 77 80 81 remove_shortcode( 'someshortcode' ); 82 78 83 $this->assertEquals( trim( $classic_filtered_content ), trim( $block_filtered_content ) ); 79 84 } … … 81 86 function handle_shortcode( $atts, $content ) { 82 87 return $content; 88 } 89 90 public function test_can_nest_at_least_so_deep() { 91 $minimum_depth = 99; 92 93 $content = 'deep inside'; 94 for ( $i = 0; $i < $minimum_depth; $i++ ) { 95 $content = '<!-- wp:core/test -->' . $content . '<!-- /wp:core/test -->'; 96 } 97 98 $this->assertEquals( 'deep inside', do_blocks( $content ) ); 99 } 100 101 public function test_can_nest_at_least_so_deep_with_dynamic_blocks() { 102 $minimum_depth = 99; 103 104 $content = '0'; 105 for ( $i = 0; $i < $minimum_depth; $i++ ) { 106 $content = '<!-- wp:core/test -->' . $content . '<!-- /wp:core/test -->'; 107 } 108 109 register_block_type( 110 'core/test', 111 array( 112 'render_callback' => array( 113 $this, 114 'render_dynamic_incrementer', 115 ), 116 ) 117 ); 118 119 $this->assertEquals( $minimum_depth, (int) do_blocks( $content ) ); 120 } 121 122 public function render_dynamic_incrementer( $attrs, $content ) { 123 return (string) ( 1 + (int) $content ); 83 124 } 84 125 … … 243 284 } 244 285 286 public function test_dynamic_block_gets_inner_html() { 287 register_block_type( 288 'core/dynamic', 289 array( 290 'render_callback' => array( 291 $this, 292 'render_serialize_dynamic_block', 293 ), 294 ) 295 ); 296 297 $output = do_blocks( '<!-- wp:dynamic -->inner<!-- /wp:dynamic -->' ); 298 299 $data = unserialize( base64_decode( $output ) ); 300 301 $this->assertEquals( 'inner', $data[1] ); 302 } 303 304 public function test_dynamic_block_gets_rendered_inner_blocks() { 305 register_block_type( 306 'core/test', 307 array( 308 'render_callback' => array( 309 $this, 310 'render_test_block_numeric', 311 ), 312 ) 313 ); 314 315 register_block_type( 316 'core/dynamic', 317 array( 318 'render_callback' => array( 319 $this, 320 'render_serialize_dynamic_block', 321 ), 322 ) 323 ); 324 325 $output = do_blocks( '<!-- wp:dynamic -->before<!-- wp:test /-->after<!-- /wp:dynamic -->' ); 326 327 $data = unserialize( base64_decode( $output ) ); 328 329 $this->assertEquals( 'before10after', $data[1] ); 330 } 331 332 public function test_dynamic_block_gets_rendered_inner_dynamic_blocks() { 333 register_block_type( 334 'core/dynamic', 335 array( 336 'render_callback' => array( 337 $this, 338 'render_serialize_dynamic_block', 339 ), 340 ) 341 ); 342 343 $output = do_blocks( '<!-- wp:dynamic -->before<!-- wp:dynamic -->deep inner<!-- /wp:dynamic -->after<!-- /wp:dynamic -->' ); 344 345 $data = unserialize( base64_decode( $output ) ); 346 347 $inner = $this->render_serialize_dynamic_block( array(), 'deep inner' ); 348 349 $this->assertEquals( $data[1], 'before' . $inner . 'after' ); 350 } 351 245 352 /** 246 353 * Helper function to remove relative paths and extension from a filename, leaving just the fixture name. … … 306 413 public function render_test_block_numeric() { 307 414 return 10; 415 } 416 417 /** 418 * Test block rendering function, returning base64 encoded serialised value. 419 * 420 * @since 5.0.0 421 * 422 * @return string Block output. 423 */ 424 public function render_serialize_dynamic_block( $attributes, $content ) { 425 return base64_encode( serialize( array( $attributes, $content ) ) ); 308 426 } 309 427
Note: See TracChangeset
for help on using the changeset viewer.