mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-03 05:11:52 +00:00
[3.1.0] Create decorator validator/adapter for Interchange.
- Output flush output git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1587 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
d81bcbd208
commit
0d9c05d13c
1
NEWS
1
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.
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
45
library/HTMLPurifier/ConfigSchema/InterchangeValidator.php
Normal file
45
library/HTMLPurifier/ConfigSchema/InterchangeValidator.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Decorator for interchange that performs validations
|
||||
*/
|
||||
class HTMLPurifier_ConfigSchema_InterchangeValidator
|
||||
{
|
||||
protected $interchange;
|
||||
protected $validators = array();
|
||||
|
||||
/**
|
||||
* @param $interchange Instance of HTMLPurifier_ConfigSchema_Interchange
|
||||
* to save changes to.
|
||||
*/
|
||||
public function __construct($interchange) {
|
||||
$this->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);
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
33
tests/HTMLPurifier/ConfigSchema/InterchangeValidatorTest.php
Normal file
33
tests/HTMLPurifier/ConfigSchema/InterchangeValidatorTest.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_InterchangeValidatorTest extends UnitTestCase
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
generate_mock_once('HTMLPurifier_ConfigSchema_Interchange');
|
||||
$this->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);
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user