Make WordPress Core


Ignore:
Timestamp:
06/15/2023 03:23:25 AM (2 years ago)
Author:
peterwilsoncc
Message:

Tests/Build tools: Various term related test improvements.

Modifies the tests for get_tag_link(), get_term() and get_term_field() to:

  • use shared fixtures as possible
  • improves variable names
  • add @covers annotation as required

Props peterwilsoncc, costdev.
See #57841.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/getTagLink.php

    r46586 r55924  
    66 */
    77class Tests_Term_GetTagLink extends WP_UnitTestCase {
    8     public function test_success() {
    9         $t = self::factory()->term->create(
     8    /**
     9     * Tag ID.
     10     *
     11     * @var int
     12     */
     13    public static $tag_id;
     14
     15    /**
     16     * Test taxonomy term ID.
     17     *
     18     * @var int
     19     */
     20    public static $term_id;
     21
     22    /**
     23     * Set up shared fixtures.
     24     *
     25     * @param WP_UnitTest_Factory $factory
     26     */
     27    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     28        self::$tag_id = $factory->term->create(
    1029            array(
    1130                'taxonomy' => 'post_tag',
    12                 'slug'     => 'term-slug',
     31                'slug'     => 'test-tag',
    1332            )
    1433        );
    1534
    16         $found    = get_tag_link( $t );
    17         $expected = home_url( '?tag=term-slug' );
     35        register_taxonomy( 'wptests_tax', 'post' );
     36        self::$term_id = self::factory()->term->create(
     37            array(
     38                'taxonomy' => 'wptests_tax',
     39                'slug'     => 'test-term',
     40            )
     41        );
     42    }
     43
     44    /**
     45     * Set up the test fixture.
     46     */
     47    public function set_up() {
     48        parent::set_up();
     49        // Required as taxonomies are reset between tests.
     50        register_taxonomy( 'wptests_tax', 'post' );
     51    }
     52
     53    public function test_success() {
     54        $tag_id = self::$tag_id;
     55
     56        $found    = get_tag_link( $tag_id );
     57        $expected = home_url( '?tag=test-tag' );
    1858
    1959        $this->assertSame( $expected, $found );
     
    2464     */
    2565    public function test_should_return_link_for_term_from_another_taxonomy_on_primed_cache() {
    26         register_taxonomy( 'wptests_tax', 'post' );
     66        $term_id = self::$term_id;
    2767
    28         $t = self::factory()->term->create(
    29             array(
    30                 'taxonomy' => 'wptests_tax',
    31                 'slug'     => 'test-term',
    32             )
    33         );
     68        $term = get_term( $term_id );
    3469
    35         $term = get_term( $t );
    36 
    37         $found    = get_tag_link( $t );
     70        $found    = get_tag_link( $term_id );
    3871        $expected = home_url( '?wptests_tax=test-term' );
    3972
     
    4578     */
    4679    public function test_should_return_link_for_term_from_another_taxonomy_on_empty_cache() {
    47         register_taxonomy( 'wptests_tax', 'post' );
     80        $term_id = self::$term_id;
    4881
    49         $t = self::factory()->term->create(
    50             array(
    51                 'taxonomy' => 'wptests_tax',
    52                 'slug'     => 'test-term',
    53             )
    54         );
     82        clean_term_cache( $term_id );
    5583
    56         clean_term_cache( $t );
    57 
    58         $found    = get_tag_link( $t );
     84        $found    = get_tag_link( $term_id );
    5985        $expected = home_url( '?wptests_tax=test-term' );
    6086
Note: See TracChangeset for help on using the changeset viewer.