diff --git a/library/HTMLPurifier.includes.php b/library/HTMLPurifier.includes.php
index 511175c9..7f78c017 100644
--- a/library/HTMLPurifier.includes.php
+++ b/library/HTMLPurifier.includes.php
@@ -129,6 +129,8 @@ require 'HTMLPurifier/ConfigSchema/StringHash.php';
require 'HTMLPurifier/ConfigSchema/StringHashAdapter.php';
require 'HTMLPurifier/ConfigSchema/StringHashParser.php';
require 'HTMLPurifier/ConfigSchema/StringHashReverseAdapter.php';
+require 'HTMLPurifier/ConfigSchema/Interchange/Validator.php';
+require 'HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php';
require 'HTMLPurifier/DefinitionCache/Decorator.php';
require 'HTMLPurifier/DefinitionCache/Null.php';
require 'HTMLPurifier/DefinitionCache/Serializer.php';
diff --git a/library/HTMLPurifier/ConfigSchema/Interchange.php b/library/HTMLPurifier/ConfigSchema/Interchange.php
index a155dff4..5bfe1128 100644
--- a/library/HTMLPurifier/ConfigSchema/Interchange.php
+++ b/library/HTMLPurifier/ConfigSchema/Interchange.php
@@ -11,11 +11,11 @@ class HTMLPurifier_ConfigSchema_Interchange
/**
* Hash table of allowed types.
*/
- public $types = array(
+ protected $types = array(
'string' => 'String',
'istring' => 'Case-insensitive string',
'text' => 'Text',
- 'itext' => 'Case-insensitive text',
+ 'itext' => 'Case-insensitive text',
'int' => 'Integer',
'float' => 'Float',
'bool' => 'Boolean',
@@ -28,18 +28,34 @@ class HTMLPurifier_ConfigSchema_Interchange
/**
* Array of Namespace ID => array(namespace info)
*/
- public $namespaces;
+ protected $namespaces;
/**
* Array of Directive ID => array(directive info)
*/
- public $directives;
+ protected $directives;
+
+ /** Get all namespaces */
+ public function getNamespaces() {return $this->namespaces;}
+ /** Get a namespace */
+ public function getNamespace($id) {return $this->namespaces[$id];}
+ /** Check if a namespace exists */
+ public function namespaceExists($id) {return isset($this->namespaces[$id]);}
+
+ /** Get all directives */
+ public function getDirectives() {return $this->directives;}
+ /** Get a directive */
+ public function getDirective($id) {return $this->directives[$id];}
+ /** Check if a directive exists */
+ public function directiveExists($id) {return isset($this->directives[$id]);}
+
+ /** Get all types */
+ public function getTypes() {return $this->types;}
/**
* Adds a namespace array to $namespaces
*/
public function addNamespace($arr) {
- if (!isset($arr['ID'])) throw new HTMLPurifier_ConfigSchema_Exception('Namespace must have ID');
$this->namespaces[$arr['ID']] = $arr;
}
@@ -47,8 +63,17 @@ class HTMLPurifier_ConfigSchema_Interchange
* Adds a directive array to $directives
*/
public function addDirective($arr) {
- if (!isset($arr['ID'])) throw new HTMLPurifier_ConfigSchema_Exception('Directive must have ID');
$this->directives[$arr['ID']] = $arr;
}
+ /**
+ * Retrieves a version of this object wrapped in the validator adapter
+ * to be used for data-input.
+ */
+ public function getValidatorAdapter() {
+ return
+ new HTMLPurifier_ConfigSchema_Interchange_Validator_IdExists(
+ $this);
+ }
+
}
diff --git a/library/HTMLPurifier/ConfigSchema/Interchange/Validator.php b/library/HTMLPurifier/ConfigSchema/Interchange/Validator.php
new file mode 100644
index 00000000..fae8557d
--- /dev/null
+++ b/library/HTMLPurifier/ConfigSchema/Interchange/Validator.php
@@ -0,0 +1,43 @@
+decorate($i);
+ }
+
+ /** Wrap this decorator around an object. */
+ public function decorate($i) {
+ $this->interchange = $i;
+ }
+
+ public function getNamespaces() {
+ return $this->interchange->getNamespaces();
+ }
+
+ public function getDirectives() {
+ return $this->interchange->getDirectives();
+ }
+
+ public function getTypes() {
+ return $this->interchange->getTypes();
+ }
+
+ public function addNamespace($arr) {
+ $this->interchange->addNamespace($arr);
+ }
+
+ public function addDirective($arr) {
+ $this->interchange->addNamespace($arr);
+ }
+
+}
diff --git a/library/HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php b/library/HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php
new file mode 100644
index 00000000..23153242
--- /dev/null
+++ b/library/HTMLPurifier/ConfigSchema/Interchange/Validator/IdExists.php
@@ -0,0 +1,20 @@
+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();
+ }
+
+}
diff --git a/tests/HTMLPurifier/ConfigSchema/Interchange/ValidatorHarness.php b/tests/HTMLPurifier/ConfigSchema/Interchange/ValidatorHarness.php
new file mode 100644
index 00000000..204a8c0a
--- /dev/null
+++ b/tests/HTMLPurifier/ConfigSchema/Interchange/ValidatorHarness.php
@@ -0,0 +1,18 @@
+mock = new HTMLPurifier_ConfigSchema_InterchangeMock();
+ }
+
+ protected function expectSchemaException($msg) {
+ $this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
+ }
+
+}
diff --git a/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php b/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php
index fd0e654d..d8c53e4b 100644
--- a/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php
+++ b/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php
@@ -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'));
}
}
diff --git a/tests/test_files.php b/tests/test_files.php
index 48dcfa7b..1c818b31 100644
--- a/tests/test_files.php
+++ b/tests/test_files.php
@@ -66,6 +66,7 @@ $test_files[] = 'HTMLPurifier/ChildDef/StrictBlockquoteTest.php';
$test_files[] = 'HTMLPurifier/ChildDef/TableTest.php';
$test_files[] = 'HTMLPurifier/ConfigSchemaTest.php';
$test_files[] = 'HTMLPurifier/ConfigSchema/InterchangeTest.php';
+$test_files[] = 'HTMLPurifier/ConfigSchema/Interchange/Validator/IdExistsTest.php';
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashAdapterTest.php';
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashReverseAdapterTest.php';
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashParserTest.php';