4 * General-purpose test-harness that makes testing functions that require
5 * configuration and context objects easier when those two parameters are
6 * meaningless. See HTMLPurifier_ChildDefTest for a good example of usage.
8 class HTMLPurifier_ComplexHarness
extends HTMLPurifier_Harness
12 * Instance of the object that will execute the method.
18 * Name of the function to be executed.
24 * Whether or not the method deals in tokens.
25 * If set to true, assertResult()
26 * will transparently convert HTML to and back from tokens.
29 protected $to_tokens = false;
32 * Whether or not to convert tokens back into HTML before performing
33 * equality check, has no effect on bools.
36 protected $to_html = false;
39 * Instance of an HTMLPurifier_Lexer implementation.
40 * @type HTMLPurifier_Lexer
44 public function __construct()
46 $this->lexer
= new HTMLPurifier_Lexer_DirectLex();
47 parent
::__construct();
51 * Asserts a specific result from a one parameter + config/context function
52 * @param string $input Input parameter
53 * @param bool|string $expect Expectation
55 protected function assertResult($input, $expect = true)
57 if ($this->to_tokens
&& is_string($input)) {
58 // $func may cause $input to change, so "clone" another copy
60 $input = $this->tokenize($temp = $input);
61 $input_c = $this->tokenize($temp);
68 $result = $this->obj
->$func($input_c, $this->config
, $this->context
);
71 if (is_bool($result)) {
72 $this->assertIdentical($expect, $result);
74 } elseif (is_bool($expect)) {
79 $result = $this->generate($result);
80 if (is_array($expect)) {
81 $expect = $this->generate($expect);
84 $this->assertIdentical($expect, $result);
86 if ($expect !== $result) {
87 echo '<pre>' . var_dump($result) . '</pre>';
93 * Tokenize HTML into tokens, uses member variables for common variables
95 protected function tokenize($html)
97 return $this->lexer
->tokenizeHTML($html, $this->config
, $this->context
);
101 * Generate textual HTML from tokens
103 protected function generate($tokens)
105 $generator = new HTMLPurifier_Generator($this->config
, $this->context
);
106 return $generator->generateFromTokens($tokens);
111 // vim: et sw=4 sts=4