aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML
diff options
context:
space:
mode:
Diffstat (limited to 'lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML')
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php22
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/ClassTest.php48
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php20
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php28
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php108
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php32
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php21
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php28
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php35
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php45
10 files changed, 387 insertions, 0 deletions
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php
new file mode 100644
index 000000000..060d0fc8f
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/BoolTest.php
@@ -0,0 +1,22 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_BoolTest extends HTMLPurifier_AttrDefHarness
+{
+
+ function test() {
+ $this->def = new HTMLPurifier_AttrDef_HTML_Bool('foo');
+ $this->assertDef('foo');
+ $this->assertDef('', false);
+ $this->assertDef('bar', 'foo');
+ }
+
+ function test_make() {
+ $factory = new HTMLPurifier_AttrDef_HTML_Bool();
+ $def = $factory->make('foo');
+ $def2 = new HTMLPurifier_AttrDef_HTML_Bool('foo');
+ $this->assertIdentical($def, $def2);
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/ClassTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/ClassTest.php
new file mode 100644
index 000000000..6effd3cde
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/ClassTest.php
@@ -0,0 +1,48 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_ClassTest extends HTMLPurifier_AttrDef_HTML_NmtokensTest
+{
+ function setUp() {
+ parent::setUp();
+ $this->def = new HTMLPurifier_AttrDef_HTML_Class();
+ }
+ function testAllowedClasses() {
+ $this->config->set('Attr.AllowedClasses', array('foo'));
+ $this->assertDef('foo');
+ $this->assertDef('bar', false);
+ $this->assertDef('foo bar', 'foo');
+ }
+ function testForbiddenClasses() {
+ $this->config->set('Attr.ForbiddenClasses', array('bar'));
+ $this->assertDef('foo');
+ $this->assertDef('bar', false);
+ $this->assertDef('foo bar', 'foo');
+ }
+ function testDefault() {
+ $this->assertDef('valid');
+ $this->assertDef('a0-_');
+ $this->assertDef('-valid');
+ $this->assertDef('_valid');
+ $this->assertDef('double valid');
+
+ $this->assertDef('0stillvalid');
+ $this->assertDef('-0');
+
+ // test conditional replacement
+ $this->assertDef('validassoc 0valid', 'validassoc 0valid');
+
+ // test whitespace leniency
+ $this->assertDef(" double\nvalid\r", 'double valid');
+
+ // test case sensitivity
+ $this->assertDef('VALID');
+
+ // test duplicate removal
+ $this->assertDef('valid valid', 'valid');
+ }
+ function testXHTML11Behavior() {
+ $this->config->set('HTML.Doctype', 'XHTML 1.1');
+ $this->assertDef('0invalid', false);
+ $this->assertDef('valid valid', 'valid');
+ }
+}
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php
new file mode 100644
index 000000000..8b4a46347
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php
@@ -0,0 +1,20 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness
+{
+
+ function test() {
+ $this->def = new HTMLPurifier_AttrDef_HTML_Color();
+ $this->assertDef('', false);
+ $this->assertDef('foo', false);
+ $this->assertDef('43', false);
+ $this->assertDef('red', '#FF0000');
+ $this->assertDef('#FF0000');
+ $this->assertDef('#453443');
+ $this->assertDef('453443', '#453443');
+ $this->assertDef('#345', '#334455');
+ $this->assertDef('120', '#112200');
+ }
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php
new file mode 100644
index 000000000..7d3e24c75
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php
@@ -0,0 +1,28 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_FrameTargetTest extends HTMLPurifier_AttrDefHarness
+{
+
+ function setup() {
+ parent::setup();
+ $this->def = new HTMLPurifier_AttrDef_HTML_FrameTarget();
+ }
+
+ function testNoneAllowed() {
+ $this->assertDef('', false);
+ $this->assertDef('foo', false);
+ $this->assertDef('_blank', false);
+ $this->assertDef('baz', false);
+ }
+
+ function test() {
+ $this->config->set('Attr.AllowedFrameTargets', 'foo,_blank');
+ $this->assertDef('', false);
+ $this->assertDef('foo');
+ $this->assertDef('_blank');
+ $this->assertDef('baz', false);
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php
new file mode 100644
index 000000000..245db16da
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php
@@ -0,0 +1,108 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
+{
+
+ function setUp() {
+ parent::setUp();
+
+ $id_accumulator = new HTMLPurifier_IDAccumulator();
+ $this->context->register('IDAccumulator', $id_accumulator);
+ $this->config->set('Attr.EnableID', true);
+ $this->def = new HTMLPurifier_AttrDef_HTML_ID();
+
+ }
+
+ function test() {
+
+ // valid ID names
+ $this->assertDef('alpha');
+ $this->assertDef('al_ha');
+ $this->assertDef('a0-:.');
+ $this->assertDef('a');
+
+ // invalid ID names
+ $this->assertDef('<asa', false);
+ $this->assertDef('0123', false);
+ $this->assertDef('.asa', false);
+
+ // test duplicate detection
+ $this->assertDef('once');
+ $this->assertDef('once', false);
+
+ // valid once whitespace stripped, but needs to be amended
+ $this->assertDef(' whee ', 'whee');
+
+ }
+
+ function testPrefix() {
+
+ $this->config->set('Attr.IDPrefix', 'user_');
+
+ $this->assertDef('alpha', 'user_alpha');
+ $this->assertDef('<asa', false);
+ $this->assertDef('once', 'user_once');
+ $this->assertDef('once', false);
+
+ // if already prefixed, leave alone
+ $this->assertDef('user_alas');
+ $this->assertDef('user_user_alas'); // how to bypass
+
+ }
+
+ function testTwoPrefixes() {
+
+ $this->config->set('Attr.IDPrefix', 'user_');
+ $this->config->set('Attr.IDPrefixLocal', 'story95_');
+
+ $this->assertDef('alpha', 'user_story95_alpha');
+ $this->assertDef('<asa', false);
+ $this->assertDef('once', 'user_story95_once');
+ $this->assertDef('once', false);
+
+ $this->assertDef('user_story95_alas');
+ $this->assertDef('user_alas', 'user_story95_user_alas'); // !
+ }
+
+ function testLocalPrefixWithoutMainPrefix() {
+ // no effect when IDPrefix isn't set
+ $this->config->set('Attr.IDPrefix', '');
+ $this->config->set('Attr.IDPrefixLocal', 'story95_');
+ $this->expectError('%Attr.IDPrefixLocal cannot be used unless '.
+ '%Attr.IDPrefix is set');
+ $this->assertDef('amherst');
+
+ }
+
+ // reference functionality is disabled for now
+ function disabled_testIDReference() {
+
+ $this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
+
+ $this->assertDef('good_id');
+ $this->assertDef('good_id'); // duplicates okay
+ $this->assertDef('<b>', false);
+
+ $this->def = new HTMLPurifier_AttrDef_HTML_ID();
+
+ $this->assertDef('good_id');
+ $this->assertDef('good_id', false); // duplicate now not okay
+
+ $this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
+
+ $this->assertDef('good_id'); // reference still okay
+
+ }
+
+ function testRegexp() {
+
+ $this->config->set('Attr.IDBlacklistRegexp', '/^g_/');
+
+ $this->assertDef('good_id');
+ $this->assertDef('g_bad_id', false);
+
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php
new file mode 100644
index 000000000..d165e30b5
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/LengthTest.php
@@ -0,0 +1,32 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_LengthTest extends HTMLPurifier_AttrDef_HTML_PixelsTest
+{
+
+ function setup() {
+ $this->def = new HTMLPurifier_AttrDef_HTML_Length();
+ }
+
+ function test() {
+
+ // pixel check
+ parent::test();
+
+ // percent check
+ $this->assertDef('25%');
+
+ // Firefox maintains percent, so will we
+ $this->assertDef('0%');
+
+ // 0% <= percent <= 100%
+ $this->assertDef('-15%', '0%');
+ $this->assertDef('120%', '100%');
+
+ // fractional percents, apparently, aren't allowed
+ $this->assertDef('56.5%', '56%');
+
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php
new file mode 100644
index 000000000..d90b65b1f
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php
@@ -0,0 +1,21 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_LinkTypesTest extends HTMLPurifier_AttrDefHarness
+{
+
+ function testNull() {
+
+ $this->def = new HTMLPurifier_AttrDef_HTML_LinkTypes('rel');
+ $this->config->set('Attr.AllowedRel', array('nofollow', 'foo'));
+
+ $this->assertDef('', false);
+ $this->assertDef('nofollow', true);
+ $this->assertDef('nofollow foo', true);
+ $this->assertDef('nofollow bar', 'nofollow');
+ $this->assertDef('bar', false);
+
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php
new file mode 100644
index 000000000..eb6f34011
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php
@@ -0,0 +1,28 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_MultiLengthTest extends HTMLPurifier_AttrDef_HTML_LengthTest
+{
+
+ function setup() {
+ $this->def = new HTMLPurifier_AttrDef_HTML_MultiLength();
+ }
+
+ function test() {
+
+ // length check
+ parent::test();
+
+ $this->assertDef('*');
+ $this->assertDef('1*', '*');
+ $this->assertDef('56*');
+
+ $this->assertDef('**', false); // plain old bad
+
+ $this->assertDef('5.4*', '5*'); // no decimals
+ $this->assertDef('-3*', false); // no negatives
+
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php
new file mode 100644
index 000000000..bb64ff6e2
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php
@@ -0,0 +1,35 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_NmtokensTest extends HTMLPurifier_AttrDefHarness
+{
+
+ function setUp() {
+ parent::setUp();
+ $this->def = new HTMLPurifier_AttrDef_HTML_Nmtokens();
+ }
+
+ function testDefault() {
+
+ $this->assertDef('valid');
+ $this->assertDef('a0-_');
+ $this->assertDef('-valid');
+ $this->assertDef('_valid');
+ $this->assertDef('double valid');
+
+ $this->assertDef('0invalid', false);
+ $this->assertDef('-0', false);
+
+ // test conditional replacement
+ $this->assertDef('validassoc 0invalid', 'validassoc');
+
+ // test whitespace leniency
+ $this->assertDef(" double\nvalid\r", 'double valid');
+
+ // test case sensitivity
+ $this->assertDef('VALID');
+
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php
new file mode 100644
index 000000000..08f25be64
--- /dev/null
+++ b/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php
@@ -0,0 +1,45 @@
+<?php
+
+class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness
+{
+
+ function setup() {
+ $this->def = new HTMLPurifier_AttrDef_HTML_Pixels();
+ }
+
+ function test() {
+
+ $this->assertDef('1');
+ $this->assertDef('0');
+
+ $this->assertDef('2px', '2'); // rm px suffix
+
+ $this->assertDef('dfs', false); // totally invalid value
+
+ // conceivably we could repair this value, but we won't for now
+ $this->assertDef('9in', false);
+
+ // test trim
+ $this->assertDef(' 45 ', '45');
+
+ // no negatives
+ $this->assertDef('-2', '0');
+
+ // remove empty
+ $this->assertDef('', false);
+
+ // round down
+ $this->assertDef('4.9', '4');
+
+ }
+
+ function test_make() {
+ $factory = new HTMLPurifier_AttrDef_HTML_Pixels();
+ $this->def = $factory->make('30');
+ $this->assertDef('25');
+ $this->assertDef('35', '30');
+ }
+
+}
+
+// vim: et sw=4 sts=4