mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 03:10:09 +02:00
[2.0.1] Implement haphazard error collection for AttrValidator.
- Error collector / Language can take arrays and listify them - AttrValidator takes token by reference - Formatted errors now have their severity <strong> - 100 test-cases! W00t! git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1250 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
50
tests/HTMLPurifier/AttrValidator_ErrorsTest.php
Normal file
50
tests/HTMLPurifier/AttrValidator_ErrorsTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/ErrorsHarness.php';
|
||||
require_once 'HTMLPurifier/AttrValidator.php';
|
||||
|
||||
class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
{
|
||||
|
||||
function invoke($input) {
|
||||
$validator = new HTMLPurifier_AttrValidator();
|
||||
$validator->validateToken($input, $this->config, $this->context);
|
||||
}
|
||||
|
||||
function testAttributesTransformedGlobalPre() {
|
||||
$this->config->set('HTML', 'DefinitionID',
|
||||
'HTMLPurifier_AttrValidator_ErrorsTest::testAttributesTransformedGlobalPre');
|
||||
$def =& $this->config->getHTMLDefinition(true);
|
||||
generate_mock_once('HTMLPurifier_AttrTransform');
|
||||
$transform = new HTMLPurifier_AttrTransformMock();
|
||||
$input = array('original' => 'value');
|
||||
$output = array('class' => 'value'); // must be valid
|
||||
$transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
|
||||
$def->info_attr_transform_pre[] = $transform;
|
||||
$this->expectErrorCollection(E_NOTICE, 'AttrValidator: Attributes transformed', $input, $output);
|
||||
$token = new HTMLPurifier_Token_Start('span', $input, 1);
|
||||
$this->invoke($token);
|
||||
}
|
||||
|
||||
function testAttributesTransformedLocalPre() {
|
||||
$this->config->set('HTML', 'TidyLevel', 'heavy');
|
||||
$input = array('align' => 'right');
|
||||
$output = array('style' => 'text-align:right;');
|
||||
$this->expectErrorCollection(E_NOTICE, 'AttrValidator: Attributes transformed', $input, $output);
|
||||
$token = new HTMLPurifier_Token_Start('p', $input, 1);
|
||||
$this->invoke($token);
|
||||
}
|
||||
|
||||
// to lazy to check for global post and global pre
|
||||
|
||||
function testAttributeRemoved() {
|
||||
$this->expectErrorCollection(E_ERROR, 'AttrValidator: Attribute removed');
|
||||
$this->expectContext('CurrentAttr', 'foobar');
|
||||
$token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
|
||||
$this->expectContext('CurrentToken', $token);
|
||||
$this->invoke($token);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -45,8 +45,8 @@ class HTMLPurifier_ErrorCollectorTest extends UnitTestCase
|
||||
$this->assertIdentical($collector->getRaw(), $result);
|
||||
|
||||
$formatted_result =
|
||||
'<ul><li>Warning: Message 2 at line 3</li>'.
|
||||
'<li>Error: Message 1 at line 23</li></ul>';
|
||||
'<ul><li><strong>Warning</strong>: Message 2 at line 3</li>'.
|
||||
'<li><strong>Error</strong>: Message 1 at line 23</li></ul>';
|
||||
|
||||
$config = HTMLPurifier_Config::create(array('Core.MaintainLineNumbers' => true));
|
||||
|
||||
@@ -91,8 +91,8 @@ class HTMLPurifier_ErrorCollectorTest extends UnitTestCase
|
||||
$this->assertIdentical($collector->getRaw(), $result);
|
||||
|
||||
$formatted_result =
|
||||
'<ul><li>Error: Message 1</li>'.
|
||||
'<li>Error: Message 2</li></ul>';
|
||||
'<ul><li><strong>Error</strong>: Message 1</li>'.
|
||||
'<li><strong>Error</strong>: Message 2</li></ul>';
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$this->assertIdentical($collector->getHTMLFormatted($config), $formatted_result);
|
||||
}
|
||||
|
@@ -7,6 +7,13 @@ class HTMLPurifier_LanguageTest extends UnitTestCase
|
||||
|
||||
var $lang;
|
||||
|
||||
function generateEnLanguage() {
|
||||
$factory = HTMLPurifier_LanguageFactory::instance();
|
||||
$config = HTMLPurifier_Config::create(array('Core.Language' => 'en'));
|
||||
$context = new HTMLPurifier_Context();
|
||||
return $factory->create($config, $context);
|
||||
}
|
||||
|
||||
function test_getMessage() {
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$context = new HTMLPurifier_Context();
|
||||
@@ -26,7 +33,7 @@ class HTMLPurifier_LanguageTest extends UnitTestCase
|
||||
$this->assertIdentical($lang->formatMessage('LanguageTest: Error', array(1=>'fatal', 32)), 'Error is fatal on line 32');
|
||||
}
|
||||
|
||||
function test_formatMessage_complexParameter() {
|
||||
function test_formatMessage_tokenParameter() {
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$context = new HTMLPurifier_Context();
|
||||
$generator = new HTMLPurifier_Generator(); // replace with mock if this gets icky
|
||||
@@ -43,6 +50,29 @@ class HTMLPurifier_LanguageTest extends UnitTestCase
|
||||
'Data Token: data>, data>, data>, 23');
|
||||
}
|
||||
|
||||
function test_listify() {
|
||||
$lang = $this->generateEnLanguage();
|
||||
$this->assertEqual($lang->listify(array('Item')), 'Item');
|
||||
$this->assertEqual($lang->listify(array('Item', 'Item2')), 'Item and Item2');
|
||||
$this->assertEqual($lang->listify(array('Item', 'Item2', 'Item3')), 'Item, Item2 and Item3');
|
||||
}
|
||||
|
||||
function test_formatMessage_arrayParameter() {
|
||||
$lang = $this->generateEnLanguage();
|
||||
|
||||
$array = array('Item1', 'Item2', 'Item3');
|
||||
$this->assertIdentical(
|
||||
$lang->formatMessage('LanguageTest: List', array(1=>$array)),
|
||||
'Item1, Item2 and Item3'
|
||||
);
|
||||
|
||||
$array = array('Key1' => 'Value1', 'Key2' => 'Value2');
|
||||
$this->assertIdentical(
|
||||
$lang->formatMessage('LanguageTest: Hash', array(1=>$array)),
|
||||
'Key1 and Key2; Value1 and Value2'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user