PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/ezyang/htmlpurifier/tests/HTMLPurifier/Injector/AutoParagraphTest.php

https://gitlab.com/Griffolion/Game-Embargo-Tracker
PHP | 577 lines | 512 code | 64 blank | 1 comment | 0 complexity | 2f7849a091daf7f6cf9256ff205e256c MD5 | raw file
  1. <?php
  2. class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarness
  3. {
  4. public function setup()
  5. {
  6. parent::setup();
  7. $this->config->set('AutoFormat.AutoParagraph', true);
  8. }
  9. public function testSingleParagraph()
  10. {
  11. $this->assertResult(
  12. 'Foobar',
  13. '<p>Foobar</p>'
  14. );
  15. }
  16. public function testSingleMultiLineParagraph()
  17. {
  18. $this->assertResult(
  19. 'Par 1
  20. Par 1 still',
  21. '<p>Par 1
  22. Par 1 still</p>'
  23. );
  24. }
  25. public function testTwoParagraphs()
  26. {
  27. $this->assertResult(
  28. 'Par1
  29. Par2',
  30. "<p>Par1</p>
  31. <p>Par2</p>"
  32. );
  33. }
  34. public function testTwoParagraphsWithLotsOfSpace()
  35. {
  36. $this->assertResult(
  37. 'Par1
  38. Par2',
  39. '<p>Par1</p>
  40. <p>Par2</p>'
  41. );
  42. }
  43. public function testTwoParagraphsWithInlineElements()
  44. {
  45. $this->assertResult(
  46. '<b>Par1</b>
  47. <i>Par2</i>',
  48. '<p><b>Par1</b></p>
  49. <p><i>Par2</i></p>'
  50. );
  51. }
  52. public function testSingleParagraphThatLooksLikeTwo()
  53. {
  54. $this->assertResult(
  55. '<b>Par1
  56. Par2</b>',
  57. '<p><b>Par1
  58. Par2</b></p>'
  59. );
  60. }
  61. public function testAddParagraphAdjacentToParagraph()
  62. {
  63. $this->assertResult(
  64. 'Par1<p>Par2</p>',
  65. '<p>Par1</p>
  66. <p>Par2</p>'
  67. );
  68. }
  69. public function testParagraphUnclosedInlineElement()
  70. {
  71. $this->assertResult(
  72. '<b>Par1',
  73. '<p><b>Par1</b></p>'
  74. );
  75. }
  76. public function testPreservePreTags()
  77. {
  78. $this->assertResult(
  79. '<pre>Par1
  80. Par1</pre>'
  81. );
  82. }
  83. public function testIgnoreTrailingWhitespace()
  84. {
  85. $this->assertResult(
  86. 'Par1
  87. ',
  88. '<p>Par1</p>
  89. '
  90. );
  91. }
  92. public function testDoNotParagraphBlockElements()
  93. {
  94. $this->assertResult(
  95. 'Par1
  96. <div>Par2</div>
  97. Par3',
  98. '<p>Par1</p>
  99. <div>Par2</div>
  100. <p>Par3</p>'
  101. );
  102. }
  103. public function testParagraphTextAndInlineNodes()
  104. {
  105. $this->assertResult(
  106. 'Par<b>1</b>',
  107. '<p>Par<b>1</b></p>'
  108. );
  109. }
  110. public function testPreserveLeadingWhitespace()
  111. {
  112. $this->assertResult(
  113. '
  114. Par',
  115. '
  116. <p>Par</p>'
  117. );
  118. }
  119. public function testPreserveSurroundingWhitespace()
  120. {
  121. $this->assertResult(
  122. '
  123. Par
  124. ',
  125. '
  126. <p>Par</p>
  127. '
  128. );
  129. }
  130. public function testParagraphInsideBlockNode()
  131. {
  132. $this->assertResult(
  133. '<div>Par1
  134. Par2</div>',
  135. '<div><p>Par1</p>
  136. <p>Par2</p></div>'
  137. );
  138. }
  139. public function testParagraphInlineNodeInsideBlockNode()
  140. {
  141. $this->assertResult(
  142. '<div><b>Par1</b>
  143. Par2</div>',
  144. '<div><p><b>Par1</b></p>
  145. <p>Par2</p></div>'
  146. );
  147. }
  148. public function testNoParagraphWhenOnlyOneInsideBlockNode()
  149. {
  150. $this->assertResult('<div>Par1</div>');
  151. }
  152. public function testParagraphTwoInlineNodesInsideBlockNode()
  153. {
  154. $this->assertResult(
  155. '<div><b>Par1</b>
  156. <i>Par2</i></div>',
  157. '<div><p><b>Par1</b></p>
  158. <p><i>Par2</i></p></div>'
  159. );
  160. }
  161. public function testPreserveInlineNodesInPreTag()
  162. {
  163. $this->assertResult(
  164. '<pre><b>Par1</b>
  165. <i>Par2</i></pre>'
  166. );
  167. }
  168. public function testSplitUpInternalsOfPTagInBlockNode()
  169. {
  170. $this->assertResult(
  171. '<div><p>Foo
  172. Bar</p></div>',
  173. '<div><p>Foo</p>
  174. <p>Bar</p></div>'
  175. );
  176. }
  177. public function testSplitUpInlineNodesInPTagInBlockNode()
  178. {
  179. $this->assertResult(
  180. '<div><p><b>Foo</b>
  181. <i>Bar</i></p></div>',
  182. '<div><p><b>Foo</b></p>
  183. <p><i>Bar</i></p></div>'
  184. );
  185. }
  186. public function testNoParagraphSingleInlineNodeInBlockNode()
  187. {
  188. $this->assertResult( '<div><b>Foo</b></div>' );
  189. }
  190. public function testParagraphInBlockquote()
  191. {
  192. $this->assertResult(
  193. '<blockquote>Par1
  194. Par2</blockquote>',
  195. '<blockquote><p>Par1</p>
  196. <p>Par2</p></blockquote>'
  197. );
  198. }
  199. public function testNoParagraphBetweenListItem()
  200. {
  201. $this->assertResult(
  202. '<ul><li>Foo</li>
  203. <li>Bar</li></ul>'
  204. );
  205. }
  206. public function testParagraphSingleElementWithSurroundingSpace()
  207. {
  208. $this->assertResult(
  209. '<div>
  210. Bar
  211. </div>',
  212. '<div>
  213. <p>Bar</p>
  214. </div>'
  215. );
  216. }
  217. public function testIgnoreExtraSpaceWithLeadingInlineNode()
  218. {
  219. $this->assertResult(
  220. '<b>Par1</b>a
  221. Par2',
  222. '<p><b>Par1</b>a</p>
  223. <p>Par2</p>'
  224. );
  225. }
  226. public function testAbsorbExtraEndingPTag()
  227. {
  228. $this->assertResult(
  229. 'Par1
  230. Par2</p>',
  231. '<p>Par1</p>
  232. <p>Par2</p>'
  233. );
  234. }
  235. public function testAbsorbExtraEndingDivTag()
  236. {
  237. $this->assertResult(
  238. 'Par1
  239. Par2</div>',
  240. '<p>Par1</p>
  241. <p>Par2</p>'
  242. );
  243. }
  244. public function testDoNotParagraphSingleSurroundingSpaceInBlockNode()
  245. {
  246. $this->assertResult(
  247. '<div>
  248. Par1
  249. </div>'
  250. );
  251. }
  252. public function testBlockNodeTextDelimeterInBlockNode()
  253. {
  254. $this->assertResult(
  255. '<div>Par1
  256. <div>Par2</div></div>',
  257. '<div><p>Par1</p>
  258. <div>Par2</div></div>'
  259. );
  260. }
  261. public function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode()
  262. {
  263. $this->assertResult(
  264. '<div>Par1
  265. <div>Par2</div></div>'
  266. );
  267. }
  268. public function testBlockNodeTextDelimeterWithoutDoublespace()
  269. {
  270. $this->assertResult(
  271. 'Par1
  272. <div>Par2</div>',
  273. '<p>Par1
  274. </p>
  275. <div>Par2</div>'
  276. );
  277. }
  278. public function testTwoParagraphsOfTextAndInlineNode()
  279. {
  280. $this->assertResult(
  281. 'Par1
  282. <b>Par2</b>',
  283. '<p>Par1</p>
  284. <p><b>Par2</b></p>'
  285. );
  286. }
  287. public function testLeadingInlineNodeParagraph()
  288. {
  289. $this->assertResult(
  290. '<img /> Foo',
  291. '<p><img /> Foo</p>'
  292. );
  293. }
  294. public function testTrailingInlineNodeParagraph()
  295. {
  296. $this->assertResult(
  297. '<li>Foo <a>bar</a></li>'
  298. );
  299. }
  300. public function testTwoInlineNodeParagraph()
  301. {
  302. $this->assertResult(
  303. '<li><b>baz</b><a>bar</a></li>'
  304. );
  305. }
  306. public function testNoParagraphTrailingBlockNodeInBlockNode()
  307. {
  308. $this->assertResult(
  309. '<div><div>asdf</div><b>asdf</b></div>'
  310. );
  311. }
  312. public function testParagraphTrailingBlockNodeWithDoublespaceInBlockNode()
  313. {
  314. $this->assertResult(
  315. '<div><div>asdf</div>
  316. <b>asdf</b></div>',
  317. '<div><div>asdf</div>
  318. <p><b>asdf</b></p></div>'
  319. );
  320. }
  321. public function testParagraphTwoInlineNodesAndWhitespaceNode()
  322. {
  323. $this->assertResult(
  324. '<b>One</b> <i>Two</i>',
  325. '<p><b>One</b> <i>Two</i></p>'
  326. );
  327. }
  328. public function testNoParagraphWithInlineRootNode()
  329. {
  330. $this->config->set('HTML.Parent', 'span');
  331. $this->assertResult(
  332. 'Par
  333. Par2'
  334. );
  335. }
  336. public function testInlineAndBlockTagInDivNoParagraph()
  337. {
  338. $this->assertResult(
  339. '<div><code>bar</code> mmm <pre>asdf</pre></div>'
  340. );
  341. }
  342. public function testInlineAndBlockTagInDivNeedingParagraph()
  343. {
  344. $this->assertResult(
  345. '<div><code>bar</code> mmm
  346. <pre>asdf</pre></div>',
  347. '<div><p><code>bar</code> mmm</p>
  348. <pre>asdf</pre></div>'
  349. );
  350. }
  351. public function testTextInlineNodeTextThenDoubleNewlineNeedsParagraph()
  352. {
  353. $this->assertResult(
  354. '<div>asdf <code>bar</code> mmm
  355. <pre>asdf</pre></div>',
  356. '<div><p>asdf <code>bar</code> mmm</p>
  357. <pre>asdf</pre></div>'
  358. );
  359. }
  360. public function testUpcomingTokenHasNewline()
  361. {
  362. $this->assertResult(
  363. '<div>Test<b>foo</b>bar<b>bing</b>bang
  364. boo</div>',
  365. '<div><p>Test<b>foo</b>bar<b>bing</b>bang</p>
  366. <p>boo</p></div>'
  367. );
  368. }
  369. public function testEmptyTokenAtEndOfDiv()
  370. {
  371. $this->assertResult(
  372. '<div><p>foo</p>
  373. </div>',
  374. '<div><p>foo</p>
  375. </div>'
  376. );
  377. }
  378. public function testEmptyDoubleLineTokenAtEndOfDiv()
  379. {
  380. $this->assertResult(
  381. '<div><p>foo</p>
  382. </div>',
  383. '<div><p>foo</p>
  384. </div>'
  385. );
  386. }
  387. public function testTextState11Root()
  388. {
  389. $this->assertResult('<div></div> ');
  390. }
  391. public function testTextState11Element()
  392. {
  393. $this->assertResult(
  394. "<div><div></div>
  395. </div>");
  396. }
  397. public function testTextStateLikeElementState111NoWhitespace()
  398. {
  399. $this->assertResult('<div><p>P</p>Boo</div>', '<div><p>P</p>Boo</div>');
  400. }
  401. public function testElementState111NoWhitespace()
  402. {
  403. $this->assertResult('<div><p>P</p><b>Boo</b></div>', '<div><p>P</p><b>Boo</b></div>');
  404. }
  405. public function testElementState133()
  406. {
  407. $this->assertResult(
  408. "<div><b>B</b><pre>Ba</pre>
  409. Bar</div>",
  410. "<div><b>B</b><pre>Ba</pre>
  411. <p>Bar</p></div>"
  412. );
  413. }
  414. public function testElementState22()
  415. {
  416. $this->assertResult(
  417. '<ul><li>foo</li></ul>'
  418. );
  419. }
  420. public function testElementState311()
  421. {
  422. $this->assertResult(
  423. '<p>Foo</p><b>Bar</b>',
  424. '<p>Foo</p>
  425. <p><b>Bar</b></p>'
  426. );
  427. }
  428. public function testAutoClose()
  429. {
  430. $this->assertResult(
  431. '<p></p>
  432. <hr />'
  433. );
  434. }
  435. public function testErrorNeeded()
  436. {
  437. $this->config->set('HTML.Allowed', 'b');
  438. $this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
  439. $this->assertResult('<b>foobar</b>');
  440. }
  441. public function testParentElement()
  442. {
  443. $this->config->set('HTML.Allowed', 'p,ul,li');
  444. $this->assertResult('Foo<ul><li>Bar</li></ul>', "<p>Foo</p>\n\n<ul><li>Bar</li></ul>");
  445. }
  446. }
  447. // vim: et sw=4 sts=4