Ticket #33981: 33981.2.diff
File 33981.2.diff, 4.2 KB (added by , 7 years ago) |
---|
-
src/wp-includes/media.php
diff --git src/wp-includes/media.php src/wp-includes/media.php index dbc9c7dd01..a280e3e41e 100644
function img_caption_shortcode( $attr, $content = null ) { 1578 1578 1579 1579 $style = ''; 1580 1580 if ( $caption_width ) { 1581 $style = 'style=" width: ' . (int) $caption_width . 'px" ';1581 $style = 'style="max-width: ' . (int) $caption_width . 'px" '; 1582 1582 } 1583 1583 1584 1584 if ( $html5 ) { -
tests/phpunit/tests/media.php
diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php index 8fb3cc09d7..cebc948f25 100644
class Tests_Media extends WP_UnitTestCase { 28 28 function setUp() { 29 29 parent::setUp(); 30 30 $this->caption = 'A simple caption.'; 31 $this->alternate_caption = 'Alternate caption.'; 31 32 $this->html_content = <<<CAP 32 33 A <strong class='classy'>bolded</strong> <em>caption</em> with a <a href="#">link</a>. 33 34 CAP; … … CAP; 51 52 $this->assertNull( $result ); 52 53 } 53 54 54 function test_img_caption_shortcode_with_bad_attr() { 55 $result = img_caption_shortcode( array(), 'content' ); 56 $this->assertEquals( 'content', 'content' ); 55 /** 56 * @ticket 33981 57 */ 58 function test_img_caption_shortcode_with_empty_params_but_content() { 59 $result = img_caption_shortcode( array(), $this->caption ); 60 $this->assertEquals( $this->caption, $result ); 61 } 62 63 /** 64 * @ticket 33981 65 */ 66 function test_img_caption_shortcode_short_circuit_filter() { 67 add_filter( 'img_caption_shortcode', array( $this, '_return_alt_caption' ) ); 68 69 $result = img_caption_shortcode( array(), $this->caption ); 70 $this->assertEquals( $this->alternate_caption, $result ); 71 } 72 73 /** 74 * Filter used in test_img_caption_shortcode_short_circuit_filter() 75 */ 76 function _return_alt_caption() { 77 return $this->alternate_caption; 78 } 79 80 /** 81 * @ticket 33981 82 */ 83 function test_img_caption_shortcode_empty_width() { 84 $result = img_caption_shortcode( 85 array( 86 'width' => 0, 87 ), 88 $this->caption 89 ); 90 $this->assertEquals( $this->caption, $result ); 91 } 92 93 /** 94 * @ticket 33981 95 */ 96 function test_img_caption_shortcode_empty_caption() { 97 $result = img_caption_shortcode( 98 array( 99 'caption' => '', 100 ) 101 ); 102 $this->assertNull( $result ); 103 } 104 105 /** 106 * @ticket 33981 107 */ 108 function test_img_caption_shortcode_empty_caption_and_content() { 109 $result = img_caption_shortcode( 110 array( 111 'caption' => '', 112 ), 113 $this->caption 114 ); 115 $this->assertEquals( $this->caption, $result ); 57 116 } 58 117 59 118 function test_img_caption_shortcode_with_old_format() { … … CAP; 66 125 $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); 67 126 68 127 if ( current_theme_supports( 'html5', 'caption' ) ) { 69 $this->assertEquals( 1, preg_match_all( "/ width: 20/", $result, $_r ) );128 $this->assertEquals( 1, preg_match_all( "/max-width: 20/", $result, $_r ) ); 70 129 } else { 71 $this->assertEquals( 1, preg_match_all( "/ width: 30/", $result, $_r ) );130 $this->assertEquals( 1, preg_match_all( "/max-width: 30/", $result, $_r ) ); 72 131 } 73 132 } 74 133 … … CAP; 86 145 $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); 87 146 } 88 147 148 function test_img_caption_shortcode_with_old_format_and_class() { 149 $result = img_caption_shortcode( 150 array( 151 'width' => 20, 152 'class' => 'some-class another-class', 153 'caption' => $this->caption, 154 ) 155 ); 156 $this->assertEquals( 1, preg_match_all( '/wp-caption alignnone some-class another-class/', $result, $_r ) ); 157 158 } 159 89 160 function test_new_img_caption_shortcode_with_html_caption() { 90 161 $result = img_caption_shortcode( 91 162 array( 'width' => 20, 'caption' => $this->html_content ) -
tests/phpunit/tests/shortcode.php
diff --git tests/phpunit/tests/shortcode.php tests/phpunit/tests/shortcode.php index 273d04d715..08ef1ac01a 100644
EOF; 477 477 ), 478 478 array( 479 479 '[caption caption="test" width="2"]<div>hello</div>[/caption]', 480 '<div style=" width: 12px" class="wp-caption alignnone"><div>hello</div><p class="wp-caption-text">test</p></div>',480 '<div style="max-width: 12px" class="wp-caption alignnone"><div>hello</div><p class="wp-caption-text">test</p></div>', 481 481 ), 482 482 array( 483 483 '<div [gallery]>',