1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 03:10:09 +02:00

[2.1.2?] Final migration for Injectors, deprecate the config and context parameters in assertResult

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1378 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-08-08 05:38:52 +00:00
parent 71301b36eb
commit 8f58c7f49e
5 changed files with 184 additions and 97 deletions

View File

@@ -67,41 +67,20 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
* @param $context_array Context array in form of Key => Value or an actual
* context object.
*/
function assertResult($input, $expect = true,
$config_array = array(), $context_array = array()
) {
// setup config
if ($this->config) {
$config = HTMLPurifier_Config::create($this->config);
$config->autoFinalize = false;
$config->loadArray($config_array);
} else {
$config = HTMLPurifier_Config::create($config_array);
}
// setup context object. Note that we are operating on a copy of it!
// When necessary, extend the test harness to allow post-tests
// on the context object
if (empty($this->context)) {
$context = new HTMLPurifier_Context();
$context->loadArray($context_array);
} else {
$context =& $this->context;
}
function assertResult($input, $expect = true) {
if ($this->to_tokens && is_string($input)) {
// $func may cause $input to change, so "clone" another copy
// to sacrifice
$input = $this->lexer->tokenizeHTML($s = $input, $config, $context);
$input_c = $this->lexer->tokenizeHTML($s, $config, $context);
$input = $this->tokenize($temp = $input);
$input_c = $this->tokenize($temp);
} else {
$input_c = $input;
}
// call the function
$func = $this->func;
$result = $this->obj->$func($input_c, $config, $context);
$result = $this->obj->$func($input_c, $this->config, $this->context);
// test a bool result
if (is_bool($result)) {
@@ -112,11 +91,9 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
}
if ($this->to_html) {
$result = $this->generator->
generateFromTokens($result, $config, $context);
$result = $this->generate($result);
if (is_array($expect)) {
$expect = $this->generator->
generateFromTokens($expect, $config, $context);
$expect = $this->generate($expect);
}
}
@@ -124,6 +101,20 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
}
/**
* Tokenize HTML into tokens, uses member variables for common variables
*/
function tokenize($html) {
return $this->lexer->tokenizeHTML($html, $this->config, $this->context);
}
/**
* Generate textual HTML from tokens
*/
function generate($tokens) {
return $this->generator->generateFromTokens($tokens, $this->config, $this->context);
}
}