1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Comment; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\RichText\TextElement; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Color; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class CommentTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testCreateComment(): void |
15
|
|
|
{ |
16
|
|
|
$comment = new Comment(); |
17
|
|
|
self::assertEquals('Author', $comment->getAuthor()); |
18
|
|
|
self::assertEquals('96pt', $comment->getWidth()); |
19
|
|
|
self::assertEquals('59.25pt', $comment->getMarginLeft()); |
20
|
|
|
self::assertEquals('1.5pt', $comment->getMarginTop()); |
21
|
|
|
self::assertEquals('55.5pt', $comment->getHeight()); |
22
|
|
|
self::assertInstanceOf(Color::class, $comment->getFillColor()); |
23
|
|
|
self::assertEquals('FFFFFFE1', $comment->getFillColor()->getARGB()); |
24
|
|
|
self::assertInstanceOf(RichText::class, $comment->getText()); |
25
|
|
|
self::assertEquals(Alignment::HORIZONTAL_GENERAL, $comment->getAlignment()); |
26
|
|
|
self::assertFalse($comment->getVisible()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testSetAuthor(): void |
30
|
|
|
{ |
31
|
|
|
$comment = new Comment(); |
32
|
|
|
$comment->setAuthor('Mark Baker'); |
33
|
|
|
self::assertEquals('Mark Baker', $comment->getAuthor()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testSetMarginLeft(): void |
37
|
|
|
{ |
38
|
|
|
$comment = new Comment(); |
39
|
|
|
$comment->setMarginLeft('20pt'); |
40
|
|
|
self::assertEquals('20pt', $comment->getMarginLeft()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testSetMarginTop(): void |
44
|
|
|
{ |
45
|
|
|
$comment = new Comment(); |
46
|
|
|
$comment->setMarginTop('2.5pt'); |
47
|
|
|
self::assertEquals('2.5pt', $comment->getMarginTop()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testSetWidth(): void |
51
|
|
|
{ |
52
|
|
|
$comment = new Comment(); |
53
|
|
|
$comment->setWidth('120pt'); |
54
|
|
|
self::assertEquals('120pt', $comment->getWidth()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testSetHeight(): void |
58
|
|
|
{ |
59
|
|
|
$comment = new Comment(); |
60
|
|
|
$comment->setHeight('60px'); |
61
|
|
|
self::assertEquals('60px', $comment->getHeight()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testSetFillColor(): void |
65
|
|
|
{ |
66
|
|
|
$comment = new Comment(); |
67
|
|
|
$comment->setFillColor(new Color('RED')); |
68
|
|
|
self::assertEquals('RED', $comment->getFillColor()->getARGB()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testSetAlignment(): void |
72
|
|
|
{ |
73
|
|
|
$comment = new Comment(); |
74
|
|
|
$comment->setAlignment(Alignment::HORIZONTAL_CENTER); |
75
|
|
|
self::assertEquals(Alignment::HORIZONTAL_CENTER, $comment->getAlignment()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testSetText(): void |
79
|
|
|
{ |
80
|
|
|
$comment = new Comment(); |
81
|
|
|
$test = new RichText(); |
82
|
|
|
$test->addText(new TextElement('This is a test comment')); |
83
|
|
|
$comment->setText($test); |
84
|
|
|
self::assertEquals('This is a test comment', (string) $comment); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|