gallery.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * @group media
  4. * @group gallery
  5. * @ticket UT30
  6. */
  7. class Tests_Post_Gallery extends WP_UnitTestCase { // _WPDataset1
  8. function setUp() {
  9. parent::setUp();
  10. global $wp_rewrite;
  11. $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
  12. $wp_rewrite->flush_rules();
  13. }
  14. function test_the_content() {
  15. // permalink page
  16. $link = '/2008/04/01/simple-gallery-test/';
  17. $this->go_to('/2008/04/01/simple-gallery-test/');
  18. the_post();
  19. // filtered output
  20. $out = get_echo('the_content');
  21. $this->assertNotEmpty($out, "Could not get the_content for $link.");
  22. $expected = <<<EOF
  23. <p>There are ten images attached to this post.  Here&#8217;s a gallery:</p>
  24. <style type='text/css'>
  25. .gallery {
  26. margin: auto;
  27. }
  28. .gallery-item {
  29. float: left;
  30. margin-top: 10px;
  31. text-align: center;
  32. width: 33%; }
  33. .gallery img {
  34. border: 2px solid #cfcfcf;
  35. }
  36. .gallery-caption {
  37. margin-left: 0;
  38. }
  39. </style>
  40. <!-- see gallery_shortcode() in wp-includes/media.php -->
  41. <div class='gallery'><dl class='gallery-item'>
  42. <dt class='gallery-icon'>
  43. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20040724_152504_53/' title='dsc20040724_152504_53'><img src="http://example.com/wp-content/uploads/2008/04/dsc20040724_152504_537.jpg" class="attachment-thumbnail" alt="" /></a>
  44. </dt></dl><dl class='gallery-item'>
  45. <dt class='gallery-icon'>
  46. <a href='http://example.com/2008/04/01/simple-gallery-test/canola/' title='canola'><img src="http://example.com/wp-content/uploads/2008/04/canola3.jpg" class="attachment-thumbnail" alt="" /></a>
  47. </dt></dl><dl class='gallery-item'>
  48. <dt class='gallery-icon'>
  49. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050315_145007_13/' title='dsc20050315_145007_13'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050315_145007_134.jpg" class="attachment-thumbnail" alt="" /></a>
  50. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  51. <dt class='gallery-icon'>
  52. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050604_133440_34/' title='dsc20050604_133440_34'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050604_133440_343.jpg" class="attachment-thumbnail" alt="" /></a>
  53. </dt></dl><dl class='gallery-item'>
  54. <dt class='gallery-icon'>
  55. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050831_165238_33/' title='dsc20050831_165238_33'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050831_165238_333.jpg" class="attachment-thumbnail" alt="" /></a>
  56. </dt></dl><dl class='gallery-item'>
  57. <dt class='gallery-icon'>
  58. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050901_105100_21/' title='dsc20050901_105100_21'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050901_105100_213.jpg" class="attachment-thumbnail" alt="" /></a>
  59. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  60. <dt class='gallery-icon'>
  61. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050813_115856_5/' title='dsc20050813_115856_5'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050813_115856_54.jpg" class="attachment-thumbnail" alt="" /></a>
  62. </dt></dl><dl class='gallery-item'>
  63. <dt class='gallery-icon'>
  64. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050720_123726_27/' title='dsc20050720_123726_27'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050720_123726_274.jpg" class="attachment-thumbnail" alt="" /></a>
  65. </dt></dl><dl class='gallery-item'>
  66. <dt class='gallery-icon'>
  67. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050727_091048_22/' title='Title: Seedlings'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050727_091048_224.jpg" class="attachment-thumbnail" alt="" /></a>
  68. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  69. <dt class='gallery-icon'>
  70. <a href='http://example.com/2008/04/01/simple-gallery-test/dsc20050726_083116_18/' title='dsc20050726_083116_18'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050726_083116_184.jpg" class="attachment-thumbnail" alt="" /></a>
  71. </dt></dl>
  72. <br style='clear: both;' />
  73. </div>
  74. <p>It&#8217;s the simplest form of the gallery tag.  All images are from the public domain site burningwell.org.</p>
  75. <p>The images have various combinations of titles, captions and descriptions.</p>
  76. EOF;
  77. $this->assertEquals(strip_ws($expected), strip_ws($out));
  78. }
  79. function test_gallery_attributes() {
  80. // make sure the gallery shortcode attributes are parsed correctly
  81. $id = 575;
  82. $post = get_post($id);
  83. $this->assertNotNull($post, "get_post($id) could not find the post.");
  84. $post->post_content = '[gallery columns="1" size="medium"]';
  85. wp_update_post($post);
  86. // permalink page
  87. $this->go_to('/2008/04/01/simple-gallery-test/');
  88. the_post();
  89. // filtered output
  90. $out = get_echo('the_content');
  91. $expected = <<<EOF
  92. <style type='text/css'>
  93. .gallery {
  94. margin: auto;
  95. }
  96. .gallery-item {
  97. float: left;
  98. margin-top: 10px;
  99. text-align: center;
  100. width: 100%; }
  101. .gallery img {
  102. border: 2px solid #cfcfcf;
  103. }
  104. .gallery-caption {
  105. margin-left: 0;
  106. }
  107. </style>
  108. <!-- see gallery_shortcode() in wp-includes/media.php -->
  109. <div class='gallery'><dl class='gallery-item'>
  110. <dt class='gallery-icon'>
  111. <a href='http://example.com/?attachment_id=565' title='dsc20040724_152504_53'><img src="http://example.com/wp-content/uploads/2008/04/dsc20040724_152504_537.jpg" class="attachment-medium" alt="" /></a>
  112. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  113. <dt class='gallery-icon'>
  114. <a href='http://example.com/?attachment_id=566' title='canola'><img src="http://example.com/wp-content/uploads/2008/04/canola3.jpg" class="attachment-medium" alt="" /></a>
  115. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  116. <dt class='gallery-icon'>
  117. <a href='http://example.com/?attachment_id=567' title='dsc20050315_145007_13'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050315_145007_134.jpg" class="attachment-medium" alt="" /></a>
  118. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  119. <dt class='gallery-icon'>
  120. <a href='http://example.com/?attachment_id=568' title='dsc20050604_133440_34'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050604_133440_343.jpg" class="attachment-medium" alt="" /></a>
  121. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  122. <dt class='gallery-icon'>
  123. <a href='http://example.com/?attachment_id=569' title='dsc20050831_165238_33'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050831_165238_333.jpg" class="attachment-medium" alt="" /></a>
  124. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  125. <dt class='gallery-icon'>
  126. <a href='http://example.com/?attachment_id=570' title='dsc20050901_105100_21'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050901_105100_213.jpg" class="attachment-medium" alt="" /></a>
  127. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  128. <dt class='gallery-icon'>
  129. <a href='http://example.com/?attachment_id=571' title='dsc20050813_115856_5'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050813_115856_54.jpg" class="attachment-medium" alt="" /></a>
  130. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  131. <dt class='gallery-icon'>
  132. <a href='http://example.com/?attachment_id=572' title='dsc20050720_123726_27'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050720_123726_274.jpg" class="attachment-medium" alt="" /></a>
  133. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  134. <dt class='gallery-icon'>
  135. <a href='http://example.com/?attachment_id=573' title='Title: Seedlings'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050727_091048_224.jpg" class="attachment-medium" alt="" /></a>
  136. </dt></dl><br style="clear: both" /><dl class='gallery-item'>
  137. <dt class='gallery-icon'>
  138. <a href='http://example.com/?attachment_id=574' title='dsc20050726_083116_18'><img src="http://example.com/wp-content/uploads/2008/04/dsc20050726_083116_184.jpg" class="attachment-medium" alt="" /></a>
  139. </dt></dl><br style="clear: both" />
  140. <br style='clear: both;' />
  141. </div>
  142. EOF;
  143. $this->assertEquals(strip_ws($expected), strip_ws($out));
  144. }
  145. }