Docblock update
[htmlpurifier.git] / tests / HTMLPurifier / Harness.php
blob764c077994e16df205c7c5e29b84219f3d03b023
1 <?php
3 /**
4 * All-use harness, use this rather than SimpleTest's
5 */
6 class HTMLPurifier_Harness extends UnitTestCase
9 public function __construct($name = null)
11 parent::__construct($name);
14 /**
15 * @type HTMLPurifier_Config
17 protected $config;
19 /**
20 * @type HTMLPurifier_Context
22 protected $context;
24 /**
25 * @type HTMLPurifier
27 protected $purifier;
29 /**
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', '
37 ');
38 $this->purifier = new HTMLPurifier();
41 /**
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) {
49 $expect = $input;
51 $result = $this->purifier->purify($input, $this->config);
52 $this->assertIdentical($expect, $result);
56 /**
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);
64 if (!$context) {
65 $context = new HTMLPurifier_Context();
69 /**
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);
78 /**
79 * Normalizes a string to Unix (\n) endings
81 protected function normalize(&$string)
83 $string = str_replace(array("\r\n", "\r"), "\n", $string);
86 /**
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');
97 } else {
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