categoryDescription.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @group taxonomy
  4. * @covers ::category_description
  5. */
  6. class Tests_Category_CategoryDescription extends WP_UnitTestCase {
  7. public function test_success_query_by_id() {
  8. $description = 'Foo';
  9. $c = self::factory()->category->create(
  10. array(
  11. 'description' => $description,
  12. )
  13. );
  14. $found = category_description( $c );
  15. $expected = apply_filters( 'term_description', $description );
  16. $this->assertSame( $expected, $found );
  17. }
  18. public function test_success_query_by_object() {
  19. $description = 'Foo';
  20. $c = self::factory()->category->create(
  21. array(
  22. 'description' => $description,
  23. 'slug' => 'bar',
  24. )
  25. );
  26. $category = get_term( $c );
  27. $found = category_description( $c );
  28. $expected = apply_filters( 'term_description', $description );
  29. $this->assertSame( $expected, $found );
  30. }
  31. /**
  32. * @ticket 42605
  33. * @ticket 42771
  34. */
  35. public function test_should_return_description_for_term_from_another_taxonomy_on_primed_cache() {
  36. register_taxonomy( 'wptests_tax', 'post' );
  37. $description = 'Foo';
  38. $t = self::factory()->term->create(
  39. array(
  40. 'taxonomy' => 'wptests_tax',
  41. 'description' => $description,
  42. )
  43. );
  44. $term = get_term( $t );
  45. $found = category_description( $t );
  46. $expected = apply_filters( 'term_description', $description );
  47. $this->assertSame( $expected, $found );
  48. }
  49. /**
  50. * @ticket 42605
  51. * @ticket 42771
  52. */
  53. public function test_should_return_description_for_term_from_another_taxonomy_on_empty_cache() {
  54. register_taxonomy( 'wptests_tax', 'post' );
  55. $description = 'Foo';
  56. $t = self::factory()->term->create(
  57. array(
  58. 'taxonomy' => 'wptests_tax',
  59. 'description' => $description,
  60. )
  61. );
  62. clean_term_cache( $t );
  63. $found = category_description( $t );
  64. $expected = apply_filters( 'term_description', $description );
  65. $this->assertSame( $expected, $found );
  66. }
  67. }