2008-03-23 02:35:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Special test-case for cases that can't be tested using
|
|
|
|
* HTMLPurifier_ConfigSchema_ValidatorTestCase.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
|
|
|
{
|
|
|
|
public $validator, $interchange;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-23 02:35:47 +00:00
|
|
|
public function setup() {
|
|
|
|
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
|
|
|
|
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testDirectiveIntegrityViolation() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$d = $this->makeDirective('Ns.Dir');
|
|
|
|
$d->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Ns.Dir2');
|
2008-03-23 02:35:47 +00:00
|
|
|
$this->expectValidationException("Integrity violation: key 'Ns.Dir' does not match internal id 'Ns.Dir2'");
|
|
|
|
$this->validator->validate($this->interchange);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testDirectiveTypeNotEmpty() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$d = $this->makeDirective('Ns.Dir');
|
2008-03-23 02:35:47 +00:00
|
|
|
$d->default = 0;
|
|
|
|
$d->description = 'Description';
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-23 02:35:47 +00:00
|
|
|
$this->expectValidationException("Type in directive 'Ns.Dir' must not be empty");
|
|
|
|
$this->validator->validate($this->interchange);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testDirectiveDefaultInvalid() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$d = $this->makeDirective('Ns.Dir');
|
2008-03-23 02:35:47 +00:00
|
|
|
$d->default = 'asdf';
|
|
|
|
$d->type = 'int';
|
|
|
|
$d->description = 'Description';
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-23 02:35:47 +00:00
|
|
|
$this->expectValidationException("Default in directive 'Ns.Dir' had error: Expected type int, got string");
|
|
|
|
$this->validator->validate($this->interchange);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
function testDirectiveIdIsString() {
|
|
|
|
$d = $this->makeDirective(3);
|
2008-03-23 02:35:47 +00:00
|
|
|
$d->default = 0;
|
|
|
|
$d->type = 'int';
|
|
|
|
$d->description = 'Description';
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
$this->expectValidationException("Key in id '3' in directive '3' must be a string");
|
2008-03-23 02:35:47 +00:00
|
|
|
$this->validator->validate($this->interchange);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testDirectiveTypeAllowsNullIsBool() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$d = $this->makeDirective('Ns.Dir');
|
2008-04-04 21:33:37 +00:00
|
|
|
$d->default = 0;
|
|
|
|
$d->type = 'int';
|
|
|
|
$d->description = 'Description';
|
|
|
|
$d->typeAllowsNull = 'yes';
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->expectValidationException("TypeAllowsNull in directive 'Ns.Dir' must be a boolean");
|
|
|
|
$this->validator->validate($this->interchange);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testDirectiveValueAliasesIsArray() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$d = $this->makeDirective('Ns.Dir');
|
2008-04-04 21:33:37 +00:00
|
|
|
$d->default = 'a';
|
|
|
|
$d->type = 'string';
|
|
|
|
$d->description = 'Description';
|
|
|
|
$d->valueAliases = 2;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->expectValidationException("ValueAliases in directive 'Ns.Dir' must be an array");
|
|
|
|
$this->validator->validate($this->interchange);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
function testDirectiveAllowedIsLookup() {
|
2009-02-07 07:53:20 +00:00
|
|
|
$d = $this->makeDirective('Ns.Dir');
|
2008-04-04 21:33:37 +00:00
|
|
|
$d->default = 'foo';
|
|
|
|
$d->type = 'string';
|
|
|
|
$d->description = 'Description';
|
|
|
|
$d->allowed = array('foo' => 1);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-04 21:33:37 +00:00
|
|
|
$this->expectValidationException("Allowed in directive 'Ns.Dir' must be a lookup array");
|
|
|
|
$this->validator->validate($this->interchange);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-23 02:35:47 +00:00
|
|
|
// helper functions
|
2008-12-06 07:28:20 +00:00
|
|
|
|
|
|
|
|
2009-02-07 07:53:20 +00:00
|
|
|
protected function makeDirective($key) {
|
2008-03-23 02:35:47 +00:00
|
|
|
$directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
|
2009-02-07 07:53:20 +00:00
|
|
|
$directive->id = new HTMLPurifier_ConfigSchema_Interchange_Id($key);
|
2008-03-23 02:35:47 +00:00
|
|
|
$this->interchange->addDirective($directive);
|
|
|
|
return $directive;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-23 02:35:47 +00:00
|
|
|
protected function expectValidationException($msg) {
|
|
|
|
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-03-23 02:35:47 +00:00
|
|
|
}
|
2008-12-06 09:24:59 +00:00
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|