@@ -20,30 +20,52 @@ public function testHtmlDivTagsBalanceOnPostEditScreen(): void
2020 $ this ->assertDivBalanced ($ html , 'post edit screen ($needWrapper=false) ' );
2121 }
2222
23+ public function testHtmlDivTagsBalanceOnBulkSubmitScreen (): void
24+ {
25+ $ html = $ this ->resolveTemplate (false , true );
26+ $ this ->assertDivBalanced ($ html , 'bulk submit screen ($isBulkSubmitPage=true) ' );
27+ }
28+
2329 public function testHiddenWrapperHasClosingTag (): void
2430 {
25- $ source = $ this ->stripNonHtml (file_get_contents (self ::VIEW_FILE ));
26- $ hiddenOpens = preg_match_all ('#<div\s+style\s*=\s*"display:\s*none#i ' , $ source );
27- $ this ->assertGreaterThan (
28- 0 ,
29- $ hiddenOpens ,
30- 'Legacy display:none wrapper should still open (it hides the legacy .job-wizard fallback) '
31+ $ html = $ this ->resolveTemplate (false );
32+
33+ $ this ->assertSame (
34+ 1 ,
35+ preg_match (
36+ '#<div\s+style\s*=\s*"display:\s*none[^"]*"\s*>#i ' ,
37+ $ html ,
38+ $ matches ,
39+ PREG_OFFSET_CAPTURE
40+ ),
41+ 'Hidden display:none wrapper opening <div> should exist '
42+ );
43+
44+ $ tail = substr ($ html , $ matches [0 ][1 ]);
45+ $ opens = preg_match_all ('#<div\b#i ' , $ tail );
46+ $ closes = preg_match_all ('#</div\s*>#i ' , $ tail );
47+
48+ $ this ->assertSame (
49+ $ opens ,
50+ $ closes ,
51+ 'Hidden display:none wrapper must have a matching closing </div> ' .
52+ '(an unclosed wrapper here is what caused WP-1004). '
3153 );
3254 }
3355
34- private function resolveTemplate (bool $ needWrapper ): string
56+ private function resolveTemplate (bool $ needWrapper, bool $ isBulkSubmitPage = false ): string
3557 {
3658 $ source = $ this ->stripNonHtml (file_get_contents (self ::VIEW_FILE ));
3759
38- $ source = preg_replace (
39- '#<\?php\s+if\s*\(\s*\$needWrapper\s*&&\s*false\s*\ )\s*:\s*\?>(?:(?!<\?php\s+endif).)*<\?php\s+endif\s*;\s*\?>#s ' ,
40- '' ,
60+ $ source = preg_replace_callback (
61+ '#<\?php\s+if\s*\(\s*\$needWrapper\s*\ )\s*:\s*\?>(( ?:(?!<\?php\s+endif).)*) <\?php\s+endif\s*;\s*\?>#s ' ,
62+ static fn ( array $ m ): string => $ needWrapper ? $ m [ 1 ] : '' ,
4163 $ source
4264 );
4365
4466 $ source = preg_replace_callback (
45- '#<\?php\s+if\s*\(\s*\$needWrapper \s*\)\s*:\s*\?>((?:(?!<\?php\s+endif).)*)<\?php\s+endif\s*;\s*\?>#s ' ,
46- static fn (array $ m ): string => $ needWrapper ? $ m [1 ] : '' ,
67+ '#<\?php\s+if\s*\(\s*!\$isBulkSubmitPage \s*\)\s*:\s*\?>((?:(?!<\?php\s+endif).)*)<\?php\s+endif\s*;\s*\?>#s ' ,
68+ static fn (array $ m ): string => $ isBulkSubmitPage ? '' : $ m [1 ],
4769 $ source
4870 );
4971
0 commit comments