1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-30 19:00:10 +02:00

[3.1.0] Initial validator implementation for namespaces.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1622 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-03-22 20:26:04 +00:00
parent 56cfcba5d1
commit 34ba0e408f
6 changed files with 175 additions and 3 deletions

View File

@@ -0,0 +1,69 @@
<?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);
}
/**
* 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 testNamespaceNamespaceString() {
$this->addNamespace(3, 'Description');
$this->expectValidationException("Member variable 'namespace' in namespace '3' must be a string");
$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 testNamespaceDescriptionString() {
$this->addNamespace('Ns', 3);
$this->expectValidationException("Member variable 'description' in namespace 'Ns' must be a string");
$this->validate();
}
public function testNamespaceDescriptionNotEmpty() {
$this->addNamespace('Ns', '');
$this->expectValidationException("Member variable 'description' in namespace 'Ns' must not be empty");
$this->validate();
}
}