|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace OpenMage\Tests\Unit\Mage\Core\Model\Security; |
| 6 | + |
| 7 | +use Mage_Core_Model_Security_HtmlEscapedString; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +class HtmlEscapedStringTest extends TestCase |
| 11 | +{ |
| 12 | + public const TEST_STRING = 'This is a bold <b>string></b>'; |
| 13 | + |
| 14 | + /** |
| 15 | + * @var Mage_Core_Model_Security_HtmlEscapedString |
| 16 | + */ |
| 17 | + public Mage_Core_Model_Security_HtmlEscapedString $subject; |
| 18 | + |
| 19 | + /** |
| 20 | + * @dataProvider provideHtmlEscapedStringAsStringData |
| 21 | + * @param string $expectedResult |
| 22 | + * @param string $string |
| 23 | + * @param string|array<int, string> $allowedTags |
| 24 | + * @return void |
| 25 | + */ |
| 26 | + public function test__toSting(string $expectedResult, string $string, ?array $allowedTags): void |
| 27 | + { |
| 28 | + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation |
| 29 | + $this->subject = new Mage_Core_Model_Security_HtmlEscapedString($string, $allowedTags); |
| 30 | + $this->assertSame($expectedResult, (string) $this->subject); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @dataProvider provideHtmlEscapedStringGetUnescapedValueData |
| 35 | + * @param string $expectedResult |
| 36 | + * @param string $string |
| 37 | + * @param string|array<int, string> $allowedTags |
| 38 | + * @return void |
| 39 | + */ |
| 40 | + public function testGetUnescapedValue(string $expectedResult, string $string, ?array $allowedTags): void |
| 41 | + { |
| 42 | + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation |
| 43 | + $this->subject = new Mage_Core_Model_Security_HtmlEscapedString($string, $allowedTags); |
| 44 | + $this->assertSame($expectedResult, $this->subject->getUnescapedValue()); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @return array<string, array<int, int|string>> |
| 49 | + */ |
| 50 | + public function provideHtmlEscapedStringAsStringData(): array |
| 51 | + { |
| 52 | + return [ |
| 53 | + 'tags_null' => [ |
| 54 | + 'This is a bold <b>string></b>', |
| 55 | + 'This is a bold <b>string></b>', |
| 56 | + null |
| 57 | + ], |
| 58 | +// 'tags_array' => [ |
| 59 | +// 'This is a bold <b>string></b>', |
| 60 | +// 'This is a bold <b>string></b>', |
| 61 | +// ['b'] |
| 62 | +// ], |
| 63 | + ]; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @return array<string, array<int, int|string>> |
| 68 | + */ |
| 69 | + public function provideHtmlEscapedStringGetUnescapedValueData(): array |
| 70 | + { |
| 71 | + return [ |
| 72 | + 'tags_null' => [ |
| 73 | + self::TEST_STRING, |
| 74 | + self::TEST_STRING, |
| 75 | + null |
| 76 | + ], |
| 77 | + 'tags_array' => [ |
| 78 | + self::TEST_STRING, |
| 79 | + self::TEST_STRING, |
| 80 | + ['some-invalid-value'] |
| 81 | + ], |
| 82 | + ]; |
| 83 | + } |
| 84 | +} |
0 commit comments