PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/modules/Customerportal/include/htmlpurify/tests/HTMLPurifier/Injector/AutoParagraphTest.php

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