getTheCategoryById.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @group taxonomy
  4. * @covers ::get_the_category_by_ID
  5. */
  6. class Tests_Category_GetTheCategoryById extends WP_UnitTestCase {
  7. public function test_success() {
  8. $c = self::factory()->category->create(
  9. array(
  10. 'name' => 'Foo',
  11. )
  12. );
  13. $found = get_the_category_by_ID( $c );
  14. $this->assertSame( 'Foo', $found );
  15. }
  16. /**
  17. * @ticket 42771
  18. */
  19. public function test_should_return_link_for_term_from_another_taxonomy_on_primed_cache() {
  20. register_taxonomy( 'wptests_tax', 'post' );
  21. $t = self::factory()->term->create(
  22. array(
  23. 'taxonomy' => 'wptests_tax',
  24. 'name' => 'Foo',
  25. )
  26. );
  27. $term = get_term( $t );
  28. $found = get_the_category_by_ID( $t );
  29. $this->assertSame( 'Foo', $found );
  30. }
  31. /**
  32. * @ticket 42771
  33. */
  34. public function test_should_return_link_for_term_from_another_taxonomy_on_empty_cache() {
  35. register_taxonomy( 'wptests_tax', 'post' );
  36. $t = self::factory()->term->create(
  37. array(
  38. 'taxonomy' => 'wptests_tax',
  39. 'name' => 'Foo',
  40. )
  41. );
  42. clean_term_cache( $t );
  43. $found = get_the_category_by_ID( $t );
  44. $this->assertSame( 'Foo', $found );
  45. }
  46. }