@@ -130,21 +130,59 @@ public function test_apply_block_hooks_to_content_from_post_object_inserts_hooke
130130 $ this ->assertSame ( $ expected , $ actual );
131131 }
132132
133+ /**
134+ * @ticket 65008
135+ */
136+ public function test_apply_block_hooks_to_content_from_post_object_sets_ignored_hooked_blocks () {
137+ $ ignored_hooked_blocks_at_root = array ();
138+
139+ $ expected = '<!-- wp:tests/hooked-block-first-child /--> ' .
140+ '<!-- wp:heading {"level":1,"metadata":{"ignoredHookedBlocks":["tests/hooked-block"]}} --> ' .
141+ '<h1>Hello World!</h1> ' .
142+ '<!-- /wp:heading --> ' .
143+ '<!-- wp:tests/hooked-block /--> ' ;
144+ $ actual = apply_block_hooks_to_content_from_post_object (
145+ self ::$ post ->post_content ,
146+ self ::$ post ,
147+ 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata ' ,
148+ $ ignored_hooked_blocks_at_root
149+ );
150+ $ this ->assertSame ( $ expected , $ actual , "Markup wasn't updated correctly. " );
151+ $ this ->assertSame (
152+ array ( 'tests/hooked-block-first-child ' ),
153+ $ ignored_hooked_blocks_at_root ,
154+ "Hooked block added at 'first_child' position wasn't added to ignoredHookedBlocks metadata. "
155+ );
156+ }
157+
133158 /**
134159 * @ticket 62716
160+ * @ticket 65008
135161 */
136162 public function test_apply_block_hooks_to_content_from_post_object_respects_ignored_hooked_blocks_post_meta () {
137- $ expected = self ::$ post_with_ignored_hooked_block ->post_content . '<!-- wp:tests/hooked-block /--> ' ;
163+ $ ignored_hooked_blocks_at_root = array ();
164+
165+ $ expected = '<!-- wp:heading {"level":1,"metadata":{"ignoredHookedBlocks":["tests/hooked-block"]}} --> ' .
166+ '<h1>Hello World!</h1> ' .
167+ '<!-- /wp:heading --> ' .
168+ '<!-- wp:tests/hooked-block /--> ' ;
138169 $ actual = apply_block_hooks_to_content_from_post_object (
139170 self ::$ post_with_ignored_hooked_block ->post_content ,
140171 self ::$ post_with_ignored_hooked_block ,
141- 'insert_hooked_blocks '
172+ 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata ' ,
173+ $ ignored_hooked_blocks_at_root
142174 );
143175 $ this ->assertSame ( $ expected , $ actual );
176+ $ this ->assertSame (
177+ array ( 'tests/hooked-block-first-child ' ),
178+ $ ignored_hooked_blocks_at_root ,
179+ "Pre-existing ignored hooked block at root level wasn't reflected in metadata. "
180+ );
144181 }
145182
146183 /**
147184 * @ticket 63287
185+ * @ticket 65008
148186 */
149187 public function test_apply_block_hooks_to_content_from_post_object_does_not_insert_hooked_block_before_container_block () {
150188 $ filter = function ( $ hooked_block_types , $ relative_position , $ anchor_block_type ) {
@@ -155,31 +193,50 @@ public function test_apply_block_hooks_to_content_from_post_object_does_not_inse
155193 return $ hooked_block_types ;
156194 };
157195
196+ $ ignored_hooked_blocks_at_root = array ();
197+
158198 $ expected = '<!-- wp:tests/hooked-block-first-child /--> ' .
159- self ::$ post ->post_content .
199+ '<!-- wp:heading {"level":1,"metadata":{"ignoredHookedBlocks":["tests/hooked-block"]}} --> ' .
200+ '<h1>Hello World!</h1> ' .
201+ '<!-- /wp:heading --> ' .
160202 '<!-- wp:tests/hooked-block /--> ' ;
161203
162204 add_filter ( 'hooked_block_types ' , $ filter , 10 , 3 );
163205 $ actual = apply_block_hooks_to_content_from_post_object (
164206 self ::$ post ->post_content ,
165207 self ::$ post ,
166- 'insert_hooked_blocks '
208+ 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata ' ,
209+ $ ignored_hooked_blocks_at_root
167210 );
168211 remove_filter ( 'hooked_block_types ' , $ filter , 10 );
169212
170- $ this ->assertSame ( $ expected , $ actual );
213+ $ this ->assertSame ( $ expected , $ actual , "Hooked block added before 'core/post-content' block shouldn't be inserted. " );
214+ $ this ->assertSame (
215+ array ( 'tests/hooked-block-first-child ' ),
216+ $ ignored_hooked_blocks_at_root ,
217+ "ignoredHookedBlocks metadata wasn't set correctly. "
218+ );
171219 }
172220
173221 /**
174222 * @ticket 62716
223+ * @ticket 65008
175224 */
176225 public function test_apply_block_hooks_to_content_from_post_object_inserts_hooked_block_if_content_contains_no_blocks () {
226+ $ ignored_hooked_blocks_at_root = array ();
227+
177228 $ expected = '<!-- wp:tests/hooked-block-first-child /--> ' . self ::$ post_with_non_block_content ->post_content ;
178229 $ actual = apply_block_hooks_to_content_from_post_object (
179230 self ::$ post_with_non_block_content ->post_content ,
180231 self ::$ post_with_non_block_content ,
181- 'insert_hooked_blocks '
232+ 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata ' ,
233+ $ ignored_hooked_blocks_at_root
234+ );
235+ $ this ->assertSame ( $ expected , $ actual , "Markup wasn't updated correctly. " );
236+ $ this ->assertSame (
237+ array ( 'tests/hooked-block-first-child ' ),
238+ $ ignored_hooked_blocks_at_root ,
239+ "Hooked block added at 'first_child' position wasn't added to ignoredHookedBlocks metadata. "
182240 );
183- $ this ->assertSame ( $ expected , $ actual );
184241 }
185242}
0 commit comments