From bb0ca6f111baad3f00c1546b83b3d9245d50abf6 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 29 Jan 2015 20:48:03 +0000 Subject: [PATCH] Add tests for `get_category_parents()`. See #30415. git-svn-id: https://develop.svn.wordpress.org/trunk@31299 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/category/getCategoryParents.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/phpunit/tests/category/getCategoryParents.php diff --git a/tests/phpunit/tests/category/getCategoryParents.php b/tests/phpunit/tests/category/getCategoryParents.php new file mode 100644 index 0000000000..c8cc1b9159 --- /dev/null +++ b/tests/phpunit/tests/category/getCategoryParents.php @@ -0,0 +1,64 @@ +c1 = $this->factory->category->create_and_get(); + $this->c2 = $this->factory->category->create_and_get( array( + 'parent' => $this->c1->term_id, + ) ); + } + + public function test_should_return_wp_error_for_invalid_category() { + $this->assertWPError( get_category_parents( '' ) ); + } + + public function test_with_default_parameters() { + $expected = $this->c1->name . '/'. $this->c2->name . '/'; + $found = get_category_parents( $this->c2->term_id ); + $this->assertSame( $expected, $found ); + } + + public function test_link_true() { + $expected = '' . $this->c1->name . '/'. $this->c2->name . '/'; + $found = get_category_parents( $this->c2->term_id, true ); + $this->assertSame( $expected, $found ); + } + + public function test_separator() { + $expected = $this->c1->name . ' --- ' . $this->c2->name . ' --- '; + $found = get_category_parents( $this->c2->term_id, false, ' --- ', false ); + $this->assertSame( $expected, $found ); + } + + public function test_nicename_false() { + $expected = $this->c1->name . '/'. $this->c2->name . '/'; + $found = get_category_parents( $this->c2->term_id, false, '/', false ); + $this->assertSame( $expected, $found ); + } + + public function test_nicename_true() { + $expected = $this->c1->slug . '/'. $this->c2->slug . '/'; + $found = get_category_parents( $this->c2->term_id, false, '/', true ); + $this->assertSame( $expected, $found ); + } + + public function test_visited() { + $c3 = $this->factory->category->create_and_get( array( + 'parent' => $this->c2->term_id, + ) ); + $c4 = $this->factory->category->create_and_get( array( + 'parent' => $c3->term_id, + ) ); + + $expected = $this->c1->name . '/'. $this->c2->name . '/' . $c4->name . '/'; + $found = get_category_parents( $this->c2->term_id, false, '/', false, array( $c3->term_id ) ); + } +}