|
6 | 6 |
|
7 | 7 | use Nowo\Ckeditor5EditorBundle\DependencyInjection\Configuration; |
8 | 8 | use Nowo\Ckeditor5EditorBundle\DependencyInjection\NowoCkeditor5EditorExtension; |
| 9 | +use Nowo\Ckeditor5EditorBundle\Form\Ckeditor5EditorType; |
9 | 10 | use Nowo\Ckeditor5EditorBundle\Security\AllowlistCkeditor5HtmlSanitizer; |
10 | 11 | use Nowo\Ckeditor5EditorBundle\Security\Ckeditor5HtmlSanitizerInterface; |
11 | 12 | use PHPUnit\Framework\TestCase; |
| 13 | +use ReflectionMethod; |
12 | 14 | use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; |
13 | 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
14 | 16 | use Symfony\Component\DependencyInjection\Extension\Extension; |
| 17 | +use Symfony\Component\DependencyInjection\Reference; |
15 | 18 |
|
16 | 19 | /** |
17 | 20 | * @covers \Nowo\Ckeditor5EditorBundle\DependencyInjection\NowoCkeditor5EditorExtension |
@@ -79,6 +82,48 @@ public function testLoadWithAllowlistHtmlSanitizer(): void |
79 | 82 | AllowlistCkeditor5HtmlSanitizer::class, |
80 | 83 | (string) $container->getAlias(Ckeditor5HtmlSanitizerInterface::class), |
81 | 84 | ); |
| 85 | + |
| 86 | + $typeDefinition = $container->getDefinition(Ckeditor5EditorType::class); |
| 87 | + $arg = $typeDefinition->getArgument('$htmlSanitizer'); |
| 88 | + self::assertInstanceOf(Reference::class, $arg); |
| 89 | + self::assertSame(Ckeditor5HtmlSanitizerInterface::class, (string) $arg); |
| 90 | + } |
| 91 | + |
| 92 | + public function testLoadWithHtmlSanitizerCustomService(): void |
| 93 | + { |
| 94 | + $container = new ContainerBuilder(); |
| 95 | + $extension = new NowoCkeditor5EditorExtension(); |
| 96 | + $extension->load([['html_sanitizer' => 'app.custom_sanitizer']], $container); |
| 97 | + |
| 98 | + self::assertTrue($container->hasAlias(Ckeditor5HtmlSanitizerInterface::class)); |
| 99 | + self::assertSame('app.custom_sanitizer', (string) $container->getAlias(Ckeditor5HtmlSanitizerInterface::class)); |
| 100 | + } |
| 101 | + |
| 102 | + public function testLoadWithHtmlSanitizerEmptyDisables(): void |
| 103 | + { |
| 104 | + $container = new ContainerBuilder(); |
| 105 | + $extension = new NowoCkeditor5EditorExtension(); |
| 106 | + $extension->load([['html_sanitizer' => '']], $container); |
| 107 | + |
| 108 | + $typeDefinition = $container->getDefinition(Ckeditor5EditorType::class); |
| 109 | + self::assertNull($typeDefinition->getArgument('$htmlSanitizer')); |
| 110 | + } |
| 111 | + |
| 112 | + public function testConfigureHtmlSanitizerRegistersAllowlistWhenMissing(): void |
| 113 | + { |
| 114 | + $container = new ContainerBuilder(); |
| 115 | + $container->register(Ckeditor5EditorType::class, Ckeditor5EditorType::class) |
| 116 | + ->setAutowired(true) |
| 117 | + ->setAutoconfigured(true) |
| 118 | + ->addTag('form.type'); |
| 119 | + |
| 120 | + $extension = new NowoCkeditor5EditorExtension(); |
| 121 | + $method = new ReflectionMethod(NowoCkeditor5EditorExtension::class, 'configureHtmlSanitizer'); |
| 122 | + $method->setAccessible(true); |
| 123 | + $method->invoke($extension, $container, 'allowlist'); |
| 124 | + |
| 125 | + self::assertTrue($container->hasDefinition(AllowlistCkeditor5HtmlSanitizer::class)); |
| 126 | + self::assertTrue($container->hasAlias(Ckeditor5HtmlSanitizerInterface::class)); |
82 | 127 | } |
83 | 128 |
|
84 | 129 | public function testPrependAddsTwigFormTheme(): void |
|
0 commit comments