0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-13 00:38:42 +00:00
htmlpurifier/tests/HTMLPurifier/ConfigSchema/ValidatorTest.php
Edward Z. Yang b8f00ace1a [3.1.0]
- Add tests for the atoms.
- Add Id validation for Directives

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1623 48356398-32a2-884e-a903-53898d9a118a
2008-03-22 21:06:55 +00:00

76 lines
2.5 KiB
PHP

<?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');
}
}