Skip to content

Commit

Permalink
Added test, ref OpenMage#4123
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Aug 5, 2024
1 parent bf03ca8 commit 154229e
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions dev/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Mage\Core\Model\Security;

use Mage_Core_Model_Security_HtmlEscapedString;
use PHPUnit\Framework\TestCase;

class HtmlEscapedStringTest extends TestCase
{
public const TEST_STRING = 'This is a bold <b>string></b>';

/**
* @var Mage_Core_Model_Security_HtmlEscapedString
*/
public Mage_Core_Model_Security_HtmlEscapedString $subject;

/**
* @dataProvider provideHtmlEscapedStringAsStringData
* @param string $expectedResult
* @param string $string
* @param string|array<int, string> $allowedTags
* @return void
*/
public function test__toSting(string $expectedResult, string $string, ?array $allowedTags): void

Check failure on line 26 in dev/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php

View workflow job for this annotation

GitHub Actions / PHPStan / Analyze (ubuntu-latest, 8.3)

PHPDoc tag @param for parameter $allowedTags with type array<int, string>|string is not subtype of native type array|null.
{
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$this->subject = new Mage_Core_Model_Security_HtmlEscapedString($string, $allowedTags);
$this->assertSame($expectedResult, (string) $this->subject);
}

/**
* @dataProvider provideHtmlEscapedStringGetUnescapedValueData
* @param string $expectedResult
* @param string $string
* @param string|array<int, string> $allowedTags
* @return void
*/
public function testGetUnescapedValue(string $expectedResult, string $string, ?array $allowedTags): void

Check failure on line 40 in dev/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php

View workflow job for this annotation

GitHub Actions / PHPStan / Analyze (ubuntu-latest, 8.3)

PHPDoc tag @param for parameter $allowedTags with type array<int, string>|string is not subtype of native type array|null.
{
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$this->subject = new Mage_Core_Model_Security_HtmlEscapedString($string, $allowedTags);
$this->assertSame($expectedResult, $this->subject->getUnescapedValue());
}

/**
* @return array<string, array<int, int|string>>
*/
public function provideHtmlEscapedStringAsStringData(): array
{
return [

Check failure on line 52 in dev/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php

View workflow job for this annotation

GitHub Actions / PHPStan / Analyze (ubuntu-latest, 8.3)

Method OpenMage\Tests\Unit\Mage\Core\Model\Security\HtmlEscapedStringTest::provideHtmlEscapedStringAsStringData() should return array<string, array<int, int|string>> but returns array<string, array<int, string|null>>.
'tags_null' => [
'This is a bold &lt;b&gt;string&gt;&lt;/b&gt;',
'This is a bold <b>string></b>',
null
],
// 'tags_array' => [
// 'This is a bold <b>string></b>',
// 'This is a bold <b>string></b>',
// ['b']
// ],
];
}

/**
* @return array<string, array<int, int|string>>
*/
public function provideHtmlEscapedStringGetUnescapedValueData(): array
{
return [

Check failure on line 71 in dev/tests/unit/Mage/Core/Model/Security/HtmlEscapedStringTest.php

View workflow job for this annotation

GitHub Actions / PHPStan / Analyze (ubuntu-latest, 8.3)

Method OpenMage\Tests\Unit\Mage\Core\Model\Security\HtmlEscapedStringTest::provideHtmlEscapedStringGetUnescapedValueData() should return array<string, array<int, int|string>> but returns array<string, array<int, array<int, string>|string|null>>.
'tags_null' => [
self::TEST_STRING,
self::TEST_STRING,
null
],
'tags_array' => [
self::TEST_STRING,
self::TEST_STRING,
['some-invalid-value']
],
];
}
}

0 comments on commit 154229e

Please sign in to comment.