0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-05 14:11:52 +00:00

Make PEAR tests configurable.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@201 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-08-10 12:41:39 +00:00
parent 4d224c5013
commit 3c2c0c1a1b
2 changed files with 34 additions and 17 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
require_once 'HTMLPurifier/Lexer/DirectLex.php'; require_once 'HTMLPurifier/Lexer/DirectLex.php';
require_once 'HTMLPurifier/Lexer/PEARSax3.php';
class HTMLPurifier_LexerTest extends UnitTestCase class HTMLPurifier_LexerTest extends UnitTestCase
{ {
@ -9,13 +8,19 @@ class HTMLPurifier_LexerTest extends UnitTestCase
var $Lexer; var $Lexer;
var $DirectLex, $PEARSax3, $DOMLex; var $DirectLex, $PEARSax3, $DOMLex;
var $_entity_lookup; var $_entity_lookup;
var $_has_dom; var $_has_pear = false;
var $_has_dom = false;
function setUp() { function setUp() {
$this->Lexer = new HTMLPurifier_Lexer(); $this->Lexer = new HTMLPurifier_Lexer();
$this->DirectLex = new HTMLPurifier_Lexer_DirectLex(); $this->DirectLex = new HTMLPurifier_Lexer_DirectLex();
if ( $GLOBALS['HTMLPurifierTest']['PEAR'] ) {
$this->_has_pear = true;
require_once 'HTMLPurifier/Lexer/PEARSax3.php';
$this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3(); $this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3();
}
$this->_has_dom = version_compare(PHP_VERSION, '5', '>='); $this->_has_dom = version_compare(PHP_VERSION, '5', '>=');
if ($this->_has_dom) { if ($this->_has_dom) {
@ -216,6 +221,7 @@ class HTMLPurifier_LexerTest extends UnitTestCase
$this->assertEqual($expect[$i], $result, 'DirectLexTest '.$i.': %s'); $this->assertEqual($expect[$i], $result, 'DirectLexTest '.$i.': %s');
paintIf($result, $expect[$i] != $result); paintIf($result, $expect[$i] != $result);
if ($this->_has_pear) {
// assert unless I say otherwise // assert unless I say otherwise
$sax_result = $this->PEARSax3->tokenizeHTML($input[$i]); $sax_result = $this->PEARSax3->tokenizeHTML($input[$i]);
if (!isset($sax_expect[$i])) { if (!isset($sax_expect[$i])) {
@ -230,6 +236,8 @@ class HTMLPurifier_LexerTest extends UnitTestCase
$this->assertEqual($sax_expect[$i], $sax_result, 'PEARSax3Test (custom) '.$i.': %s'); $this->assertEqual($sax_expect[$i], $sax_result, 'PEARSax3Test (custom) '.$i.': %s');
paintIf($sax_result, $sax_expect[$i] != $sax_result); paintIf($sax_result, $sax_expect[$i] != $sax_result);
} }
}
if ($this->_has_dom) { if ($this->_has_dom) {
$dom_result = $this->DOMLex->tokenizeHTML($input[$i]); $dom_result = $this->DOMLex->tokenizeHTML($input[$i]);
// same structure as SAX // same structure as SAX

View File

@ -5,17 +5,26 @@ error_reporting(E_ALL);
// wishlist: automated calling of this file from multiple PHP versions so we // wishlist: automated calling of this file from multiple PHP versions so we
// don't have to constantly switch around // don't have to constantly switch around
// configuration
$GLOBALS['HTMLPurifierTest']['PEAR'] = false; // do PEAR tests
$simpletest_location = 'simpletest/'; $simpletest_location = 'simpletest/';
if (file_exists('../config.php')) include_once '../config.php'; if (file_exists('../config.php')) include_once '../config.php';
require_once $simpletest_location . 'unit_tester.php'; require_once $simpletest_location . 'unit_tester.php';
require_once $simpletest_location . 'reporter.php'; require_once $simpletest_location . 'reporter.php';
require_once $simpletest_location . 'mock_objects.php'; require_once $simpletest_location . 'mock_objects.php';
// configure PEAR if necessary
if ( is_string($GLOBALS['HTMLPurifierTest']['PEAR']) ) {
set_include_path($GLOBALS['HTMLPurifierTest']['PEAR'] . PATH_SEPARATOR .
get_include_path());
}
// debugger // debugger
require_once 'Debugger.php'; require_once 'Debugger.php';
// emulates inserting a dir called HTMLPurifier into your class dir // emulates inserting a dir called HTMLPurifier into your class dir
set_include_path(get_include_path() . PATH_SEPARATOR . '../library'); set_include_path('../library' . PATH_SEPARATOR . get_include_path());
// since Mocks can't be called from within test files, we need to do // since Mocks can't be called from within test files, we need to do
// a little jumping through hoops to generate them // a little jumping through hoops to generate them