first commit

This commit is contained in:
aschwarz
2023-02-23 10:52:06 +01:00
commit 8bb9cee456
2426 changed files with 471082 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<?php
class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase
{
protected $interchange;
public function setup()
{
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
}
public function testAddDirective()
{
$v = new HTMLPurifier_ConfigSchema_Interchange_Directive();
$v->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Namespace.Directive');
$this->interchange->addDirective($v);
$this->assertIdentical($v, $this->interchange->directives['Namespace.Directive']);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,13 @@
ERROR: Alias 'Ns.BothWantThisName' in aliases in directive 'Ns.Dir2' collides with alias for directive 'Ns.Dir'
----
Ns.Dir
DESCRIPTION: Directive
TYPE: int
DEFAULT: 3
ALIASES: Ns.BothWantThisName
----
Ns.Dir2
DESCRIPTION: Directive
TYPE: string
DEFAULT: 'a'
ALIASES: Ns.BothWantThisName

View File

@ -0,0 +1,12 @@
ERROR: Alias 'Ns.Innocent' in aliases in directive 'Ns.Dir' collides with another directive
----
Ns.Innocent
DESCRIPTION: Innocent directive
TYPE: int
DEFAULT: 3
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string
DEFAULT: 'a'
ALIASES: Ns.Innocent

View File

@ -0,0 +1,7 @@
ERROR: Value 3 in allowed in directive 'Ns.Dir' must be a string
----
ID: Ns.Dir
TYPE: string
DESCRIPTION: Description
DEFAULT: 'asdf'
ALLOWED: 'asdf', 3

View File

@ -0,0 +1,7 @@
ERROR: Allowed in directive 'Ns.Dir' must not be empty
----
ID: Ns.Dir
TYPE: string
DESCRIPTION: Description
DEFAULT: 'asdf'
ALLOWED:

View File

@ -0,0 +1,7 @@
ERROR: Default in directive 'Ns.Dir' must be an allowed value
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string
DEFAULT: 'a'
ALLOWED: 'b'

View File

@ -0,0 +1,5 @@
Ns.Dir
DESCRIPTION: Directive
TYPE: string/null
DEFAULT: null
ALLOWED: 'a'

View File

@ -0,0 +1,6 @@
ERROR: Expected type string, got integer in DEFAULT in directive hash 'Ns.Dir'
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string
DEFAULT: 0

View File

@ -0,0 +1,5 @@
ERROR: Description in directive 'Ns.Dir' must not be empty
----
Ns.Dir
TYPE: int
DEFAULT: 0

View File

@ -0,0 +1,3 @@
Ns
DESCRIPTION: Namespace

View File

@ -0,0 +1,5 @@
ERROR: TYPE in directive hash 'Ns.Dir' not defined
----
Ns.Dir
DESCRIPTION: Notice that TYPE is missing
DEFAULT: 0

View File

@ -0,0 +1,6 @@
ERROR: Invalid type 'foobar' in DEFAULT in directive hash 'Ns.Dir'
----
Ns.Dir
DESCRIPTION: Directive
TYPE: foobar
DEFAULT: 0

View File

@ -0,0 +1,7 @@
ERROR: Type in directive 'Ns.Dir' must be a string type when used with allowed or value aliases
----
Ns.Dir
DESCRIPTION: Directive
TYPE: int
DEFAULT: 3
ALLOWED: 1, 2, 3

View File

@ -0,0 +1,7 @@
ERROR: Type in directive 'Ns.Dir' must be a string type when used with allowed or value aliases
----
Ns.Dir
DESCRIPTION: Directive
TYPE: int
DEFAULT: 3
VALUE-ALIASES: 2 => 3

View File

@ -0,0 +1,11 @@
ERROR: Cannot redefine directive 'Ns.Dir'
----
ID: Ns.Dir
DESCRIPTION: Version 1
TYPE: int
DEFAULT: 0
----
ID: Ns.Dir
DESCRIPTION: Version 2
TYPE: int
DEFAULT: 0

View File

@ -0,0 +1,7 @@
ERROR: Alias 3 in valueAliases in directive 'Ns.Dir' must be a string
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string
DEFAULT: 'a'
VALUE-ALIASES: 3 => 'a'

View File

@ -0,0 +1,8 @@
ERROR: Alias 'b' in valueAliases in directive 'Ns.Dir' must not be an allowed value
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string
DEFAULT: 'a'
ALLOWED: 'a', 'b', 'c'
VALUE-ALIASES: 'b' => 'c'

View File

@ -0,0 +1,7 @@
ERROR: Alias 'bar' in valueAliases in directive 'Ns.Dir' must not be an alias to itself
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string
DEFAULT: 'foo'
VALUE-ALIASES: 'bar' => 'bar'

View File

@ -0,0 +1,8 @@
ERROR: Alias 'c' in valueAliases in directive 'Ns.Dir' must be an alias to an allowed value
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string
DEFAULT: 'a'
ALLOWED: 'a', 'b'
VALUE-ALIASES: 'c' => 'd'

View File

@ -0,0 +1,7 @@
ERROR: Alias target 3 from alias 'b' in valueAliases in directive 'Ns.Dir' must be a string
----
Ns.Dir
DESCRIPTION: Directive
TYPE: string
DEFAULT: 'a'
VALUE-ALIASES: 'b' => 3

View File

@ -0,0 +1,110 @@
<?php
class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
{
protected function expectValidationException($msg)
{
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
}
protected function makeAtom($value)
{
$obj = new stdClass();
$obj->property = $value;
// Note that 'property' and 'context' are magic wildcard values
return new HTMLPurifier_ConfigSchema_ValidatorAtom('context', $obj, 'property');
}
public function testAssertIsString()
{
$this->makeAtom('foo')->assertIsString();
}
public function testAssertIsStringFail()
{
$this->expectValidationException("Property in context must be a string");
$this->makeAtom(3)->assertIsString();
}
public function testAssertNotNull()
{
$this->makeAtom('foo')->assertNotNull();
}
public function testAssertNotNullFail()
{
$this->expectValidationException("Property in context must not be null");
$this->makeAtom(null)->assertNotNull();
}
public function testAssertAlnum()
{
$this->makeAtom('foo2')->assertAlnum();
}
public function testAssertAlnumFail()
{
$this->expectValidationException("Property in context must be alphanumeric");
$this->makeAtom('%a')->assertAlnum();
}
public function testAssertAlnumFailIsString()
{
$this->expectValidationException("Property in context must be a string");
$this->makeAtom(3)->assertAlnum();
}
public function testAssertNotEmpty()
{
$this->makeAtom('foo')->assertNotEmpty();
}
public function testAssertNotEmptyFail()
{
$this->expectValidationException("Property in context must not be empty");
$this->makeAtom('')->assertNotEmpty();
}
public function testAssertIsBool()
{
$this->makeAtom(false)->assertIsBool();
}
public function testAssertIsBoolFail()
{
$this->expectValidationException("Property in context must be a boolean");
$this->makeAtom('0')->assertIsBool();
}
public function testAssertIsArray()
{
$this->makeAtom(array())->assertIsArray();
}
public function testAssertIsArrayFail()
{
$this->expectValidationException("Property in context must be an array");
$this->makeAtom('asdf')->assertIsArray();
}
public function testAssertIsLookup()
{
$this->makeAtom(array('foo' => true))->assertIsLookup();
}
public function testAssertIsLookupFail()
{
$this->expectValidationException("Property in context must be a lookup array");
$this->makeAtom(array('foo' => 4))->assertIsLookup();
}
public function testAssertIsLookupFailIsArray()
{
$this->expectValidationException("Property in context must be an array");
$this->makeAtom('asdf')->assertIsLookup();
}
}
// vim: et sw=4 sts=4

View File

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

View File

@ -0,0 +1,47 @@
<?php
/**
* Controller for validator test-cases.
*/
class HTMLPurifier_ConfigSchema_ValidatorTestCase extends UnitTestCase
{
protected $_path, $_parser, $_builder;
public $validator;
public function __construct($path)
{
$this->_path = $path;
$this->_parser = new HTMLPurifier_StringHashParser();
$this->_builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
parent::__construct($path);
}
public function setup()
{
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
}
public function testValidator()
{
$hashes = $this->_parser->parseMultiFile($this->_path);
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
$error = null;
foreach ($hashes as $hash) {
if (!isset($hash['ID'])) {
if (isset($hash['ERROR'])) {
$this->expectException(
new HTMLPurifier_ConfigSchema_Exception($hash['ERROR'])
);
}
continue;
}
$this->_builder->build($interchange, new HTMLPurifier_StringHash($hash));
}
$this->validator->validate($interchange);
$this->pass();
}
}
// vim: et sw=4 sts=4