mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-22 16:19:19 +00:00
e53e44d8cc
* Allow Users to Support Additional Tags in Helper/Html Fix #3751. User wants to add bullets for list items, and possibly handle table rows and other currently unsupported tags where one size might not fit all. * Update CHANGELOG.md
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Helper;
|
|
|
|
use DOMElement;
|
|
use PhpOffice\PhpSpreadsheet\Helper\Html;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class HtmlTest extends TestCase
|
|
{
|
|
/**
|
|
* @dataProvider providerUtf8EncodingSupport
|
|
*/
|
|
public function testUtf8EncodingSupport(mixed $expected, mixed $input): void
|
|
{
|
|
$html = new Html();
|
|
$actual = $html->toRichTextObject($input);
|
|
|
|
self::assertSame($expected, $actual->getPlainText());
|
|
}
|
|
|
|
public static function providerUtf8EncodingSupport(): array
|
|
{
|
|
return [
|
|
['foo', 'foo'],
|
|
['können', 'können'],
|
|
['русский', 'русский'],
|
|
["foo\nbar", '<p>foo</p><p>bar</p>'],
|
|
'issue2810' => ['0', '0'],
|
|
["Hello\nItem 1Item 2Goodbye", 'Hello<ul><li>Item 1</li><li>Item 2</li></ul>Goodbye'],
|
|
];
|
|
}
|
|
|
|
public function testLiTag(): void
|
|
{
|
|
$html = new Html();
|
|
/** @var callable */
|
|
$htmlBreakTag = [Html::class, 'breakTag'];
|
|
$html->addStartTagCallback('li', function (DOMElement $tag, Html $object): void {
|
|
$object->stringData .= "\u{00A0}\u{2022} \u{00A0}";
|
|
});
|
|
$html->addEndTagCallback('li', $htmlBreakTag);
|
|
$input = 'Hello<ul><li>Item 1</li><li>Item 2</li></ul>Goodbye';
|
|
$expected = "Hello\n\u{00A0}\u{2022} \u{00A0}Item 1\n\u{00A0}\u{2022} \u{00A0}Item 2\nGoodbye";
|
|
$actual = $html->toRichTextObject($input);
|
|
|
|
self::assertSame($expected, $actual->getPlainText());
|
|
}
|
|
}
|