mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-03-11 17:18:44 +00:00
Implement ParseDefault.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1608 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
b65942a2c5
commit
e83573a3ad
library
tests/HTMLPurifier/ConfigSchema/Validator
@ -138,6 +138,7 @@ require 'HTMLPurifier/ConfigSchema/Validator/Composite.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Validator/Exists.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Validator/NamespaceExists.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Validator/Or.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Validator/ParseDefault.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Validator/ParseId.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Validator/ParseType.php';
|
||||
require 'HTMLPurifier/ConfigSchema/Validator/Unique.php';
|
||||
|
@ -66,6 +66,7 @@ class HTMLPurifier_ConfigSchema_Interchange
|
||||
$directive->addValidator($this->make('Exists', '_TYPE'));
|
||||
$directive->addValidator($this->make('Exists', '_NULL'));
|
||||
$directive->addValidator($this->make('Exists', 'DEFAULT'));
|
||||
$directive->addValidator($this->make('ParseDefault'));
|
||||
|
||||
// Common tests
|
||||
$validator->addValidator($this->make('Exists', 'DESCRIPTION'));
|
||||
|
18
library/HTMLPurifier/ConfigSchema/Validator/ParseDefault.php
Normal file
18
library/HTMLPurifier/ConfigSchema/Validator/ParseDefault.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Parses DEFAULT into _DEFAULT. Expects DEFAULT, _TYPE, _NULL and ID to exist.
|
||||
*/
|
||||
class HTMLPurifier_ConfigSchema_Validator_ParseDefault extends HTMLPurifier_ConfigSchema_Validator
|
||||
{
|
||||
|
||||
public function validate(&$arr, $interchange) {
|
||||
$parser = new HTMLPurifier_VarParser_Native(); // not configurable yet
|
||||
try {
|
||||
$arr['_DEFAULT'] = $parser->parse($arr['DEFAULT'], $arr['_TYPE'], $arr['_NULL']);
|
||||
} catch (HTMLPurifier_VarParserException $e) {
|
||||
throw new HTMLPurifier_ConfigSchema_Exception('Invalid type for default value in '. $arr['ID'] .': ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_ParseDefaultTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function testValidate() {
|
||||
$arr = array(
|
||||
'ID' => 'N.D',
|
||||
'DEFAULT' => 'true',
|
||||
'_TYPE' => 'bool',
|
||||
'_NULL' => false,
|
||||
);
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
$this->assertIdentical($arr, array(
|
||||
'ID' => 'N.D',
|
||||
'DEFAULT' => 'true',
|
||||
'_TYPE' => 'bool',
|
||||
'_NULL' => false,
|
||||
'_DEFAULT' => true,
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateFail() {
|
||||
$arr = array(
|
||||
'ID' => 'N.D',
|
||||
'DEFAULT' => '"asdf"',
|
||||
'_TYPE' => 'int',
|
||||
'_NULL' => true,
|
||||
);
|
||||
$this->expectSchemaException('Invalid type for default value in N.D: Expected type int, got string');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user