Rewrite CSS url() and font-family output logic.
[htmlpurifier.git] / tests / HTMLPurifier / Harness.php
blobd6490a117d91a5e08f6b0f070125a3a0162b29d7
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) {
10 parent::__construct($name);
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->config->set('Output.Newline', '
22 ');
23 $this->purifier = new HTMLPurifier();
26 /**
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);
36 /**
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();
46 /**
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);
54 /**
55 * Normalizes a string to Unix (\n) endings
57 protected function normalize(&$string) {
58 $string = str_replace(array("\r\n", "\r"), "\n", $string);
61 /**
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');
71 } else {
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();
90 // vim: et sw=4 sts=4