Make WordPress Core


Ignore:
Timestamp:
05/09/2022 05:56:36 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Move get_inline_data() tests to a more appropriate place.

Since this is an admin template function and the tests check for specific output with certain taxonomy parameters, placing the tests along with other tests for the functions in the same file should make them easier to find and extend than when placed between general taxonomy registration tests.

Follow-up to [52841], [53368].

See #55652.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesTemplate.php

    r51858 r53371  
    4242            array( 1 ),
    4343        );
     44    }
     45
     46    /**
     47     * @ticket 49701
     48     *
     49     * @covers ::get_inline_data
     50     */
     51    public function test_get_inline_data_contains_term_if_show_ui_is_false_but_show_on_quick_edit_is_true_for_hierarchical_taxonomy() {
     52        // Create a post with a term from a hierarchical taxonomy.
     53        register_taxonomy(
     54            'wptests_tax_1',
     55            'post',
     56            array(
     57                'show_ui'            => false,
     58                'show_in_quick_edit' => true,
     59                'hierarchical'       => true,
     60            )
     61        );
     62        $term = wp_insert_term( 'Test', 'wptests_tax_1' );
     63        $post = self::factory()->post->create_and_get();
     64        wp_set_object_terms( $post->ID, $term['term_id'], 'wptests_tax_1' );
     65
     66        // Test that get_inline_data() has `post_category` div containing the assigned term.
     67        wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     68        get_inline_data( $post );
     69        $this->expectOutputRegex( '/<div class="post_category" id="wptests_tax_1_' . $post->ID . '">' . $term['term_id'] . '<\/div>/' );
     70    }
     71
     72    /**
     73     * @ticket 49701
     74     *
     75     * @covers ::get_inline_data
     76     */
     77    public function test_get_inline_data_contains_term_if_show_ui_is_false_but_show_on_quick_edit_is_true_for_nonhierarchical_taxonomy() {
     78        // Create a post with a term from a non-hierarchical taxonomy.
     79        register_taxonomy(
     80            'wptests_tax_1',
     81            'post',
     82            array(
     83                'show_ui'            => false,
     84                'show_in_quick_edit' => true,
     85                'hierarchical'       => false,
     86            )
     87        );
     88        $term = wp_insert_term( 'Test', 'wptests_tax_1' );
     89        $post = self::factory()->post->create_and_get();
     90        wp_set_object_terms( $post->ID, $term['term_id'], 'wptests_tax_1' );
     91
     92        // Test that get_inline_data() has `tags_input` div containing the assigned term.
     93        wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
     94        get_inline_data( $post );
     95        $this->expectOutputRegex( '/<div class="tags_input" id="wptests_tax_1_' . $post->ID . '">Test<\/div>/' );
    4496    }
    4597
Note: See TracChangeset for help on using the changeset viewer.