lexer = new HTMLPurifier_Lexer_DirectLex (); parent::__construct (); } /** * Asserts a specific result from a one parameter + config/context function * * @param string $input * Input parameter * @param bool|string $expect * Expectation */ protected function assertResult($input, $expect = true) { // $func may cause $input to change, so "clone" another copy // to sacrifice if ($this->to_node_list && is_string ( $input )) { $input = HTMLPurifier_Arborize::arborize ( $this->tokenize ( $temp = $input ), $this->config, $this->context )->children; $input_c = HTMLPurifier_Arborize::arborize ( $this->tokenize ( $temp ), $this->config, $this->context )->children; } elseif ($this->to_tokens && is_string ( $input )) { $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, $this->config, $this->context ); // test a bool result if (is_bool ( $result )) { $this->assertIdentical ( $expect, $result ); return; } elseif (is_bool ( $expect )) { $expect = $input; } if ($this->to_html) { if ($this->to_node_list) { $result = $this->generateTokens ( $result ); if (is_array ( $expect ) && ! empty ( $expect ) && $expect [0] instanceof HTMLPurifier_Node) { $expect = $this->generateTokens ( $expect ); } } $result = $this->generate ( $result ); if (is_array ( $expect )) { $expect = $this->generate ( $expect ); } } $this->assertIdentical ( $expect, $result ); if ($expect !== $result) { echo '
' . var_dump ( $result ) . '
'; } } /** * Tokenize HTML into tokens, uses member variables for common variables */ protected function tokenize($html) { return $this->lexer->tokenizeHTML ( $html, $this->config, $this->context ); } /** * Generate textual HTML from tokens */ protected function generate($tokens) { $generator = new HTMLPurifier_Generator ( $this->config, $this->context ); return $generator->generateFromTokens ( $tokens ); } /** * Generate tokens from node list */ protected function generateTokens($children) { $dummy = new HTMLPurifier_Node_Element ( "dummy" ); $dummy->children = $children; return HTMLPurifier_Arborize::flatten ( $dummy, $this->context, $this->config ); } } // vim: et sw=4 sts=4