merge from 1.6 ( html purifier lib )

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10579 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ovclas 2012-04-20 07:34:00 +00:00
parent 8943ff97f3
commit 7ea7157ce7
813 changed files with 65203 additions and 0 deletions

View file

@ -0,0 +1,21 @@
<?php
class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase
{
protected $interchange;
public function setup() {
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
}
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,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,92 @@
<?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');
}
function testAssertIsString() {
$this->makeAtom('foo')->assertIsString();
}
function testAssertIsStringFail() {
$this->expectValidationException("Property in context must be a string");
$this->makeAtom(3)->assertIsString();
}
function testAssertNotNull() {
$this->makeAtom('foo')->assertNotNull();
}
function testAssertNotNullFail() {
$this->expectValidationException("Property in context must not be null");
$this->makeAtom(null)->assertNotNull();
}
function testAssertAlnum() {
$this->makeAtom('foo2')->assertAlnum();
}
function testAssertAlnumFail() {
$this->expectValidationException("Property in context must be alphanumeric");
$this->makeAtom('%a')->assertAlnum();
}
function testAssertAlnumFailIsString() {
$this->expectValidationException("Property in context must be a string");
$this->makeAtom(3)->assertAlnum();
}
function testAssertNotEmpty() {
$this->makeAtom('foo')->assertNotEmpty();
}
function testAssertNotEmptyFail() {
$this->expectValidationException("Property in context must not be empty");
$this->makeAtom('')->assertNotEmpty();
}
function testAssertIsBool() {
$this->makeAtom(false)->assertIsBool();
}
function testAssertIsBoolFail() {
$this->expectValidationException("Property in context must be a boolean");
$this->makeAtom('0')->assertIsBool();
}
function testAssertIsArray() {
$this->makeAtom(array())->assertIsArray();
}
function testAssertIsArrayFail() {
$this->expectValidationException("Property in context must be an array");
$this->makeAtom('asdf')->assertIsArray();
}
function testAssertIsLookup() {
$this->makeAtom(array('foo' => true))->assertIsLookup();
}
function testAssertIsLookupFail() {
$this->expectValidationException("Property in context must be a lookup array");
$this->makeAtom(array('foo' => 4))->assertIsLookup();
}
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,101 @@
<?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();
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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,44 @@
<?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();
}
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