-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTMLPurifierFactoryTest.php
111 lines (90 loc) · 3.18 KB
/
HTMLPurifierFactoryTest.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* @author Stefano Torresi (http://stefanotorresi.it)
* @license See the file LICENSE.txt for copying permission.
* ************************************************
*/
namespace MyBase\Test\ServiceManager;
use HTMLPurifier;
use MyBase\ServiceManager\HTMLPurifierFactory;
use MyBase\Test\Bootstrap;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Stdlib\ArrayUtils;
class HTMLPurifierFactoryTest extends TestCase
{
/**
* @var HTMLPurifierFactory
*/
protected $factory;
/**
* @var array
*/
protected $config;
public function setUp()
{
if (!class_exists('HTMLPurifier')) {
$this->markTestSkipped('HTMLPurifier not found');
}
$this->factory = new HTMLPurifierFactory();
$this->config = ArrayUtils::merge(
include '../vendor/soflomo/purifier/config/module.config.php',
[
'soflomo_purifier' => [
'definitions' => [
],
],
]
);
}
protected function getServiceManagerMock()
{
$serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager');
$serviceManager
->expects($this->once())
->method('get')
->with('config')
->will($this->returnValue($this->config));
return $serviceManager;
}
public function testCreateService()
{
/** @var HTMLPurifier $htmlPurifier */
$htmlPurifier = $this->factory->createService($this->getServiceManagerMock());
$this->assertInstanceOf('HTMLPurifier', $htmlPurifier);
}
public function testConfigurationSetter()
{
$this->config['soflomo_purifier']['config']['HTML.Doctype'] = 'HTML 4.01 Strict';
/** @var HTMLPurifier $htmlPurifier */
$htmlPurifier = $this->factory->createService($this->getServiceManagerMock());
$this->assertEquals('HTML 4.01 Strict', $htmlPurifier->config->get('HTML.Doctype'));
}
public function testDefinitionsSetting()
{
$this->config = ArrayUtils::merge($this->config, [
'soflomo_purifier' => [
'config' => [
'HTML.DefinitionID' => 'test',
'Cache.DefinitionImpl' => null,
],
'definitions' => [
'HTML' => [
'addAttribute' => [ 'div', 'data-id', 'Number#1' ],
]
],
]
]);
/** @var HTMLPurifier $htmlPurifier */
$htmlPurifier = $this->factory->createService($this->getServiceManagerMock());
$this->assertEquals('<div data-id="1"></div>', $htmlPurifier->purify('<div data-id="1" data-foo="invalid"></div>'));
}
public function testServiceManagerIntegration()
{
$serviceManager = Bootstrap::getServiceManager();
/** @var HTMLPurifier $htmlPurifier */
$htmlPurifier = $serviceManager->get('HTMLPurifier');
$this->assertInstanceOf('HTMLPurifier', $htmlPurifier);
// test default module configuration
$this->assertEquals('<a target="_blank"></a>', $htmlPurifier->purify('<a target="_blank"></a>'));
}
}