1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-06 06:07:26 +02:00

[3.1.0] Implement NamespaceExists and ParseId

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1599 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-03-04 05:21:04 +00:00
parent 14437cbf47
commit c0b5bc3eea
12 changed files with 114 additions and 18 deletions

View File

@@ -4,8 +4,8 @@ class HTMLPurifier_ConfigSchema_Validator_AlnumTest extends HTMLPurifier_ConfigS
{
public function setup() {
parent::setup();
$this->validator = new HTMLPurifier_ConfigSchema_Validator_Alnum('ID');
parent::setup();
}
public function testValidate() {

View File

@@ -4,8 +4,8 @@ class HTMLPurifier_ConfigSchema_Validator_ExistsTest extends HTMLPurifier_Config
{
public function setup() {
parent::setup();
$this->validator = new HTMLPurifier_ConfigSchema_Validator_Exists('ID');
parent::setup();
}
public function testValidate() {

View File

@@ -0,0 +1,18 @@
<?php
class HTMLPurifier_ConfigSchema_Validator_NamespaceExistsTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
{
public function testValidateFail() {
$arr = array('_NAMESPACE' => 'Namespace');
$this->expectSchemaException('Cannot define directive for undefined namespace Namespace');
$this->validator->validate($arr, $this->interchange);
}
public function testValidatePass() {
$arr = array('_NAMESPACE' => 'Namespace');
$this->interchange->addNamespace(array('ID' => 'Namespace'));
$this->validator->validate($arr, $this->interchange);
}
}

View File

@@ -0,0 +1,25 @@
<?php
class HTMLPurifier_ConfigSchema_Validator_ParseIdTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
{
public function testValidateNamespace() {
$arr = array('ID' => 'Namespace');
$this->validator->validate($arr, $this->interchange);
$this->assertIdentical($arr, array(
'ID' => 'Namespace',
'_NAMESPACE' => 'Namespace'
));
}
public function testValidateDirective() {
$arr = array('ID' => 'Namespace.Directive');
$this->validator->validate($arr, $this->interchange);
$this->assertIdentical($arr, array(
'ID' => 'Namespace.Directive',
'_NAMESPACE' => 'Namespace',
'_DIRECTIVE' => 'Directive'
));
}
}

View File

@@ -3,11 +3,6 @@
class HTMLPurifier_ConfigSchema_Validator_UniqueTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
{
public function setup() {
parent::setup();
$this->validator = new HTMLPurifier_ConfigSchema_Validator_Unique();
}
public function testValidateNamespace() {
$this->interchange->addNamespace(array('ID' => 'Namespace'));
$this->expectSchemaException('Cannot redefine namespace');

View File

@@ -7,6 +7,14 @@ class HTMLPurifier_ConfigSchema_ValidatorHarness extends UnitTestCase
public function setup() {
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
if (empty($this->validator)) {
$class_to_test = substr(get_class($this), 0, -4);
$this->validator = new $class_to_test;
}
}
public function teardown() {
unset($this->validator, $this->interchange);
}
protected function expectSchemaException($msg) {