Make WordPress Core


Ignore:
Timestamp:
01/27/2026 11:18:32 AM (8 months ago)
Author:
jonsurrell
Message:

Build/Test Tools: Ensure assertEqualHTML() recognizes whitespace text.

Ensure whitespace text nodes are correctly represented by build_visual_html_tree().

The build_visual_html_tree() function used by assertEqualHTML() would remove some leading whitespace from text nodes. Some whitespace-only text nodes were omitted from the tree.

Developed in https://github.com/WordPress/wordpress-develop/pull/10765.

Follow-up to [60295].

Reviewed by wildworks.
Merges [61519] to the 6.9 branch.

Props jonsurrell, dmsnell, bernhard-reiter.
Fixes #64531.

Location:
branches/6.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.9

  • branches/6.9/tests/phpunit/tests/build-visual-html-tree.php

    r60295 r61536  
    1010class Tests_Build_Equivalent_HTML_Semantic_Tree extends WP_UnitTestCase {
    1111        public function data_build_equivalent_html_semantic_tree() {
    12                 $block_markup = <<<END
    13                         <!-- wp:separator {"className":"is-style-default has-custom-classname","style":{"spacing":{"margin":{"top":"50px","bottom":"50px"}}},"backgroundColor":"accent-1"} -->
    14                           <hr class="wp-block-separator is-style-default has-custom-classname" style="margin-top: 50px; margin-bottom: 50px" />
    15                         <!-- /wp:separator -->
    16 END;
    17 
    18                 $tree_structure = <<<END
     12                $block_markup = <<<'HTML'
     13<!-- wp:separator {"className":"is-style-default has-custom-classname","style":{"spacing":{"margin":{"top":"50px","bottom":"50px"}}},"backgroundColor":"accent-1"} -->
     14  <hr class="wp-block-separator is-style-default has-custom-classname" style="margin-top: 50px; margin-bottom: 50px" />
     15<!-- /wp:separator -->
     16HTML;
     17
     18                $tree_structure = <<<'TREE'
    1919BLOCK["core/separator"]
    2020  {
     
    3030    }
    3131  }
     32  "
     33  "
    3234  <hr>
    3335    class="has-custom-classname is-style-default wp-block-separator"
    3436    style="margin-top:50px;margin-bottom:50px;"
    35 
    36 END;
    37 
    38                 return array(
    39                         'Block delimiter' => array( $block_markup, $tree_structure ),
    40                 );
     37  "
     38"
     39
     40TREE;
     41
     42                yield 'Block delimiter' => array( $block_markup, $tree_structure );
     43
     44                $block_markup = <<<'HTML'
     45<!-- wp:example/block -->
     46        One
     47        <!-- wp:example/nested-void /-->
     48        Two
     49        <!-- wp:example/nested -->
     50                Three
     51        <!-- /wp:example/nested -->
     52        Four
     53<!-- /wp:example/block -->
     54HTML;
     55
     56                $tree_structure = <<<'TREE'
     57BLOCK["example/block"]
     58  "
     59        One
     60        "
     61  BLOCK["example/nested-void"]
     62  "
     63        Two
     64        "
     65  BLOCK["example/nested"]
     66    "
     67                Three
     68        "
     69  "
     70        Four
     71"
     72
     73TREE;
     74
     75                yield 'Text nodes in blocks' => array( $block_markup, $tree_structure );
    4176        }
    4277
    4378        /**
    4479         * @ticket 63527
     80         * @ticket 64531
    4581         *
    4682         * @covers ::build_visual_html_tree
     
    142178                $this->assertNotSame( $tree_expected, $tree_actual );
    143179        }
     180
     181        /**
     182         * @ticket 64531
     183         *
     184         * @covers ::build_visual_html_tree
     185         */
     186        public function test_spacing() {
     187                $html = <<<'HTML'
     188<p> space-surrounded&#x20;</p>
     189<p>&nbsp;nbsp-surrounded&#xA0;</p>
     190<p>
     191newline-surrounded&#xA;</p>
     192<p>&#x9;tab-surrounded  </p>
     193<p>ok</p>
     194HTML;
     195
     196                $expected = <<<TREE
     197<p>
     198  " space-surrounded "
     199"\n"
     200<p>
     201  "\u{00A0}nbsp-surrounded\u{00A0}"
     202"\n"
     203<p>
     204  "\nnewline-surrounded\n"
     205"\n"
     206<p>
     207  "\ttab-surrounded\t"
     208"\n"
     209<p>
     210  "ok"
     211
     212TREE;
     213
     214                $tree_result = build_visual_html_tree( $html, '<body>' );
     215                $this->assertSame( $expected, $tree_result );
     216        }
    144217}
Note: See TracChangeset for help on using the changeset viewer.