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:
@@ -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');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user