-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from heahprod/configure-definition
[3.0] Fixed warming up custom configs and added support for custom config definition
- Loading branch information
Showing
25 changed files
with
953 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Exercise\HTMLPurifierBundle\Tests; | ||
|
||
use Exercise\HTMLPurifierBundle\HTMLPurifierConfigFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class HTMLPurifierConfigFactoryTest extends TestCase | ||
{ | ||
private static $cacheDir; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$cacheDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'html_purifier'; | ||
(new Filesystem())->mkdir(self::$cacheDir); | ||
} | ||
|
||
public static function tearDownAfterClass(): void | ||
{ | ||
(new Filesystem())->remove(self::$cacheDir); | ||
} | ||
|
||
public function testCreateUseDoesNotBuildDefinitionByDefault() | ||
{ | ||
TestHTMLPurifierConfigFactory::create('default', []); | ||
|
||
$this->assertSame(0, TestHTMLPurifierConfigFactory::$calledBuild); | ||
} | ||
|
||
public function testCreateUseSerializedCache() | ||
{ | ||
$configArgs = [ | ||
'test', /* profile */ | ||
[/* config array */ | ||
'Cache.SerializerPath' => self::$cacheDir, | ||
'HTML.Nofollow' => true, | ||
], | ||
null, /* default config */ | ||
[], /* parents */ | ||
['a' => ['href' => 'URI']], /* attributes */ | ||
]; | ||
|
||
(new \HTMLPurifier( | ||
TestHTMLPurifierConfigFactory::create(...$configArgs) | ||
))->purify('<div>test</div>'); | ||
|
||
TestHTMLPurifierConfigFactory::create(...$configArgs); | ||
|
||
$this->assertSame(1, TestHTMLPurifierConfigFactory::$calledBuild); | ||
} | ||
} | ||
|
||
class TestHTMLPurifierConfigFactory extends HTMLPurifierConfigFactory | ||
{ | ||
public static $calledBuild = 0; | ||
|
||
public static function buildHTMLDefinition( | ||
\HTMLPurifier_Definition $def, | ||
array $attributes, | ||
array $elements, | ||
array $blankElements | ||
): void { | ||
++self::$calledBuild; | ||
parent::buildHTMLDefinition($def, $attributes, $elements, $blankElements); | ||
} | ||
} |
Oops, something went wrong.