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

Commit 3bcbae1

Browse files
author
Florian Krämer
committed
Docs and coding style
1 parent 3ab880e commit 3bcbae1

File tree

9 files changed

+117
-196
lines changed

9 files changed

+117
-196
lines changed

docs/Documentation/Configuration.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

docs/Documentation/If-you-use-APC.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/Documentation/Installation.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/Usage.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ cake purify <table> <fields> --config myconfig
5151

5252
Where ever you need the purifier you can simply add it to your class by using the [PurifierTrait](../src/Lib/PurifierTrait.php).
5353

54+
The trait add two methods:
55+
56+
* **purifyHtml($markup, $config = 'default')**: Cleans a passed string of HTML.
57+
* **getHtmlPurifier($config = 'default')**: Gets a `\HtmlPurifier` instance by config name.
58+
5459
[See the official php documentation](http://php.net/manual/en/language.oop5.traits.php) for traits if you don't know how to use it.

src/Shell/PurifierShell.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ public function purify()
117117
* @param int $chunkSize
118118
* @return void
119119
*/
120-
protected function _process(Table $table, $chunkCount, $chunkSize) {
120+
protected function _process(Table $table, $chunkCount, $chunkSize)
121+
{
121122
$query = $table->find();
122123
if ($table->hasFinder('purifier')) {
123124
$query->find('purifier');
@@ -150,7 +151,8 @@ protected function _process(Table $table, $chunkCount, $chunkSize) {
150151
/**
151152
* {@inheritDoc}
152153
*/
153-
public function getOptionParser() {
154+
public function getOptionParser()
155+
{
154156
$parser = parent::getOptionParser();
155157

156158
$parser->description([

tests/TestCase/Case/Lib/PurifierTest.php

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,64 @@
77

88
class PurifierTest extends TestCase {
99

10-
public function setUp() {
11-
parent::setUp();
10+
public function setUp()
11+
{
12+
parent::setUp();
1213

13-
Purifier::config('default', [
14-
'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
15-
'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt, *.style',
16-
'CSS.AllowedProperties' => 'text-decoration',
17-
'HTML.TidyLevel' => 'heavy',
18-
'HTML.Doctype' => 'XHTML 1.0 Transitional'
19-
]);
20-
}
14+
Purifier::config('default', [
15+
'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
16+
'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt, *.style',
17+
'CSS.AllowedProperties' => 'text-decoration',
18+
'HTML.TidyLevel' => 'heavy',
19+
'HTML.Doctype' => 'XHTML 1.0 Transitional'
20+
]);
21+
}
2122

22-
/**
23-
* getPurifierInstance
24-
*
25-
* @return void
26-
*/
27-
public function testConfig() {
28-
$this->assertInstanceOf('HTMLPurifier_Config', Purifier::config('default'));
29-
}
23+
/**
24+
* getPurifierInstance
25+
*
26+
* @return void
27+
*/
28+
public function testConfig()
29+
{
30+
$this->assertInstanceOf('HTMLPurifier_Config', Purifier::config('default'));
31+
}
3032

31-
/**
32-
* @expectedException \InvalidArgumentException
33-
*/
34-
public function testConfigInvalidArgumentException() {
35-
Purifier::config('does-not-exist');
36-
}
33+
/**
34+
* @expectedException \InvalidArgumentException
35+
*/
36+
public function testConfigInvalidArgumentException()
37+
{
38+
Purifier::config('does-not-exist');
39+
}
3740

38-
/**
39-
* getPurifierInstance
40-
*
41-
* @return void
42-
*/
43-
public function testGetPurifierInstance() {
44-
$this->assertInstanceOf('HTMLPurifier', Purifier::getPurifierInstance('default'));
45-
}
41+
/**
42+
* getPurifierInstance
43+
*
44+
* @return void
45+
*/
46+
public function testGetPurifierInstance()
47+
{
48+
$this->assertInstanceOf('HTMLPurifier', Purifier::getPurifierInstance('default'));
49+
}
4650

47-
/**
48-
* @expectedException \InvalidArgumentException
49-
*/
50-
public function testGetPurifierInstanceInvalidArgumentException() {
51-
Purifier::getPurifierInstance('does-not-exist');
52-
}
51+
/**
52+
* @expectedException \InvalidArgumentException
53+
*/
54+
public function testGetPurifierInstanceInvalidArgumentException() {
55+
Purifier::getPurifierInstance('does-not-exist');
56+
}
5357

54-
/**
55-
* testPurifyHtml
56-
*
57-
* @return void
58-
*/
59-
public function testPurifyHtml() {
60-
$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>';
61-
$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>';
62-
$result = Purifier::clean($html);
63-
$this->assertEquals($result, $expected);
64-
}
58+
/**
59+
* testPurifyHtml
60+
*
61+
* @return void
62+
*/
63+
public function testPurifyHtml()
64+
{
65+
$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>';
66+
$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>';
67+
$result = Purifier::clean($html);
68+
$this->assertEquals($result, $expected);
69+
}
6570
}

tests/TestCase/Case/Lib/PurifierTraitTest.php

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,61 @@
88

99
class PurifierTraitTestClass {
1010

11-
use PurifierTrait;
11+
use PurifierTrait;
1212
}
1313

1414
class PurifierTraitTest extends TestCase {
1515

16-
/**
17-
* @var Burzum\HtmlPurifier\Test\TestCase\Lib\PurifierTraitTestClass
18-
*/
19-
public $testClass;
16+
/**
17+
* @var Burzum\HtmlPurifier\Test\TestCase\Lib\PurifierTraitTestClass
18+
*/
19+
public $testClass;
2020

21-
public function setUp() {
22-
parent::setUp();
21+
public function setUp()
22+
{
23+
parent::setUp();
2324

24-
$this->testClass = new PurifierTraitTestClass();
25+
$this->testClass = new PurifierTraitTestClass();
2526

26-
Purifier::config('default', [
27-
'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
28-
'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt, *.style',
29-
'CSS.AllowedProperties' => 'text-decoration',
30-
'HTML.TidyLevel' => 'heavy',
31-
'HTML.Doctype' => 'XHTML 1.0 Transitional'
32-
]);
33-
}
27+
Purifier::config('default', [
28+
'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
29+
'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt, *.style',
30+
'CSS.AllowedProperties' => 'text-decoration',
31+
'HTML.TidyLevel' => 'heavy',
32+
'HTML.Doctype' => 'XHTML 1.0 Transitional'
33+
]);
34+
}
3435

35-
/**
36-
* testTraitMethods
37-
*
38-
* @return void
39-
*/
40-
public function testTraitMethods() {
41-
$this->assertTrue(method_exists($this->testClass, 'purifyHtml'));
42-
$this->assertTrue(method_exists($this->testClass, 'getHtmlPurifier'));
43-
}
36+
/**
37+
* testTraitMethods
38+
*
39+
* @return void
40+
*/
41+
public function testTraitMethods()
42+
{
43+
$this->assertTrue(method_exists($this->testClass, 'purifyHtml'));
44+
$this->assertTrue(method_exists($this->testClass, 'getHtmlPurifier'));
45+
}
4446

45-
/**
46-
* testPurifyHtml
47-
*
48-
* @return void
49-
*/
50-
public function testPurifyHtml() {
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-
$html = $this->testClass->purifyHtml($html, 'default');
53-
$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>');
54-
}
47+
/**
48+
* testPurifyHtml
49+
*
50+
* @return void
51+
*/
52+
public function testPurifyHtml()
53+
{
54+
$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>';
55+
$html = $this->testClass->purifyHtml($html, 'default');
56+
$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>');
57+
}
5558

56-
/**
57-
* testGetHtmlPurifier
58-
*
59-
* @return void
60-
*/
61-
public function testGetHtmlPurifier() {
62-
$this->assertInstanceOf('HTMLPurifier', $this->testClass->getHtmlPurifier());
63-
}
59+
/**
60+
* testGetHtmlPurifier
61+
*
62+
* @return void
63+
*/
64+
public function testGetHtmlPurifier()
65+
{
66+
$this->assertInstanceOf('HTMLPurifier', $this->testClass->getHtmlPurifier());
67+
}
6468
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ class VoidModel extends Table {
4040
* @param array $config
4141
* @return void
4242
*/
43-
public function initialize(array $config)
44-
{
45-
parent::initialize($config);
46-
$this->addBehavior('Burzum/HtmlPurifier.HtmlPurifier', [
47-
'fields' => ['field1']
48-
]);
49-
}
43+
public function initialize(array $config)
44+
{
45+
parent::initialize($config);
46+
$this->addBehavior('Burzum/HtmlPurifier.HtmlPurifier', [
47+
'fields' => ['field1']
48+
]);
49+
}
5050
}
5151

5252
/**

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace Burzum\HtmlPurifier\Test\TestCase\View\Helper;
33

4-
use Cake\Controller\Controller;
54
use Cake\TestSuite\TestCase;
65
use Cake\View\View;
76
use Burzum\HtmlPurifier\Lib\Purifier;
@@ -58,5 +57,4 @@ public function testCleanSomeTinyMceOutput()
5857
$html = $this->Purifier->clean($html, 'default');
5958
$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>');
6059
}
61-
6260
}

0 commit comments

Comments
 (0)