2006-08-11 20:23:41 +00:00
|
|
|
<?php
|
|
|
|
|
2007-08-01 14:06:59 +00:00
|
|
|
class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
2006-08-11 20:23:41 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
protected $schema;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
public function setUp() {
|
2006-09-30 18:55:17 +00:00
|
|
|
// set up a dummy schema object for testing
|
2008-02-16 00:40:30 +00:00
|
|
|
$this->schema = new HTMLPurifier_ConfigSchema();
|
2006-08-27 18:49:16 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// test functionality based on ConfigSchema
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
function testNormal() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Element.Abbr', 'H', 'string', false);
|
|
|
|
$this->schema->add('Element.Name', 'hydrogen', 'istring', false);
|
|
|
|
$this->schema->add('Element.Number', 1, 'int', false);
|
|
|
|
$this->schema->add('Element.Mass', 1.00794, 'float', false);
|
|
|
|
$this->schema->add('Element.Radioactive', false, 'bool', false);
|
|
|
|
$this->schema->add('Element.Isotopes', array(1 => true, 2 => true, 3 => true), 'lookup', false);
|
|
|
|
$this->schema->add('Element.Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', false);
|
|
|
|
$this->schema->add('Element.IsotopeNames', array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'), 'hash', false);
|
|
|
|
$this->schema->add('Element.Object', new stdClass(), 'mixed', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->autoFinalize = false;
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->chatty = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// test default value retrieval
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->assertIdentical($config->get('Element.Abbr'), 'H');
|
|
|
|
$this->assertIdentical($config->get('Element.Name'), 'hydrogen');
|
|
|
|
$this->assertIdentical($config->get('Element.Number'), 1);
|
|
|
|
$this->assertIdentical($config->get('Element.Mass'), 1.00794);
|
|
|
|
$this->assertIdentical($config->get('Element.Radioactive'), false);
|
|
|
|
$this->assertIdentical($config->get('Element.Isotopes'), array(1 => true, 2 => true, 3 => true));
|
|
|
|
$this->assertIdentical($config->get('Element.Traits'), array('nonmetallic', 'odorless', 'flammable'));
|
|
|
|
$this->assertIdentical($config->get('Element.IsotopeNames'), array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'));
|
|
|
|
$this->assertIdentical($config->get('Element.Object'), new stdClass());
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// test setting values
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Element.Abbr', 'Pu');
|
|
|
|
$config->set('Element.Name', 'PLUTONIUM'); // test decaps
|
|
|
|
$config->set('Element.Number', '94'); // test parsing
|
|
|
|
$config->set('Element.Mass', '244.'); // test parsing
|
|
|
|
$config->set('Element.Radioactive', true);
|
|
|
|
$config->set('Element.Isotopes', array(238, 239)); // test inversion
|
|
|
|
$config->set('Element.Traits', 'nuclear, heavy, actinide'); // test parsing
|
|
|
|
$config->set('Element.IsotopeNames', array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
|
|
|
|
$config->set('Element.Object', false); // unmodeled
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-16 20:21:00 +00:00
|
|
|
$this->expectError('Cannot set undefined directive Element.Metal to value');
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Element.Metal', true);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-16 20:21:00 +00:00
|
|
|
$this->expectError('Value for Element.Radioactive is of invalid type, should be bool');
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Element.Radioactive', 'very');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// test value retrieval
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->assertIdentical($config->get('Element.Abbr'), 'Pu');
|
|
|
|
$this->assertIdentical($config->get('Element.Name'), 'plutonium');
|
|
|
|
$this->assertIdentical($config->get('Element.Number'), 94);
|
|
|
|
$this->assertIdentical($config->get('Element.Mass'), 244.);
|
|
|
|
$this->assertIdentical($config->get('Element.Radioactive'), true);
|
|
|
|
$this->assertIdentical($config->get('Element.Isotopes'), array(238 => true, 239 => true));
|
|
|
|
$this->assertIdentical($config->get('Element.Traits'), array('nuclear', 'heavy', 'actinide'));
|
|
|
|
$this->assertIdentical($config->get('Element.IsotopeNames'), array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
|
|
|
|
$this->assertIdentical($config->get('Element.Object'), false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-16 20:21:00 +00:00
|
|
|
$this->expectError('Cannot retrieve value of undefined directive Element.Metal');
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->get('Element.Metal');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
function testEnumerated() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// case sensitive
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Instrument.Manufacturer', 'Yamaha', 'string', false);
|
|
|
|
$this->schema->addAllowedValues('Instrument.Manufacturer', array(
|
2008-03-22 03:55:59 +00:00
|
|
|
'Yamaha' => true, 'Conn-Selmer' => true, 'Vandoren' => true,
|
|
|
|
'Laubin' => true, 'Buffet' => true, 'other' => true));
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->addValueAliases('Instrument.Manufacturer', array(
|
2007-01-21 04:37:02 +00:00
|
|
|
'Selmer' => 'Conn-Selmer'));
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// case insensitive
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Instrument.Family', 'woodwind', 'istring', false);
|
|
|
|
$this->schema->addAllowedValues('Instrument.Family', array(
|
2008-03-22 03:55:59 +00:00
|
|
|
'brass' => true, 'woodwind' => true, 'percussion' => true,
|
|
|
|
'string' => true, 'keyboard' => true, 'electronic' => true));
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->addValueAliases('Instrument.Family', array(
|
2007-01-21 04:37:02 +00:00
|
|
|
'synth' => 'electronic'));
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->autoFinalize = false;
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->chatty = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// case sensitive
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Instrument.Manufacturer', 'Vandoren');
|
|
|
|
$this->assertIdentical($config->get('Instrument.Manufacturer'), 'Vandoren');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Instrument.Manufacturer', 'Selmer');
|
|
|
|
$this->assertIdentical($config->get('Instrument.Manufacturer'), 'Conn-Selmer');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-16 20:21:00 +00:00
|
|
|
$this->expectError('Value not supported, valid values are: Yamaha, Conn-Selmer, Vandoren, Laubin, Buffet, other');
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Instrument.Manufacturer', 'buffet');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// case insensitive
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Instrument.Family', 'brass');
|
|
|
|
$this->assertIdentical($config->get('Instrument.Family'), 'brass');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Instrument.Family', 'PERCUSSION');
|
|
|
|
$this->assertIdentical($config->get('Instrument.Family'), 'percussion');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Instrument.Family', 'synth');
|
|
|
|
$this->assertIdentical($config->get('Instrument.Family'), 'electronic');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Instrument.Family', 'Synth');
|
|
|
|
$this->assertIdentical($config->get('Instrument.Family'), 'electronic');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
function testNull() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('ReportCard.English', null, 'string', true);
|
|
|
|
$this->schema->add('ReportCard.Absences', 0, 'int', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->autoFinalize = false;
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->chatty = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('ReportCard.English', 'B-');
|
|
|
|
$this->assertIdentical($config->get('ReportCard.English'), 'B-');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('ReportCard.English', null); // not yet graded
|
|
|
|
$this->assertIdentical($config->get('ReportCard.English'), null);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// error
|
2007-06-16 20:21:00 +00:00
|
|
|
$this->expectError('Value for ReportCard.Absences is of invalid type, should be int');
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('ReportCard.Absences', null);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
function testAliases() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Home.Rug', 3, 'int', false);
|
|
|
|
$this->schema->addAlias('Home.Carpet', 'Home.Rug');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->autoFinalize = false;
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->chatty = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->assertIdentical($config->get('Home.Rug'), 3);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-16 20:21:00 +00:00
|
|
|
$this->expectError('Cannot get value from aliased directive, use real name Home.Rug');
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->get('Home.Carpet');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-03 21:53:06 +00:00
|
|
|
$this->expectError('Home.Carpet is an alias, preferred directive name is Home.Rug');
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Home.Carpet', 999);
|
|
|
|
$this->assertIdentical($config->get('Home.Rug'), 999);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
// test functionality based on method
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 04:37:02 +00:00
|
|
|
function test_getBatch() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Variables.TangentialAcceleration', 'a_tan', 'string', false);
|
|
|
|
$this->schema->add('Variables.AngularAcceleration', 'alpha', 'string', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->autoFinalize = false;
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->chatty = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-24 07:12:16 +00:00
|
|
|
// grab a namespace
|
|
|
|
$this->assertIdentical(
|
2007-01-21 04:37:02 +00:00
|
|
|
$config->getBatch('Variables'),
|
2006-11-24 07:12:16 +00:00
|
|
|
array(
|
2007-01-21 04:37:02 +00:00
|
|
|
'TangentialAcceleration' => 'a_tan',
|
|
|
|
'AngularAcceleration' => 'alpha'
|
2006-11-24 07:12:16 +00:00
|
|
|
)
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-24 07:12:16 +00:00
|
|
|
// grab a non-existant namespace
|
2007-06-16 20:21:00 +00:00
|
|
|
$this->expectError('Cannot retrieve undefined namespace Constants');
|
2007-01-21 04:37:02 +00:00
|
|
|
$config->getBatch('Constants');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-11 20:23:41 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 14:29:46 +00:00
|
|
|
function test_loadIni() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Shortcut.Copy', 'c', 'istring', false);
|
|
|
|
$this->schema->add('Shortcut.Paste', 'v', 'istring', false);
|
|
|
|
$this->schema->add('Shortcut.Cut', 'x', 'istring', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->autoFinalize = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 14:29:46 +00:00
|
|
|
$config->loadIni(dirname(__FILE__) . '/ConfigTest-loadIni.ini');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->assertIdentical($config->get('Shortcut.Copy'), 'q');
|
|
|
|
$this->assertIdentical($config->get('Shortcut.Paste'), 'p');
|
|
|
|
$this->assertIdentical($config->get('Shortcut.Cut'), 't');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 14:29:46 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 01:44:06 +00:00
|
|
|
function test_getHTMLDefinition() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-16 23:58:33 +00:00
|
|
|
// we actually want to use the old copy, because the definition
|
|
|
|
// generation routines have dependencies on configuration values
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-09-30 18:55:17 +00:00
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('HTML.Doctype', 'XHTML 1.0 Strict');
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->autoFinalize = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 01:44:06 +00:00
|
|
|
$def = $config->getCSSDefinition();
|
|
|
|
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-23 02:40:17 +00:00
|
|
|
$def = $config->getHTMLDefinition();
|
|
|
|
$def2 = $config->getHTMLDefinition();
|
2006-09-30 18:55:17 +00:00
|
|
|
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
|
2008-04-23 02:40:17 +00:00
|
|
|
$this->assertSame($def, $def2);
|
2007-02-14 01:44:06 +00:00
|
|
|
$this->assertTrue($def->setup);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-23 02:40:17 +00:00
|
|
|
$old_def = clone $def2;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
|
2007-02-14 01:44:06 +00:00
|
|
|
$def = $config->getHTMLDefinition();
|
|
|
|
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
|
2008-04-23 02:40:17 +00:00
|
|
|
$this->assertNotEqual($def, $old_def);
|
2007-02-14 01:44:06 +00:00
|
|
|
$this->assertTrue($def->setup);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 01:44:06 +00:00
|
|
|
// test retrieval of raw definition
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()');
|
|
|
|
$config->set('HTML.DefinitionRev', 3);
|
2008-04-23 02:40:17 +00:00
|
|
|
$def = $config->getHTMLDefinition(true);
|
|
|
|
$this->assertNotEqual($def, $old_def);
|
2007-06-23 14:05:09 +00:00
|
|
|
$this->assertEqual(false, $def->setup);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 01:44:06 +00:00
|
|
|
// auto initialization
|
|
|
|
$config->getHTMLDefinition();
|
|
|
|
$this->assertTrue($def->setup);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 01:44:06 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-16 20:21:00 +00:00
|
|
|
function test_getHTMLDefinition_rawError() {
|
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
2008-04-23 02:40:17 +00:00
|
|
|
$this->expectException(new HTMLPurifier_Exception('Cannot retrieve raw version without specifying %HTML.DefinitionID'));
|
|
|
|
$def = $config->getHTMLDefinition(true);
|
2007-06-16 20:21:00 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-14 01:44:06 +00:00
|
|
|
function test_getCSSDefinition() {
|
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
2006-09-30 18:55:17 +00:00
|
|
|
$def = $config->getCSSDefinition();
|
|
|
|
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-16 20:21:00 +00:00
|
|
|
function test_getDefinition() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Cache.DefinitionImpl', null, 'string', true);
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2008-04-23 02:40:17 +00:00
|
|
|
$this->expectException(new HTMLPurifier_Exception("Definition of Crust type not supported"));
|
2007-06-16 20:21:00 +00:00
|
|
|
$config->getDefinition('Crust');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-10-21 18:18:36 +00:00
|
|
|
function test_loadArray() {
|
|
|
|
// setup a few dummy namespaces/directives for our testing
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Zoo.Aadvark', 0, 'int', false);
|
|
|
|
$this->schema->add('Zoo.Boar', 0, 'int', false);
|
|
|
|
$this->schema->add('Zoo.Camel', 0, 'int', false);
|
|
|
|
$this->schema->add('Zoo.Others', array(), 'list', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config_manual = new HTMLPurifier_Config($this->schema);
|
|
|
|
$config_loadabbr = new HTMLPurifier_Config($this->schema);
|
|
|
|
$config_loadfull = new HTMLPurifier_Config($this->schema);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$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!
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-10-21 18:18:36 +00:00
|
|
|
// condensed form
|
|
|
|
$config_loadabbr->loadArray(array(
|
|
|
|
'Zoo.Aadvark' => 3,
|
|
|
|
'Zoo.Boar' => 5,
|
|
|
|
'Zoo.Camel' => 2000,
|
|
|
|
'Zoo.Others' => array('Peacock', 'Dodo')
|
|
|
|
));
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-10-21 18:18:36 +00:00
|
|
|
// fully expanded form
|
|
|
|
$config_loadfull->loadArray(array(
|
|
|
|
'Zoo' => array(
|
|
|
|
'Aadvark' => 3,
|
|
|
|
'Boar' => 5,
|
|
|
|
'Camel' => 2000,
|
|
|
|
'Others' => array('Peacock', 'Dodo')
|
|
|
|
)
|
|
|
|
));
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical($config_manual, $config_loadabbr);
|
|
|
|
$this->assertIdentical($config_manual, $config_loadfull);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-10-21 18:18:36 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-12-15 02:12:03 +00:00
|
|
|
function test_create() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Cake.Sprinkles', 666, 'int', false);
|
|
|
|
$this->schema->add('Cake.Flavor', 'vanilla', 'string', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Cake.Sprinkles', 42);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-12-15 02:12:03 +00:00
|
|
|
// test flat pass-through
|
2008-02-16 00:40:30 +00:00
|
|
|
$created_config = HTMLPurifier_Config::create($config, $this->schema);
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical($config, $created_config);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-12-15 02:12:03 +00:00
|
|
|
// test loadArray
|
2008-02-16 00:40:30 +00:00
|
|
|
$created_config = HTMLPurifier_Config::create(array('Cake.Sprinkles' => 42), $this->schema);
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical($config, $created_config);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-01-21 14:29:46 +00:00
|
|
|
// test loadIni
|
2008-02-16 00:40:30 +00:00
|
|
|
$created_config = HTMLPurifier_Config::create(dirname(__FILE__) . '/ConfigTest-create.ini', $this->schema);
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical($config, $created_config);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-12-15 02:12:03 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 18:06:51 +00:00
|
|
|
function test_finalize() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 18:06:51 +00:00
|
|
|
// test finalization
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Poem.Meter', 'iambic', 'string', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->autoFinalize = false;
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->chatty = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Poem.Meter', 'irregular');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 18:06:51 +00:00
|
|
|
$config->finalize();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 18:06:51 +00:00
|
|
|
$this->expectError('Cannot set directive after finalization');
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('Poem.Meter', 'vedic');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 18:06:51 +00:00
|
|
|
$this->expectError('Cannot load directives after finalization');
|
|
|
|
$config->loadArray(array('Poem.Meter' => 'octosyllable'));
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 18:06:51 +00:00
|
|
|
$this->expectError('Cannot load directives after finalization');
|
|
|
|
$config->loadIni(dirname(__FILE__) . '/ConfigTest-finalize.ini');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 18:06:51 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-09 01:56:19 +00:00
|
|
|
function test_loadArrayFromForm() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Pancake.Mix', 'buttermilk', 'string', false);
|
|
|
|
$this->schema->add('Pancake.Served', true, 'bool', false);
|
|
|
|
$this->schema->add('Toppings.Syrup', true, 'bool', false);
|
|
|
|
$this->schema->add('Toppings.Flavor', 'maple', 'string', false);
|
|
|
|
$this->schema->add('Toppings.Strawberries', 3, 'int', false);
|
|
|
|
$this->schema->add('Toppings.Calories', 2000, 'int', true);
|
|
|
|
$this->schema->add('Toppings.DefinitionID', null, 'string', true);
|
|
|
|
$this->schema->add('Toppings.DefinitionRev', 1, 'int', false);
|
|
|
|
$this->schema->add('Toppings.Protected', 1, 'int', false);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-25 18:38:39 +00:00
|
|
|
$get = array(
|
|
|
|
'breakfast' => array(
|
|
|
|
'Pancake.Mix' => 'nasty',
|
|
|
|
'Pancake.Served' => '0',
|
|
|
|
'Toppings.Syrup' => '0',
|
2007-06-26 03:34:29 +00:00
|
|
|
'Toppings.Flavor' => "juice",
|
2007-06-25 18:38:39 +00:00
|
|
|
'Toppings.Strawberries' => '999',
|
|
|
|
'Toppings.Calories' => '',
|
|
|
|
'Null_Toppings.Calories' => '1',
|
|
|
|
'Toppings.DefinitionID' => '<argh>',
|
|
|
|
'Toppings.DefinitionRev' => '65',
|
|
|
|
'Toppings.Protected' => '4',
|
|
|
|
)
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-25 18:38:39 +00:00
|
|
|
$config_expect = HTMLPurifier_Config::create(array(
|
|
|
|
'Pancake.Served' => false,
|
|
|
|
'Toppings.Syrup' => false,
|
2007-06-26 03:34:29 +00:00
|
|
|
'Toppings.Flavor' => "juice",
|
2007-06-25 18:38:39 +00:00
|
|
|
'Toppings.Strawberries' => 999,
|
|
|
|
'Toppings.Calories' => null
|
2008-02-16 00:40:30 +00:00
|
|
|
), $this->schema);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-02-16 00:40:30 +00:00
|
|
|
$config_result = HTMLPurifier_Config::loadArrayFromForm(
|
|
|
|
$get, 'breakfast',
|
|
|
|
array('Pancake.Served', 'Toppings', '-Toppings.Protected'),
|
2008-03-01 18:09:52 +00:00
|
|
|
false, // mq fix
|
2008-02-16 00:40:30 +00:00
|
|
|
$this->schema
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-25 18:38:39 +00:00
|
|
|
$this->assertEqual($config_expect, $config_result);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-26 03:34:29 +00:00
|
|
|
/*
|
|
|
|
MAGIC QUOTES NOT TESTED!!!
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-25 18:38:39 +00:00
|
|
|
$get = array(
|
|
|
|
'breakfast' => array(
|
|
|
|
'Pancake.Mix' => 'n\\asty'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$config_expect = HTMLPurifier_Config::create(array(
|
|
|
|
'Pancake.Mix' => 'n\\asty'
|
|
|
|
));
|
|
|
|
$config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', true, false);
|
|
|
|
$this->assertEqual($config_expect, $config_result);
|
2007-06-26 03:34:29 +00:00
|
|
|
*/
|
2007-06-25 18:38:39 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-25 18:38:39 +00:00
|
|
|
function test_getAllowedDirectivesForForm() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->schema->add('Unused.Unused', 'Foobar', 'string', false);
|
|
|
|
$this->schema->add('Partial.Allowed', true, 'bool', false);
|
|
|
|
$this->schema->add('Partial.Unused', 'Foobar', 'string', false);
|
|
|
|
$this->schema->add('All.Allowed', true, 'bool', false);
|
|
|
|
$this->schema->add('All.Blacklisted', 'Foobar', 'string', false); // explicitly blacklisted
|
|
|
|
$this->schema->add('All.DefinitionID', 'Foobar', 'string', true); // auto-blacklisted
|
|
|
|
$this->schema->add('All.DefinitionRev', 2, 'int', false); // auto-blacklisted
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-25 18:38:39 +00:00
|
|
|
$input = array('Partial.Allowed', 'All', '-All.Blacklisted');
|
2008-02-16 00:40:30 +00:00
|
|
|
$output = HTMLPurifier_Config::getAllowedDirectivesForForm($input, $this->schema);
|
2007-06-25 18:38:39 +00:00
|
|
|
$expect = array(
|
|
|
|
array('Partial', 'Allowed'),
|
|
|
|
array('All', 'Allowed')
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-25 18:38:39 +00:00
|
|
|
$this->assertEqual($output, $expect);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-25 18:38:39 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
function testDeprecatedAPI() {
|
|
|
|
$this->schema->add('Foo.Bar', 2, 'int', false);
|
|
|
|
$config = new HTMLPurifier_Config($this->schema);
|
|
|
|
$config->chatty = false;
|
|
|
|
$this->expectError('Using deprecated API: use $config->set(\'Foo.Bar\', ...) instead');
|
|
|
|
$config->set('Foo', 'Bar', 4);
|
|
|
|
$this->expectError('Using deprecated API: use $config->get(\'Foo.Bar\') instead');
|
|
|
|
$this->assertIdentical($config->get('Foo', 'Bar'), 4);
|
|
|
|
}
|
2006-08-11 20:23:41 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|