2006-10-01 20:47:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2007-08-01 14:06:59 +00:00
|
|
|
* All-use harness, use this rather than SimpleTest's
|
2006-10-01 20:47:07 +00:00
|
|
|
*/
|
|
|
|
class HTMLPurifier_Harness extends UnitTestCase
|
|
|
|
{
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
2006-10-01 20:47:07 +00:00
|
|
|
}
|
|
|
|
|
2008-04-26 03:14:01 +00:00
|
|
|
protected $config, $context, $purifier;
|
2007-08-01 18:34:46 +00:00
|
|
|
|
2007-08-02 01:12:27 +00:00
|
|
|
/**
|
2008-04-26 03:14:01 +00:00
|
|
|
* Generates easily accessible default config/context, as well as
|
|
|
|
* a convenience purifier for integration testing.
|
2007-08-02 01:12:27 +00:00
|
|
|
*/
|
2008-04-21 15:24:18 +00:00
|
|
|
public function setUp() {
|
2007-08-01 18:34:46 +00:00
|
|
|
list($this->config, $this->context) = $this->createCommon();
|
2008-04-26 03:14:01 +00:00
|
|
|
$this->purifier = new HTMLPurifier();
|
2007-08-01 18:34:46 +00:00
|
|
|
}
|
|
|
|
|
2008-04-26 03:14:01 +00:00
|
|
|
/**
|
|
|
|
* Asserts a purification. Good for integration testing.
|
|
|
|
*/
|
|
|
|
function assertPurification($input, $expect = null) {
|
|
|
|
if ($expect === null) $expect = $input;
|
|
|
|
$result = $this->purifier->purify($input, $this->config);
|
|
|
|
$this->assertIdentical($expect, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-02 01:12:27 +00:00
|
|
|
/**
|
|
|
|
* Accepts config and context and prepares them into a valid state
|
|
|
|
* @param &$config Reference to config variable
|
|
|
|
* @param &$context Reference to context variable
|
|
|
|
*/
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function prepareCommon(&$config, &$context) {
|
2007-08-01 14:06:59 +00:00
|
|
|
$config = HTMLPurifier_Config::create($config);
|
|
|
|
if (!$context) $context = new HTMLPurifier_Context();
|
2006-10-01 20:47:07 +00:00
|
|
|
}
|
|
|
|
|
2007-08-02 01:12:27 +00:00
|
|
|
/**
|
|
|
|
* Generates default configuration and context objects
|
|
|
|
* @return Defaults in form of array($config, $context)
|
|
|
|
*/
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function createCommon() {
|
2007-08-01 18:34:46 +00:00
|
|
|
return array(HTMLPurifier_Config::createDefault(), new HTMLPurifier_Context);
|
|
|
|
}
|
|
|
|
|
2008-01-05 19:19:55 +00:00
|
|
|
/**
|
|
|
|
* Normalizes a string to Unix (\n) endings
|
|
|
|
*/
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function normalize(&$string) {
|
2008-01-05 19:19:55 +00:00
|
|
|
$string = str_replace(array("\r\n", "\r"), "\n", $string);
|
|
|
|
}
|
|
|
|
|
2007-08-02 01:12:27 +00:00
|
|
|
/**
|
|
|
|
* If $expect is false, ignore $result and check if status failed.
|
|
|
|
* Otherwise, check if $status if true and $result === $expect.
|
|
|
|
* @param $status Boolean status
|
|
|
|
* @param $result Mixed result from processing
|
|
|
|
* @param $expect Mixed expectation for result
|
|
|
|
*/
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function assertEitherFailOrIdentical($status, $result, $expect) {
|
2007-08-02 01:12:27 +00:00
|
|
|
if ($expect === false) {
|
|
|
|
$this->assertFalse($status, 'Expected false result, got true');
|
|
|
|
} else {
|
|
|
|
$this->assertTrue($status, 'Expected true result, got false');
|
|
|
|
$this->assertIdentical($result, $expect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
public function getTests() {
|
2007-08-04 14:51:06 +00:00
|
|
|
// __onlytest makes only one test get triggered
|
|
|
|
foreach (get_class_methods(get_class($this)) as $method) {
|
|
|
|
if (strtolower(substr($method, 0, 10)) == '__onlytest') {
|
2008-05-20 01:19:00 +00:00
|
|
|
$this->reporter->paintSkip('All test methods besides ' . $method);
|
2007-08-04 14:51:06 +00:00
|
|
|
return array($method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parent::getTests();
|
|
|
|
}
|
|
|
|
|
2006-10-01 20:47:07 +00:00
|
|
|
}
|
|
|
|
|