4 * All-use harness, use this rather than SimpleTest's
6 class HTMLPurifier_Harness
extends UnitTestCase
9 public function __construct($name = null)
11 parent
::__construct($name);
15 * @type HTMLPurifier_Config
20 * @type HTMLPurifier_Context
30 * Generates easily accessible default config/context, as well as
31 * a convenience purifier for integration testing.
33 public function setUp()
35 list($this->config
, $this->context
) = $this->createCommon();
36 $this->config
->set('Output.Newline', '
38 $this->purifier
= new HTMLPurifier();
42 * Asserts a purification. Good for integration testing.
43 * @param string $input
44 * @param string $expect
46 public function assertPurification($input, $expect = null)
48 if ($expect === null) {
51 $result = $this->purifier
->purify($input, $this->config
);
52 $this->assertIdentical($expect, $result);
57 * Accepts config and context and prepares them into a valid state
58 * @param &$config Reference to config variable
59 * @param &$context Reference to context variable
61 protected function prepareCommon(&$config, &$context)
63 $config = HTMLPurifier_Config
::create($config);
65 $context = new HTMLPurifier_Context();
70 * Generates default configuration and context objects
71 * @return Defaults in form of array($config, $context)
73 protected function createCommon()
75 return array(HTMLPurifier_Config
::createDefault(), new HTMLPurifier_Context
);
79 * Normalizes a string to Unix (\n) endings
81 protected function normalize(&$string)
83 $string = str_replace(array("\r\n", "\r"), "\n", $string);
87 * If $expect is false, ignore $result and check if status failed.
88 * Otherwise, check if $status if true and $result === $expect.
89 * @param $status Boolean status
90 * @param $result Mixed result from processing
91 * @param $expect Mixed expectation for result
93 protected function assertEitherFailOrIdentical($status, $result, $expect)
95 if ($expect === false) {
96 $this->assertFalse($status, 'Expected false result, got true');
98 $this->assertTrue($status, 'Expected true result, got false');
99 $this->assertIdentical($result, $expect);
103 public function getTests()
105 // __onlytest makes only one test get triggered
106 foreach (get_class_methods(get_class($this)) as $method) {
107 if (strtolower(substr($method, 0, 10)) == '__onlytest') {
108 $this->reporter
->paintSkip('All test methods besides ' . $method);
109 return array($method);
112 return parent
::getTests();
117 // vim: et sw=4 sts=4