mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-07 22:56:32 +02:00
[3.1.0] De-crudify the ConfigSchema space; we're starting over again
- Optimize ConfigSchema by removing non-essential runtime data. We can probably optimize even more by collapsing object structures to arrays. - Removed validation data from ConfigSchema; this will be reimplemented on Interchange - Implement a sane Interchange composite hierarchy that doesn't use arrays - Implement StringHash -> Interchange -> ConfigSchema, and rewrite maintenance file to account for this git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1615 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_AlnumTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator_Alnum('ID');
|
||||
parent::setup();
|
||||
}
|
||||
|
||||
public function testValidate() {
|
||||
$this->expectSchemaException('R&D in ID must be alphanumeric');
|
||||
$arr = array('ID' => 'R&D');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_CompositeTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function testValidate() {
|
||||
$arr = array('ID' => 'RD');
|
||||
|
||||
generate_mock_once('HTMLPurifier_ConfigSchema_Validator');
|
||||
$mock1 = new HTMLPurifier_ConfigSchema_ValidatorMock();
|
||||
$mock2 = new HTMLPurifier_ConfigSchema_ValidatorMock();
|
||||
$mock1->expectOnce('validate', array($arr, $this->interchange));
|
||||
$mock2->expectOnce('validate', array($arr, $this->interchange));
|
||||
$this->validator->addValidator($mock1);
|
||||
$this->validator->addValidator($mock2);
|
||||
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_ExistsTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator_Exists('ID');
|
||||
parent::setup();
|
||||
}
|
||||
|
||||
public function testValidate() {
|
||||
$this->expectSchemaException('ID must exist');
|
||||
$arr = array();
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_IfTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
generate_mock_once('HTMLPurifier_ConfigSchema_Validator');
|
||||
}
|
||||
|
||||
public function testValidate() {
|
||||
$arr = array('ID' => 'RD');
|
||||
$this->validator->setCondition(new HTMLPurifier_ConfigSchema_Validator_Exists('ID'));
|
||||
$this->validator->setThen($mock1 = new HTMLPurifier_ConfigSchema_ValidatorMock());
|
||||
$mock1->expectOnce('validate', array($arr, $this->interchange));
|
||||
$this->validator->setElse($mock2 = new HTMLPurifier_ConfigSchema_ValidatorMock());
|
||||
$mock2->expectNever('validate');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
public function testValidateConditionIsFalse() {
|
||||
$arr = array('ID' => 'RD');
|
||||
$this->validator->setCondition(new HTMLPurifier_ConfigSchema_Validator_Exists('ALTID'));
|
||||
$this->validator->setThen($mock1 = new HTMLPurifier_ConfigSchema_ValidatorMock());
|
||||
$mock1->expectNever('validate');
|
||||
$this->validator->setElse($mock2 = new HTMLPurifier_ConfigSchema_ValidatorMock());
|
||||
$mock2->expectOnce('validate', array($arr, $this->interchange));
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_NamespaceExistsTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function testValidateFail() {
|
||||
$arr = array('_NAMESPACE' => 'Namespace');
|
||||
$this->expectSchemaException('Cannot define directive for undefined namespace Namespace');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
public function testValidatePass() {
|
||||
$arr = array('_NAMESPACE' => 'Namespace');
|
||||
$this->interchange->addNamespace(array('ID' => 'Namespace'));
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_OrTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function testValidatePass() {
|
||||
$arr = array('ID' => 'RD');
|
||||
$this->validator->addValidator(new HTMLPurifier_ConfigSchema_Validator_Alnum('ID'));
|
||||
// Never called:
|
||||
$this->validator->addValidator(new HTMLPurifier_ConfigSchema_Validator_Exists('ALT-ID'));
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
public function testValidatePassLater() {
|
||||
$arr = array('ID' => 'RD');
|
||||
// This one fails:
|
||||
$this->validator->addValidator(new HTMLPurifier_ConfigSchema_Validator_Exists('ALT-ID'));
|
||||
// But this one passes:
|
||||
$this->validator->addValidator(new HTMLPurifier_ConfigSchema_Validator_Alnum('ID'));
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
public function testValidateFail() {
|
||||
$arr = array('ID' => 'RD');
|
||||
$this->validator->addValidator(new HTMLPurifier_ConfigSchema_Validator_Exists('ALT-ID'));
|
||||
$this->validator->addValidator(new HTMLPurifier_ConfigSchema_Validator_Exists('FOOBAR'));
|
||||
$this->expectException('HTMLPurifier_ConfigSchema_Exception');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_ParseDefaultTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function testValidate() {
|
||||
$arr = array(
|
||||
'ID' => 'N.D',
|
||||
'DEFAULT' => 'true',
|
||||
'_TYPE' => 'bool',
|
||||
'_NULL' => false,
|
||||
);
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
$this->assertIdentical($arr, array(
|
||||
'ID' => 'N.D',
|
||||
'DEFAULT' => 'true',
|
||||
'_TYPE' => 'bool',
|
||||
'_NULL' => false,
|
||||
'_DEFAULT' => true,
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateFail() {
|
||||
$arr = array(
|
||||
'ID' => 'N.D',
|
||||
'DEFAULT' => '"asdf"',
|
||||
'_TYPE' => 'int',
|
||||
'_NULL' => true,
|
||||
);
|
||||
$this->expectSchemaException('Invalid type for default value in N.D: Expected type int, got string');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_ParseIdTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function testValidateNamespace() {
|
||||
$arr = array('ID' => 'Namespace');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
$this->assertIdentical($arr, array(
|
||||
'ID' => 'Namespace',
|
||||
'_NAMESPACE' => 'Namespace'
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateDirective() {
|
||||
$arr = array('ID' => 'Namespace.Directive');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
$this->assertIdentical($arr, array(
|
||||
'ID' => 'Namespace.Directive',
|
||||
'_NAMESPACE' => 'Namespace',
|
||||
'_DIRECTIVE' => 'Directive'
|
||||
));
|
||||
}
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_ParseTypeTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function testValidatePlain() {
|
||||
$arr = array('ID' => 'N.D', 'TYPE' => 'string');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
$this->assertIdentical($arr, array(
|
||||
'ID' => 'N.D',
|
||||
'TYPE' => 'string',
|
||||
'_TYPE' => 'string',
|
||||
'_NULL' => false,
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateWithNull() {
|
||||
$arr = array('ID' => 'N.D', 'TYPE' => 'int/null');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
$this->assertIdentical($arr, array(
|
||||
'ID' => 'N.D',
|
||||
'TYPE' => 'int/null',
|
||||
'_TYPE' => 'int',
|
||||
'_NULL' => true,
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateInvalidType() {
|
||||
$arr = array('ID' => 'N.D', 'TYPE' => 'aint/null');
|
||||
$this->expectSchemaException('Invalid type aint for configuration directive N.D');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_ConfigSchema_Validator_UniqueTest extends HTMLPurifier_ConfigSchema_ValidatorHarness
|
||||
{
|
||||
|
||||
public function testValidateNamespace() {
|
||||
$this->interchange->addNamespace(array('ID' => 'Namespace'));
|
||||
$this->expectSchemaException('Cannot redefine namespace');
|
||||
$arr = array('ID' => 'Namespace');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
public function testValidateDirective() {
|
||||
$this->interchange->addDirective(array('ID' => 'Namespace.Directive'));
|
||||
$this->expectSchemaException('Cannot redefine directive');
|
||||
$arr = array('ID' => 'Namespace.Directive');
|
||||
$this->validator->validate($arr, $this->interchange);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user