Changeset 57574 for trunk/tests/phpunit/tests/block-bindings/render.php
- Timestamp:
- 02/09/2024 10:38:38 AM (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/block-bindings/render.php
r57526 r57574 53 53 54 54 $block_content = <<<HTML 55 <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source"}}}} --><p>This should not appear</p><!-- /wp:paragraph --> 55 <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source"}}}} --> 56 <p>This should not appear</p> 57 <!-- /wp:paragraph --> 56 58 HTML; 57 58 59 $parsed_blocks = parse_blocks( $block_content ); 59 60 $block = new WP_Block( $parsed_blocks[0] ); 61 $result = $block->render(); 60 62 61 $expected = '<p>test source value</p>'; 62 $result = $block->render(); 63 64 $this->assertEquals( $expected, $result, 'The block content should be updated with the value returned by the source.' ); 63 $this->assertSame( 64 'test source value', 65 $block->attributes['content'], 66 "The 'content' attribute should be updated with the value returned by the source." 67 ); 68 $this->assertSame( 69 '<p>test source value</p>', 70 trim( $result ), 71 'The block content should be updated with the value returned by the source.' 72 ); 65 73 } 66 74 … … 86 94 ); 87 95 88 $value = 'test';89 96 $block_content = <<<HTML 90 <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source", "args": {"key": "$value"}}}}} --><p>This should not appear</p><!-- /wp:paragraph --> 97 <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source", "args": {"key": "test"}}}}} --> 98 <p>This should not appear</p> 99 <!-- /wp:paragraph --> 91 100 HTML; 92 93 101 $parsed_blocks = parse_blocks( $block_content ); 94 102 $block = new WP_Block( $parsed_blocks[0] ); 103 $result = $block->render(); 95 104 96 $expected = "<p>The attribute name is 'content' and its binding has argument 'key' with value '$value'.</p>"; 97 $result = $block->render(); 105 $this->assertSame( 106 "The attribute name is 'content' and its binding has argument 'key' with value 'test'.", 107 $block->attributes['content'], 108 "The 'content' attribute should be updated with the value returned by the source." 109 ); 110 $this->assertSame( 111 "<p>The attribute name is 'content' and its binding has argument 'key' with value 'test'.</p>", 112 trim( $result ), 113 'The block content should be updated with the value returned by the source.' 114 ); 115 } 98 116 99 $this->assertEquals( $expected, $result, 'The block content should be updated with the value returned by the source.' ); 117 /** 118 * Tests if the block content is updated with the value returned by the source 119 * for the Image block in the placeholder state. 120 * 121 * @ticket 60282 122 * 123 * @covers ::register_block_bindings_source 124 */ 125 public function test_update_block_with_value_from_source_image_placeholder() { 126 $get_value_callback = function () { 127 return 'https://example.com/image.jpg'; 128 }; 129 130 register_block_bindings_source( 131 self::SOURCE_NAME, 132 array( 133 'label' => self::SOURCE_LABEL, 134 'get_value_callback' => $get_value_callback, 135 ) 136 ); 137 138 $block_content = <<<HTML 139 <!-- wp:image {"metadata":{"bindings":{"url":{"source":"test/source"}}}} --> 140 <figure class="wp-block-image"><img alt=""/></figure> 141 <!-- /wp:image --> 142 HTML; 143 $parsed_blocks = parse_blocks( $block_content ); 144 $block = new WP_Block( $parsed_blocks[0] ); 145 $result = $block->render(); 146 147 $this->assertSame( 148 'https://example.com/image.jpg', 149 $block->attributes['url'], 150 "The 'url' attribute should be updated with the value returned by the source." 151 ); 152 $this->assertSame( 153 '<figure class="wp-block-image"><img src="https://example.com/image.jpg" alt=""/></figure>', 154 trim( $result ), 155 'The block content should be updated with the value returned by the source.' 156 ); 100 157 } 101 158 }
Note: See TracChangeset
for help on using the changeset viewer.