1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-06 06:07:26 +02:00

Generic implementation of property-lists.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang
2008-12-06 00:43:42 -05:00
parent 90110a4e3a
commit 3a6b63dff1
4 changed files with 188 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
<?php
class HTMLPurifier_PropertyListTest extends UnitTestCase
{
function testBasic() {
$plist = new HTMLPurifier_PropertyList();
$plist->set('key', 'value');
$this->assertIdentical($plist->get('key'), 'value');
}
function testNotFound() {
$this->expectException(new HTMLPurifier_Exception("Key 'key' not found"));
$plist = new HTMLPurifier_PropertyList();
$plist->get('key');
}
function testRecursion() {
$parent_plist = new HTMLPurifier_PropertyList();
$parent_plist->set('key', 'value');
$plist = new HTMLPurifier_PropertyList();
$plist->setParent($parent_plist);
$this->assertIdentical($plist->get('key'), 'value');
}
function testOverride() {
$parent_plist = new HTMLPurifier_PropertyList();
$parent_plist->set('key', 'value');
$plist = new HTMLPurifier_PropertyList();
$plist->setParent($parent_plist);
$plist->set('key', 'value2');
$this->assertIdentical($plist->get('key'), 'value2');
}
function testRecursionNotFound() {
$this->expectException(new HTMLPurifier_Exception("Key 'key' not found"));
$parent_plist = new HTMLPurifier_PropertyList();
$plist = new HTMLPurifier_PropertyList();
$plist->setParent($parent_plist);
$this->assertIdentical($plist->get('key'), 'value');
}
function testHas() {
$plist = new HTMLPurifier_PropertyList();
$this->assertIdentical($plist->has('key'), false);
$plist->set('key', 'value');
$this->assertIdentical($plist->has('key'), true);
}
function testReset() {
$plist = new HTMLPurifier_PropertyList();
$plist->set('key1', 'value');
$plist->set('key2', 'value');
$plist->set('key3', 'value');
$this->assertIdentical($plist->has('key1'), true);
$this->assertIdentical($plist->has('key2'), true);
$this->assertIdentical($plist->has('key3'), true);
$plist->reset('key2');
$this->assertIdentical($plist->has('key1'), true);
$this->assertIdentical($plist->has('key2'), false);
$this->assertIdentical($plist->has('key3'), true);
$plist->reset();
$this->assertIdentical($plist->has('key1'), false);
$this->assertIdentical($plist->has('key2'), false);
$this->assertIdentical($plist->has('key3'), false);
}
function testIterator() {
$plist = new HTMLPurifier_PropertyList();
$plist->set('nkey1', 'v');
$plist->set('nkey2', 'v');
$plist->set('rkey3', 'v');
$a = array();
foreach ($plist->getIterator() as $key => $value) {
$a[$key] = $value;
}
$this->assertIdentical($a, array('nkey1' => 'v', 'nkey2' => 'v', 'rkey3' => 'v'));
$a = array();
foreach ($plist->getIterator('nkey') as $key => $value) {
$a[$key] = $value;
}
$this->assertIdentical($a, array('nkey1' => 'v', 'nkey2' => 'v'));
}
}