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.

git-svn-id: https://develop.svn.wordpress.org/trunk@53371 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-05-09 17:56:36 +00:00
parent 90f953603b
commit fc4ac1f123
2 changed files with 52 additions and 53 deletions

View File

@ -43,6 +43,58 @@ class Tests_Admin_IncludesTemplate extends WP_UnitTestCase {
);
}
/**
* @ticket 49701
*
* @covers ::get_inline_data
*/
public function test_get_inline_data_contains_term_if_show_ui_is_false_but_show_on_quick_edit_is_true_for_hierarchical_taxonomy() {
// Create a post with a term from a hierarchical taxonomy.
register_taxonomy(
'wptests_tax_1',
'post',
array(
'show_ui' => false,
'show_in_quick_edit' => true,
'hierarchical' => true,
)
);
$term = wp_insert_term( 'Test', 'wptests_tax_1' );
$post = self::factory()->post->create_and_get();
wp_set_object_terms( $post->ID, $term['term_id'], 'wptests_tax_1' );
// Test that get_inline_data() has `post_category` div containing the assigned term.
wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
get_inline_data( $post );
$this->expectOutputRegex( '/<div class="post_category" id="wptests_tax_1_' . $post->ID . '">' . $term['term_id'] . '<\/div>/' );
}
/**
* @ticket 49701
*
* @covers ::get_inline_data
*/
public function test_get_inline_data_contains_term_if_show_ui_is_false_but_show_on_quick_edit_is_true_for_nonhierarchical_taxonomy() {
// Create a post with a term from a non-hierarchical taxonomy.
register_taxonomy(
'wptests_tax_1',
'post',
array(
'show_ui' => false,
'show_in_quick_edit' => true,
'hierarchical' => false,
)
);
$term = wp_insert_term( 'Test', 'wptests_tax_1' );
$post = self::factory()->post->create_and_get();
wp_set_object_terms( $post->ID, $term['term_id'], 'wptests_tax_1' );
// Test that get_inline_data() has `tags_input` div containing the assigned term.
wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
get_inline_data( $post );
$this->expectOutputRegex( '/<div class="tags_input" id="wptests_tax_1_' . $post->ID . '">Test<\/div>/' );
}
public function test_add_meta_box() {
global $wp_meta_boxes;

View File

@ -221,7 +221,6 @@ class Tests_Taxonomy extends WP_UnitTestCase {
$this->assertFalse( $tax_2->show_in_quick_edit );
}
/**
* @ticket 53212
*/
@ -238,58 +237,6 @@ class Tests_Taxonomy extends WP_UnitTestCase {
$this->assertSame( 3, $action->get_call_count() );
}
/**
* @ticket 49701
*
* @covers ::get_inline_data
*/
public function test_get_inline_data_contains_term_if_show_ui_false_but_show_on_quick_edit_true_for_hierarchical_taxonomy() {
// Create a post with a term from a hierarchical taxonomy.
register_taxonomy(
'wptests_tax_1',
'post',
array(
'show_ui' => false,
'show_in_quick_edit' => true,
'hierarchical' => true,
)
);
$term = wp_insert_term( 'Test', 'wptests_tax_1' );
$post = self::factory()->post->create_and_get();
wp_set_object_terms( $post->ID, $term['term_id'], 'wptests_tax_1' );
// Test get_inline_data() has post_category div containing assigned term.
wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
get_inline_data( $post );
$this->expectOutputRegex( '/<div class="post_category" id="wptests_tax_1_' . $post->ID . '">' . $term['term_id'] . '<\/div>/' );
}
/**
* @ticket 49701
*
* @covers ::get_inline_data
*/
public function test_get_inline_data_contains_term_if_show_ui_false_but_show_on_quick_edit_true_for_nonhierarchical_taxonomy() {
// Create a post with a term from a hierarchical taxonomy.
register_taxonomy(
'wptests_tax_1',
'post',
array(
'show_ui' => false,
'show_in_quick_edit' => true,
'hierarchical' => false,
)
);
$term = wp_insert_term( 'Test', 'wptests_tax_1' );
$post = self::factory()->post->create_and_get();
wp_set_object_terms( $post->ID, $term['term_id'], 'wptests_tax_1' );
// Test get_inline_data() has tags_input div containing assigned term.
wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
get_inline_data( $post );
$this->expectOutputRegex( '/<div class="tags_input" id="wptests_tax_1_' . $post->ID . '">Test<\/div>/' );
}
/**
* @ticket 11058
*/