You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

401 lines
9.7KB

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