-
Notifications
You must be signed in to change notification settings - Fork 12
/
BaseTestCase.php
62 lines (53 loc) · 1.44 KB
/
BaseTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
class BaseTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var HTMLPurifier_HTML5Config
*/
protected $config;
/**
* @var array
*/
private $errors;
protected function setUp()
{
$this->config = HTMLPurifier_HTML5Config::create(null);
$this->config->set('Cache.DefinitionImpl', null);
$this->errors = array();
set_error_handler(array($this, 'errorHandler'), E_USER_NOTICE | E_USER_WARNING);
}
protected function tearDown()
{
set_error_handler(null);
}
/**
* @param int $errno
* @param string $message
*/
public function errorHandler($errno, $message)
{
$this->errors[] = compact('errno', 'message');
}
/**
* @param string $input
* @param string $expect OPTIONAL
*/
public function assertPurification($input, $expect = null)
{
$purifier = new HTMLPurifier($this->config);
$output = $purifier->purify($input);
$this->assertEquals((string) ($expect !== null ? $expect : $input), $output);
}
/**
* @param string $message
*/
public function assertWarning($message)
{
foreach ($this->errors as $error) {
if ($error['message'] === $message && $error['errno'] === E_USER_WARNING) {
return;
}
}
$this->fail("Failed asserting that error of type 'E_USER_WARNING' is triggered.");
}
}