support.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * @group themes
  4. */
  5. class Tests_Theme_Support extends WP_UnitTestCase {
  6. function test_the_basics() {
  7. add_theme_support( 'automatic-feed-links' );
  8. $this->assertTrue( current_theme_supports( 'automatic-feed-links' ) );
  9. remove_theme_support( 'automatic-feed-links' );
  10. $this->assertFalse( current_theme_supports( 'automatic-feed-links' ) );
  11. add_theme_support( 'automatic-feed-links' );
  12. $this->assertTrue( current_theme_supports( 'automatic-feed-links' ) );
  13. }
  14. function test_admin_bar() {
  15. add_theme_support( 'admin-bar' );
  16. $this->assertTrue( current_theme_supports( 'admin-bar' ) );
  17. remove_theme_support( 'admin-bar' );
  18. $this->assertFalse( current_theme_supports( 'admin-bar' ) );
  19. add_theme_support( 'admin-bar' );
  20. $this->assertTrue( current_theme_supports( 'admin-bar' ) );
  21. add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
  22. $this->assertTrue( current_theme_supports( 'admin-bar' ) );
  23. $this->assertEquals(
  24. array( 0 => array( 'callback' => '__return_false' ) ),
  25. get_theme_support( 'admin-bar' )
  26. );
  27. remove_theme_support( 'admin-bar' );
  28. $this->assertFalse( current_theme_supports( 'admin-bar' ) );
  29. $this->assertFalse( get_theme_support( 'admin-bar' ) );
  30. }
  31. function test_post_thumbnails() {
  32. add_theme_support( 'post-thumbnails' );
  33. $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
  34. remove_theme_support( 'post-thumbnails' );
  35. $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
  36. add_theme_support( 'post-thumbnails' );
  37. $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
  38. // simple array of post types.
  39. add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
  40. $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
  41. $this->assertTrue( current_theme_supports( 'post-thumbnails', 'post' ) );
  42. $this->assertFalse( current_theme_supports( 'post-thumbnails', 'book' ) );
  43. remove_theme_support( 'post-thumbnails' );
  44. $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
  45. #WP18548
  46. if ( ! function_exists( '_wp_render_title_tag' ) )
  47. return;
  48. // array of arguments, with the key of 'types' holding the post types.
  49. add_theme_support( 'post-thumbnails', array( 'types' => array( 'post', 'page' ) ) );
  50. $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
  51. $this->assertTrue( current_theme_supports( 'post-thumbnails', 'post' ) );
  52. $this->assertFalse( current_theme_supports( 'post-thumbnails', 'book' ) );
  53. remove_theme_support( 'post-thumbnails' );
  54. $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
  55. // array of arguments, with the key of 'types' holding the post types.
  56. add_theme_support( 'post-thumbnails', array( 'types' => true ) );
  57. $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
  58. $this->assertTrue( current_theme_supports( 'post-thumbnails', rand_str() ) ); // any type
  59. remove_theme_support( 'post-thumbnails' );
  60. $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
  61. // array of arguments, with some other argument, and no 'types' argument.
  62. add_theme_support( 'post-thumbnails', array( rand_str() => rand_str() ) );
  63. $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
  64. $this->assertTrue( current_theme_supports( 'post-thumbnails', rand_str() ) ); // any type
  65. remove_theme_support( 'post-thumbnails' );
  66. $this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
  67. }
  68. /**
  69. * @ticket 24932
  70. */
  71. function test_supports_html5() {
  72. remove_theme_support( 'html5' );
  73. $this->assertFalse( current_theme_supports( 'html5' ) );
  74. $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
  75. $this->assertNotSame( false, add_theme_support( 'html5' ) );
  76. $this->assertTrue( current_theme_supports( 'html5' ) );
  77. $this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
  78. $this->assertTrue( current_theme_supports( 'html5', 'comment-list' ) );
  79. $this->assertTrue( current_theme_supports( 'html5', 'search-form' ) );
  80. $this->assertFalse( current_theme_supports( 'html5', 'something-else' ) );
  81. }
  82. /**
  83. * @ticket 24932
  84. *
  85. * @expectedIncorrectUsage add_theme_support( 'html5' )
  86. */
  87. function test_supports_html5_subset() {
  88. remove_theme_support( 'html5' );
  89. $this->assertFalse( current_theme_supports( 'html5' ) );
  90. $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
  91. $this->assertFalse( add_theme_support( 'html5', 'comment-form' ) );
  92. $this->assertNotSame( false, add_theme_support( 'html5', array( 'comment-form' ) ) );
  93. $this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
  94. // This will return true, which might help a plugin author decide what markup to serve,
  95. // but core should never check for it.
  96. $this->assertTrue( current_theme_supports( 'html5' ) );
  97. // It appends, rather than replaces.
  98. $this->assertFalse( current_theme_supports( 'html5', 'comment-list' ) );
  99. $this->assertNotSame( false, add_theme_support( 'html5', array( 'comment-list' ) ) );
  100. $this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
  101. $this->assertTrue( current_theme_supports( 'html5', 'comment-list' ) );
  102. $this->assertFalse( current_theme_supports( 'html5', 'search-form' ) );
  103. // Removal is all or nothing.
  104. $this->assertTrue( remove_theme_support( 'html5' ) );
  105. $this->assertFalse( current_theme_supports( 'html5', 'comment-list' ) );
  106. $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
  107. $this->assertFalse( current_theme_supports( 'html5', 'search-form' ) );
  108. }
  109. /**
  110. * @ticket 24932
  111. *
  112. * @expectedIncorrectUsage add_theme_support( 'html5' )
  113. */
  114. function test_supports_html5_invalid() {
  115. remove_theme_support( 'html5' );
  116. $this->assertFalse( add_theme_support( 'html5', 'comment-form' ) );
  117. $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
  118. $this->assertFalse( current_theme_supports( 'html5' ) );
  119. }
  120. function supports_foobar( $yesno, $args, $feature ) {
  121. if ( $args[0] == $feature[0] )
  122. return true;
  123. return false;
  124. }
  125. function test_plugin_hook() {
  126. $this->assertFalse( current_theme_supports( 'foobar' ) );
  127. add_theme_support( 'foobar' );
  128. $this->assertTrue( current_theme_supports( 'foobar' ) );
  129. add_filter( 'current_theme_supports-foobar', array( $this, 'supports_foobar'), 10, 3 );
  130. add_theme_support( 'foobar', 'bar' );
  131. $this->assertFalse( current_theme_supports( 'foobar', 'foo' ) );
  132. $this->assertTrue( current_theme_supports( 'foobar', 'bar' ) );
  133. remove_theme_support( 'foobar' );
  134. $this->assertFalse( current_theme_supports( 'foobar', 'bar' ) );
  135. }
  136. }