| | 84 | $attributes = array( |
| | 85 | 'class' => 'classname', |
| | 86 | 'id' => 'idattr', |
| | 87 | 'style' => 'color: red;', |
| | 88 | 'alt' => 'alt', |
| | 89 | 'src' => '/test.png', |
| | 90 | 'srcset' => '/test.png 1x, /test-2x.png 2x', |
| | 91 | 'width' => '100', |
| | 92 | 'height' => '100', |
| | 93 | 'usemap' => '#hash', |
| | 94 | 'vspace' => '20', |
| | 95 | 'hspace' => '20', |
| | 96 | 'longdesc' => 'this is the longdesc', |
| | 97 | 'align' => 'middle', |
| | 98 | 'border' => '5', |
| | 99 | ); |
| | 100 | |
| | 101 | foreach ( $attributes as $name => $value ) { |
| | 102 | if ( $name === $value ) { |
| | 103 | $string = "<img $value />"; |
| | 104 | $expect_string = '<img ' . trim( $value, ';' ) . ' />'; |
| | 105 | } else { |
| | 106 | $string = "<img $name='$value' />"; |
| | 107 | $expect_string = "<img $name='" . trim( $value, ';' ) . "' />"; |
| | 108 | } |
| | 109 | |
| | 110 | $this->assertEquals( $expect_string, wp_kses( $string, $allowedposttags ) ); |
| | 111 | } |
| | 112 | } |
| | 113 | |
| | 114 | /** |
| | 115 | * @ticket 29807 |
| | 116 | */ |
| | 117 | function data_wp_kses_srcset() { |
| | 118 | return array( |
| | 119 | array( |
| | 120 | '/test.png 1x, /test-2x.png 2x', |
| | 121 | '/test.png 1x, /test-2x.png 2x', |
| | 122 | ), |
| | 123 | array( |
| | 124 | 'bad://localhost/test.png 1x, http://localhost/test-2x.png 2x', |
| | 125 | 'http://localhost/test-2x.png 2x', |
| | 126 | ), |
| | 127 | array( |
| | 128 | 'path/to/test.png 1x, path/to/test-2x.png 2x', |
| | 129 | 'path/to/test.png 1x, path/to/test-2x.png 2x', |
| | 130 | ), |
| | 131 | ); |
| | 132 | } |
| | 133 | |
| | 134 | /** |
| | 135 | * @ticket 29807 |
| | 136 | * |
| | 137 | * @param string $unfiltered Unfiltered srcset value before wp_kses. |
| | 138 | * @param string $expected Expected srset value after wp_kses. |
| | 139 | * |
| | 140 | * @dataProvider data_wp_kses_srcset |
| | 141 | */ |
| | 142 | function test_wp_kses_srcset( $unfiltered, $expected ) { |
| | 143 | $unfiltered = "<img src='test.png' srcset='{$original}' />"; |
| | 144 | $expected = "<img src='test.png' srcset='{$expected}' />"; |
| | 145 | $this->assertEquals( $expected, wp_kses_post( $unfiltered ) ); |
| | 146 | } |
| | 147 | |
| | 148 | /** |
| | 149 | * @ticket 29807 |
| | 150 | */ |
| | 151 | function test_wp_filter_post_kses_picture() { |
| | 152 | global $allowedposttags; |
| | 153 | |
| | 154 | $html = '<picture><source srcset="pear-mobile.jpeg" media="(max-width: 720px)" type="image/png"><source srcset="pear-tablet.jpeg" media="(max-width: 1280px)" type="image/png"><img src="pear-desktop.jpeg" alt="The pear is juicy."></picture>'; |
| | 155 | $this->assertEquals( $html, wp_kses( $html, $allowedposttags ) ); |
| | 156 | |
| | 157 | $html = '<picture><source srcset="https://wordpress.org/pear-mobile.jpeg" media="(max-width: 720px)" type="image/png"><source srcset="https://wordpress.org/pear-tablet.jpeg 500w, https://wordpress.org/pear-tablet.jpeg" media="(max-width: 1280px)" type="image/png"><img src="pear-desktop.jpeg" alt="The pear is juicy."></picture>'; |
| | 158 | $this->assertEquals( $html, wp_kses( $html, $allowedposttags ) ); |
| | 159 | |
| | 160 | // Test bad protocol in srcset |
| | 161 | $original = '<picture><source srcset="bad://pear-mobile.jpeg" media="(max-width: 720px)" type="image/png"><source srcset="pear-tablet.jpeg" media="(max-width: 1280px)" type="image/png"><img src="pear-desktop.jpeg" alt="The pear is juicy."></picture>'; |
| | 162 | $expected = '<picture><source srcset="//pear-mobile.jpeg" media="(max-width: 720px)" type="image/png"><source srcset="pear-tablet.jpeg" media="(max-width: 1280px)" type="image/png"><img src="pear-desktop.jpeg" alt="The pear is juicy."></picture>'; |
| | 163 | $this->assertEquals( $expected, wp_kses( $original, $allowedposttags ) ); |
| | 164 | } |
| | 165 | |
| | 166 | function test_feed_links() { |
| | 167 | global $allowedposttags; |