[3.1.1] Added HTMLPurifier_UnitConverter and HTMLPurifier_Length for convenient handl...
[htmlpurifier.git] / tests / HTMLPurifier / Harness.php
blob97c898d2060dbc907ad555a305e55889645dbc76
1 <?php
3 /**
4 * All-use harness, use this rather than SimpleTest's
5 */
6 class HTMLPurifier_Harness extends UnitTestCase
9 public function __construct() {
10 parent::__construct();
13 protected $config, $context, $purifier;
15 /**
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->purifier = new HTMLPurifier();
24 /**
25 * Asserts a purification. Good for integration testing.
27 function assertPurification($input, $expect = null) {
28 if ($expect === null) $expect = $input;
29 $result = $this->purifier->purify($input, $this->config);
30 $this->assertIdentical($expect, $result);
34 /**
35 * Accepts config and context and prepares them into a valid state
36 * @param &$config Reference to config variable
37 * @param &$context Reference to context variable
39 protected function prepareCommon(&$config, &$context) {
40 $config = HTMLPurifier_Config::create($config);
41 if (!$context) $context = new HTMLPurifier_Context();
44 /**
45 * Generates default configuration and context objects
46 * @return Defaults in form of array($config, $context)
48 protected function createCommon() {
49 return array(HTMLPurifier_Config::createDefault(), new HTMLPurifier_Context);
52 /**
53 * Normalizes a string to Unix (\n) endings
55 protected function normalize(&$string) {
56 $string = str_replace(array("\r\n", "\r"), "\n", $string);
59 /**
60 * If $expect is false, ignore $result and check if status failed.
61 * Otherwise, check if $status if true and $result === $expect.
62 * @param $status Boolean status
63 * @param $result Mixed result from processing
64 * @param $expect Mixed expectation for result
66 protected function assertEitherFailOrIdentical($status, $result, $expect) {
67 if ($expect === false) {
68 $this->assertFalse($status, 'Expected false result, got true');
69 } else {
70 $this->assertTrue($status, 'Expected true result, got false');
71 $this->assertIdentical($result, $expect);
75 public function getTests() {
76 // __onlytest makes only one test get triggered
77 foreach (get_class_methods(get_class($this)) as $method) {
78 if (strtolower(substr($method, 0, 10)) == '__onlytest') {
79 $this->reporter->paintSkip('All test methods besides ' . $method);
80 return array($method);
83 return parent::getTests();