mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-04 05:07:55 +02:00
[1.7.0] Configuration object now finalizes itself after first read operation
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1075 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -42,6 +42,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
CS::define('Element', 'Object', new stdClass(), 'mixed', 'Model representation.');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
// test default value retrieval
|
||||
$this->assertIdentical($config->get('Element', 'Abbr'), 'H');
|
||||
@@ -65,6 +66,12 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
$config->set('Element', 'IsotopeNames', array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
|
||||
$config->set('Element', 'Object', false); // unmodeled
|
||||
|
||||
$this->expectError('Cannot set undefined directive to value');
|
||||
$config->set('Element', 'Metal', true);
|
||||
|
||||
$this->expectError('Value is of invalid type');
|
||||
$config->set('Element', 'Radioactive', 'very');
|
||||
|
||||
// test value retrieval
|
||||
$this->assertIdentical($config->get('Element', 'Abbr'), 'Pu');
|
||||
$this->assertIdentical($config->get('Element', 'Name'), 'plutonium');
|
||||
@@ -76,17 +83,9 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
$this->assertIdentical($config->get('Element', 'IsotopeNames'), array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
|
||||
$this->assertIdentical($config->get('Element', 'Object'), false);
|
||||
|
||||
// errors
|
||||
|
||||
$this->expectError('Cannot retrieve value of undefined directive');
|
||||
$config->get('Element', 'Metal');
|
||||
|
||||
$this->expectError('Cannot set undefined directive to value');
|
||||
$config->set('Element', 'Metal', true);
|
||||
|
||||
$this->expectError('Value is of invalid type');
|
||||
$config->set('Element', 'Radioactive', 'very');
|
||||
|
||||
}
|
||||
|
||||
function testEnumerated() {
|
||||
@@ -108,6 +107,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
'synth' => 'electronic'));
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
// case sensitive
|
||||
|
||||
@@ -143,6 +143,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
CS::define('ReportCard', 'Absences', 0, 'int', 'How many times missing from school?');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
$config->set('ReportCard', 'English', 'B-');
|
||||
$this->assertIdentical($config->get('ReportCard', 'English'), 'B-');
|
||||
@@ -158,11 +159,12 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
|
||||
function testAliases() {
|
||||
|
||||
HTMLPurifier_ConfigSchema::defineNamespace('Home', 'Sweet home.');
|
||||
HTMLPurifier_ConfigSchema::define('Home', 'Rug', 3, 'int', 'ID.');
|
||||
HTMLPurifier_ConfigSchema::defineAlias('Home', 'Carpet', 'Home', 'Rug');
|
||||
CS::defineNamespace('Home', 'Sweet home.');
|
||||
CS::define('Home', 'Rug', 3, 'int', 'ID.');
|
||||
CS::defineAlias('Home', 'Carpet', 'Home', 'Rug');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
$this->assertIdentical($config->get('Home', 'Rug'), 3);
|
||||
|
||||
@@ -183,6 +185,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
CS::define('Variables', 'AngularAcceleration', 'alpha', 'string', 'In rad/s^2');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
// grab a namespace
|
||||
$this->assertIdentical(
|
||||
@@ -207,6 +210,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
CS::define('Shortcut', 'Cut', 'x', 'istring', 'Cut text');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
$config->loadIni(dirname(__FILE__) . '/ConfigTest-loadIni.ini');
|
||||
|
||||
@@ -224,6 +228,7 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
$this->old_copy = HTMLPurifier_ConfigSchema::instance($this->old_copy);
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
$def = $config->getCSSDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
|
||||
@@ -253,9 +258,10 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
}
|
||||
|
||||
function test_getCSSDefinition() {
|
||||
$this->old_copy = HTMLPurifier_ConfigSchema::instance($this->old_copy);
|
||||
$this->old_copy = CS::instance($this->old_copy);
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
$def = $config->getCSSDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
|
||||
@@ -263,11 +269,11 @@ 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(
|
||||
CS::defineNamespace('Zoo', 'Animals we have.');
|
||||
CS::define('Zoo', 'Aadvark', 0, 'int', 'Have?');
|
||||
CS::define('Zoo', 'Boar', 0, 'int', 'Have?');
|
||||
CS::define('Zoo', 'Camel', 0, 'int', 'Have?');
|
||||
CS::define(
|
||||
'Zoo', 'Others', array(), 'list', 'Other animals we have one of.'
|
||||
);
|
||||
|
||||
@@ -305,9 +311,9 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
|
||||
function test_create() {
|
||||
|
||||
HTMLPurifier_ConfigSchema::defineNamespace('Cake', 'Properties of it.');
|
||||
HTMLPurifier_ConfigSchema::define('Cake', 'Sprinkles', 666, 'int', 'Number of.');
|
||||
HTMLPurifier_ConfigSchema::define('Cake', 'Flavor', 'vanilla', 'string', 'Flavor of the batter.');
|
||||
CS::defineNamespace('Cake', 'Properties of it.');
|
||||
CS::define('Cake', 'Sprinkles', 666, 'int', 'Number of.');
|
||||
CS::define('Cake', 'Flavor', 'vanilla', 'string', 'Flavor of the batter.');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('Cake', 'Sprinkles', 42);
|
||||
@@ -326,6 +332,31 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
||||
|
||||
}
|
||||
|
||||
function test_finalize() {
|
||||
|
||||
// test finalization
|
||||
|
||||
CS::defineNamespace('Poem', 'Violets are red, roses are blue...');
|
||||
CS::define('Poem', 'Meter', 'iambic', 'string', 'Rhythm of poem.');
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->autoFinalize = false;
|
||||
|
||||
$config->set('Poem', 'Meter', 'irregular');
|
||||
|
||||
$config->finalize();
|
||||
|
||||
$this->expectError('Cannot set directive after finalization');
|
||||
$config->set('Poem', 'Meter', 'vedic');
|
||||
|
||||
$this->expectError('Cannot load directives after finalization');
|
||||
$config->loadArray(array('Poem.Meter' => 'octosyllable'));
|
||||
|
||||
$this->expectError('Cannot load directives after finalization');
|
||||
$config->loadIni(dirname(__FILE__) . '/ConfigTest-finalize.ini');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user