1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 19:30:21 +02:00

[3.1.1] Memory optimizations for ConfigSchema. Changes include:

- Elimination of ConfigDef and subclasses in favor of stdclass. Most property names stay the same
- Added benchmark script for ConfigSchema
- Types are internally handled as magic integers. Use HTMLPurifier_VarParser->getTypeName to convert to human readable form. HTMLPurifier_VarParser still accepts strings.
- Parser in config schema only used for legacy interface


git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1764 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-05-23 16:43:24 +00:00
parent 9db891c3aa
commit 8ab30e24b7
18 changed files with 171 additions and 218 deletions

View File

@@ -21,16 +21,12 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
$this->schema->add('Car', 'Seats', 5, 'int', false);
$this->assertIdentical($this->schema->defaults['Car']['Seats'], 5);
$this->assertIdentical($this->schema->info['Car']['Seats'],
new HTMLPurifier_ConfigDef_Directive('int')
);
$this->assertIdentical($this->schema->info['Car']['Seats']->type, HTMLPurifier_VarParser::INT);
$this->schema->add('Car', 'Age', null, 'int', true);
$this->assertIdentical($this->schema->defaults['Car']['Age'], null);
$this->assertIdentical($this->schema->info['Car']['Age'],
new HTMLPurifier_ConfigDef_Directive('int', true)
);
$this->assertIdentical($this->schema->info['Car']['Age']->type, HTMLPurifier_VarParser::INT);
}
@@ -45,15 +41,13 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
);
$this->assertIdentical($this->schema->defaults['QuantumNumber']['Difficulty'], null);
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty'],
new HTMLPurifier_ConfigDef_Directive(
'string',
true,
array(
'easy' => true,
'medium' => true,
'hard' => true
)
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->type, HTMLPurifier_VarParser::STRING);
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allow_null, true);
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allowed,
array(
'easy' => true,
'medium' => true,
'hard' => true
)
);
@@ -82,20 +76,19 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
);
$this->assertIdentical($this->schema->defaults['Abbrev']['HTH'], 'Happy to Help');
$this->assertIdentical($this->schema->info['Abbrev']['HTH'],
new HTMLPurifier_ConfigDef_Directive(
'string',
false,
array(
'Happy to Help' => true,
'Hope that Helps' => true,
'HAIL THE HAND!' => true
),
array(
'happy' => 'Happy to Help',
'hope' => 'Hope that Helps',
'hail' => 'HAIL THE HAND!'
)
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->type, HTMLPurifier_VarParser::STRING);
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->allowed,
array(
'Happy to Help' => true,
'Hope that Helps' => true,
'HAIL THE HAND!' => true
)
);
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->aliases,
array(
'happy' => 'Happy to Help',
'hope' => 'Hope that Helps',
'hail' => 'HAIL THE HAND!'
)
);
@@ -107,9 +100,9 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
$this->schema->addAlias('Home', 'Carpet', 'Home', 'Rug');
$this->assertTrue(!isset($this->schema->defaults['Home']['Carpet']));
$this->assertIdentical($this->schema->info['Home']['Carpet'],
new HTMLPurifier_ConfigDef_DirectiveAlias('Home', 'Rug')
);
$this->assertIdentical($this->schema->info['Home']['Carpet']->namespace, 'Home');
$this->assertIdentical($this->schema->info['Home']['Carpet']->name, 'Rug');
$this->assertIdentical($this->schema->info['Home']['Carpet']->isAlias, true);
}

View File

@@ -29,6 +29,14 @@ class HTMLPurifier_SimpleTest_Reporter extends HTMLReporter
flush();
}
public function paintFooter($test_name) {
if (function_exists('xdebug_peak_memory_usage')) {
$max_mem = number_format(xdebug_peak_memory_usage());
echo "<div>Max memory usage: $max_mem bytes</div>";
}
parent::paintFooter($test_name);
}
protected function getCss() {
$css = parent::getCss();
$css .= '

View File

@@ -6,7 +6,7 @@ class HTMLPurifier_VarParser_FlexibleTest extends HTMLPurifier_VarParserHarness
function testValidate() {
$this->assertValid('foobar', 'string');
$this->assertValid('foobar', 'text'); // aliases, lstring = long string
$this->assertValid('foobar', 'text');
$this->assertValid('FOOBAR', 'istring', 'foobar');
$this->assertValid('FOOBAR', 'itext', 'foobar');
@@ -51,6 +51,10 @@ class HTMLPurifier_VarParser_FlexibleTest extends HTMLPurifier_VarParserHarness
}
function testValidate_withMagicNumbers() {
$this->assertValid('foobar', HTMLPurifier_VarParser::STRING);
}
function testValidate_null() {
$this->assertIdentical($this->parser->parse(null, 'string', true), null);
$this->expectException('HTMLPurifier_VarParserException');