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.

CSSTest.php 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
  3. {
  4. public function setup()
  5. {
  6. parent::setup();
  7. $this->def = new HTMLPurifier_AttrDef_CSS();
  8. }
  9. public function test()
  10. {
  11. // regular cases, singular
  12. $this->assertDef('text-align:right;');
  13. $this->assertDef('border-left-style:solid;');
  14. $this->assertDef('border-style:solid dotted;');
  15. $this->assertDef('clear:right;');
  16. $this->assertDef('float:left;');
  17. $this->assertDef('font-style:italic;');
  18. $this->assertDef('font-variant:small-caps;');
  19. $this->assertDef('font-weight:bold;');
  20. $this->assertDef('list-style-position:outside;');
  21. $this->assertDef('list-style-type:upper-roman;');
  22. $this->assertDef('list-style:upper-roman inside;');
  23. $this->assertDef('text-transform:capitalize;');
  24. $this->assertDef('background-color:rgb(0,0,255);');
  25. $this->assertDef('background-color:transparent;');
  26. $this->assertDef('background:#333 url("chess.png") repeat fixed 50% top;');
  27. $this->assertDef('color:#F00;');
  28. $this->assertDef('border-top-color:#F00;');
  29. $this->assertDef('border-color:#F00 #FF0;');
  30. $this->assertDef('border-top-width:thin;');
  31. $this->assertDef('border-top-width:12px;');
  32. $this->assertDef('border-width:5px 1px 4px 2px;');
  33. $this->assertDef('border-top-width:-12px;', false);
  34. $this->assertDef('letter-spacing:normal;');
  35. $this->assertDef('letter-spacing:2px;');
  36. $this->assertDef('word-spacing:normal;');
  37. $this->assertDef('word-spacing:3em;');
  38. $this->assertDef('font-size:200%;');
  39. $this->assertDef('font-size:larger;');
  40. $this->assertDef('font-size:12pt;');
  41. $this->assertDef('line-height:2;');
  42. $this->assertDef('line-height:2em;');
  43. $this->assertDef('line-height:20%;');
  44. $this->assertDef('line-height:normal;');
  45. $this->assertDef('line-height:-20%;', false);
  46. $this->assertDef('margin-left:5px;');
  47. $this->assertDef('margin-right:20%;');
  48. $this->assertDef('margin-top:auto;');
  49. $this->assertDef('margin:auto 5%;');
  50. $this->assertDef('padding-bottom:5px;');
  51. $this->assertDef('padding-top:20%;');
  52. $this->assertDef('padding:20% 10%;');
  53. $this->assertDef('padding-top:-20%;', false);
  54. $this->assertDef('text-indent:3em;');
  55. $this->assertDef('text-indent:5%;');
  56. $this->assertDef('text-indent:-3em;');
  57. $this->assertDef('width:50%;');
  58. $this->assertDef('width:50px;');
  59. $this->assertDef('width:auto;');
  60. $this->assertDef('width:-50px;', false);
  61. $this->assertDef('text-decoration:underline;');
  62. $this->assertDef('font-family:sans-serif;');
  63. $this->assertDef("font-family:Gill, 'Times New Roman', sans-serif;");
  64. $this->assertDef('font:12px serif;');
  65. $this->assertDef('border:1px solid #000;');
  66. $this->assertDef('border-bottom:2em double #FF00FA;');
  67. $this->assertDef('border-collapse:collapse;');
  68. $this->assertDef('border-collapse:separate;');
  69. $this->assertDef('caption-side:top;');
  70. $this->assertDef('vertical-align:middle;');
  71. $this->assertDef('vertical-align:12px;');
  72. $this->assertDef('vertical-align:50%;');
  73. $this->assertDef('table-layout:fixed;');
  74. $this->assertDef('list-style-image:url("nice.jpg");');
  75. $this->assertDef('list-style:disc url("nice.jpg") inside;');
  76. $this->assertDef('background-image:url("foo.jpg");');
  77. $this->assertDef('background-image:none;');
  78. $this->assertDef('background-repeat:repeat-y;');
  79. $this->assertDef('background-attachment:fixed;');
  80. $this->assertDef('background-position:left 90%;');
  81. $this->assertDef('border-spacing:1em;');
  82. $this->assertDef('border-spacing:1em 2em;');
  83. // duplicates
  84. $this->assertDef('text-align:right;text-align:left;',
  85. 'text-align:left;');
  86. // a few composites
  87. $this->assertDef('font-variant:small-caps;font-weight:900;');
  88. $this->assertDef('float:right;text-align:right;');
  89. // selective removal
  90. $this->assertDef('text-transform:capitalize;destroy:it;',
  91. 'text-transform:capitalize;');
  92. // inherit works for everything
  93. $this->assertDef('text-align:inherit;');
  94. // bad props
  95. $this->assertDef('nodice:foobar;', false);
  96. $this->assertDef('position:absolute;', false);
  97. $this->assertDef('background-image:url(\'javascript:alert\(\)\');', false);
  98. // airy input
  99. $this->assertDef(' font-weight : bold; color : #ff0000',
  100. 'font-weight:bold;color:#ff0000;');
  101. // case-insensitivity
  102. $this->assertDef('FLOAT:LEFT;', 'float:left;');
  103. // !important stripping
  104. $this->assertDef('float:left !important;', 'float:left;');
  105. }
  106. public function testProprietary()
  107. {
  108. $this->config->set('CSS.Proprietary', true);
  109. $this->assertDef('scrollbar-arrow-color:#ff0;');
  110. $this->assertDef('scrollbar-base-color:#ff6347;');
  111. $this->assertDef('scrollbar-darkshadow-color:#ffa500;');
  112. $this->assertDef('scrollbar-face-color:#008080;');
  113. $this->assertDef('scrollbar-highlight-color:#ff69b4;');
  114. $this->assertDef('scrollbar-shadow-color:#f0f;');
  115. $this->assertDef('opacity:.2;');
  116. $this->assertDef('-moz-opacity:.2;');
  117. $this->assertDef('-khtml-opacity:.2;');
  118. $this->assertDef('filter:alpha(opacity=20);');
  119. }
  120. public function testImportant()
  121. {
  122. $this->config->set('CSS.AllowImportant', true);
  123. $this->assertDef('float:left !important;');
  124. }
  125. public function testTricky()
  126. {
  127. $this->config->set('CSS.AllowTricky', true);
  128. $this->assertDef('display:none;');
  129. $this->assertDef('visibility:visible;');
  130. $this->assertDef('overflow:scroll;');
  131. }
  132. public function testForbidden()
  133. {
  134. $this->config->set('CSS.ForbiddenProperties', 'float');
  135. $this->assertDef('float:left;', false);
  136. $this->assertDef('text-align:right;');
  137. }
  138. public function testTrusted()
  139. {
  140. $this->config->set('CSS.Trusted', true);
  141. $this->assertDef('position:relative;');
  142. $this->assertDef('left:2px;');
  143. $this->assertDef('right:100%;');
  144. $this->assertDef('top:auto;');
  145. $this->assertDef('z-index:-2;');
  146. }
  147. }
  148. // vim: et sw=4 sts=4