From 3c2c0c1a1b33dd2e8919a1c259a47d066f2bd3e4 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 10 Aug 2006 12:41:39 +0000 Subject: [PATCH] Make PEAR tests configurable. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@201 48356398-32a2-884e-a903-53898d9a118a --- tests/HTMLPurifier/LexerTest.php | 40 +++++++++++++++++++------------- tests/index.php | 11 ++++++++- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/tests/HTMLPurifier/LexerTest.php b/tests/HTMLPurifier/LexerTest.php index d91e535c..15869944 100644 --- a/tests/HTMLPurifier/LexerTest.php +++ b/tests/HTMLPurifier/LexerTest.php @@ -1,7 +1,6 @@ Lexer = new HTMLPurifier_Lexer(); $this->DirectLex = new HTMLPurifier_Lexer_DirectLex(); - $this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3(); + + if ( $GLOBALS['HTMLPurifierTest']['PEAR'] ) { + $this->_has_pear = true; + require_once 'HTMLPurifier/Lexer/PEARSax3.php'; + $this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3(); + } $this->_has_dom = version_compare(PHP_VERSION, '5', '>='); if ($this->_has_dom) { @@ -216,20 +221,23 @@ class HTMLPurifier_LexerTest extends UnitTestCase $this->assertEqual($expect[$i], $result, 'DirectLexTest '.$i.': %s'); paintIf($result, $expect[$i] != $result); - // assert unless I say otherwise - $sax_result = $this->PEARSax3->tokenizeHTML($input[$i]); - if (!isset($sax_expect[$i])) { - // by default, assert with normal result - $this->assertEqual($expect[$i], $sax_result, 'PEARSax3Test '.$i.': %s'); - paintIf($sax_result, $expect[$i] != $sax_result); - } elseif ($sax_expect[$i] === false) { - // assertions were turned off, optionally dump - // paintIf($sax_expect, $i == NUMBER); - } else { - // match with a custom SAX result array - $this->assertEqual($sax_expect[$i], $sax_result, 'PEARSax3Test (custom) '.$i.': %s'); - paintIf($sax_result, $sax_expect[$i] != $sax_result); + if ($this->_has_pear) { + // assert unless I say otherwise + $sax_result = $this->PEARSax3->tokenizeHTML($input[$i]); + if (!isset($sax_expect[$i])) { + // by default, assert with normal result + $this->assertEqual($expect[$i], $sax_result, 'PEARSax3Test '.$i.': %s'); + paintIf($sax_result, $expect[$i] != $sax_result); + } elseif ($sax_expect[$i] === false) { + // assertions were turned off, optionally dump + // paintIf($sax_expect, $i == NUMBER); + } else { + // match with a custom SAX result array + $this->assertEqual($sax_expect[$i], $sax_result, 'PEARSax3Test (custom) '.$i.': %s'); + paintIf($sax_result, $sax_expect[$i] != $sax_result); + } } + if ($this->_has_dom) { $dom_result = $this->DOMLex->tokenizeHTML($input[$i]); // same structure as SAX diff --git a/tests/index.php b/tests/index.php index 8a41a244..72826aac 100644 --- a/tests/index.php +++ b/tests/index.php @@ -5,17 +5,26 @@ error_reporting(E_ALL); // wishlist: automated calling of this file from multiple PHP versions so we // don't have to constantly switch around +// configuration +$GLOBALS['HTMLPurifierTest']['PEAR'] = false; // do PEAR tests + $simpletest_location = 'simpletest/'; if (file_exists('../config.php')) include_once '../config.php'; require_once $simpletest_location . 'unit_tester.php'; require_once $simpletest_location . 'reporter.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 require_once 'Debugger.php'; // 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 // a little jumping through hoops to generate them