mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
[3.1.0] Define *.vtest test hierarchy, and continue work on validator.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1625 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -11,7 +11,7 @@ class HTMLPurifier_ConfigSchema_Validator
|
||||
/**
|
||||
* Volatile context variables to provide a fluent interface.
|
||||
*/
|
||||
protected $context, $obj, $member;
|
||||
protected $context = array(), $obj, $member;
|
||||
|
||||
/**
|
||||
* Validates a fully-formed interchange object. Throws an
|
||||
@@ -28,38 +28,53 @@ class HTMLPurifier_ConfigSchema_Validator
|
||||
}
|
||||
|
||||
public function validateNamespace($n) {
|
||||
$this->context = "namespace '{$n->namespace}'";
|
||||
$this->context[] = "namespace '{$n->namespace}'";
|
||||
$this->with($n, 'namespace')
|
||||
->assertNotEmpty()
|
||||
->assertAlnum();
|
||||
$this->with($n, 'description')
|
||||
->assertIsString()
|
||||
->assertNotEmpty();
|
||||
->assertNotEmpty()
|
||||
->assertIsString(); // technically redundant
|
||||
array_pop($this->context);
|
||||
}
|
||||
|
||||
public function validateDirective($d) {
|
||||
$this->context = "directive '{$d->id}'";
|
||||
$this->context[] = "directive '{$d->id}'";
|
||||
$this->validateId($d->id);
|
||||
$this->with($d, 'description')
|
||||
->assertNotEmpty();
|
||||
if (!isset(HTMLPurifier_VarParser::$types[$d->type])) {
|
||||
$this->error('type', 'is invalid');
|
||||
}
|
||||
array_pop($this->context);
|
||||
}
|
||||
|
||||
public function validateId($id) {
|
||||
$this->context = "id '$id'";
|
||||
$this->context[] = "id '$id'";
|
||||
if (!isset($this->interchange->namespaces[$id->namespace])) {
|
||||
$this->error('namespace', 'does not exist');
|
||||
}
|
||||
$this->with($id, 'namespace')
|
||||
->assertNotEmpty()
|
||||
->assertAlnum();
|
||||
$this->with($id, 'directive')
|
||||
->assertNotEmpty()
|
||||
->assertAlnum();
|
||||
array_pop($this->context);
|
||||
}
|
||||
|
||||
// protected helper functions
|
||||
|
||||
protected function with($obj, $member) {
|
||||
return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->context, $obj, $member);
|
||||
return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->getFormattedContext(), $obj, $member);
|
||||
}
|
||||
|
||||
protected function error($msg) {
|
||||
throw new HTMLPurifier_ConfigSchema_Exception($msg . ' in ' . $this->context);
|
||||
protected function error($target, $msg) {
|
||||
throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($target) . ' in ' . $this->getFormattedContext() . ' ' . $msg);
|
||||
}
|
||||
|
||||
protected function getFormattedContext() {
|
||||
return implode(' in ', array_reverse($this->context));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user