mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 03:10:09 +02:00
[3.1.0] Refactor out validation framework for Interchange
- Implement IdExists validator git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1584 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Interchange_Validator_IdExistsTest extends HTMLPurifier_ConfigSchema_Interchange_ValidatorHarness
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Interchange_Validator_IdExists($this->mock);
|
||||
}
|
||||
|
||||
public function testNamespace() {
|
||||
$this->mock->expectNever('addNamespace');
|
||||
$this->expectSchemaException('Namespace must have ID');
|
||||
$this->validator->addNamespace();
|
||||
}
|
||||
|
||||
public function testDirective() {
|
||||
$this->mock->expectNever('addDirective');
|
||||
$this->expectSchemaException('Directive must have ID');
|
||||
$this->validator->addDirective();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Interchange_ValidatorHarness extends UnitTestCase
|
||||
{
|
||||
|
||||
protected $validator;
|
||||
protected $mock;
|
||||
|
||||
public function setup() {
|
||||
generate_mock_once('HTMLPurifier_ConfigSchema_Interchange');
|
||||
$this->mock = new HTMLPurifier_ConfigSchema_InterchangeMock();
|
||||
}
|
||||
|
||||
protected function expectSchemaException($msg) {
|
||||
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
|
||||
}
|
||||
|
||||
}
|
@@ -12,33 +12,17 @@ class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase
|
||||
public function testAddNamespace() {
|
||||
$this->interchange->addNamespace($v = array(
|
||||
'ID' => 'Namespace',
|
||||
'Foo' => 'Bar',
|
||||
'DESCRIPTION' => 'Bar',
|
||||
));
|
||||
$this->assertIdentical($v, $this->interchange->namespaces['Namespace']);
|
||||
}
|
||||
|
||||
public function testAddNamespaceError() {
|
||||
try {
|
||||
$this->interchange->addNamespace(array());
|
||||
} catch (HTMLPurifier_ConfigSchema_Exception $e) {
|
||||
$this->assertIdentical($e->getMessage(), 'Namespace must have ID');
|
||||
}
|
||||
$this->assertIdentical($v, $this->interchange->getNamespace('Namespace'));
|
||||
}
|
||||
|
||||
public function testAddDirective() {
|
||||
$this->interchange->addDirective($v = array(
|
||||
'ID' => 'Namespace.Directive',
|
||||
'Foo' => 'Bar',
|
||||
'DESCRIPTION' => 'Bar',
|
||||
));
|
||||
$this->assertIdentical($v, $this->interchange->directives['Namespace.Directive']);
|
||||
}
|
||||
|
||||
public function testAddDirectiveError() {
|
||||
try {
|
||||
$this->interchange->addDirective(array());
|
||||
} catch (HTMLPurifier_ConfigSchema_Exception $e) {
|
||||
$this->assertIdentical($e->getMessage(), 'Directive must have ID');
|
||||
}
|
||||
$this->assertIdentical($v, $this->interchange->getDirective('Namespace.Directive'));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user