4 * All-use harness, use this rather than SimpleTest's
6 class HTMLPurifier_Harness
extends UnitTestCase
9 public function __construct($name = null) {
10 parent
::__construct($name);
13 protected $config, $context, $purifier;
16 * Generates easily accessible default config/context, as well as
17 * a convenience purifier for integration testing.
19 public function setUp() {
20 list($this->config
, $this->context
) = $this->createCommon();
21 $this->config
->set('Output.Newline', '
23 $this->purifier
= new HTMLPurifier();
27 * Asserts a purification. Good for integration testing.
29 function assertPurification($input, $expect = null) {
30 if ($expect === null) $expect = $input;
31 $result = $this->purifier
->purify($input, $this->config
);
32 $this->assertIdentical($expect, $result);
37 * Accepts config and context and prepares them into a valid state
38 * @param &$config Reference to config variable
39 * @param &$context Reference to context variable
41 protected function prepareCommon(&$config, &$context) {
42 $config = HTMLPurifier_Config
::create($config);
43 if (!$context) $context = new HTMLPurifier_Context();
47 * Generates default configuration and context objects
48 * @return Defaults in form of array($config, $context)
50 protected function createCommon() {
51 return array(HTMLPurifier_Config
::createDefault(), new HTMLPurifier_Context
);
55 * Normalizes a string to Unix (\n) endings
57 protected function normalize(&$string) {
58 $string = str_replace(array("\r\n", "\r"), "\n", $string);
62 * If $expect is false, ignore $result and check if status failed.
63 * Otherwise, check if $status if true and $result === $expect.
64 * @param $status Boolean status
65 * @param $result Mixed result from processing
66 * @param $expect Mixed expectation for result
68 protected function assertEitherFailOrIdentical($status, $result, $expect) {
69 if ($expect === false) {
70 $this->assertFalse($status, 'Expected false result, got true');
72 $this->assertTrue($status, 'Expected true result, got false');
73 $this->assertIdentical($result, $expect);
77 public function getTests() {
78 // __onlytest makes only one test get triggered
79 foreach (get_class_methods(get_class($this)) as $method) {
80 if (strtolower(substr($method, 0, 10)) == '__onlytest') {
81 $this->reporter
->paintSkip('All test methods besides ' . $method);
82 return array($method);
85 return parent
::getTests();