mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
Refactor validators so that they can be reused between directives and namespaces.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1589 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -27,7 +27,7 @@ class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase
|
||||
|
||||
public function testValidator() {
|
||||
$adapter = $this->interchange->getValidatorAdapter();
|
||||
$this->expectException(new HTMLPurifier_ConfigSchema_Exception('ID must exist in directive'));
|
||||
$this->expectException(new HTMLPurifier_ConfigSchema_Exception('ID must exist'));
|
||||
$adapter->addDirective(array());
|
||||
}
|
||||
|
||||
|
@@ -9,10 +9,11 @@ class HTMLPurifier_ConfigSchema_InterchangeValidatorTest extends UnitTestCase
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_InterchangeValidator($this->mock);
|
||||
}
|
||||
|
||||
protected function makeValidator($expect_method, $expect_params) {
|
||||
protected function makeValidator($expect_params = null) {
|
||||
generate_mock_once('HTMLPurifier_ConfigSchema_Validator');
|
||||
$validator = new HTMLPurifier_ConfigSchema_ValidatorMock();
|
||||
$validator->expectOnce($expect_method, $expect_params);
|
||||
if ($expect_params !== null) $validator->expectOnce('validate', $expect_params);
|
||||
else $validator->expectNever('validate');
|
||||
return $validator;
|
||||
}
|
||||
|
||||
@@ -24,10 +25,20 @@ class HTMLPurifier_ConfigSchema_InterchangeValidatorTest extends UnitTestCase
|
||||
|
||||
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->validator->addValidator($this->makeValidator(array($hash, $this->mock)));
|
||||
$this->validator->addNamespaceValidator($this->makeValidator(array($hash, $this->mock)));
|
||||
$this->validator->addDirectiveValidator($this->makeValidator()); // not called
|
||||
$this->mock->expectOnce('addNamespace', array($hash));
|
||||
$this->validator->addNamespace($hash);
|
||||
}
|
||||
|
||||
public function testAddDirectiveWithValidators() {
|
||||
$hash = array('ID' => 'Namespace.Directive');
|
||||
$this->validator->addValidator($this->makeValidator(array($hash, $this->mock)));
|
||||
$this->validator->addNamespaceValidator($this->makeValidator()); // not called
|
||||
$this->validator->addDirectiveValidator($this->makeValidator(array($hash, $this->mock)));
|
||||
$this->mock->expectOnce('addDirective', array($hash));
|
||||
$this->validator->addDirective($hash);
|
||||
}
|
||||
|
||||
}
|
||||
|
17
tests/HTMLPurifier/ConfigSchema/Validator/AlnumTest.php
Normal file
17
tests/HTMLPurifier/ConfigSchema/Validator/AlnumTest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_AlnumTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator_Alnum('ID');
|
||||
}
|
||||
|
||||
public function testValidate() {
|
||||
$this->expectSchemaException('R&D in ID must be alphanumeric');
|
||||
$arr = array('ID' => 'R&D');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
17
tests/HTMLPurifier/ConfigSchema/Validator/ExistsTest.php
Normal file
17
tests/HTMLPurifier/ConfigSchema/Validator/ExistsTest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_ExistsTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator_Exists('ID');
|
||||
}
|
||||
|
||||
public function testValidate() {
|
||||
$this->expectSchemaException('ID must exist');
|
||||
$arr = array();
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_IdExistsTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator_IdExists();
|
||||
}
|
||||
|
||||
public function testValidateNamespace() {
|
||||
$this->expectSchemaException('ID must exist in namespace');
|
||||
$arr = array();
|
||||
$this->validator->validateNamespace($arr, $this->interchange);
|
||||
}
|
||||
|
||||
public function testValidateDirective() {
|
||||
$this->expectSchemaException('ID must exist in directive');
|
||||
$arr = array();
|
||||
$this->validator->validateDirective($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user