Autop.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_Autop extends WP_UnitTestCase {
  6. /**
  7. * @ticket 11008
  8. */
  9. function test_first_post() {
  10. $expected = '<p>Welcome to WordPress! This post contains important information. After you read it, you can make it private to hide it from visitors but still have the information handy for future reference.</p>
  11. <p>First things first:</p>
  12. <ul>
  13. <li><a href="%1$s" title="Subscribe to the WordPress mailing list for Release Notifications">Subscribe to the WordPress mailing list for release notifications</a></li>
  14. </ul>
  15. <p>As a subscriber, you will receive an email every time an update is available (and only then). This will make it easier to keep your site up to date, and secure from evildoers.<br />
  16. When a new version is released, <a href="%2$s" title="If you are already logged in, this will take you directly to the Dashboard">log in to the Dashboard</a> and follow the instructions.<br />
  17. Upgrading is a couple of clicks!</p>
  18. <p>Then you can start enjoying the WordPress experience:</p>
  19. <ul>
  20. <li>Edit your personal information at <a href="%3$s" title="Edit settings like your password, your display name and your contact information">Users &#8250; Profile</a></li>
  21. <li>Start publishing at <a href="%4$s" title="Create a new post">Posts &#8250; Add New</a> and at <a href="%5$s" title="Create a new page">Pages &#8250; Add New</a></li>
  22. <li>Browse and install plugins at <a href="%6$s" title="Browse and install plugins at the official WordPress repository directly from your Dashboard">Plugins &#8250; Add New</a></li>
  23. <li>Browse and install themes at <a href="%7$s" title="Browse and install themes at the official WordPress repository directly from your Dashboard">Appearance &#8250; Add New Themes</a></li>
  24. <li>Modify and prettify your website&#8217;s links at <a href="%8$s" title="For example, select a link structure like: http://example.com/1999/12/post-name">Settings &#8250; Permalinks</a></li>
  25. <li>Import content from another system or WordPress site at <a href="%9$s" title="WordPress comes with importers for the most common publishing systems">Tools &#8250; Import</a></li>
  26. <li>Find answers to your questions at the <a href="%10$s" title="The official WordPress documentation, maintained by the WordPress community">WordPress Codex</a></li>
  27. </ul>
  28. <p>To keep this post for reference, <a href="%11$s" title="Click to edit the content and settings of this post">click to edit it</a>, go to the Publish box and change its Visibility from Public to Private.</p>
  29. <p>Thank you for selecting WordPress. We wish you happy publishing!</p>
  30. <p>PS. Not yet subscribed for update notifications? <a href="%1$s" title="Subscribe to the WordPress mailing list for Release Notifications">Do it now!</a></p>
  31. ';
  32. $test_data = '
  33. Welcome to WordPress! This post contains important information. After you read it, you can make it private to hide it from visitors but still have the information handy for future reference.
  34. First things first:
  35. <ul>
  36. <li><a href="%1$s" title="Subscribe to the WordPress mailing list for Release Notifications">Subscribe to the WordPress mailing list for release notifications</a></li>
  37. </ul>
  38. As a subscriber, you will receive an email every time an update is available (and only then). This will make it easier to keep your site up to date, and secure from evildoers.
  39. When a new version is released, <a href="%2$s" title="If you are already logged in, this will take you directly to the Dashboard">log in to the Dashboard</a> and follow the instructions.
  40. Upgrading is a couple of clicks!
  41. Then you can start enjoying the WordPress experience:
  42. <ul>
  43. <li>Edit your personal information at <a href="%3$s" title="Edit settings like your password, your display name and your contact information">Users &#8250; Profile</a></li>
  44. <li>Start publishing at <a href="%4$s" title="Create a new post">Posts &#8250; Add New</a> and at <a href="%5$s" title="Create a new page">Pages &#8250; Add New</a></li>
  45. <li>Browse and install plugins at <a href="%6$s" title="Browse and install plugins at the official WordPress repository directly from your Dashboard">Plugins &#8250; Add New</a></li>
  46. <li>Browse and install themes at <a href="%7$s" title="Browse and install themes at the official WordPress repository directly from your Dashboard">Appearance &#8250; Add New Themes</a></li>
  47. <li>Modify and prettify your website&#8217;s links at <a href="%8$s" title="For example, select a link structure like: http://example.com/1999/12/post-name">Settings &#8250; Permalinks</a></li>
  48. <li>Import content from another system or WordPress site at <a href="%9$s" title="WordPress comes with importers for the most common publishing systems">Tools &#8250; Import</a></li>
  49. <li>Find answers to your questions at the <a href="%10$s" title="The official WordPress documentation, maintained by the WordPress community">WordPress Codex</a></li>
  50. </ul>
  51. To keep this post for reference, <a href="%11$s" title="Click to edit the content and settings of this post">click to edit it</a>, go to the Publish box and change its Visibility from Public to Private.
  52. Thank you for selecting WordPress. We wish you happy publishing!
  53. PS. Not yet subscribed for update notifications? <a href="%1$s" title="Subscribe to the WordPress mailing list for Release Notifications">Do it now!</a>
  54. ';
  55. // On Windows environments, the EOL-style is \r\n.
  56. $expected = str_replace( "\r\n", "\n", $expected );
  57. $this->assertSame( $expected, wpautop( $test_data ) );
  58. }
  59. /**
  60. * wpautop() Should not alter the contents of "<pre>" elements
  61. *
  62. * @ticket 19855
  63. */
  64. public function test_skip_pre_elements() {
  65. $code = file_get_contents( DIR_TESTDATA . '/formatting/sizzle.js' );
  66. $code = str_replace( "\r", '', $code );
  67. $code = htmlentities( $code );
  68. // Not wrapped in <p> tags.
  69. $str = "<pre>$code</pre>";
  70. $this->assertSame( $str, trim( wpautop( $str ) ) );
  71. // Text before/after is wrapped in <p> tags.
  72. $str = "Look at this code\n\n<pre>$code</pre>\n\nIsn't that cool?";
  73. // Expected text after wpautop().
  74. $expected = '<p>Look at this code</p>' . "\n<pre>" . $code . "</pre>\n" . '<p>Isn\'t that cool?</p>';
  75. $this->assertSame( $expected, trim( wpautop( $str ) ) );
  76. // Make sure HTML breaks are maintained if manually inserted.
  77. $str = "Look at this code\n\n<pre>Line1<br />Line2<br>Line3<br/>Line4\nActual Line 2\nActual Line 3</pre>\n\nCool, huh?";
  78. $expected = "<p>Look at this code</p>\n<pre>Line1<br />Line2<br>Line3<br/>Line4\nActual Line 2\nActual Line 3</pre>\n<p>Cool, huh?</p>";
  79. $this->assertSame( $expected, trim( wpautop( $str ) ) );
  80. }
  81. /**
  82. * wpautop() Should not add <br/> to "<input>" elements
  83. *
  84. * @ticket 16456
  85. */
  86. public function test_skip_input_elements() {
  87. $str = 'Username: <input type="text" id="username" name="username" /><br />Password: <input type="password" id="password1" name="password1" />';
  88. $this->assertSame( "<p>$str</p>", trim( wpautop( $str ) ) );
  89. }
  90. /**
  91. * wpautop() Should not add <p> and <br/> around <source> and <track>
  92. *
  93. * @ticket 26864
  94. */
  95. public function test_source_track_elements() {
  96. $content = "Paragraph one.\n\n" .
  97. '<video class="wp-video-shortcode" id="video-0-1" width="640" height="360" preload="metadata" controls="controls">
  98. <source type="video/mp4" src="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4" />
  99. <!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
  100. <source type="video/webm" src="myvideo.webm" />
  101. <!-- Ogg/Vorbis for older Firefox and Opera versions -->
  102. <source type="video/ogg" src="myvideo.ogv" />
  103. <!-- Optional: Add subtitles for each language -->
  104. <track kind="subtitles" src="subtitles.srt" srclang="en" />
  105. <!-- Optional: Add chapters -->
  106. <track kind="chapters" src="chapters.srt" srclang="en" />
  107. <a href="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4">http://domain.tld/wp-content/uploads/2013/12/xyz.mp4</a>
  108. </video>' .
  109. "\n\nParagraph two.";
  110. $content2 = "Paragraph one.\n\n" .
  111. '<video class="wp-video-shortcode" id="video-0-1" width="640" height="360" preload="metadata" controls="controls">
  112. <source type="video/mp4" src="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4" />
  113. <!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
  114. <source type="video/webm" src="myvideo.webm" />
  115. <!-- Ogg/Vorbis for older Firefox and Opera versions -->
  116. <source type="video/ogg" src="myvideo.ogv" />
  117. <!-- Optional: Add subtitles for each language -->
  118. <track kind="subtitles" src="subtitles.srt" srclang="en" />
  119. <!-- Optional: Add chapters -->
  120. <track kind="chapters" src="chapters.srt" srclang="en" />
  121. <a href="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4">http://domain.tld/wp-content/uploads/2013/12/xyz.mp4</a>
  122. </video>' .
  123. "\n\nParagraph two.";
  124. $expected = "<p>Paragraph one.</p>\n" . // Line breaks only after <p>.
  125. '<p><video class="wp-video-shortcode" id="video-0-1" width="640" height="360" preload="metadata" controls="controls">' .
  126. '<source type="video/mp4" src="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4" />' .
  127. '<!-- WebM/VP8 for Firefox4, Opera, and Chrome -->' .
  128. '<source type="video/webm" src="myvideo.webm" />' .
  129. '<!-- Ogg/Vorbis for older Firefox and Opera versions -->' .
  130. '<source type="video/ogg" src="myvideo.ogv" />' .
  131. '<!-- Optional: Add subtitles for each language -->' .
  132. '<track kind="subtitles" src="subtitles.srt" srclang="en" />' .
  133. '<!-- Optional: Add chapters -->' .
  134. '<track kind="chapters" src="chapters.srt" srclang="en" />' .
  135. '<a href="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4">' .
  136. "http://domain.tld/wp-content/uploads/2013/12/xyz.mp4</a></video></p>\n" .
  137. '<p>Paragraph two.</p>';
  138. // When running the content through wpautop() from wp_richedit_pre().
  139. $shortcode_content = "Paragraph one.\n\n" .
  140. '[video width="720" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"]
  141. <!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
  142. <source type="video/webm" src="myvideo.webm" />
  143. <!-- Ogg/Vorbis for older Firefox and Opera versions -->
  144. <source type="video/ogg" src="myvideo.ogv" />
  145. <!-- Optional: Add subtitles for each language -->
  146. <track kind="subtitles" src="subtitles.srt" srclang="en" />
  147. <!-- Optional: Add chapters -->
  148. <track kind="chapters" src="chapters.srt" srclang="en" />
  149. [/video]' .
  150. "\n\nParagraph two.";
  151. $shortcode_expected = "<p>Paragraph one.</p>\n" . // Line breaks only after <p>.
  152. '<p>[video width="720" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"]' .
  153. '<!-- WebM/VP8 for Firefox4, Opera, and Chrome --><source type="video/webm" src="myvideo.webm" />' .
  154. '<!-- Ogg/Vorbis for older Firefox and Opera versions --><source type="video/ogg" src="myvideo.ogv" />' .
  155. '<!-- Optional: Add subtitles for each language --><track kind="subtitles" src="subtitles.srt" srclang="en" />' .
  156. '<!-- Optional: Add chapters --><track kind="chapters" src="chapters.srt" srclang="en" />' .
  157. "[/video]</p>\n" .
  158. '<p>Paragraph two.</p>';
  159. $this->assertSame( $expected, trim( wpautop( $content ) ) );
  160. $this->assertSame( $expected, trim( wpautop( $content2 ) ) );
  161. $this->assertSame( $shortcode_expected, trim( wpautop( $shortcode_content ) ) );
  162. }
  163. /**
  164. * wpautop() Should not add <p> and <br/> around <param> and <embed>
  165. *
  166. * @ticket 26864
  167. */
  168. public function test_param_embed_elements() {
  169. $content1 = '
  170. Paragraph one.
  171. <object width="400" height="224" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
  172. <param name="src" value="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" />
  173. <param name="allowfullscreen" value="true" />
  174. <param name="allowscriptaccess" value="always" />
  175. <param name="overstretch" value="true" />
  176. <param name="flashvars" value="isDynamicSeeking=true" />
  177. <embed width="400" height="224" type="application/x-shockwave-flash" src="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" wmode="direct" seamlesstabbing="true" allowfullscreen="true" overstretch="true" flashvars="isDynamicSeeking=true" />
  178. </object>
  179. Paragraph two.';
  180. $expected1 = "<p>Paragraph one.</p>\n" . // Line breaks only after <p>.
  181. '<p><object width="400" height="224" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">' .
  182. '<param name="src" value="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" />' .
  183. '<param name="allowfullscreen" value="true" />' .
  184. '<param name="allowscriptaccess" value="always" />' .
  185. '<param name="overstretch" value="true" />' .
  186. '<param name="flashvars" value="isDynamicSeeking=true" />' .
  187. '<embed width="400" height="224" type="application/x-shockwave-flash" src="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" wmode="direct" seamlesstabbing="true" allowfullscreen="true" overstretch="true" flashvars="isDynamicSeeking=true" />' .
  188. "</object></p>\n" .
  189. '<p>Paragraph two.</p>';
  190. $content2 = '
  191. Paragraph one.
  192. <div class="video-player" id="x-video-0">
  193. <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="360" id="video-0" standby="Standby text">
  194. <param name="movie" value="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" />
  195. <param name="quality" value="best" />
  196. <param name="seamlesstabbing" value="true" />
  197. <param name="allowfullscreen" value="true" />
  198. <param name="allowscriptaccess" value="always" />
  199. <param name="overstretch" value="true" />
  200. <!--[if !IE]--><object type="application/x-shockwave-flash" data="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" width="640" height="360" standby="Standby text">
  201. <param name="quality" value="best" />
  202. <param name="seamlesstabbing" value="true" />
  203. <param name="allowfullscreen" value="true" />
  204. <param name="allowscriptaccess" value="always" />
  205. <param name="overstretch" value="true" />
  206. </object><!--<![endif]-->
  207. </object></div>
  208. Paragraph two.';
  209. $expected2 = "<p>Paragraph one.</p>\n" . // Line breaks only after block tags.
  210. '<div class="video-player" id="x-video-0">' . "\n" .
  211. '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="360" id="video-0" standby="Standby text">' .
  212. '<param name="movie" value="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" />' .
  213. '<param name="quality" value="best" />' .
  214. '<param name="seamlesstabbing" value="true" />' .
  215. '<param name="allowfullscreen" value="true" />' .
  216. '<param name="allowscriptaccess" value="always" />' .
  217. '<param name="overstretch" value="true" />' .
  218. '<!--[if !IE]--><object type="application/x-shockwave-flash" data="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" width="640" height="360" standby="Standby text">' .
  219. '<param name="quality" value="best" />' .
  220. '<param name="seamlesstabbing" value="true" />' .
  221. '<param name="allowfullscreen" value="true" />' .
  222. '<param name="allowscriptaccess" value="always" />' .
  223. '<param name="overstretch" value="true" /></object><!--<![endif]-->' .
  224. "</object></div>\n" .
  225. '<p>Paragraph two.</p>';
  226. $this->assertSame( $expected1, trim( wpautop( $content1 ) ) );
  227. $this->assertSame( $expected2, trim( wpautop( $content2 ) ) );
  228. }
  229. /**
  230. * wpautop() Should not add <br/> to "<select>" or "<option>" elements
  231. *
  232. * @ticket 22230
  233. */
  234. public function test_skip_select_option_elements() {
  235. $str = 'Country: <select id="state" name="state"><option value="1">Alabama</option><option value="2">Alaska</option><option value="3">Arizona</option><option value="4">Arkansas</option><option value="5">California</option></select>';
  236. $this->assertSame( "<p>$str</p>", trim( wpautop( $str ) ) );
  237. }
  238. /**
  239. * wpautop() should treat block level HTML elements as blocks.
  240. *
  241. * @ticket 27268
  242. */
  243. function test_that_wpautop_treats_block_level_elements_as_blocks() {
  244. $blocks = array(
  245. 'table',
  246. 'thead',
  247. 'tfoot',
  248. 'caption',
  249. 'col',
  250. 'colgroup',
  251. 'tbody',
  252. 'tr',
  253. 'td',
  254. 'th',
  255. 'div',
  256. 'dl',
  257. 'dd',
  258. 'dt',
  259. 'ul',
  260. 'ol',
  261. 'li',
  262. 'pre',
  263. 'form',
  264. 'map',
  265. 'area',
  266. 'address',
  267. 'math',
  268. 'style',
  269. 'p',
  270. 'h1',
  271. 'h2',
  272. 'h3',
  273. 'h4',
  274. 'h5',
  275. 'h6',
  276. 'fieldset',
  277. 'legend',
  278. 'section',
  279. 'article',
  280. 'aside',
  281. 'hgroup',
  282. 'header',
  283. 'footer',
  284. 'nav',
  285. 'figure',
  286. 'details',
  287. 'menu',
  288. 'summary',
  289. );
  290. // Check whitespace normalization.
  291. $content = array();
  292. foreach ( $blocks as $block ) {
  293. $content[] = "<$block>foo</$block>";
  294. }
  295. $expected = implode( "\n", $content );
  296. $input = implode( "\n\n", $content ); // Whitespace difference.
  297. $this->assertSame( $expected, trim( wpautop( $input ) ) );
  298. $input = implode( '', $content ); // Whitespace difference.
  299. $this->assertSame( $expected, trim( wpautop( $input ) ) );
  300. // Check whitespace addition.
  301. $content = array();
  302. foreach ( $blocks as $block ) {
  303. $content[] = "<$block/>";
  304. }
  305. $expected = implode( "\n", $content );
  306. $input = implode( '', $content );
  307. $this->assertSame( $expected, trim( wpautop( $input ) ) );
  308. // Check whitespace addition with attributes.
  309. $content = array();
  310. foreach ( $blocks as $block ) {
  311. $content[] = "<$block attr='value'>foo</$block>";
  312. }
  313. $expected = implode( "\n", $content );
  314. $input = implode( '', $content );
  315. $this->assertSame( $expected, trim( wpautop( $input ) ) );
  316. }
  317. /**
  318. * wpautop() should autop a blockquote's contents but not the blockquote itself
  319. *
  320. * @ticket 27268
  321. */
  322. function test_that_wpautop_does_not_wrap_blockquotes_but_does_autop_their_contents() {
  323. $content = '<blockquote>foo</blockquote>';
  324. $expected = '<blockquote><p>foo</p></blockquote>';
  325. $this->assertSame( $expected, trim( wpautop( $content ) ) );
  326. }
  327. /**
  328. * wpautop() should treat inline HTML elements as inline.
  329. *
  330. * @ticket 27268
  331. */
  332. function test_that_wpautop_treats_inline_elements_as_inline() {
  333. $inlines = array(
  334. 'a',
  335. 'em',
  336. 'strong',
  337. 'small',
  338. 's',
  339. 'cite',
  340. 'q',
  341. 'dfn',
  342. 'abbr',
  343. 'data',
  344. 'time',
  345. 'code',
  346. 'var',
  347. 'samp',
  348. 'kbd',
  349. 'sub',
  350. 'sup',
  351. 'i',
  352. 'b',
  353. 'u',
  354. 'mark',
  355. 'span',
  356. 'del',
  357. 'ins',
  358. 'noscript',
  359. 'select',
  360. );
  361. $content = array();
  362. $expected = array();
  363. foreach ( $inlines as $inline ) {
  364. $content[] = "<$inline>foo</$inline>";
  365. $expected[] = "<p><$inline>foo</$inline></p>";
  366. }
  367. $content = implode( "\n\n", $content );
  368. $expected = implode( "\n", $expected );
  369. $this->assertSame( $expected, trim( wpautop( $content ) ) );
  370. }
  371. /**
  372. * Do not allow newlines within HTML elements to become mangled.
  373. *
  374. * @ticket 33106
  375. * @dataProvider data_element_sanity
  376. */
  377. function test_element_sanity( $input, $output ) {
  378. return $this->assertSame( $output, wpautop( $input ) );
  379. }
  380. function data_element_sanity() {
  381. return array(
  382. array(
  383. "Hello <a\nhref='world'>",
  384. "<p>Hello <a\nhref='world'></p>\n",
  385. ),
  386. array(
  387. "Hello <!-- a\nhref='world' -->",
  388. "<p>Hello <!-- a\nhref='world' --></p>\n",
  389. ),
  390. array(
  391. "Hello <!-- <object>\n<param>\n<param>\n<embed>\n</embed>\n</object>\n -->",
  392. "<p>Hello <!-- <object>\n<param>\n<param>\n<embed>\n</embed>\n</object>\n --></p>\n",
  393. ),
  394. array(
  395. "Hello <!-- <object>\n<param/>\n<param/>\n<embed>\n</embed>\n</object>\n -->",
  396. "<p>Hello <!-- <object>\n<param/>\n<param/>\n<embed>\n</embed>\n</object>\n --></p>\n",
  397. ),
  398. /* Block elements inside comments will fail this test in all versions, it's not a regression.
  399. array(
  400. "Hello <!-- <hr> a\nhref='world' -->",
  401. "<p>Hello <!-- <hr> a\nhref='world' --></p>\n",
  402. ),
  403. array(
  404. "Hello <![CDATA[ <hr> a\nhttps://youtu.be/jgz0uSaOZbE\n ]]>",
  405. "<p>Hello <![CDATA[ <hr> a\nhttps://youtu.be/jgz0uSaOZbE\n ]]></p>\n",
  406. ),
  407. */
  408. array(
  409. "Hello <![CDATA[ a\nhttps://youtu.be/jgz0uSaOZbE\n ]]>",
  410. "<p>Hello <![CDATA[ a\nhttps://youtu.be/jgz0uSaOZbE\n ]]></p>\n",
  411. ),
  412. array(
  413. "Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 ]]> -->",
  414. "<p>Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 ]]> --></p>\n",
  415. ),
  416. array(
  417. "Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 --> a\n9 ]]>",
  418. "<p>Hello <![CDATA[ <!-- a\nhttps://youtu.be/jgz0uSaOZbE\n a\n9 --> a\n9 ]]></p>\n",
  419. ),
  420. );
  421. }
  422. /**
  423. * wpautop() should not convert line breaks after <br /> tags
  424. *
  425. * @ticket 33377
  426. */
  427. function test_that_wpautop_skips_line_breaks_after_br() {
  428. $content = '
  429. line 1<br>
  430. line 2<br/>
  431. line 3<br />
  432. line 4
  433. line 5
  434. ';
  435. $expected = '<p>line 1<br />
  436. line 2<br />
  437. line 3<br />
  438. line 4<br />
  439. line 5</p>';
  440. $this->assertSameIgnoreEOL( $expected, trim( wpautop( $content ) ) );
  441. }
  442. /**
  443. * wpautop() should convert multiple line breaks into a paragraph regarless of <br /> format
  444. *
  445. * @ticket 33377
  446. */
  447. function test_that_wpautop_adds_a_paragraph_after_multiple_br() {
  448. $content = '
  449. line 1<br>
  450. <br/>
  451. line 2<br/>
  452. <br />
  453. ';
  454. $expected = '<p>line 1</p>
  455. <p>line 2</p>';
  456. $this->assertSameIgnoreEOL( $expected, trim( wpautop( $content ) ) );
  457. }
  458. /**
  459. * @ticket 4857
  460. */
  461. function test_that_text_before_blocks_is_peed() {
  462. $content = 'a<div>b</div>';
  463. $expected = "<p>a</p>\n<div>b</div>";
  464. $this->assertSame( $expected, trim( wpautop( $content ) ) );
  465. }
  466. /**
  467. * wpautop() should not add extra </p> before <figcaption>
  468. *
  469. * @covers ::wpautop
  470. * @uses ::trim
  471. *
  472. * @ticket 39307
  473. */
  474. function test_that_wpautop_does_not_add_extra_closing_p_in_figure() {
  475. $content1 = '<figure><img src="example.jpg" /><figcaption>Caption</figcaption></figure>';
  476. $expected1 = $content1;
  477. $content2 = '<figure>
  478. <img src="example.jpg" />
  479. <figcaption>Caption</figcaption>
  480. </figure>';
  481. $expected2 = '<figure>
  482. <img src="example.jpg" /><figcaption>Caption</figcaption></figure>';
  483. $this->assertSame( $expected1, trim( wpautop( $content1 ) ) );
  484. $this->assertSameIgnoreEOL( $expected2, trim( wpautop( $content2 ) ) );
  485. }
  486. /**
  487. * @ticket 14674
  488. */
  489. function test_the_hr_is_not_peed() {
  490. $content = 'paragraph1<hr>paragraph2';
  491. $expected = "<p>paragraph1</p>\n<hr>\n<p>paragraph2</p>";
  492. $this->assertSame( $expected, trim( wpautop( $content ) ) );
  493. }
  494. /**
  495. * wpautop() should ignore inline SVG graphics
  496. *
  497. * @ticket 9437
  498. */
  499. function test_that_wpautop_ignores_inline_svgs() {
  500. $content =
  501. '<svg xmlns="http://www.w3.org/2000/svg">
  502. <circle cx="50" cy="50" r="30" fill="blue">
  503. <animateTransform attributeName="transform" type="scale" to="1.5" dur="2s" fill="freeze"/>
  504. </circle>
  505. </svg>';
  506. $expected = '<p>' . $content . '</p>';
  507. $this->assertSameIgnoreEOL( $expected, trim( wpautop( $content ) ) );
  508. }
  509. /**
  510. * wpautop() should ignore inline scripts
  511. *
  512. * @ticket 9437
  513. */
  514. function test_that_wpautop_ignores_inline_scripts() {
  515. $content =
  516. '<script type="text/javascript">
  517. var dummy = 1;
  518. </script>';
  519. $expected = '<p>' . $content . '</p>';
  520. $this->assertSameIgnoreEOL( $expected, trim( wpautop( $content ) ) );
  521. }
  522. }