mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-06 15:52:43 +00:00
58c6e51992
* Sync composer.lock/.json and Phpstan Upgrade For some reason, a version newly cloned from master receives a complaint from composer that the lock and json files aren't in sync. So I ran composer update. The only thing that needs special attention is, as usual, Phpstan. There are an unusually large number of new differences when Phpstan is run with Php7.4 vs Php8.1. These are handled easily enough. But Reader/Xlsx seems very fragile; a change which would have eliminated one of the new errors seems to have caused Phpstan to go into a loop, as does an annotation without a code change, and, indeed, as does just about any change to that member. This bears watching, and it's a reason I will delay installing this. * Deleting Phpstan Cache Helps It lets me change Reader/Xlsx as I wished. Not a great resolution, but probably good enough. I will continue to think about it for a couple of days. * Minor DocBlock Changes Correct some PhpDocumentor problems.
98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Comment;
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
|
use PhpOffice\PhpSpreadsheet\RichText\TextElement;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
use PhpOffice\PhpSpreadsheet\Style\Color;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class CommentTest extends TestCase
|
|
{
|
|
public function testCreateComment(): void
|
|
{
|
|
$comment = new Comment();
|
|
self::assertEquals('Author', $comment->getAuthor());
|
|
self::assertEquals('96pt', $comment->getWidth());
|
|
self::assertEquals('59.25pt', $comment->getMarginLeft());
|
|
self::assertEquals('1.5pt', $comment->getMarginTop());
|
|
self::assertEquals('55.5pt', $comment->getHeight());
|
|
self::assertInstanceOf(Color::class, $comment->getFillColor());
|
|
self::assertEquals('FFFFFFE1', $comment->getFillColor()->getARGB());
|
|
self::assertInstanceOf(RichText::class, $comment->getText());
|
|
self::assertEquals(Alignment::HORIZONTAL_GENERAL, $comment->getAlignment());
|
|
self::assertFalse($comment->getVisible());
|
|
}
|
|
|
|
public function testSetAuthor(): void
|
|
{
|
|
$comment = new Comment();
|
|
$comment->setAuthor('Mark Baker');
|
|
self::assertEquals('Mark Baker', $comment->getAuthor());
|
|
}
|
|
|
|
public function testSetMarginLeft(): void
|
|
{
|
|
$comment = new Comment();
|
|
$comment->setMarginLeft('20pt');
|
|
self::assertEquals('20pt', $comment->getMarginLeft());
|
|
}
|
|
|
|
public function testSetMarginTop(): void
|
|
{
|
|
$comment = new Comment();
|
|
$comment->setMarginTop('2.5pt');
|
|
self::assertEquals('2.5pt', $comment->getMarginTop());
|
|
}
|
|
|
|
public function testSetWidth(): void
|
|
{
|
|
$comment = new Comment();
|
|
$comment->setWidth('120pt');
|
|
self::assertEquals('120pt', $comment->getWidth());
|
|
}
|
|
|
|
public function testSetHeight(): void
|
|
{
|
|
$comment = new Comment();
|
|
$comment->setHeight('60px');
|
|
self::assertEquals('60px', $comment->getHeight());
|
|
}
|
|
|
|
public function testSetFillColor(): void
|
|
{
|
|
$comment = new Comment();
|
|
$comment->setFillColor(new Color('RED'));
|
|
self::assertEquals(Color::COLOR_RED, $comment->getFillColor()->getARGB());
|
|
}
|
|
|
|
public function testSetAlignment(): void
|
|
{
|
|
$comment = new Comment();
|
|
$comment->setAlignment(Alignment::HORIZONTAL_CENTER);
|
|
self::assertEquals(Alignment::HORIZONTAL_CENTER, $comment->getAlignment());
|
|
}
|
|
|
|
public function testSetText(): void
|
|
{
|
|
$comment = new Comment();
|
|
$test = new RichText();
|
|
$test->addText(new TextElement('This is a test comment'));
|
|
$comment->setText($test);
|
|
self::assertEquals('This is a test comment', (string) $comment);
|
|
}
|
|
|
|
public function testRemoveComment(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->getComment('A2')->getText()->createText('Comment to delete');
|
|
self::assertArrayHasKey('A2', $sheet->getComments());
|
|
$sheet->removeComment('A2');
|
|
self::assertEmpty($sheet->getComments()); // @phpstan-ignore-line
|
|
}
|
|
}
|