mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-22 16:19:19 +00:00
ec4098c8fd
While we might never be able to have 100% of our code strict, we can at the very least do it for all of our tests. This ensures that our tests are using our API with the types as intended by the test author, and not silently be cast to what our API requires.
74 lines
2.3 KiB
PHP
74 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Html;
|
|
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheetTests\Functional;
|
|
|
|
class HtmlCommentsTest extends Functional\AbstractFunctional
|
|
{
|
|
/**
|
|
* @var Spreadsheet
|
|
*/
|
|
private $spreadsheet;
|
|
|
|
public static function providerCommentRichText(): array
|
|
{
|
|
$valueSingle = 'I am comment.';
|
|
$valueMulti = 'I am ' . PHP_EOL . 'multi-line' . PHP_EOL . 'comment.';
|
|
|
|
$plainSingle = new RichText();
|
|
$plainSingle->createText($valueSingle);
|
|
|
|
$plainMulti = new RichText();
|
|
$plainMulti->createText($valueMulti);
|
|
|
|
$richSingle = new RichText();
|
|
$font = $richSingle->createTextRun($valueSingle)->getFont();
|
|
self::assertNotNull($font);
|
|
$font->setBold(true);
|
|
|
|
$richMultiSimple = new RichText();
|
|
$font = $richMultiSimple->createTextRun($valueMulti)->getFont();
|
|
self::assertNotNull($font);
|
|
$font->setBold(true);
|
|
|
|
$richMultiMixed = new RichText();
|
|
$richMultiMixed->createText('I am' . PHP_EOL);
|
|
$font = $richMultiMixed->createTextRun('multi-line')->getFont();
|
|
self::assertNotNull($font);
|
|
$font->setBold(true);
|
|
$richMultiMixed->createText(PHP_EOL . 'comment!');
|
|
|
|
return [
|
|
'single line plain text' => [$plainSingle],
|
|
'multi-line plain text' => [$plainMulti],
|
|
'single line simple rich text' => [$richSingle],
|
|
'multi-line simple rich text' => [$richMultiSimple],
|
|
'multi-line mixed rich text' => [$richMultiMixed],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerCommentRichText
|
|
*/
|
|
public function testComments(RichText $richText): void
|
|
{
|
|
$this->spreadsheet = new Spreadsheet();
|
|
|
|
$this->spreadsheet->getActiveSheet()->getCell('A1')->setValue('Comment');
|
|
|
|
$this->spreadsheet->getActiveSheet()
|
|
->getComment('A1')
|
|
->setText($richText);
|
|
|
|
$reloadedSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Html');
|
|
|
|
$actual = $reloadedSpreadsheet->getActiveSheet()->getComment('A1')->getText()->getPlainText();
|
|
self::assertSame($richText->getPlainText(), $actual);
|
|
}
|
|
}
|