1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use ZipArchive; |
12
|
|
|
|
13
|
|
|
class Issue4477Test extends TestCase |
14
|
|
|
{ |
15
|
|
|
private string $tempfile = ''; |
16
|
|
|
|
17
|
|
|
protected function tearDown(): void |
18
|
|
|
{ |
19
|
|
|
if ($this->tempfile !== '') { |
20
|
|
|
unlink($this->tempfile); |
21
|
|
|
$this->tempfile = ''; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testDataonlyNoPrinter(): void |
26
|
|
|
{ |
27
|
|
|
// Need to ignore printer settings when Read Dataonly |
28
|
|
|
$infile = 'tests/data/Reader/XLSX/issue.4477.disclaimer.xlsx'; |
29
|
|
|
$zip = new ZipArchive(); |
30
|
|
|
if ($zip->open($infile) !== true) { |
31
|
|
|
self::fail("failed to open $infile"); |
32
|
|
|
} |
33
|
|
|
$num = $zip->numFiles; |
34
|
|
|
$foundPrinter = $foundWorksheet = false; |
35
|
|
|
for ($i = 0; $i < $num; ++$i) { |
36
|
|
|
$filename = (string) $zip->getNameIndex($i); |
37
|
|
|
if (str_contains($filename, 'printer')) { |
38
|
|
|
$foundPrinter = true; |
39
|
|
|
} elseif ($filename === 'xl/worksheets/sheet1.xml') { |
40
|
|
|
$foundWorksheet = true; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
$zip->close(); |
44
|
|
|
self::assertTrue($foundPrinter); |
45
|
|
|
self::assertTrue($foundWorksheet); |
46
|
|
|
|
47
|
|
|
$reader = new XlsxReader(); |
48
|
|
|
$reader->setReadDataOnly(true); |
49
|
|
|
$spreadsheet = $reader->load($infile); |
50
|
|
|
$writer = new XlsxWriter($spreadsheet); |
51
|
|
|
$this->tempfile = File::temporaryFileName(); |
52
|
|
|
$writer->save($this->tempfile); |
53
|
|
|
$spreadsheet->disconnectWorksheets(); |
54
|
|
|
|
55
|
|
|
$zip = new ZipArchive(); |
56
|
|
|
if ($zip->open($this->tempfile) !== true) { |
57
|
|
|
self::fail("failed to open {$infile}"); |
58
|
|
|
} |
59
|
|
|
$num = $zip->numFiles; |
60
|
|
|
$foundPrinter = $foundWorksheet = false; |
61
|
|
|
for ($i = 0; $i < $num; ++$i) { |
62
|
|
|
$filename = (string) $zip->getNameIndex($i); |
63
|
|
|
if (str_contains($filename, 'printer')) { |
64
|
|
|
$foundPrinter = true; |
65
|
|
|
} elseif ($filename === 'xl/worksheets/sheet1.xml') { |
66
|
|
|
$foundWorksheet = true; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
$zip->close(); |
70
|
|
|
self::assertFalse($foundPrinter); |
71
|
|
|
self::assertTrue($foundWorksheet); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|