3 require_once 'HTMLPurifier/Lexer/DirectLex.php';
6 * General-purpose test-harness that makes testing functions that require
7 * configuration and context objects easier when those two parameters are
8 * meaningless. See HTMLPurifier_ChildDefTest for a good example of usage.
10 class HTMLPurifier_Harness
extends UnitTestCase
14 * Instance of the object that will execute the method
19 * Name of the function to be executed
24 * Whether or not the method deals in tokens. If set to true, assertResult()
25 * will transparently convert HTML to and back from tokens.
27 var $to_tokens = false;
30 * Whether or not to convert tokens back into HTML before performing
31 * equality check, has no effect on bools.
36 * Instance of an HTMLPurifier_Lexer implementation.
41 * Instance of HTMLPurifier_Generator
45 function HTMLPurifier_Harness() {
46 $this->lexer
= new HTMLPurifier_Lexer_DirectLex();
47 $this->generator
= new HTMLPurifier_Generator();
48 parent
::UnitTestCase();
52 * Asserts a specific result from a one parameter + config/context function
53 * @param $input Input parameter
54 * @param $expect Expectation
55 * @param $config_array Configuration array in form of
56 * Namespace.Directive => Value or an actual config
58 * @param $context_array Context array in form of Key => Value or an actual
61 function assertResult($input, $expect = true,
62 $config_array = array(), $context_array = array()
65 // setup config object
66 $config = HTMLPurifier_Config
::createDefault();
67 $config->loadArray($config_array);
69 // setup context object. Note that we are operating on a copy of it!
70 // We will extend the test harness to allow you to do post-tests
71 // on the context object
72 $context = new HTMLPurifier_Context();
73 $context->loadArray($context_array);
75 if ($this->to_tokens
&& is_string($input)) {
76 $input = $this->lexer
->tokenizeHTML($input, $config, $context);
81 $result = $this->obj
->$func($input, $config, $context);
84 if (is_bool($result)) {
85 $this->assertIdentical($expect, $result);
87 } elseif (is_bool($expect)) {
92 $result = $this->generator
->
93 generateFromTokens($result, $config, $context);
94 if (is_array($expect)) {
95 $expect = $this->generator
->
96 generateFromTokens($expect, $config, $context);
100 $this->assertIdentical($expect, $result);