diff --git a/NEWS b/NEWS index 2d52c284..5481ccfc 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - Fix bug with trusted script handling in libxml versions later than 2.6.28. - Fix bug in ExtractStyleBlocks with comments in style tags - Fix bug in comment parsing for DirectLex +- Flush output now displayed when in command line mode for unit tester . Plugins now get their own changelogs according to project conventions. . Convert tokens to use instanceof, reducing memory footprint and improving comparison speed. diff --git a/library/HTMLPurifier.includes.php b/library/HTMLPurifier.includes.php index 27094120..a18e2384 100644 --- a/library/HTMLPurifier.includes.php +++ b/library/HTMLPurifier.includes.php @@ -125,6 +125,7 @@ require 'HTMLPurifier/ConfigDef/DirectiveAlias.php'; require 'HTMLPurifier/ConfigDef/Namespace.php'; require 'HTMLPurifier/ConfigSchema/Exception.php'; require 'HTMLPurifier/ConfigSchema/Interchange.php'; +require 'HTMLPurifier/ConfigSchema/InterchangeValidator.php'; require 'HTMLPurifier/ConfigSchema/StringHash.php'; require 'HTMLPurifier/ConfigSchema/StringHashAdapter.php'; require 'HTMLPurifier/ConfigSchema/StringHashParser.php'; diff --git a/library/HTMLPurifier/ConfigSchema/Interchange.php b/library/HTMLPurifier/ConfigSchema/Interchange.php index 47c1ce5a..09f49fa6 100644 --- a/library/HTMLPurifier/ConfigSchema/Interchange.php +++ b/library/HTMLPurifier/ConfigSchema/Interchange.php @@ -11,7 +11,7 @@ class HTMLPurifier_ConfigSchema_Interchange /** * Hash table of allowed types. */ - private $types = array( + public $types = array( 'string' => 'String', 'istring' => 'Case-insensitive string', 'text' => 'Text', @@ -28,29 +28,12 @@ class HTMLPurifier_ConfigSchema_Interchange /** * Array of Namespace ID => array(namespace info) */ - private $namespaces; + public $namespaces; /** * Array of Directive ID => array(directive info) */ - private $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;} + public $directives; /** * Adds a namespace array to $namespaces @@ -71,7 +54,9 @@ class HTMLPurifier_ConfigSchema_Interchange * to be used for data-input. */ public function getValidatorAdapter() { - + $validator = new HTMLPurifier_ConfigSchema_InterchangeValidator($this); + $validator->addValidator(new HTMLPurifier_ConfigSchema_Validator_IdExists()); + return $validator; } } diff --git a/library/HTMLPurifier/ConfigSchema/InterchangeValidator.php b/library/HTMLPurifier/ConfigSchema/InterchangeValidator.php new file mode 100644 index 00000000..55a83bc6 --- /dev/null +++ b/library/HTMLPurifier/ConfigSchema/InterchangeValidator.php @@ -0,0 +1,45 @@ +interchange = $interchange; + } + + /** + * Registers a HTMLPurifier_ConfigSchema_Validator to run when adding. + */ + public function addValidator($validator) { + $this->validators[] = $validator; + } + + /** + * Validates and adds a namespace hash + */ + public function addNamespace($hash) { + foreach ($this->validators as $validator) { + $validator->validateNamespace($hash, $this->interchange); + } + $this->interchange->addNamespace($hash); + } + + /** + * Validates and adds a directive hash + */ + public function addDirective($hash) { + foreach ($this->validators as $validator) { + $validator->validateDirective($hash, $this->interchange); + } + $this->interchange->addDirective($hash); + } +} diff --git a/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php b/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php index d8c53e4b..1432e604 100644 --- a/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php +++ b/tests/HTMLPurifier/ConfigSchema/InterchangeTest.php @@ -14,7 +14,7 @@ class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase 'ID' => 'Namespace', 'DESCRIPTION' => 'Bar', )); - $this->assertIdentical($v, $this->interchange->getNamespace('Namespace')); + $this->assertIdentical($v, $this->interchange->namespaces['Namespace']); } public function testAddDirective() { @@ -22,7 +22,13 @@ class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase 'ID' => 'Namespace.Directive', 'DESCRIPTION' => 'Bar', )); - $this->assertIdentical($v, $this->interchange->getDirective('Namespace.Directive')); + $this->assertIdentical($v, $this->interchange->directives['Namespace.Directive']); + } + + public function testValidator() { + $adapter = $this->interchange->getValidatorAdapter(); + $this->expectException(new HTMLPurifier_ConfigSchema_Exception('ID must exist in directive')); + $adapter->addDirective(array()); } } diff --git a/tests/HTMLPurifier/ConfigSchema/InterchangeValidatorTest.php b/tests/HTMLPurifier/ConfigSchema/InterchangeValidatorTest.php new file mode 100644 index 00000000..1e42133f --- /dev/null +++ b/tests/HTMLPurifier/ConfigSchema/InterchangeValidatorTest.php @@ -0,0 +1,33 @@ +mock = new HTMLPurifier_ConfigSchema_InterchangeMock(); + $this->validator = new HTMLPurifier_ConfigSchema_InterchangeValidator($this->mock); + } + + protected function makeValidator($expect_method, $expect_params) { + generate_mock_once('HTMLPurifier_ConfigSchema_Validator'); + $validator = new HTMLPurifier_ConfigSchema_ValidatorMock(); + $validator->expectOnce($expect_method, $expect_params); + return $validator; + } + + public function testAddNamespaceNullValidator() { + $hash = array('ID' => 'Namespace'); + $this->mock->expectOnce('addNamespace', array($hash)); + $this->validator->addNamespace($hash); + } + + public function testAddNamespaceWithValidators() { + $hash = array('ID' => 'Namespace'); + $this->validator->addValidator($this->makeValidator('validateNamespace', array($hash, $this->mock))); + $this->validator->addValidator($this->makeValidator('validateNamespace', array($hash, $this->mock))); + $this->mock->expectOnce('addNamespace', array($hash)); + $this->validator->addNamespace($hash); + } + +} diff --git a/tests/index.php b/tests/index.php index 7d94fc26..45eab7c9 100755 --- a/tests/index.php +++ b/tests/index.php @@ -71,7 +71,11 @@ require 'HTMLPurifier/Harness.php'; // Shell-script code is executed if ($AC['flush']) { - shell_exec($AC['php'] . ' ../maintenance/flush.php'); + if (SimpleReporter::inCli() && !$AC['xml']) { + passthru($AC['php'] . ' ../maintenance/flush.php'); + } else { + shell_exec($AC['php'] . ' ../maintenance/flush.php'); + } } // Now, userland code begins to be executed