1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xls; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xls; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class Issue642Test extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function testCharOutsideBMP(): void |
13
|
|
|
{ |
14
|
|
|
$spreadsheet = new Spreadsheet(); |
15
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
16
|
|
|
$stringUtf8 = "Hello\u{1f600}goodbye"; |
17
|
|
|
self::assertSame(13, mb_strlen($stringUtf8)); |
18
|
|
|
$stringUtf16 = (string) iconv('UTF-8', 'UTF-16LE', $stringUtf8); |
19
|
|
|
self::assertSame(28, strlen($stringUtf16)); // each character requires 2 bytes except for non-BMP which requires 4 |
20
|
|
|
$sheet->getCell('A1')->setValue($stringUtf8); |
21
|
|
|
$outputFilename = File::temporaryFilename(); |
22
|
|
|
$writer = new Xls($spreadsheet); |
23
|
|
|
$writer->save($outputFilename); |
24
|
|
|
$spreadsheet->disconnectWorksheets(); |
25
|
|
|
$contents = (string) file_get_contents($outputFilename); |
26
|
|
|
unlink($outputFilename); |
27
|
|
|
$expected = "\x00\x0e\x00\x01" . $stringUtf16; // length is 14 (0e), not 13 |
28
|
|
|
self::assertStringContainsString($expected, $contents); |
29
|
|
|
$unexpected = "\x00\x0d\x00\x01" . $stringUtf16; // length is 14 (0e), not 13 |
30
|
|
|
self::assertStringNotContainsString($unexpected, $contents); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|