1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Functional; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
7
|
|
|
|
8
|
|
|
class HtmlCommentsTest extends AbstractFunctional |
9
|
|
|
{ |
10
|
|
|
private $spreadsheet; |
11
|
|
|
|
12
|
|
|
public function providerCommentRichText() |
13
|
|
|
{ |
14
|
|
|
$valueSingle = 'I am comment.'; |
15
|
|
|
$valueMulti = 'I am ' . PHP_EOL . 'multi-line' . PHP_EOL . 'comment.'; |
16
|
|
|
|
17
|
|
|
$plainSingle = new RichText(); |
18
|
|
|
$plainSingle->createText($valueSingle); |
19
|
|
|
|
20
|
|
|
$plainMulti = new RichText(); |
21
|
|
|
$plainMulti->createText($valueMulti); |
22
|
|
|
|
23
|
|
|
$richSingle = new RichText(); |
24
|
|
|
$richSingle->createTextRun($valueSingle)->getFont()->setBold(true); |
25
|
|
|
|
26
|
|
|
$richMultiSimple = new RichText(); |
27
|
|
|
$richMultiSimple->createTextRun($valueMulti)->getFont()->setBold(true); |
28
|
|
|
|
29
|
|
|
$richMultiMixed = new RichText(); |
30
|
|
|
$richMultiMixed->createText('I am' . PHP_EOL); |
31
|
|
|
$richMultiMixed->createTextRun('multi-line')->getFont()->setBold(true); |
32
|
|
|
$richMultiMixed->createText(PHP_EOL . 'comment!'); |
33
|
|
|
|
34
|
|
|
return [ |
35
|
|
|
'single line plain text' => [$plainSingle], |
36
|
|
|
'multi-line plain text' => [$plainMulti], |
37
|
|
|
'single line simple rich text' => [$richSingle], |
38
|
|
|
'multi-line simple rich text' => [$richMultiSimple], |
39
|
|
|
'multi-line mixed rich text' => [$richMultiMixed], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @dataProvider providerCommentRichText |
45
|
|
|
* |
46
|
|
|
* @param mixed $richText |
47
|
|
|
*/ |
48
|
|
|
public function testComments($richText) |
49
|
|
|
{ |
50
|
|
|
$this->spreadsheet = new Spreadsheet(); |
51
|
|
|
|
52
|
|
|
$this->spreadsheet->getActiveSheet()->getCell('A1')->setValue('Comment'); |
53
|
|
|
|
54
|
|
|
$this->spreadsheet->getActiveSheet() |
55
|
|
|
->getComment('A1') |
56
|
|
|
->setText($richText); |
57
|
|
|
|
58
|
|
|
$reloadedSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Html'); |
59
|
|
|
|
60
|
|
|
$actual = $reloadedSpreadsheet->getActiveSheet()->getComment('A1')->getText()->getPlainText(); |
61
|
|
|
self::assertSame($richText->getPlainText(), $actual); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|