mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
[29863] made the corresponding change in `term_exists()`. Failure to change the default value in `category_exists()` meant that an unspecified value for `$parent` would limit results to top-level categories. Includes unit tests and corrected function documentation. Props hissy. Fixes #30975 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@31140 602fd350-edb4-49c9-b593-d223f7449a82
78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
class Tests_Term_CategoryExists extends WP_UnitTestCase {
|
|
/**
|
|
* @ticket 30975
|
|
*/
|
|
public function test_category_exists_should_return_only_top_level_categories_when_parent_is_0() {
|
|
$c1 = $this->factory->category->create();
|
|
$c2 = $this->factory->category->create( array(
|
|
'name' => 'Foo',
|
|
'parent' => $c1,
|
|
) );
|
|
$c3 = $this->factory->category->create( array(
|
|
'name' => 'Foo',
|
|
) );
|
|
|
|
$found = category_exists( 'Foo', 0 );
|
|
|
|
$this->assertEquals( $found, $c3 );
|
|
}
|
|
|
|
/**
|
|
* @ticket 30975
|
|
*/
|
|
public function test_category_exists_should_select_oldest_matching_category_when_no_parent_is_specified_1() {
|
|
// Foo child of c1 is created first.
|
|
$c1 = $this->factory->category->create();
|
|
$c2 = $this->factory->category->create( array(
|
|
'name' => 'Foo',
|
|
'parent' => $c1,
|
|
) );
|
|
$c3 = $this->factory->category->create( array(
|
|
'name' => 'Foo',
|
|
) );
|
|
|
|
$found = category_exists( 'Foo' );
|
|
|
|
$this->assertEquals( $found, $c2 );
|
|
}
|
|
|
|
/**
|
|
* @ticket 30975
|
|
*/
|
|
public function test_category_exists_should_select_oldest_matching_category_when_no_parent_is_specified_2() {
|
|
// Top-level Foo is created first.
|
|
$c1 = $this->factory->category->create();
|
|
$c2 = $this->factory->category->create( array(
|
|
'name' => 'Foo',
|
|
) );
|
|
$c3 = $this->factory->category->create( array(
|
|
'name' => 'Foo',
|
|
'parent' => $c1,
|
|
) );
|
|
|
|
$found = category_exists( 'Foo' );
|
|
|
|
$this->assertEquals( $found, $c2 );
|
|
}
|
|
|
|
/**
|
|
* @ticket 30975
|
|
*/
|
|
public function test_category_exists_should_respect_nonempty_parent() {
|
|
$c1 = $this->factory->category->create();
|
|
$c2 = $this->factory->category->create( array(
|
|
'name' => 'Foo',
|
|
'parent' => $c1,
|
|
) );
|
|
$c3 = $this->factory->category->create( array(
|
|
'name' => 'Foo',
|
|
) );
|
|
|
|
$found = category_exists( 'Foo', $c1 );
|
|
|
|
$this->assertEquals( $found, $c2 );
|
|
}
|
|
}
|