walkerCategory.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @group taxonomy
  4. * @group walker
  5. */
  6. class Tests_Category_Walker_Category extends WP_UnitTestCase {
  7. /**
  8. * @var \Walker_Category The instance of the walker.
  9. */
  10. public $walker;
  11. /**
  12. * Setup.
  13. */
  14. public function setUp() {
  15. parent::setUp();
  16. /** Walker_Category class */
  17. require_once ABSPATH . 'wp-includes/class-walker-category.php';
  18. $this->walker = new Walker_Category();
  19. }
  20. /**
  21. * @ticket 47720
  22. *
  23. * @dataProvider data_start_el_with_empty_attributes
  24. */
  25. public function test_start_el_with_empty_attributes( $value, $expected ) {
  26. $output = '';
  27. $category = $this->factory->category->create_and_get();
  28. $link = get_term_link( $category );
  29. $args = array(
  30. 'use_desc_for_title' => 0,
  31. 'style' => 'list',
  32. );
  33. add_filter(
  34. 'category_list_link_attributes',
  35. function( $atts ) use ( $value ) {
  36. $atts['data-test'] = $value;
  37. return $atts;
  38. }
  39. );
  40. $this->walker->start_el( $output, $category, 0, $args );
  41. if ( '' !== $expected ) {
  42. $expected = sprintf( ' data-test="%s"', $expected );
  43. }
  44. $this->assertSame( "<li class=\"cat-item cat-item-{$category->term_id}\"><a href=\"{$link}\"{$expected}>{$category->name}</a>", trim( $output ) );
  45. }
  46. public function data_start_el_with_empty_attributes() {
  47. return array(
  48. array(
  49. '',
  50. '',
  51. ),
  52. array(
  53. 0,
  54. '0',
  55. ),
  56. array(
  57. 0.0,
  58. '0',
  59. ),
  60. array(
  61. '0',
  62. '0',
  63. ),
  64. array(
  65. null,
  66. '',
  67. ),
  68. array(
  69. false,
  70. '',
  71. ),
  72. array(
  73. true,
  74. '1',
  75. ),
  76. array(
  77. array(),
  78. '',
  79. ),
  80. );
  81. }
  82. }