ValidateAttributes_TidyTest.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?php
  2. class HTMLPurifier_Strategy_ValidateAttributes_TidyTest extends HTMLPurifier_StrategyHarness
  3. {
  4. function setUp() {
  5. parent::setUp();
  6. $this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
  7. $this->config->set('HTML.TidyLevel', 'heavy');
  8. }
  9. function testConvertCenterAlign() {
  10. $this->assertResult(
  11. '<h1 align="center">Centered Headline</h1>',
  12. '<h1 style="text-align:center;">Centered Headline</h1>'
  13. );
  14. }
  15. function testConvertRightAlign() {
  16. $this->assertResult(
  17. '<h1 align="right">Right-aligned Headline</h1>',
  18. '<h1 style="text-align:right;">Right-aligned Headline</h1>'
  19. );
  20. }
  21. function testConvertLeftAlign() {
  22. $this->assertResult(
  23. '<h1 align="left">Left-aligned Headline</h1>',
  24. '<h1 style="text-align:left;">Left-aligned Headline</h1>'
  25. );
  26. }
  27. function testConvertJustifyAlign() {
  28. $this->assertResult(
  29. '<p align="justify">Justified Paragraph</p>',
  30. '<p style="text-align:justify;">Justified Paragraph</p>'
  31. );
  32. }
  33. function testRemoveInvalidAlign() {
  34. $this->assertResult(
  35. '<h1 align="invalid">Invalid Headline</h1>',
  36. '<h1>Invalid Headline</h1>'
  37. );
  38. }
  39. function testConvertTableLengths() {
  40. $this->assertResult(
  41. '<td width="5%" height="10" /><th width="10" height="5%" /><hr width="10" height="10" />',
  42. '<td style="width:5%;height:10px;" /><th style="width:10px;height:5%;" /><hr style="width:10px;" />'
  43. );
  44. }
  45. function testTdConvertNowrap() {
  46. $this->assertResult(
  47. '<td nowrap />',
  48. '<td style="white-space:nowrap;" />'
  49. );
  50. }
  51. function testCaptionConvertAlignLeft() {
  52. $this->assertResult(
  53. '<caption align="left" />',
  54. '<caption style="text-align:left;" />'
  55. );
  56. }
  57. function testCaptionConvertAlignRight() {
  58. $this->assertResult(
  59. '<caption align="right" />',
  60. '<caption style="text-align:right;" />'
  61. );
  62. }
  63. function testCaptionConvertAlignTop() {
  64. $this->assertResult(
  65. '<caption align="top" />',
  66. '<caption style="caption-side:top;" />'
  67. );
  68. }
  69. function testCaptionConvertAlignBottom() {
  70. $this->assertResult(
  71. '<caption align="bottom" />',
  72. '<caption style="caption-side:bottom;" />'
  73. );
  74. }
  75. function testCaptionRemoveInvalidAlign() {
  76. $this->assertResult(
  77. '<caption align="nonsense" />',
  78. '<caption />'
  79. );
  80. }
  81. function testTableConvertAlignLeft() {
  82. $this->assertResult(
  83. '<table align="left" />',
  84. '<table style="float:left;" />'
  85. );
  86. }
  87. function testTableConvertAlignCenter() {
  88. $this->assertResult(
  89. '<table align="center" />',
  90. '<table style="margin-left:auto;margin-right:auto;" />'
  91. );
  92. }
  93. function testTableConvertAlignRight() {
  94. $this->assertResult(
  95. '<table align="right" />',
  96. '<table style="float:right;" />'
  97. );
  98. }
  99. function testTableRemoveInvalidAlign() {
  100. $this->assertResult(
  101. '<table align="top" />',
  102. '<table />'
  103. );
  104. }
  105. function testImgConvertAlignLeft() {
  106. $this->assertResult(
  107. '<img src="foobar.jpg" alt="foobar" align="left" />',
  108. '<img src="foobar.jpg" alt="foobar" style="float:left;" />'
  109. );
  110. }
  111. function testImgConvertAlignRight() {
  112. $this->assertResult(
  113. '<img src="foobar.jpg" alt="foobar" align="right" />',
  114. '<img src="foobar.jpg" alt="foobar" style="float:right;" />'
  115. );
  116. }
  117. function testImgConvertAlignBottom() {
  118. $this->assertResult(
  119. '<img src="foobar.jpg" alt="foobar" align="bottom" />',
  120. '<img src="foobar.jpg" alt="foobar" style="vertical-align:baseline;" />'
  121. );
  122. }
  123. function testImgConvertAlignMiddle() {
  124. $this->assertResult(
  125. '<img src="foobar.jpg" alt="foobar" align="middle" />',
  126. '<img src="foobar.jpg" alt="foobar" style="vertical-align:middle;" />'
  127. );
  128. }
  129. function testImgConvertAlignTop() {
  130. $this->assertResult(
  131. '<img src="foobar.jpg" alt="foobar" align="top" />',
  132. '<img src="foobar.jpg" alt="foobar" style="vertical-align:top;" />'
  133. );
  134. }
  135. function testImgRemoveInvalidAlign() {
  136. $this->assertResult(
  137. '<img src="foobar.jpg" alt="foobar" align="outerspace" />',
  138. '<img src="foobar.jpg" alt="foobar" />'
  139. );
  140. }
  141. function testBorderConvertHVSpace() {
  142. $this->assertResult(
  143. '<img src="foo" alt="foo" hspace="1" vspace="3" />',
  144. '<img src="foo" alt="foo" style="margin-top:3px;margin-bottom:3px;margin-left:1px;margin-right:1px;" />'
  145. );
  146. }
  147. function testHrConvertSize() {
  148. $this->assertResult(
  149. '<hr size="3" />',
  150. '<hr style="height:3px;" />'
  151. );
  152. }
  153. function testHrConvertNoshade() {
  154. $this->assertResult(
  155. '<hr noshade />',
  156. '<hr style="color:#808080;background-color:#808080;border:0;" />'
  157. );
  158. }
  159. function testHrConvertAlignLeft() {
  160. $this->assertResult(
  161. '<hr align="left" />',
  162. '<hr style="margin-left:0;margin-right:auto;text-align:left;" />'
  163. );
  164. }
  165. function testHrConvertAlignCenter() {
  166. $this->assertResult(
  167. '<hr align="center" />',
  168. '<hr style="margin-left:auto;margin-right:auto;text-align:center;" />'
  169. );
  170. }
  171. function testHrConvertAlignRight() {
  172. $this->assertResult(
  173. '<hr align="right" />',
  174. '<hr style="margin-left:auto;margin-right:0;text-align:right;" />'
  175. );
  176. }
  177. function testHrRemoveInvalidAlign() {
  178. $this->assertResult(
  179. '<hr align="bottom" />',
  180. '<hr />'
  181. );
  182. }
  183. function testBrConvertClearLeft() {
  184. $this->assertResult(
  185. '<br clear="left" />',
  186. '<br style="clear:left;" />'
  187. );
  188. }
  189. function testBrConvertClearRight() {
  190. $this->assertResult(
  191. '<br clear="right" />',
  192. '<br style="clear:right;" />'
  193. );
  194. }
  195. function testBrConvertClearAll() {
  196. $this->assertResult(
  197. '<br clear="all" />',
  198. '<br style="clear:both;" />'
  199. );
  200. }
  201. function testBrConvertClearNone() {
  202. $this->assertResult(
  203. '<br clear="none" />',
  204. '<br style="clear:none;" />'
  205. );
  206. }
  207. function testBrRemoveInvalidClear() {
  208. $this->assertResult(
  209. '<br clear="foo" />',
  210. '<br />'
  211. );
  212. }
  213. function testUlConvertTypeDisc() {
  214. $this->assertResult(
  215. '<ul type="disc" />',
  216. '<ul style="list-style-type:disc;" />'
  217. );
  218. }
  219. function testUlConvertTypeSquare() {
  220. $this->assertResult(
  221. '<ul type="square" />',
  222. '<ul style="list-style-type:square;" />'
  223. );
  224. }
  225. function testUlConvertTypeCircle() {
  226. $this->assertResult(
  227. '<ul type="circle" />',
  228. '<ul style="list-style-type:circle;" />'
  229. );
  230. }
  231. function testUlConvertTypeCaseInsensitive() {
  232. $this->assertResult(
  233. '<ul type="CIRCLE" />',
  234. '<ul style="list-style-type:circle;" />'
  235. );
  236. }
  237. function testUlRemoveInvalidType() {
  238. $this->assertResult(
  239. '<ul type="a" />',
  240. '<ul />'
  241. );
  242. }
  243. function testOlConvertType1() {
  244. $this->assertResult(
  245. '<ol type="1" />',
  246. '<ol style="list-style-type:decimal;" />'
  247. );
  248. }
  249. function testOlConvertTypeLowerI() {
  250. $this->assertResult(
  251. '<ol type="i" />',
  252. '<ol style="list-style-type:lower-roman;" />'
  253. );
  254. }
  255. function testOlConvertTypeUpperI() {
  256. $this->assertResult(
  257. '<ol type="I" />',
  258. '<ol style="list-style-type:upper-roman;" />'
  259. );
  260. }
  261. function testOlConvertTypeLowerA() {
  262. $this->assertResult(
  263. '<ol type="a" />',
  264. '<ol style="list-style-type:lower-alpha;" />'
  265. );
  266. }
  267. function testOlConvertTypeUpperA() {
  268. $this->assertResult(
  269. '<ol type="A" />',
  270. '<ol style="list-style-type:upper-alpha;" />'
  271. );
  272. }
  273. function testOlRemoveInvalidType() {
  274. $this->assertResult(
  275. '<ol type="disc" />',
  276. '<ol />'
  277. );
  278. }
  279. function testLiConvertTypeCircle() {
  280. $this->assertResult(
  281. '<li type="circle" />',
  282. '<li style="list-style-type:circle;" />'
  283. );
  284. }
  285. function testLiConvertTypeA() {
  286. $this->assertResult(
  287. '<li type="A" />',
  288. '<li style="list-style-type:upper-alpha;" />'
  289. );
  290. }
  291. function testLiConvertTypeCaseSensitive() {
  292. $this->assertResult(
  293. '<li type="CIRCLE" />',
  294. '<li />'
  295. );
  296. }
  297. }
  298. // vim: et sw=4 sts=4