alert("Harmful Script");

Test

'; protected function setUp(): void { parent::setUp(); $this->app['config']->set('purify.serializer', [ 'driver' => 'file', 'cache' => CacheDefinitionCache::class, ]); } public function test_configuration_file_is_published() { $this->artisan('vendor:publish', ['--provider' => PurifyServiceProvider::class]); $this->assertFileExists(config_path('purify.php')); File::delete(config_path('purify.php')); File::deleteDirectory(storage_path('app/purify')); } public function test_input_is_sanitized() { $cleaned = Purify::clean($this->testInput); $expected = '

Test

'; $this->assertEquals($expected, $cleaned); } public function test_input_arrays_are_sanitized() { $cleaned = Purify::clean([$this->testInput, $this->testInput]); $expected = ['

Test

', '

Test

']; $this->assertEquals($expected, $cleaned); } public function test_config_alias_is_available() { $instance = Purify::config(); $this->assertInstanceOf(\Stevebauman\Purify\Purify::class, $instance); } public function test_config_set_can_be_chosen() { $input = 'Google'; $this->app['config']->set('purify.configs.foo', [ 'HTML.TargetBlank' => true, ]); $cleaned = Purify::driver('foo')->clean($input); $expected = 'Google'; $this->assertEquals($expected, $cleaned); } public function test_config_can_be_provided_inline() { $input = 'Google'; $cleaned = Purify::config([ 'HTML.TargetBlank' => true, ])->clean($input); $expected = 'Google'; $this->assertEquals($expected, $cleaned); } public function test_configs_are_independent() { $input = 'Google'; $this->app['config']->set('purify.configs.foo', [ 'HTML.TargetBlank' => true, ]); $this->app['config']->set('purify.configs.bar', [ 'HTML.TargetBlank' => true, 'HTML.TargetNoopener' => false, ]); $cleaned1 = Purify::clean($input); $cleaned2 = Purify::driver('foo')->clean($input); $cleaned3 = Purify::driver('bar')->clean($input); $expected1 = 'Google'; $expected2 = 'Google'; $expected3 = 'Google'; $this->assertEquals($expected1, $cleaned1); $this->assertEquals($expected2, $cleaned2); $this->assertEquals($expected3, $cleaned3); } public function test_custom_definitions_are_applied() { $this->app['config']->set('purify.definitions', FooDefinition::class); $this->assertEquals( 'Test', Purify::clean('Test') ); $this->assertEquals( 'Test', Purify::config(['HTML.Allowed' => 'span[class]'])->clean('Test') ); $this->assertEquals( 'Test', Purify::config(['HTML.Allowed' => 'span[class]'])->clean('Test') ); } public function test_custom_css_definitions_are_applied() { $this->app['config']->set('purify.css-definitions', FooCssDefinition::class); $this->assertEquals( '

Test

', Purify::clean('

Test

') ); $this->assertEquals( '

Test

', Purify::clean('

Test

') ); $this->assertEquals( '

Test

', Purify::clean('

Test

') ); $this->assertEquals( '

Test

', Purify::clean('

Test

') ); $this->assertEquals( '

Test

', Purify::clean('

Test

') ); } } class FooDefinition implements Definition { public static function apply(HTMLPurifier_HTMLDefinition $definition) { $definition->addAttribute('span', 'class', 'Enum#foo'); } } class FooCssDefinition implements CssDefinition { public static function apply(HTMLPurifier_CSSDefinition $definition) { $definition->info['text-align'] = new \HTMLPurifier_AttrDef_Enum( ['center', 'start', 'end'], false, ); } }