-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corrections for Xlsx Read Comments (#2329)
This change was suggested by issue #2316. There was a problem reading Xlsx comments which appeared with release 18.0 but which was already fixed in master. So no source change was needed to fix the issue, but I thought we should at least add the test case to our unit tests. In developing that case, I discovered that, although comment text was read correctly, there was a problem with comment author. In fact, there were two problems. One was new, with the namespacing changes - as in several other cases, the namespaced attribute `authorId` needed some special handling. However, another problem was much older - the code was checking `!empty($comment['authorId'])`, eliminating consideration of authorId=0, and should instead have been checking `isset`. Both problems are now fixed, and tested.
- Loading branch information
Showing
3 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CommentTest extends TestCase | ||
{ | ||
public function testIssue2316(): void | ||
{ | ||
$filename = 'tests/data/Reader/XLSX/issue.2316.xlsx'; | ||
$reader = new Xlsx(); | ||
$spreadsheet = $reader->load($filename); | ||
|
||
$sheet = $spreadsheet->getActiveSheet(); | ||
$comment = $sheet->getComment('A1'); | ||
$commentString = (string) $comment; | ||
self::assertStringContainsString('編號長度限制:', $commentString); | ||
self::assertSame('jill.chen', $comment->getAuthor()); | ||
$comment = $sheet->getComment('E1'); | ||
$commentString = (string) $comment; | ||
self::assertStringContainsString('若為宅配物流僅能選「純配送」', $commentString); | ||
self::assertSame('Anderson Chen 陳宗棠', $comment->getAuthor()); | ||
} | ||
} |
Binary file not shown.