Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit b444051

Browse files
author
Florian Krämer
committed
Working on tests and indentation.
1 parent 1f10b3d commit b444051

File tree

7 files changed

+210
-56
lines changed

7 files changed

+210
-56
lines changed

src/Lib/Purifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function config($configName, $config = null)
7777
* @param string $configName
7878
* @return HTMLPurifier
7979
*/
80-
public static function getPurifierInstance($configName = null)
80+
public static function getPurifierInstance($configName = 'default')
8181
{
8282
$_this = Purifier::getInstance();
8383

@@ -97,7 +97,7 @@ public static function getPurifierInstance($configName = null)
9797
* @param string $markup
9898
* @param string $configName
9999
*/
100-
public static function clean($markup, $configName = null)
100+
public static function clean($markup, $configName = 'default')
101101
{
102102
$_this = Purifier::getInstance();
103103

src/Lib/PurifierTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait PurifierTrait {
1616
* @param string $markup
1717
* @param string $config
1818
*/
19-
public function purifyHtml($markup, $config = '')
19+
public function purifyHtml($markup, $config = 'default')
2020
{
2121
return Purifier::clean($markup, $config);
2222
}

src/View/Helper/HtmlPurifierHelper.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313

1414
class HtmlPurifierHelper extends Helper {
1515

16-
/**
17-
* Default config
18-
*
19-
* @var array
20-
*/
16+
/**
17+
* Default config
18+
*
19+
* @var array
20+
*/
2121
public $_defaultConfig = [
2222
'config' => 'default'
2323
];
2424

25-
/**
26-
* Clean markup
27-
*
28-
* @param string $markup
29-
* @param string $config
30-
* @return string
31-
*/
25+
/**
26+
* Clean markup
27+
*
28+
* @param string $markup
29+
* @param string $config
30+
* @return string
31+
*/
3232
public function clean($markup, $config = null)
3333
{
3434
if (empty($config) && !empty($this->_config['config'])) {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* PurifierTest
4+
*
5+
* @author Florian Krämer
6+
* @copyright 2012 - 2016 Florian Krämer
7+
* @license MIT
8+
*/
9+
namespace Burzum\HtmlPurifier\Test\TestCase\Model\Behavior;
10+
11+
use Burzum\HtmlPurifier\Lib\Purifier;
12+
use Cake\TestSuite\TestCase;
13+
14+
/**
15+
* PurifierTest
16+
*/
17+
class PurifierTest extends TestCase {
18+
19+
/**
20+
* Fixtures
21+
*
22+
* @var array
23+
*/
24+
public $fixtures = [];
25+
26+
/**
27+
* startTest
28+
*
29+
* @return void
30+
*/
31+
public function setUp()
32+
{
33+
parent::setUp();
34+
35+
Purifier::config('default', [
36+
'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
37+
'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt, *.style',
38+
'CSS.AllowedProperties' => 'text-decoration',
39+
'HTML.TidyLevel' => 'heavy',
40+
'HTML.Doctype' => 'XHTML 1.0 Transitional'
41+
]);
42+
}
43+
44+
/**
45+
* testPurifyHtml
46+
*
47+
* @return void
48+
*/
49+
public function testPurifyHtml()
50+
{
51+
$html = '<p style="font-weight: bold;"><script>alert("alert!");</script><span style="text-decoration: line-through;" _mce_style="text-decoration: line-through;">shsfhshs</span></p><p><strong>sdhsdhds</strong></p><p><em>shsdh</em><span style="text-decoration: underline;" _mce_style="text-decoration: underline;">dsh</span></p><ul><li>sdgsgssgd</li><li>sdgdsg</li><li>sdgsdgsg</li><li>sdgdg<br></li></ul>';
52+
$expected = '<p><span style="text-decoration:line-through;">shsfhshs</span></p><p><strong>sdhsdhds</strong></p><p><em>shsdh</em><span style="text-decoration:underline;">dsh</span></p><ul><li>sdgsgssgd</li><li>sdgdsg</li><li>sdgsdgsg</li><li>sdgdg</li></ul>';
53+
$result = Purifier::clean($html);
54+
$this->assertEquals($result, $expected);
55+
}
56+
57+
/**
58+
* testGetHtmlPurifier
59+
*
60+
* @return void
61+
*/
62+
public function testGetHtmlPurifier()
63+
{
64+
$result = Purifier::getPurifierInstance();
65+
$this->assertInstanceOf('HTMLPurifier', $result);
66+
}
67+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* PurifierTraitTest
4+
*
5+
* @author Florian Krämer
6+
* @copyright 2012 - 2016 Florian Krämer
7+
* @license MIT
8+
*/
9+
namespace Burzum\HtmlPurifier\Test\TestCase\Model\Behavior;
10+
11+
use Burzum\HtmlPurifier\Lib\Purifier;
12+
use Burzum\HtmlPurifier\Lib\PurifierTrait;
13+
use Cake\Event\Event;
14+
use Cake\ORM\TableRegistry;
15+
use Cake\ORM\Table;
16+
use Cake\Core\Plugin;
17+
use Cake\TestSuite\TestCase;
18+
19+
/**
20+
* VoidUploadModel
21+
*/
22+
class PurifierTraitTestClass
23+
{
24+
use PurifierTrait;
25+
}
26+
27+
/**
28+
* HtmlPurifierBehaviorTest
29+
*/
30+
class PurifierTraitTest extends TestCase {
31+
32+
/**
33+
* Fixtures
34+
*
35+
* @var array
36+
*/
37+
public $fixtures = [];
38+
39+
/**
40+
* startTest
41+
*
42+
* @return void
43+
*/
44+
public function setUp()
45+
{
46+
parent::setUp();
47+
48+
Purifier::config('default', [
49+
'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
50+
'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt, *.style',
51+
'CSS.AllowedProperties' => 'text-decoration',
52+
'HTML.TidyLevel' => 'heavy',
53+
'HTML.Doctype' => 'XHTML 1.0 Transitional'
54+
]);
55+
56+
$this->class = new PurifierTraitTestClass();
57+
}
58+
59+
/**
60+
* endTest
61+
*
62+
* @return void
63+
*/
64+
public function tearDown()
65+
{
66+
unset($this->class);
67+
}
68+
69+
/**
70+
* testPurifyHtml
71+
*
72+
* @return void
73+
*/
74+
public function testPurifyHtml()
75+
{
76+
$html = '<p style="font-weight: bold;"><script>alert("alert!");</script><span style="text-decoration: line-through;" _mce_style="text-decoration: line-through;">shsfhshs</span></p><p><strong>sdhsdhds</strong></p><p><em>shsdh</em><span style="text-decoration: underline;" _mce_style="text-decoration: underline;">dsh</span></p><ul><li>sdgsgssgd</li><li>sdgdsg</li><li>sdgsdgsg</li><li>sdgdg<br></li></ul>';
77+
$expected = '<p><span style="text-decoration:line-through;">shsfhshs</span></p><p><strong>sdhsdhds</strong></p><p><em>shsdh</em><span style="text-decoration:underline;">dsh</span></p><ul><li>sdgsgssgd</li><li>sdgdsg</li><li>sdgsdgsg</li><li>sdgdg</li></ul>';
78+
$result = $this->class->purifyHtml($html);
79+
$this->assertEquals($result, $expected);
80+
}
81+
82+
public function testGetHtmlPurifier()
83+
{
84+
$result = $this->class->getHtmlPurifier();
85+
$this->assertInstanceOf('HTMLPurifier_Config', $result);
86+
}
87+
}

tests/TestCase/Case/Model/Behavior/HtmlPurifierBehaviorTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ public function initialize(array $config)
5454
*/
5555
class HtmlPurifierBehaviorTest extends TestCase {
5656

57-
/**
58-
* Fixtures
59-
*
60-
* @var array
61-
*/
57+
/**
58+
* Fixtures
59+
*
60+
* @var array
61+
*/
6262
public $fixtures = [];
6363

64-
/**
65-
* startTest
66-
*
67-
* @return void
68-
*/
64+
/**
65+
* startTest
66+
*
67+
* @return void
68+
*/
6969
public function setUp()
7070
{
7171
parent::setUp();
@@ -81,21 +81,21 @@ public function setUp()
8181
$this->table = new VoidModel();
8282
}
8383

84-
/**
85-
* endTest
86-
*
87-
* @return void
88-
*/
84+
/**
85+
* endTest
86+
*
87+
* @return void
88+
*/
8989
public function tearDown()
9090
{
9191
unset($this->table);
9292
}
9393

94-
/**
95-
* configureUploadValidation
96-
*
97-
* @return void
98-
*/
94+
/**
95+
* testBeforeMarshal
96+
*
97+
* @return void
98+
*/
9999
public function testBeforeMarshal()
100100
{
101101
$html = '<p style="font-weight: bold;"><script>alert("alert!");</script><span style="text-decoration: line-through;" _mce_style="text-decoration: line-through;">shsfhshs</span></p><p><strong>sdhsdhds</strong></p><p><em>shsdh</em><span style="text-decoration: underline;" _mce_style="text-decoration: underline;">dsh</span></p><ul><li>sdgsgssgd</li><li>sdgdsg</li><li>sdgsdgsg</li><li>sdgdg<br></li></ul>';

tests/TestCase/Case/View/Helper/HtmlPurifierHelperTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99

1010
class HtmlHelperTest extends TestCase {
1111

12-
/**
13-
* Purifier property
14-
*
15-
* @var object
16-
*/
12+
/**
13+
* Purifier property
14+
*
15+
* @var object
16+
*/
1717
public $Purifier = null;
1818

19-
/**
20-
* setUp method
21-
*
22-
* @return void
23-
*/
19+
/**
20+
* setUp method
21+
*
22+
* @return void
23+
*/
2424
public function setUp()
2525
{
2626
parent::setUp();
@@ -36,27 +36,27 @@ public function setUp()
3636
]);
3737
}
3838

39-
/**
40-
* tearDown method
41-
*
42-
* @return void
43-
*/
39+
/**
40+
* tearDown method
41+
*
42+
* @return void
43+
*/
4444
public function tearDown()
4545
{
4646
parent::tearDown();
4747
unset($this->Purifier, $this->View);
4848
}
4949

50-
/**
51-
* testCleanSomeTinyMceOutput
52-
*
53-
* @return void
54-
*/
50+
/**
51+
* testCleanSomeTinyMceOutput
52+
*
53+
* @return void
54+
*/
5555
public function testCleanSomeTinyMceOutput()
5656
{
5757
$html = '<p style="font-weight: bold;"><script>alert("alert!");</script><span style="text-decoration: line-through;" _mce_style="text-decoration: line-through;">shsfhshs</span></p><p><strong>sdhsdhds</strong></p><p><em>shsdh</em><span style="text-decoration: underline;" _mce_style="text-decoration: underline;">dsh</span></p><ul><li>sdgsgssgd</li><li>sdgdsg</li><li>sdgsdgsg</li><li>sdgdg<br></li></ul>';
5858
$html = $this->Purifier->clean($html, 'default');
5959
$this->assertEquals($html, '<p><span style="text-decoration:line-through;">shsfhshs</span></p><p><strong>sdhsdhds</strong></p><p><em>shsdh</em><span style="text-decoration:underline;">dsh</span></p><ul><li>sdgsgssgd</li><li>sdgdsg</li><li>sdgsdgsg</li><li>sdgdg</li></ul>');
6060
}
6161

62-
}
62+
}

0 commit comments

Comments
 (0)