mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Taxonomy: Allow for wp_count_terms( $args ) signature, making passing a taxonomy optional.
This brings `wp_count_terms()` in line with other taxonomy functions such as `get_terms()` which technically no longer require a taxonomy. Similar to the previously modified functions, no deprecation warning is triggered when using the legacy signature. Fixes #36399. git-svn-id: https://develop.svn.wordpress.org/trunk@48840 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -65,8 +65,8 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
|
||||
$this->assertEquals( 'author@example.org', $author->user_email );
|
||||
|
||||
// Check that terms were imported correctly.
|
||||
$this->assertEquals( 30, wp_count_terms( 'category' ) );
|
||||
$this->assertEquals( 3, wp_count_terms( 'post_tag' ) );
|
||||
$this->assertEquals( 30, wp_count_terms( array( 'taxonomy' => 'category' ) ) );
|
||||
$this->assertEquals( 3, wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) );
|
||||
$foo = get_term_by( 'slug', 'foo', 'category' );
|
||||
$this->assertEquals( 0, $foo->parent );
|
||||
$bar = get_term_by( 'slug', 'bar', 'category' );
|
||||
@@ -230,8 +230,8 @@ class Tests_Import_Import extends WP_Import_UnitTestCase {
|
||||
$this->assertEquals( 'author', $author->user_login );
|
||||
$this->assertEquals( 'author@example.org', $author->user_email );
|
||||
|
||||
$this->assertEquals( 30, wp_count_terms( 'category' ) );
|
||||
$this->assertEquals( 3, wp_count_terms( 'post_tag' ) );
|
||||
$this->assertEquals( 30, wp_count_terms( array( 'taxonomy' => 'category' ) ) );
|
||||
$this->assertEquals( 3, wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) );
|
||||
$foo = get_term_by( 'slug', 'foo', 'category' );
|
||||
$this->assertEquals( 0, $foo->parent );
|
||||
$bar = get_term_by( 'slug', 'bar', 'category' );
|
||||
|
||||
@@ -65,11 +65,34 @@ class Tests_Term extends WP_UnitTestCase {
|
||||
* @ticket 15919
|
||||
*/
|
||||
function test_wp_count_terms() {
|
||||
$count = wp_count_terms( 'category', array( 'hide_empty' => true ) );
|
||||
$count = wp_count_terms(
|
||||
array(
|
||||
'hide_empty' => true,
|
||||
'taxonomy' => 'category',
|
||||
)
|
||||
);
|
||||
// There are 5 posts, all Uncategorized.
|
||||
$this->assertEquals( 1, $count );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36399
|
||||
*/
|
||||
function test_wp_count_terms_legacy_interoperability() {
|
||||
self::factory()->tag->create_many( 5 );
|
||||
|
||||
// Counts all terms (1 default category, 5 tags).
|
||||
$count = wp_count_terms();
|
||||
$this->assertEquals( 6, $count );
|
||||
|
||||
// Counts only tags (5), with both current and legacy signature.
|
||||
// Legacy usage should not trigger deprecated notice.
|
||||
$count = wp_count_terms( array( 'taxonomy' => 'post_tag' ) );
|
||||
$legacy_count = wp_count_terms( 'post_tag' );
|
||||
$this->assertEquals( 5, $count );
|
||||
$this->assertEquals( $count, $legacy_count );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 15475
|
||||
*/
|
||||
@@ -127,13 +150,13 @@ class Tests_Term extends WP_UnitTestCase {
|
||||
$term = rand_str();
|
||||
$this->assertNull( category_exists( $term ) );
|
||||
|
||||
$initial_count = wp_count_terms( 'category' );
|
||||
$initial_count = wp_count_terms( array( 'taxonomy' => 'category' ) );
|
||||
|
||||
$t = wp_insert_category( array( 'cat_name' => $term ) );
|
||||
$this->assertTrue( is_numeric( $t ) );
|
||||
$this->assertNotWPError( $t );
|
||||
$this->assertTrue( $t > 0 );
|
||||
$this->assertEquals( $initial_count + 1, wp_count_terms( 'category' ) );
|
||||
$this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => 'category' ) ) );
|
||||
|
||||
// Make sure the term exists.
|
||||
$this->assertTrue( term_exists( $term ) > 0 );
|
||||
@@ -143,7 +166,7 @@ class Tests_Term extends WP_UnitTestCase {
|
||||
$this->assertTrue( wp_delete_category( $t ) );
|
||||
$this->assertNull( term_exists( $term ) );
|
||||
$this->assertNull( term_exists( $t ) );
|
||||
$this->assertEquals( $initial_count, wp_count_terms( 'category' ) );
|
||||
$this->assertEquals( $initial_count, wp_count_terms( array( 'taxonomy' => 'category' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,14 +24,14 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
|
||||
$term = 'term';
|
||||
$this->assertNull( term_exists( $term ) );
|
||||
|
||||
$initial_count = wp_count_terms( $taxonomy );
|
||||
$initial_count = wp_count_terms( array( 'taxonomy' => $taxonomy ) );
|
||||
|
||||
$t = wp_insert_term( $term, $taxonomy );
|
||||
$this->assertInternalType( 'array', $t );
|
||||
$this->assertNotWPError( $t );
|
||||
$this->assertTrue( $t['term_id'] > 0 );
|
||||
$this->assertTrue( $t['term_taxonomy_id'] > 0 );
|
||||
$this->assertEquals( $initial_count + 1, wp_count_terms( $taxonomy ) );
|
||||
$this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => $taxonomy ) ) );
|
||||
|
||||
// Make sure the term exists.
|
||||
$this->assertTrue( term_exists( $term ) > 0 );
|
||||
@@ -43,7 +43,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase {
|
||||
remove_filter( 'delete_term', array( $this, 'deleted_term_cb' ), 10, 5 );
|
||||
$this->assertNull( term_exists( $term ) );
|
||||
$this->assertNull( term_exists( $t['term_id'] ) );
|
||||
$this->assertEquals( $initial_count, wp_count_terms( $taxonomy ) );
|
||||
$this->assertEquals( $initial_count, wp_count_terms( array( 'taxonomy' => $taxonomy ) ) );
|
||||
}
|
||||
|
||||
public function test_wp_insert_term_taxonomy_does_not_exist() {
|
||||
|
||||
Reference in New Issue
Block a user