|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2024 Adobe. |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 |
| - |
7 | 6 | declare(strict_types=1);
|
8 | 7 |
|
9 | 8 | namespace Magento\Framework\Test\Unit\Validator\HTML;
|
|
16 | 15 |
|
17 | 16 | class ConfigurableWYSIWYGValidatorTest extends TestCase
|
18 | 17 | {
|
| 18 | + /** |
| 19 | + * @var ConfigurableWYSIWYGValidator |
| 20 | + */ |
| 21 | + private ConfigurableWYSIWYGValidator $validator; |
| 22 | + |
| 23 | + protected function setUp(): void |
| 24 | + { |
| 25 | + $allowedTags = ['p', 'a', 'div']; |
| 26 | + $allowedAttributes = ['href', 'title']; |
| 27 | + $attributesAllowedByTags = ['a' => ['href', 'title']]; |
| 28 | + $attributeValidators = []; |
| 29 | + $tagValidators = []; |
| 30 | + |
| 31 | + $this->validator = new ConfigurableWYSIWYGValidator( |
| 32 | + $allowedTags, |
| 33 | + $allowedAttributes, |
| 34 | + $attributesAllowedByTags, |
| 35 | + $attributeValidators, |
| 36 | + $tagValidators |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Test that the validator error message does not contain duplicated tags body and html. |
| 42 | + * |
| 43 | + * @return void |
| 44 | + * @throws ValidationException |
| 45 | + */ |
| 46 | + public function testValidateThrowsExceptionForDisallowedTags() |
| 47 | + { |
| 48 | + $this->expectException(ValidationException::class); |
| 49 | + $this->expectExceptionMessageMatches('/^(Allowed HTML tags are: p, a, div, body, html)*$/'); |
| 50 | + |
| 51 | + $validHtml = '<html><body>test1</body></html>'; |
| 52 | + $this->validator->validate($validHtml); |
| 53 | + $validHtml = '<html><body>test2</body></html>'; |
| 54 | + $this->validator->validate($validHtml); |
| 55 | + $validHtml = '<html><body>test3</body></html>'; |
| 56 | + $this->validator->validate($validHtml); |
| 57 | + $invalidHtml = '<html><body><script>alert("XSS")</script></body></html>'; |
| 58 | + $this->validator->validate($invalidHtml); |
| 59 | + } |
| 60 | + |
19 | 61 | /**
|
20 | 62 | * Configurations to test.
|
21 | 63 | *
|
|
0 commit comments