getCategoryParents.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @group taxonomy
  4. */
  5. class Tests_Category_GetCategoryParents extends WP_UnitTestCase {
  6. protected $c1;
  7. protected $c2;
  8. public function setUp() {
  9. parent::setUp();
  10. $this->c1 = self::factory()->category->create_and_get();
  11. $this->c2 = self::factory()->category->create_and_get(
  12. array(
  13. 'parent' => $this->c1->term_id,
  14. )
  15. );
  16. }
  17. public function test_should_return_wp_error_for_invalid_category() {
  18. $this->assertWPError( get_category_parents( '' ) );
  19. }
  20. public function test_with_default_parameters() {
  21. $expected = $this->c1->name . '/' . $this->c2->name . '/';
  22. $found = get_category_parents( $this->c2->term_id );
  23. $this->assertSame( $expected, $found );
  24. }
  25. public function test_link_true() {
  26. $expected = '<a href="' . get_category_link( $this->c1->term_id ) . '">' . $this->c1->name . '</a>/<a href="' . get_category_link( $this->c2->term_id ) . '">' . $this->c2->name . '</a>/';
  27. $found = get_category_parents( $this->c2->term_id, true );
  28. $this->assertSame( $expected, $found );
  29. }
  30. public function test_separator() {
  31. $expected = $this->c1->name . ' --- ' . $this->c2->name . ' --- ';
  32. $found = get_category_parents( $this->c2->term_id, false, ' --- ', false );
  33. $this->assertSame( $expected, $found );
  34. }
  35. public function test_nicename_false() {
  36. $expected = $this->c1->name . '/' . $this->c2->name . '/';
  37. $found = get_category_parents( $this->c2->term_id, false, '/', false );
  38. $this->assertSame( $expected, $found );
  39. }
  40. public function test_nicename_true() {
  41. $expected = $this->c1->slug . '/' . $this->c2->slug . '/';
  42. $found = get_category_parents( $this->c2->term_id, false, '/', true );
  43. $this->assertSame( $expected, $found );
  44. }
  45. public function test_deprecated_argument_visited() {
  46. $this->setExpectedDeprecated( 'get_category_parents' );
  47. $found = get_category_parents( $this->c2->term_id, false, '/', false, array( $this->c1->term_id ) );
  48. }
  49. public function test_category_without_parents() {
  50. $expected = $this->c1->name . '/';
  51. $found = get_category_parents( $this->c1->term_id );
  52. $this->assertSame( $expected, $found );
  53. }
  54. }