mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-11 00:24:03 +02:00
[1.2.0]
- Factor out Config and Context object population through arrays - Bring dependent assertions together in IDTest.php - AttrDefHarness.php now resets context and configuration between tests - Add missing reference operator in AttrDef/ID.php git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@494 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -26,7 +26,8 @@ class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
|
||||
$this->assertDef('.asa', false);
|
||||
|
||||
// test duplicate detection
|
||||
$this->assertDef('a', false);
|
||||
$this->assertDef('once');
|
||||
$this->assertDef('once', false);
|
||||
|
||||
// valid once whitespace stripped, but needs to be amended
|
||||
$this->assertDef(' whee ', 'whee');
|
||||
|
@@ -188,8 +188,8 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
|
||||
}
|
||||
|
||||
// the read in values
|
||||
$this->config = isset($config[$i]) ? $config[$i] : null;
|
||||
$this->context = isset($context[$i]) ? $context[$i] : null;
|
||||
$this->config = isset($config[$i]) ? $config[$i] : HTMLPurifier_Config::createDefault();
|
||||
$this->context = isset($context[$i]) ? $context[$i] : new HTMLPurifier_Context();
|
||||
|
||||
$this->assertDef($value, $expect_uri[$i], true, "Test $i: %s");
|
||||
|
||||
|
@@ -7,11 +7,14 @@ class HTMLPurifier_AttrDefHarness extends UnitTestCase
|
||||
var $context;
|
||||
var $config;
|
||||
|
||||
function setUp() {
|
||||
$this->config = HTMLPurifier_Config::createDefault();
|
||||
$this->context = new HTMLPurifier_Context();
|
||||
}
|
||||
|
||||
// cannot be used for accumulator
|
||||
function assertDef($string, $expect = true, $ini = false, $message = '%s') {
|
||||
// $expect can be a string or bool
|
||||
if (!$this->config) $this->config = HTMLPurifier_Config::createDefault();
|
||||
if (!$this->context) $this->context = new HTMLPurifier_Context();
|
||||
if ($ini) $this->setUpAssertDef();
|
||||
$result = $this->def->validate($string, $this->config, $this->context);
|
||||
if ($expect === true) {
|
||||
|
@@ -105,6 +105,48 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
|
||||
}
|
||||
|
||||
function test_loadArray() {
|
||||
// setup a few dummy namespaces/directives for our testing
|
||||
HTMLPurifier_ConfigSchema::defineNamespace('Zoo', 'Animals we have.');
|
||||
HTMLPurifier_ConfigSchema::define('Zoo', 'Aadvark', 0, 'int', 'Have?');
|
||||
HTMLPurifier_ConfigSchema::define('Zoo', 'Boar', 0, 'int', 'Have?');
|
||||
HTMLPurifier_ConfigSchema::define('Zoo', 'Camel', 0, 'int', 'Have?');
|
||||
HTMLPurifier_ConfigSchema::define(
|
||||
'Zoo', 'Others', array(), 'list', 'Other animals we have one of.'
|
||||
);
|
||||
|
||||
$config_manual = HTMLPurifier_Config::createDefault();
|
||||
$config_loadabbr = HTMLPurifier_Config::createDefault();
|
||||
$config_loadfull = HTMLPurifier_Config::createDefault();
|
||||
|
||||
$config_manual->set('Zoo', 'Aadvark', 3);
|
||||
$config_manual->set('Zoo', 'Boar', 5);
|
||||
$config_manual->set('Zoo', 'Camel', 2000); // that's a lotta camels!
|
||||
$config_manual->set('Zoo', 'Others', array('Peacock', 'Dodo')); // wtf!
|
||||
|
||||
// condensed form
|
||||
$config_loadabbr->loadArray(array(
|
||||
'Zoo.Aadvark' => 3,
|
||||
'Zoo.Boar' => 5,
|
||||
'Zoo.Camel' => 2000,
|
||||
'Zoo.Others' => array('Peacock', 'Dodo')
|
||||
));
|
||||
|
||||
// fully expanded form
|
||||
$config_loadfull->loadArray(array(
|
||||
'Zoo' => array(
|
||||
'Aadvark' => 3,
|
||||
'Boar' => 5,
|
||||
'Camel' => 2000,
|
||||
'Others' => array('Peacock', 'Dodo')
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertEqual($config_manual, $config_loadabbr);
|
||||
$this->assertEqual($config_manual, $config_loadfull);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -57,6 +57,36 @@ class HTMLPurifier_ContextTest extends UnitTestCase
|
||||
|
||||
}
|
||||
|
||||
function test_loadArray() {
|
||||
|
||||
// references can be *really* wonky!
|
||||
|
||||
$context_manual = new HTMLPurifier_Context();
|
||||
$context_load = new HTMLPurifier_Context();
|
||||
|
||||
$var1 = 1;
|
||||
$var2 = 2;
|
||||
|
||||
$context_manual->register('var1', $var1);
|
||||
$context_manual->register('var2', $var2);
|
||||
|
||||
// you MUST set up the references when constructing the array,
|
||||
// otherwise the registered version will be a copy
|
||||
$array = array(
|
||||
'var1' => &$var1,
|
||||
'var2' => &$var2
|
||||
);
|
||||
|
||||
$context_load->loadArray($array);
|
||||
$this->assertIdentical($context_manual, $context_load);
|
||||
|
||||
$var1 = 10;
|
||||
$var2 = 20;
|
||||
|
||||
$this->assertIdentical($context_manual, $context_load);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -64,16 +64,13 @@ class HTMLPurifier_Harness extends UnitTestCase
|
||||
|
||||
// setup config object
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
foreach ($config_array as $key => $value) {
|
||||
list($namespace, $directive) = explode('.', $key);
|
||||
$config->set($namespace, $directive, $value);
|
||||
}
|
||||
$config->loadArray($config_array);
|
||||
|
||||
// setup context object
|
||||
// setup context object. Note that we are operating on a copy of it!
|
||||
// We will extend the test harness to allow you to do post-tests
|
||||
// on the context object
|
||||
$context = new HTMLPurifier_Context();
|
||||
foreach ($context_array as $key => $value) {
|
||||
$context->register($key, $value);
|
||||
}
|
||||
$context->loadArray($context_array);
|
||||
|
||||
if ($this->to_tokens && is_string($input)) {
|
||||
$input = $this->lexer->tokenizeHTML($input, $config, $context);
|
||||
|
Reference in New Issue
Block a user