Make WordPress Core


Ignore:
Timestamp:
09/30/2025 04:26:44 PM (14 months ago)
Author:
johnbillion
Message:

Menus: Prevent HTML in menu item titles from being rendered unexpectedly.

Props audrasjb, desrosj, johnbillion, jorbin, phillsav, vortfu, westonruter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r60253 r60815  
    185185                // Expected menu item array.
    186186                $expected = array(
    187                         'id'         => "post-{$post_id}",
    188                         'title'      => 'Post Title',
    189                         'type'       => 'post_type',
    190                         'type_label' => 'Post',
    191                         'object'     => 'post',
    192                         'object_id'  => (int) $post_id,
    193                         'url'        => get_permalink( (int) $post_id ),
     187                        'id'             => "post-{$post_id}",
     188                        'title'          => 'Post Title',
     189                        'original_title' => 'Post Title',
     190                        'type'           => 'post_type',
     191                        'type_label'     => 'Post',
     192                        'object'         => 'post',
     193                        'object_id'      => (int) $post_id,
     194                        'url'            => get_permalink( (int) $post_id ),
    194195                );
    195196
    … …  
    217218                // Expected menu item array.
    218219                $expected = array(
    219                         'id'         => "post-{$page_id}",
    220                         'title'      => 'Page Title',
    221                         'type'       => 'post_type',
    222                         'type_label' => 'Page',
    223                         'object'     => 'page',
    224                         'object_id'  => (int) $page_id,
    225                         'url'        => get_permalink( (int) $page_id ),
     220                        'id'             => "post-{$page_id}",
     221                        'title'          => 'Page Title',
     222                        'original_title' => 'Page Title',
     223                        'type'           => 'post_type',
     224                        'type_label'     => 'Page',
     225                        'object'         => 'page',
     226                        'object_id'      => (int) $page_id,
     227                        'url'            => get_permalink( (int) $page_id ),
    226228                );
    227229
    … …  
    243245                // Expected menu item array.
    244246                $expected = array(
    245                         'id'         => "post-{$post_id}",
    246                         'title'      => 'Post Title',
    247                         'type'       => 'post_type',
    248                         'type_label' => 'Post',
    249                         'object'     => 'post',
    250                         'object_id'  => (int) $post_id,
    251                         'url'        => get_permalink( (int) $post_id ),
     247                        'id'             => "post-{$post_id}",
     248                        'title'          => 'Post Title',
     249                        'original_title' => 'Post Title',
     250                        'type'           => 'post_type',
     251                        'type_label'     => 'Post',
     252                        'object'         => 'post',
     253                        'object_id'      => (int) $post_id,
     254                        'url'            => get_permalink( (int) $post_id ),
    252255                );
    253256
    … …  
    269272                // Expected menu item array.
    270273                $expected = array(
    271                         'id'         => "term-{$term_id}",
    272                         'title'      => 'Term Title',
    273                         'type'       => 'taxonomy',
    274                         'type_label' => 'Category',
    275                         'object'     => 'category',
    276                         'object_id'  => (int) $term_id,
    277                         'url'        => get_term_link( (int) $term_id, 'category' ),
     274                        'id'             => "term-{$term_id}",
     275                        'title'          => 'Term Title',
     276                        'original_title' => 'Term Title',
     277                        'type'           => 'taxonomy',
     278                        'type_label'     => 'Category',
     279                        'object'         => 'category',
     280                        'object_id'      => (int) $term_id,
     281                        'url'            => get_term_link( (int) $term_id, 'category' ),
    278282                );
    279283
    … …  
    786790                $this->assertNotEmpty( $post_types );
    787791
    788                 foreach ( $post_types as $type ) {
    789                         $this->assertStringContainsString( 'available-menu-items-post_type-' . esc_attr( $type->name ), $template );
    790                         $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*<button type="button" class="accordion-trigger" aria-expanded="false" aria-controls=".*">\s*' . esc_html( $type->labels->name ) . '#', $template );
    791                         $this->assertStringContainsString( 'data-type="post_type"', $template );
    792                         $this->assertStringContainsString( 'data-object="' . esc_attr( $type->name ) . '"', $template );
    793                         $this->assertStringContainsString( 'data-type_label="' . esc_attr( $type->labels->singular_name ) . '"', $template );
     792                        foreach ( $post_types as $type ) {
     793                                $this->assertStringContainsString( 'available-menu-items-post_type-' . esc_attr( $type->name ), $template );
     794                                $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*<button type="button" class="accordion-trigger" aria-expanded="false" aria-controls=".*">\s*' . esc_html( $type->labels->name ) . '#', $template );
     795                                $this->assertStringContainsString( 'data-type="post_type"', $template );
     796                                $this->assertStringContainsString( 'data-object="' . esc_attr( $type->name ) . '"', $template );
     797                                $this->assertStringContainsString( 'data-type_label="' . esc_attr( $type->labels->singular_name ) . '"', $template );
    794798                }
    795799
    … …  
    798802                $this->assertNotEmpty( $taxonomies );
    799803
    800                 foreach ( $taxonomies as $tax ) {
    801                         $this->assertStringContainsString( 'available-menu-items-taxonomy-' . esc_attr( $tax->name ), $template );
    802                         $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*<button type="button" class="accordion-trigger" aria-expanded="false" aria-controls=".*">\s*' . esc_html( $tax->labels->name ) . '#', $template );
    803                         $this->assertStringContainsString( 'data-type="taxonomy"', $template );
    804                         $this->assertStringContainsString( 'data-object="' . esc_attr( $tax->name ) . '"', $template );
    805                         $this->assertStringContainsString( 'data-type_label="' . esc_attr( $tax->labels->singular_name ) . '"', $template );
     804                        foreach ( $taxonomies as $tax ) {
     805                                $this->assertStringContainsString( 'available-menu-items-taxonomy-' . esc_attr( $tax->name ), $template );
     806                                $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*<button type="button" class="accordion-trigger" aria-expanded="false" aria-controls=".*">\s*' . esc_html( $tax->labels->name ) . '#', $template );
     807                                $this->assertStringContainsString( 'data-type="taxonomy"', $template );
     808                                $this->assertStringContainsString( 'data-object="' . esc_attr( $tax->name ) . '"', $template );
     809                                $this->assertStringContainsString( 'data-type_label="' . esc_attr( $tax->labels->singular_name ) . '"', $template );
    806810                }
    807811
Note: See TracChangeset for help on using the changeset viewer.