From 4ab930dab4d0041c7e44b7cb82e9a387063d7339 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 30 Jul 2006 15:52:25 +0000 Subject: [PATCH] Add IDAccumulator. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@129 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier/IDAccumulator.php | 27 ++++++++++++++++++++++++ tests/HTMLPurifier/IDAccumulatorTest.php | 26 +++++++++++++++++++++++ tests/index.php | 1 + 3 files changed, 54 insertions(+) create mode 100644 library/HTMLPurifier/IDAccumulator.php create mode 100644 tests/HTMLPurifier/IDAccumulatorTest.php diff --git a/library/HTMLPurifier/IDAccumulator.php b/library/HTMLPurifier/IDAccumulator.php new file mode 100644 index 00000000..a90f93f7 --- /dev/null +++ b/library/HTMLPurifier/IDAccumulator.php @@ -0,0 +1,27 @@ +ids[$id])) return false; + return $this->ids[$id] = true; + } + + function reset() { + $this->ids = array(); + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/IDAccumulatorTest.php b/tests/HTMLPurifier/IDAccumulatorTest.php new file mode 100644 index 00000000..377e973e --- /dev/null +++ b/tests/HTMLPurifier/IDAccumulatorTest.php @@ -0,0 +1,26 @@ +reset(); + + $this->assertTrue( $accumulator->add('id1')); + $this->assertTrue( $accumulator->add('id2')); + $this->assertFalse($accumulator->add('id1')); // repeated id + $accumulator->reset(); + + $this->assertTrue( $accumulator->add('id2')); // test reset + $accumulator->reset(); + + } + +} + +?> \ No newline at end of file diff --git a/tests/index.php b/tests/index.php index 5cb61927..05ec1b4a 100644 --- a/tests/index.php +++ b/tests/index.php @@ -33,6 +33,7 @@ $test->addTestFile('HTMLPurifier/Strategy/FixNestingTest.php'); $test->addTestFile('HTMLPurifier/Strategy/CompositeTest.php'); $test->addTestFile('HTMLPurifier/Strategy/CoreTest.php'); $test->addTestFile('HTMLPurifier/AttrDef/EnumTest.php'); +$test->addTestFile('HTMLPurifier/IDAccumulatorTest.php'); $test->run( new HtmlReporter() );