Make WordPress Core

Changeset 53371


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.

Location:
trunk/tests/phpunit/tests
Files:
2 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
  • trunk/tests/phpunit/tests/taxonomy.php

    r53368 r53371  
    222222    }
    223223
    224 
    225224    /**
    226225     * @ticket 53212
     
    237236
    238237        $this->assertSame( 3, $action->get_call_count() );
    239     }
    240 
    241     /**
    242      * @ticket 49701
    243      *
    244      * @covers ::get_inline_data
    245      */
    246     public function test_get_inline_data_contains_term_if_show_ui_false_but_show_on_quick_edit_true_for_hierarchical_taxonomy() {
    247         // Create a post with a term from a hierarchical taxonomy.
    248         register_taxonomy(
    249             'wptests_tax_1',
    250             'post',
    251             array(
    252                 'show_ui'            => false,
    253                 'show_in_quick_edit' => true,
    254                 'hierarchical'       => true,
    255             )
    256         );
    257         $term = wp_insert_term( 'Test', 'wptests_tax_1' );
    258         $post = self::factory()->post->create_and_get();
    259         wp_set_object_terms( $post->ID, $term['term_id'], 'wptests_tax_1' );
    260 
    261         // Test get_inline_data() has post_category div containing assigned term.
    262         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
    263         get_inline_data( $post );
    264         $this->expectOutputRegex( '/<div class="post_category" id="wptests_tax_1_' . $post->ID . '">' . $term['term_id'] . '<\/div>/' );
    265     }
    266 
    267     /**
    268      * @ticket 49701
    269      *
    270      * @covers ::get_inline_data
    271      */
    272     public function test_get_inline_data_contains_term_if_show_ui_false_but_show_on_quick_edit_true_for_nonhierarchical_taxonomy() {
    273         // Create a post with a term from a hierarchical taxonomy.
    274         register_taxonomy(
    275             'wptests_tax_1',
    276             'post',
    277             array(
    278                 'show_ui'            => false,
    279                 'show_in_quick_edit' => true,
    280                 'hierarchical'       => false,
    281             )
    282         );
    283         $term = wp_insert_term( 'Test', 'wptests_tax_1' );
    284         $post = self::factory()->post->create_and_get();
    285         wp_set_object_terms( $post->ID, $term['term_id'], 'wptests_tax_1' );
    286 
    287         // Test get_inline_data() has tags_input div containing assigned term.
    288         wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
    289         get_inline_data( $post );
    290         $this->expectOutputRegex( '/<div class="tags_input" id="wptests_tax_1_' . $post->ID . '">Test<\/div>/' );
    291238    }
    292239
Note: See TracChangeset for help on using the changeset viewer.