Changeset 60684 for trunk/tests/phpunit/tests/block-bindings/render.php
- Timestamp:
- 08/27/2025 03:41:36 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/block-bindings/render.php
r60611 r60684 62 62 } 63 63 64 public function data_update_block_with_value_from_source() { 65 return array( 66 'paragraph block' => array( 67 'content', 68 <<<HTML 69 <!-- wp:paragraph --> 70 <p>This should not appear</p> 71 <!-- /wp:paragraph --> 72 HTML 73 , 74 '<p>test source value</p>', 75 ), 76 'button block' => array( 77 'text', 78 <<<HTML 79 <!-- wp:button --> 80 <div class="wp-block-button"><a class="wp-block-button__link wp-element-button">This should not appear</a></div> 81 <!-- /wp:button --> 82 HTML 83 , 84 '<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">test source value</a></div>', 85 ), 86 ); 87 } 88 64 89 /** 65 90 * Test if the block content is updated with the value returned by the source. … … 68 93 * 69 94 * @covers ::register_block_bindings_source 70 */ 71 public function test_update_block_with_value_from_source() { 95 * 96 * @dataProvider data_update_block_with_value_from_source 97 */ 98 public function test_update_block_with_value_from_source( $bound_attribute, $block_content, $expected_result ) { 72 99 $get_value_callback = function () { 73 100 return 'test source value'; … … 82 109 ); 83 110 84 $block_content = <<<HTML 85 <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source"}}}} --> 86 <p>This should not appear</p> 87 <!-- /wp:paragraph --> 88 HTML; 89 $parsed_blocks = parse_blocks( $block_content ); 90 $block = new WP_Block( $parsed_blocks[0] ); 91 $result = $block->render(); 111 $parsed_blocks = parse_blocks( $block_content ); 112 113 $parsed_blocks[0]['attrs']['metadata'] = array( 114 'bindings' => array( 115 $bound_attribute => array( 116 'source' => self::SOURCE_NAME, 117 ), 118 ), 119 ); 120 121 $block = new WP_Block( $parsed_blocks[0] ); 122 $result = $block->render(); 92 123 93 124 $this->assertSame( 94 125 'test source value', 95 $block->attributes[ 'content'],96 "The ' content' attribute should be updated with the value returned by the source."97 ); 98 $this->assertSame( 99 '<p>test source value</p>',126 $block->attributes[ $bound_attribute ], 127 "The '{$bound_attribute}' attribute should be updated with the value returned by the source." 128 ); 129 $this->assertSame( 130 $expected_result, 100 131 trim( $result ), 101 132 'The block content should be updated with the value returned by the source.'
Note: See TracChangeset
for help on using the changeset viewer.