aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2012-05-12 17:57:41 -0700
committerfriendica <info@friendica.com>2012-07-18 20:40:31 +1000
commit7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a (patch)
treea9c3d91209cff770bb4b613b1b95e61a7bbc5a2b /lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php
parentcd727cb26b78a1dade09d510b071446898477356 (diff)
downloadvolse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.tar.gz
volse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.tar.bz2
volse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.zip
some important stuff we'll need
Diffstat (limited to 'lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php')
-rw-r--r--lib/htmlpurifier/tests/HTMLPurifier/AttrDef/HTML/IDTest.php108
1 files changed, 108 insertions, 0 deletions
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