output.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. // test the output of post template tags etc
  3. /**
  4. * @group post
  5. * @group formatting
  6. */
  7. class Tests_Post_Output extends WP_UnitTestCase {
  8. function setUp() {
  9. parent::setUp();
  10. add_shortcode( 'dumptag', array( $this, '_shortcode_dumptag' ) );
  11. add_shortcode( 'paragraph', array( $this, '_shortcode_paragraph' ) );
  12. }
  13. function tearDown() {
  14. global $shortcode_tags;
  15. unset( $shortcode_tags['dumptag'], $shortcode_tags['paragraph'] );
  16. parent::tearDown();
  17. }
  18. function _shortcode_dumptag( $atts ) {
  19. $out = '';
  20. foreach ($atts as $k=>$v)
  21. $out .= "$k = $v\n";
  22. return $out;
  23. }
  24. function _shortcode_paragraph( $atts, $content ) {
  25. extract(shortcode_atts(array(
  26. 'class' => 'graf',
  27. ), $atts));
  28. return "<p class='$class'>$content</p>\n";
  29. }
  30. function test_the_content() {
  31. $post_content = <<<EOF
  32. <i>This is the excerpt.</i>
  33. <!--more-->
  34. This is the <b>body</b>.
  35. EOF;
  36. $post_id = $this->factory->post->create( compact( 'post_content' ) );
  37. $expected = <<<EOF
  38. <p><i>This is the excerpt.</i><br />
  39. <span id="more-{$post_id}"></span><br />
  40. This is the <b>body</b>.</p>
  41. EOF;
  42. $this->go_to( get_permalink( $post_id ) );
  43. $this->assertTrue( is_single() );
  44. $this->assertTrue( have_posts() );
  45. $this->assertNull( the_post() );
  46. $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
  47. }
  48. function test_the_content_shortcode() {
  49. $post_content = <<<EOF
  50. [dumptag foo="bar" baz="123"]
  51. [dumptag foo=123 baz=bar]
  52. [dumptag http://example.com]
  53. EOF;
  54. $expected =<<<EOF
  55. foo = bar
  56. baz = 123
  57. foo = 123
  58. baz = bar
  59. 0 = http://example.com
  60. EOF;
  61. $post_id = $this->factory->post->create( compact( 'post_content' ) );
  62. $this->go_to( get_permalink( $post_id ) );
  63. $this->assertTrue( is_single() );
  64. $this->assertTrue( have_posts() );
  65. $this->assertNull( the_post() );
  66. $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
  67. }
  68. function test_the_content_shortcode_paragraph() {
  69. $post_content = <<<EOF
  70. Graf by itself:
  71. [paragraph]my graf[/paragraph]
  72. [paragraph foo="bar"]another graf with whitespace[/paragraph]
  73. An [paragraph]inline graf[/paragraph], this doesn't make much sense.
  74. A graf with a single EOL first:
  75. [paragraph]blah[/paragraph]
  76. EOF;
  77. $expected = <<<EOF
  78. <p>Graf by itself:</p>
  79. <p class='graf'>my graf</p>
  80. <p class='graf'>another graf with whitespace</p>
  81. <p>An <p class='graf'>inline graf</p>
  82. , this doesn&#8217;t make much sense.</p>
  83. <p>A graf with a single EOL first:<br />
  84. <p class='graf'>blah</p>
  85. </p>
  86. EOF;
  87. $post_id = $this->factory->post->create( compact( 'post_content' ) );
  88. $this->go_to( get_permalink( $post_id ) );
  89. $this->assertTrue( is_single() );
  90. $this->assertTrue( have_posts() );
  91. $this->assertNull( the_post() );
  92. $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
  93. }
  94. function test_the_content_attribute_filtering() {
  95. kses_init_filters();
  96. // http://bpr3.org/?p=87
  97. // the title attribute should make it through unfiltered
  98. $post_content = <<<EOF
  99. <span class="Z3988" title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.aulast=Mariat&rft.aufirst=Denis&rft. au=Denis+Mariat&rft.au=Sead+Taourit&rft.au=G%C3%A9rard+Gu%C3%A9rin& rft.title=Genetics+Selection+Evolution&rft.atitle=&rft.date=2003&rft. volume=35&rft.issue=1&rft.spage=119&rft.epage=133&rft.genre=article& rft.id=info:DOI/10.1051%2Fgse%3A2002039"></span>Mariat, D., Taourit, S., Guérin, G. (2003). . <span style="font-style: italic;">Genetics Selection Evolution, 35</span>(1), 119-133. DOI: <a rev="review" href= "http://dx.doi.org/10.1051/gse:2002039">10.1051/gse:2002039</a>
  100. EOF;
  101. $expected = <<<EOF
  102. <p><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.aulast=Mariat&amp;rft.aufirst=Denis&amp;rft. au=Denis+Mariat&amp;rft.au=Sead+Taourit&amp;rft.au=G%C3%A9rard+Gu%C3%A9rin&amp; rft.title=Genetics+Selection+Evolution&amp;rft.atitle=&amp;rft.date=2003&amp;rft. volume=35&amp;rft.issue=1&amp;rft.spage=119&amp;rft.epage=133&amp;rft.genre=article&amp; rft.id=info:DOI/10.1051%2Fgse%3A2002039"></span>Mariat, D., Taourit, S., Guérin, G. (2003). . <span style="font-style: italic">Genetics Selection Evolution, 35</span>(1), 119-133. DOI: <a rev="review" href="http://dx.doi.org/10.1051/gse:2002039">10.1051/gse:2002039</a></p>
  103. EOF;
  104. $post_id = $this->factory->post->create( compact( 'post_content' ) );
  105. $this->go_to( get_permalink( $post_id ) );
  106. $this->assertTrue( is_single() );
  107. $this->assertTrue( have_posts() );
  108. $this->assertNull( the_post() );
  109. $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
  110. kses_remove_filters();
  111. }
  112. function test_the_content_attribute_value_with_colon() {
  113. kses_init_filters();
  114. // http://bpr3.org/?p=87
  115. // the title attribute should make it through unfiltered
  116. $post_content = <<<EOF
  117. <span title="My friends: Alice, Bob and Carol">foo</span>
  118. EOF;
  119. $expected = <<<EOF
  120. <p><span title="My friends: Alice, Bob and Carol">foo</span></p>
  121. EOF;
  122. $post_id = $this->factory->post->create( compact( 'post_content' ) );
  123. $this->go_to( get_permalink( $post_id ) );
  124. $this->assertTrue( is_single() );
  125. $this->assertTrue( have_posts() );
  126. $this->assertNull( the_post() );
  127. $this->assertEquals( strip_ws( $expected ), strip_ws( get_echo( 'the_content' ) ) );
  128. kses_remove_filters();
  129. }
  130. }