Changeset 53558 for trunk/tests/phpunit/tests/media.php
- Timestamp:
- 06/23/2022 03:01:19 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/media.php
r53481 r53558 6 6 */ 7 7 class Tests_Media extends WP_UnitTestCase { 8 9 const CAPTION = 'A simple caption.'; 10 const ALTERNATE_CAPTION = 'Alternate caption.'; 11 12 const HTML_CONTENT = <<<'CAP' 13 A <strong class='classy'>bolded</strong> <em>caption</em> with a <a href="#">link</a>. 14 CAP; 15 const IMG_CONTENT = <<<'CAP' 16 <img src="pic.jpg" id='anId' alt="pic"/> 17 CAP; 18 19 const IMG_NAME = 'image.jpg'; 20 const IMG_URL = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . self::IMG_NAME; 21 const IMG_META = array( 22 'width' => 100, 23 'height' => 100, 24 'sizes' => '', 25 ); 26 8 27 protected static $large_id; 9 28 protected static $_sizes; … … 57 76 } 58 77 59 public function set_up() {60 parent::set_up();61 $this->caption = 'A simple caption.';62 $this->alternate_caption = 'Alternate caption.';63 $this->html_content = <<<CAP64 A <strong class='classy'>bolded</strong> <em>caption</em> with a <a href="#">link</a>.65 CAP;66 $this->img_content = <<<CAP67 <img src="pic.jpg" id='anId' alt="pic"/>68 CAP;69 $this->img_name = 'image.jpg';70 $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name;71 $this->img_html = '<img src="' . $this->img_url . '"/>';72 $this->img_meta = array(73 'width' => 100,74 'height' => 100,75 'sizes' => '',76 );77 }78 79 78 public function test_img_caption_shortcode_added() { 80 79 global $shortcode_tags; … … 92 91 */ 93 92 public function test_img_caption_shortcode_with_empty_params_but_content() { 94 $result = img_caption_shortcode( array(), $this->caption);95 $this->assertSame( $this->caption, $result );93 $result = img_caption_shortcode( array(), self::CAPTION ); 94 $this->assertSame( self::CAPTION, $result ); 96 95 } 97 96 … … 102 101 add_filter( 'img_caption_shortcode', array( $this, 'return_alt_caption' ) ); 103 102 104 $result = img_caption_shortcode( array(), $this->caption);105 $this->assertSame( $this->alternate_caption, $result );103 $result = img_caption_shortcode( array(), self::CAPTION ); 104 $this->assertSame( self::ALTERNATE_CAPTION, $result ); 106 105 } 107 106 … … 110 109 */ 111 110 public function return_alt_caption() { 112 return $this->alternate_caption;111 return self::ALTERNATE_CAPTION; 113 112 } 114 113 … … 121 120 'width' => 0, 122 121 ), 123 $this->caption124 ); 125 $this->assertSame( $this->caption, $result );122 self::CAPTION 123 ); 124 $this->assertSame( self::CAPTION, $result ); 126 125 } 127 126 … … 146 145 'caption' => '', 147 146 ), 148 $this->caption149 ); 150 $this->assertSame( $this->caption, $result );147 self::CAPTION 148 ); 149 $this->assertSame( self::CAPTION, $result ); 151 150 } 152 151 … … 155 154 array( 156 155 'width' => 20, 157 'caption' => $this->caption,156 'caption' => self::CAPTION, 158 157 ) 159 158 ); … … 161 160 $this->assertSame( 2, preg_match_all( '/wp-caption/', $result, $_r ) ); 162 161 $this->assertSame( 1, preg_match_all( '/alignnone/', $result, $_r ) ); 163 $this->assertSame( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) );162 $this->assertSame( 1, preg_match_all( '/' . self::CAPTION . '/', $result, $_r ) ); 164 163 165 164 if ( current_theme_supports( 'html5', 'caption' ) ) { … … 174 173 array( 175 174 'width' => 20, 176 'caption' => $this->caption,175 'caption' => self::CAPTION, 177 176 'id' => '"myId', 178 177 'align' => '&myAlignment', … … 181 180 $this->assertSame( 1, preg_match_all( '/wp-caption &myAlignment/', $result, $_r ) ); 182 181 $this->assertSame( 1, preg_match_all( '/id="myId"/', $result, $_r ) ); 183 $this->assertSame( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) );182 $this->assertSame( 1, preg_match_all( '/' . self::CAPTION . '/', $result, $_r ) ); 184 183 } 185 184 … … 189 188 'width' => 20, 190 189 'class' => 'some-class another-class', 191 'caption' => $this->caption,190 'caption' => self::CAPTION, 192 191 ) 193 192 ); … … 200 199 array( 201 200 'width' => 20, 202 'caption' => $this->html_content,201 'caption' => self::HTML_CONTENT, 203 202 ) 204 203 ); 205 $our_preg = preg_quote( $this->html_content);204 $our_preg = preg_quote( self::HTML_CONTENT ); 206 205 207 206 $this->assertSame( 1, preg_match_all( "~{$our_preg}~", $result, $_r ) ); … … 211 210 $result = img_caption_shortcode( 212 211 array( 'width' => 20 ), 213 $this->img_content . $this->html_content214 ); 215 $img_preg = preg_quote( $this->img_content);216 $content_preg = preg_quote( $this->html_content);212 self::IMG_CONTENT . self::HTML_CONTENT 213 ); 214 $img_preg = preg_quote( self::IMG_CONTENT ); 215 $content_preg = preg_quote( self::HTML_CONTENT ); 217 216 218 217 $this->assertSame( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); … … 221 220 222 221 public function test_new_img_caption_shortcode_new_format_and_linked_image() { 223 $linked_image = "<a href='#'> {$this->img_content}</a>";222 $linked_image = "<a href='#'>" . self::IMG_CONTENT . '</a>'; 224 223 $result = img_caption_shortcode( 225 224 array( 'width' => 20 ), 226 $linked_image . $this->html_content225 $linked_image . self::HTML_CONTENT 227 226 ); 228 227 $img_preg = preg_quote( $linked_image ); 229 $content_preg = preg_quote( $this->html_content);228 $content_preg = preg_quote( self::HTML_CONTENT ); 230 229 231 230 $this->assertSame( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); … … 234 233 235 234 public function test_new_img_caption_shortcode_new_format_and_linked_image_with_newline() { 236 $linked_image = "<a href='#'> {$this->img_content}</a>";235 $linked_image = "<a href='#'>" . self::IMG_CONTENT . '</a>'; 237 236 $result = img_caption_shortcode( 238 237 array( 'width' => 20 ), 239 $linked_image . "\n\n" . $this->html_content238 $linked_image . "\n\n" . self::HTML_CONTENT 240 239 ); 241 240 $img_preg = preg_quote( $linked_image ); 242 $content_preg = preg_quote( $this->html_content);241 $content_preg = preg_quote( self::HTML_CONTENT ); 243 242 244 243 $this->assertSame( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); … … 255 254 'id' => 'myId', 256 255 ), 257 $this->img_content . $this->html_content256 self::IMG_CONTENT . self::HTML_CONTENT 258 257 ); 259 258 … … 495 494 $post_id = self::factory()->post->create(); 496 495 $attachment_id = self::factory()->attachment->create_object( 497 $this->img_name,496 self::IMG_NAME, 498 497 $post_id, 499 498 array( … … 522 521 ) 523 522 ); 524 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);523 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 525 524 wp_update_attachment_metadata( $attachment_id, $metadata ); 526 525 $ids1[] = $attachment_id; … … 539 538 ) 540 539 ); 541 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);540 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 542 541 wp_update_attachment_metadata( $attachment_id, $metadata ); 543 542 $ids2[] = $attachment_id; … … 573 572 ) 574 573 ); 575 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);574 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 576 575 wp_update_attachment_metadata( $attachment_id, $metadata ); 577 576 $ids1[] = $attachment_id; … … 590 589 ) 591 590 ); 592 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);591 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 593 592 wp_update_attachment_metadata( $attachment_id, $metadata ); 594 593 $ids2[] = $attachment_id; … … 623 622 0 624 623 ); 625 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);624 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 626 625 wp_update_attachment_metadata( $attachment_id, $metadata ); 627 626 $ids[] = $attachment_id; … … 661 660 0 662 661 ); 663 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);662 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 664 663 wp_update_attachment_metadata( $attachment_id, $metadata ); 665 664 $ids[] = $attachment_id; … … 703 702 ) 704 703 ); 705 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);704 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 706 705 wp_update_attachment_metadata( $attachment_id, $metadata ); 707 706 $ids[] = $attachment_id; … … 746 745 ) 747 746 ); 748 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);747 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 749 748 wp_update_attachment_metadata( $attachment_id, $metadata ); 750 749 $ids[] = $attachment_id; … … 789 788 ) 790 789 ); 791 $metadata = array_merge( array( 'file' => "image$i.jpg" ), $this->img_meta);790 $metadata = array_merge( array( 'file' => "image$i.jpg" ), self::IMG_META ); 792 791 wp_update_attachment_metadata( $attachment_id, $metadata ); 793 792 $ids[] = $attachment_id; … … 1182 1181 */ 1183 1182 public function test_attachment_url_to_postid() { 1184 $image_path = '2014/11/' . $this->img_name;1183 $image_path = '2014/11/' . self::IMG_NAME; 1185 1184 $attachment_id = self::factory()->attachment->create_object( 1186 1185 $image_path, … … 1200 1199 */ 1201 1200 public function test_attachment_url_to_postid_with_different_scheme() { 1202 $image_path = '2014/11/' . $this->img_name;1201 $image_path = '2014/11/' . self::IMG_NAME; 1203 1202 $attachment_id = self::factory()->attachment->create_object( 1204 1203 $image_path, … … 1218 1217 */ 1219 1218 public function test_attachment_url_to_postid_should_be_case_sensitive() { 1220 $image_path_lower_case = '2014/11/' . $this->img_name;1219 $image_path_lower_case = '2014/11/' . self::IMG_NAME; 1221 1220 $attachment_id_lower_case = self::factory()->attachment->create_object( 1222 1221 $image_path_lower_case, … … 1228 1227 ); 1229 1228 1230 $image_path_upper_case = '2014/11/' . ucfirst( $this->img_name);1229 $image_path_upper_case = '2014/11/' . ucfirst( self::IMG_NAME ); 1231 1230 $attachment_id_upper_case = self::factory()->attachment->create_object( 1232 1231 $image_path_upper_case, … … 1243 1242 1244 1243 public function test_attachment_url_to_postid_filtered() { 1245 $image_path = '2014/11/' . $this->img_name;1244 $image_path = '2014/11/' . self::IMG_NAME; 1246 1245 $attachment_id = self::factory()->attachment->create_object( 1247 1246 $image_path, … … 1533 1532 $post_id = self::factory()->post->create(); 1534 1533 $attachment_id = self::factory()->attachment->create_object( 1535 $this->img_name,1534 self::IMG_NAME, 1536 1535 $post_id, 1537 1536 array( … … 1556 1555 $post_id = self::factory()->post->create(); 1557 1556 $attachment_id = self::factory()->attachment->create_object( 1558 $this->img_name,1557 self::IMG_NAME, 1559 1558 $post_id, 1560 1559 array( … … 1576 1575 $post_id = self::factory()->post->create(); 1577 1576 $attachment_id = self::factory()->attachment->create_object( 1578 $this->img_name,1577 self::IMG_NAME, 1579 1578 $post_id, 1580 1579 array( … … 3334 3333 public function test_wp_image_file_matches_image_meta_invalid_meta() { 3335 3334 $image_meta = ''; // Attachment is not an image. 3336 $image_src = $this->img_url;3335 $image_src = self::IMG_URL; 3337 3336 3338 3337 $this->assertFalse( wp_image_file_matches_image_meta( $image_src, $image_meta ) ); … … 3344 3343 public function test_wp_image_file_matches_image_meta_different_meta() { 3345 3344 $image_meta = wp_get_attachment_metadata( self::$large_id ); 3346 $image_src = $this->img_url; // Different image.3345 $image_src = self::IMG_URL; // Different image. 3347 3346 3348 3347 $this->assertFalse( wp_image_file_matches_image_meta( $image_src, $image_meta ) );
Note: See TracChangeset
for help on using the changeset viewer.