Make WordPress Core


Ignore:
Timestamp:
03/24/2023 05:10:44 PM (21 months ago)
Author:
SergeyBiryukov
Message:

Tests: Split the tests from post/template.php into individual test classes.

This aims to bring some consistency to the location of post template function tests, as well as to make the tests more discoverable and easier to expand.

Includes:

  • Adding @covers tags.
  • Renaming get_post_parent() and has_post_parent() tests to match the names of the functions.

Follow-up to [28398], [31522], [34654], [34950], [50127], [50396], [54717], [54726], [55590].

See #57841.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r55562 r55591  
    1414
    1515        $this->menu_id = wp_create_nav_menu( 'foo' );
     16    }
     17
     18    /**
     19     * @ticket 11095
     20     * @ticket 33974
     21     */
     22    public function test_wp_page_menu_wp_nav_menu_fallback() {
     23        $pages = self::factory()->post->create_many( 3, array( 'post_type' => 'page' ) );
     24
     25        // No menus + wp_nav_menu() falls back to wp_page_menu().
     26        $menu = wp_nav_menu( array( 'echo' => false ) );
     27
     28        // After falling back, the 'before' argument should be set and output as '<ul>'.
     29        $this->assertMatchesRegularExpression( '/<div class="menu"><ul>/', $menu );
     30
     31        // After falling back, the 'after' argument should be set and output as '</ul>'.
     32        $this->assertMatchesRegularExpression( '/<\/ul><\/div>/', $menu );
     33
     34        // After falling back, the markup should include whitespace around <li>'s.
     35        $this->assertMatchesRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
     36        $this->assertDoesNotMatchRegularExpression( '/><li.*>|<\/li></U', $menu );
     37
     38        // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without a container.
     39        $menu = wp_nav_menu(
     40            array(
     41                'echo'      => false,
     42                'container' => false,
     43            )
     44        );
     45
     46        // After falling back, the empty 'container' argument should still return a container element.
     47        $this->assertMatchesRegularExpression( '/<div class="menu">/', $menu );
     48
     49        // No menus + wp_nav_menu() falls back to wp_page_menu(), this time without white-space.
     50        $menu = wp_nav_menu(
     51            array(
     52                'echo'         => false,
     53                'item_spacing' => 'discard',
     54            )
     55        );
     56
     57        // After falling back, the markup should not include whitespace around <li>'s.
     58        $this->assertDoesNotMatchRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
     59        $this->assertMatchesRegularExpression( '/><li.*>|<\/li></U', $menu );
     60
    1661    }
    1762
     
    718763    }
    719764
    720 
    721765    /**
    722766     * @ticket 35272
Note: See TracChangeset for help on using the changeset viewer.