mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-30 09:09:59 +02:00
Release 2.1.3, merged in 1404 to HEAD.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/strict@1444 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -19,5 +19,9 @@ class HTMLPurifier_ChildDef_OptionalTest extends HTMLPurifier_ChildDefHarness
|
||||
$this->assertResult('Not allowed text', '');
|
||||
}
|
||||
|
||||
function testEmpty() {
|
||||
$this->assertResult('');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -74,10 +74,11 @@ extends HTMLPurifier_ChildDefHarness
|
||||
}
|
||||
|
||||
function testError() {
|
||||
$this->expectError('Cannot use non-block element as block wrapper');
|
||||
// $this->expectError('Cannot use non-block element as block wrapper');
|
||||
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
|
||||
$this->config->set('HTML', 'BlockWrapper', 'dav');
|
||||
$this->assertResult('Needs wrap', '<p>Needs wrap</p>');
|
||||
$this->swallowErrors();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,11 +27,20 @@ class HTMLPurifier_ErrorCollectorEMock extends HTMLPurifier_ErrorCollectorMock
|
||||
|
||||
function send($severity, $msg) {
|
||||
// test for context
|
||||
$test = &$this->_getCurrentTestCase();
|
||||
$context =& SimpleTest::getContext();
|
||||
$test =& $context->getTest();
|
||||
|
||||
// compat
|
||||
if (empty($this->_mock)) {
|
||||
$mock =& $this;
|
||||
} else {
|
||||
$mock =& $this->_mock;
|
||||
}
|
||||
|
||||
foreach ($this->_expected_context as $key => $value) {
|
||||
$test->assertEqual($value, $this->_context->get($key));
|
||||
}
|
||||
$step = $this->getCallCount('send');
|
||||
$step = $mock->getCallCount('send');
|
||||
if (isset($this->_expected_context_at[$step])) {
|
||||
foreach ($this->_expected_context_at[$step] as $key => $value) {
|
||||
$test->assertEqual($value, $this->_context->get($key));
|
||||
@@ -39,7 +48,7 @@ class HTMLPurifier_ErrorCollectorEMock extends HTMLPurifier_ErrorCollectorMock
|
||||
}
|
||||
// boilerplate mock code, does not have return value or references
|
||||
$args = func_get_args();
|
||||
$this->_invoke('send', $args);
|
||||
$mock->_invoke('send', $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,11 +3,15 @@
|
||||
require_once 'HTMLPurifier/ErrorCollectorEMock.php';
|
||||
require_once 'HTMLPurifier/Lexer/DirectLex.php';
|
||||
|
||||
/**
|
||||
* @todo Make the callCount variable actually work, so we can precisely
|
||||
* specify what errors we want: no more, no less
|
||||
*/
|
||||
class HTMLPurifier_ErrorsHarness extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
var $config, $context;
|
||||
var $collector, $generator;
|
||||
var $collector, $generator, $callCount;
|
||||
|
||||
function setup() {
|
||||
$this->config = HTMLPurifier_Config::create(array('Core.CollectErrors' => true));
|
||||
@@ -16,6 +20,11 @@ class HTMLPurifier_ErrorsHarness extends HTMLPurifier_Harness
|
||||
$this->collector = new HTMLPurifier_ErrorCollectorEMock();
|
||||
$this->collector->prepare($this->context);
|
||||
$this->context->register('ErrorCollector', $this->collector);
|
||||
$this->callCount = 0;
|
||||
}
|
||||
|
||||
function expectNoErrorCollection() {
|
||||
$this->collector->expectNever('send');
|
||||
}
|
||||
|
||||
function expectErrorCollection() {
|
||||
|
@@ -30,5 +30,11 @@ class HTMLPurifier_IDAccumulatorTest extends HTMLPurifier_Harness
|
||||
|
||||
}
|
||||
|
||||
function testBuild() {
|
||||
$this->config->set('Attr', 'IDBlacklist', array('foo'));
|
||||
$accumulator = HTMLPurifier_IDAccumulator::build($this->config, $this->context);
|
||||
$this->assertTrue( isset($accumulator->ids['foo']) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -194,10 +194,7 @@ Bar</p></div>',
|
||||
}
|
||||
|
||||
function testNoParagraphSingleInlineNodeInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div><b>Foo</b></div>',
|
||||
'<div><b>Foo</b></div>'
|
||||
);
|
||||
$this->assertResult( '<div><b>Foo</b></div>' );
|
||||
}
|
||||
|
||||
function testParagraphInBlockquote() {
|
||||
@@ -277,9 +274,7 @@ Par1
|
||||
function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div>Par1
|
||||
<div>Par2</div></div>',
|
||||
'<div><p>Par1
|
||||
</p><div>Par2</div></div>'
|
||||
<div>Par2</div></div>'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -351,6 +346,30 @@ Par2'
|
||||
);
|
||||
}
|
||||
|
||||
function testInlineAndBlockTagInDivNoParagraph() {
|
||||
$this->assertResult(
|
||||
'<div><code>bar</code> mmm <pre>asdf</pre></div>'
|
||||
);
|
||||
}
|
||||
|
||||
function testInlineAndBlockTagInDivNeedingParagraph() {
|
||||
$this->assertResult(
|
||||
'<div><code>bar</code> mmm
|
||||
|
||||
<pre>asdf</pre></div>',
|
||||
'<div><p><code>bar</code> mmm</p><pre>asdf</pre></div>'
|
||||
);
|
||||
}
|
||||
|
||||
function testTextInlineNodeTextThenDoubleNewlineNeedsParagraph() {
|
||||
$this->assertResult(
|
||||
'<div>asdf <code>bar</code> mmm
|
||||
|
||||
<pre>asdf</pre></div>',
|
||||
'<div><p>asdf <code>bar</code> mmm</p><pre>asdf</pre></div>'
|
||||
);
|
||||
}
|
||||
|
||||
function testErrorNeeded() {
|
||||
$this->config->set('HTML', 'Allowed', 'b');
|
||||
$this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
|
||||
|
@@ -109,8 +109,9 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
|
||||
function testInvalidParentError() {
|
||||
// test fallback to div
|
||||
$this->config->set('HTML', 'Parent', 'obviously-impossible');
|
||||
$this->expectError('Cannot use unrecognized element as parent');
|
||||
// $this->expectError('Cannot use unrecognized element as parent');
|
||||
$this->assertResult('<div>Accept</div>');
|
||||
$this->swallowErrors();
|
||||
}
|
||||
|
||||
function testCascadingRemovalOfNodesMissingRequiredChildren() {
|
||||
@@ -129,5 +130,10 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
|
||||
$this->assertResult('<table></table><table></table>', '');
|
||||
}
|
||||
|
||||
function testStrictBlockquoteInHTML401() {
|
||||
$this->config->set('HTML', 'Doctype', 'HTML 4.01 Strict');
|
||||
$this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,11 @@ class HTMLPurifier_Strategy_FixNesting_ErrorsTest extends HTMLPurifier_Strategy_
|
||||
$this->invoke("<span>Valid<div>Invalid</div></span>");
|
||||
}
|
||||
|
||||
function testNoNodeReorganizedForEmptyNode() {
|
||||
$this->expectNoErrorCollection();
|
||||
$this->invoke("<span></span>");
|
||||
}
|
||||
|
||||
function testNodeContentsRemoved() {
|
||||
$this->expectErrorCollection(E_ERROR, 'Strategy_FixNesting: Node contents removed');
|
||||
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('span', array(), 1));
|
||||
|
@@ -11,6 +11,19 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
|
||||
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
|
||||
$this->config->set('AutoFormat', 'AutoParagraph', true);
|
||||
$this->config->set('AutoFormat', 'Linkify', true);
|
||||
generate_mock_once('HTMLPurifier_Injector');
|
||||
}
|
||||
|
||||
function testEndNotification() {
|
||||
$mock = new HTMLPurifier_InjectorMock();
|
||||
$mock->skip = false;
|
||||
$mock->expectAt(0, 'notifyEnd', array(new HTMLPurifier_Token_End('b')));
|
||||
$mock->expectAt(1, 'notifyEnd', array(new HTMLPurifier_Token_End('i')));
|
||||
$mock->expectCallCount('notifyEnd', 2);
|
||||
$this->config->set('AutoFormat', 'AutoParagraph', false);
|
||||
$this->config->set('AutoFormat', 'Linkify', false);
|
||||
$this->config->set('AutoFormat', 'Custom', array($mock));
|
||||
$this->assertResult('<i><b>asdf</b>', '<i><b>asdf</b></i>');
|
||||
}
|
||||
|
||||
function testOnlyAutoParagraph() {
|
||||
@@ -62,4 +75,11 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
|
||||
);
|
||||
}
|
||||
|
||||
function testParagraphAfterLinkifiedURL() {
|
||||
$this->assertResult(
|
||||
"http://google.com\n\n<b>b</b>",
|
||||
"<p><a href=\"http://google.com\">http://google.com</a></p><p><b>b</b></p>"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -82,5 +82,14 @@ alert(<b>bold</b>);
|
||||
);
|
||||
}
|
||||
|
||||
function testRequiredAttributesTestNotPerformedOnEndTag() {
|
||||
$this->config->set('HTML', 'DefinitionID',
|
||||
'HTMLPurifier_Strategy_RemoveForeignElementsTest'.
|
||||
'->testRequiredAttributesTestNotPerformedOnEndTag');
|
||||
$def =& $this->config->getHTMLDefinition(true);
|
||||
$def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text'));
|
||||
$this->assertResult('<f req="text">Foo</f> Bar');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -111,6 +111,12 @@ class HTMLPurifier_URIFilter_MakeAbsoluteTest extends HTMLPurifier_URIFilterHarn
|
||||
$this->assertFiltering('.', '../');
|
||||
}
|
||||
|
||||
function testRemoveJavaScriptWithEmbeddedLink() {
|
||||
// credits: NykO18
|
||||
$this->setBase('http://www.example.com/');
|
||||
$this->assertFiltering('javascript: window.location = \'http://www.example.com\';', false);
|
||||
}
|
||||
|
||||
// error case
|
||||
|
||||
function testErrorNoBase() {
|
||||
|
@@ -94,6 +94,7 @@ class HTMLPurifierTest extends HTMLPurifier_Harness
|
||||
|
||||
$this->purifier = new HTMLPurifier(array('HTML.EnableAttrID' => true));
|
||||
$this->assertPurification('<span id="moon">foobar</span>');
|
||||
$this->assertPurification('<img id="folly" src="folly.png" alt="Omigosh!" />');
|
||||
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,9 @@
|
||||
// call one file using /?f=FileTest.php , see $test_files array for
|
||||
// valid values
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
if (version_compare(PHP_VERSION, '5.1', '>=')) error_reporting(E_ALL | E_STRICT);
|
||||
else error_reporting(E_ALL);
|
||||
|
||||
define('HTMLPurifierTest', 1);
|
||||
define('HTMLPURIFIER_SCHEMA_STRICT', true); // validate schemas
|
||||
|
||||
@@ -17,6 +19,7 @@ $GLOBALS['HTMLPurifierTest']['PH5P'] = version_compare(PHP_VERSION, "5", ">=") &
|
||||
$simpletest_location = 'simpletest/'; // reasonable guess
|
||||
|
||||
// load SimpleTest
|
||||
if (file_exists('../conf/test-settings.php')) include '../conf/test-settings.php';
|
||||
if (file_exists('../test-settings.php')) include '../test-settings.php';
|
||||
require_once $simpletest_location . 'unit_tester.php';
|
||||
require_once $simpletest_location . 'reporter.php';
|
||||
@@ -79,7 +82,7 @@ if ($test_file = $GLOBALS['HTMLPurifierTest']['File']) {
|
||||
|
||||
} else {
|
||||
|
||||
$test = new GroupTest('All Tests');
|
||||
$test = new GroupTest('All tests on PHP ' . PHP_VERSION);
|
||||
foreach ($test_files as $test_file) {
|
||||
require_once $test_file;
|
||||
$test->addTestClass(path2class($test_file));
|
||||
@@ -91,5 +94,3 @@ if (SimpleReporter::inCli()) $reporter = new TextReporter();
|
||||
else $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8');
|
||||
|
||||
$test->run($reporter);
|
||||
|
||||
|
||||
|
33
tests/multitest.php
Normal file
33
tests/multitest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
$versions_to_test = array(
|
||||
'FLUSH',
|
||||
'5.0.4',
|
||||
'5.0.5',
|
||||
'5.1.4',
|
||||
'5.1.6',
|
||||
'5.2.0',
|
||||
'5.2.1',
|
||||
'5.2.2',
|
||||
'5.2.3',
|
||||
'5.2.4',
|
||||
'5.2.5RC2-dev',
|
||||
'5.3.0-dev',
|
||||
// '6.0.0-dev',
|
||||
);
|
||||
|
||||
echo str_repeat('-', 70) . "\n";
|
||||
echo "HTML Purifier\n";
|
||||
echo "Multiple PHP Versions Test\n\n";
|
||||
|
||||
passthru("php ../maintenance/merge-library.php");
|
||||
|
||||
foreach ($versions_to_test as $version) {
|
||||
if ($version === 'FLUSH') {
|
||||
shell_exec('php ../maintenance/flush-definition-cache.php');
|
||||
continue;
|
||||
}
|
||||
passthru("phpv $version index.php");
|
||||
passthru("phpv $version index.php standalone");
|
||||
echo "\n\n";
|
||||
}
|
Reference in New Issue
Block a user