1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-04 21:28:06 +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:
Edward Z. Yang
2008-03-23 01:06:35 +00:00
parent 848795d4a0
commit aedfbd1e93
21 changed files with 195 additions and 110 deletions

View File

@@ -0,0 +1,7 @@
ERROR: Description in directive 'Ns.Dir' must not be empty
----
Ns
DESCRIPTION: Our namespace.
----
Ns.Dir
TYPE: int

View File

@@ -0,0 +1,8 @@
ERROR: Directive in id 'Ns.+' in directive 'Ns.+' must be alphanumeric
----
Ns
DESCRIPTION: Generic namespace.
----
ID: Ns.+
TYPE: int
DESCRIPTION: Description

View File

@@ -0,0 +1,8 @@
ERROR: Directive in id 'Ns.' in directive 'Ns.' must not be empty
----
Ns
DESCRIPTION: Our namespace
----
ID: Ns.
TYPE: int
DESCRIPTION: Description.

View File

@@ -0,0 +1,5 @@
ERROR: Namespace in id 'Rd.Dir' in directive 'Rd.Dir' does not exist
----
ID: Rd.Dir
TYPE: int
DESCRIPTION: Description

View File

@@ -0,0 +1,8 @@
ERROR: Type in directive 'Ns.Dir' is invalid
----
Ns
DESCRIPTION: Namespace
----
Ns.Dir
DESCRIPTION: Directive
TYPE: foobar

View File

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

View File

@@ -0,0 +1,3 @@
ERROR: Description in namespace 'Ns' must not be empty
----
ID: Ns

View File

@@ -0,0 +1,4 @@
ERROR: Namespace in namespace 'R&D' must be alphanumeric
----
ID: R&D
DESCRIPTION: ctype_alnum($ID) === false

View File

@@ -0,0 +1,4 @@
ERROR: Namespace in namespace '0' must not be empty
----
ID: 0
DESCRIPTION: empty($ID) === true

View File

@@ -0,0 +1,2 @@
Namespace
DESCRIPTION: This is a generic namespace.

View File

@@ -0,0 +1,7 @@
ERROR: Cannot redefine namespace 'Ns'
----
ID: Ns
DESCRIPTION: Version 1
----
ID: Ns
DESCRIPTION: Version 2

View File

@@ -19,7 +19,7 @@ class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
}
public function testAssertIsStringFail() {
$this->expectValidationException("Member variable 'property' in context must be a string");
$this->expectValidationException("Property in context must be a string");
$this->makeAtom(3)->assertIsString();
}
@@ -28,7 +28,7 @@ class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
}
public function testAssertNotNullFail() {
$this->expectValidationException("Member variable 'property' in context must not be null");
$this->expectValidationException("Property in context must not be null");
$this->makeAtom(null)->assertNotNull();
}
@@ -37,12 +37,12 @@ class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
}
public function testAssertAlnumFail() {
$this->expectValidationException("Member variable 'property' in context must be alphanumeric");
$this->expectValidationException("Property in context must be alphanumeric");
$this->makeAtom('%a')->assertAlnum();
}
public function testAssertAlnumFailIsString() {
$this->expectValidationException("Member variable 'property' in context must be a string");
$this->expectValidationException("Property in context must be a string");
$this->makeAtom(3)->assertAlnum();
}
@@ -51,7 +51,7 @@ class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
}
public function testAssertNotEmptyFail() {
$this->expectValidationException("Member variable 'property' in context must not be empty");
$this->expectValidationException("Property in context must not be empty");
$this->makeAtom('')->assertNotEmpty();
}

View File

@@ -1,75 +0,0 @@
<?php
class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
{
protected $interchange, $validator;
public function setup() {
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
}
/**
* Adds a namespace to our interchange object.
*/
protected function addNamespace($namespace, $description) {
$obj = new HTMLPurifier_ConfigSchema_Interchange_Namespace();
$obj->namespace = $namespace;
$obj->description = $description;
$this->interchange->addNamespace($obj);
return $obj;
}
protected function addDirective($namespace, $directive, $type = 'string', $description = 'Description') {
$obj = new HTMLPurifier_ConfigSchema_Interchange_Directive();
$obj->id = $this->makeId($namespace, $directive);
$obj->type = $type;
$obj->description = $description;
$this->interchange->addDirective($obj);
return $obj; // for future editing
}
protected function makeId($namespace, $directive) {
return new HTMLPurifier_ConfigSchema_Interchange_Id($namespace, $directive);
}
/**
* Invokes a validation, so we can fish for exceptions
*/
protected function validate() {
$this->validator->validate($this->interchange);
}
protected function expectValidationException($msg) {
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
}
public function testNamespace() {
$this->addNamespace('Namespace', 'This is a generic namespace');
$this->validate();
}
public function testNamespaceNamespaceNotEmpty() {
$this->addNamespace('0', 'Description');
$this->expectValidationException("Member variable 'namespace' in namespace '0' must not be empty");
$this->validate();
}
public function testNamespaceNamespaceAlnum() {
$this->addNamespace('%', 'Description');
$this->expectValidationException("Member variable 'namespace' in namespace '%' must be alphanumeric");
$this->validate();
}
public function testNamespaceDescriptionNotEmpty() {
$this->addNamespace('Ns', '');
$this->expectValidationException("Member variable 'description' in namespace 'Ns' must not be empty");
$this->validate();
}
public function testDirectiveIdNamespaceNotEmpty() {
$this->addDirective('', 'Dir');
}
}

View File

@@ -0,0 +1,42 @@
<?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::UnitTestCase($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();
}
}