1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; |
10
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
class Issue4269Test extends TestCase |
14
|
|
|
{ |
15
|
|
|
private string $outputFile = ''; |
16
|
|
|
|
17
|
|
|
protected function tearDown(): void |
18
|
|
|
{ |
19
|
|
|
if ($this->outputFile !== '') { |
20
|
|
|
unlink($this->outputFile); |
21
|
|
|
$this->outputFile = ''; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
#[DataProvider('validationProvider')] |
26
|
|
|
public function testWriteArrayFormulaTextJoin( |
27
|
|
|
bool $preCalculateFormulas, |
28
|
|
|
?bool $forceFullCalc, |
29
|
|
|
string $expected |
30
|
|
|
): void { |
31
|
|
|
$spreadsheet = new Spreadsheet(); |
32
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
33
|
|
|
$sheet->setCellValue('A1', '=A2*2'); |
34
|
|
|
$sheet->setCellValue('A2', 0); |
35
|
|
|
|
36
|
|
|
$writer = new XlsxWriter($spreadsheet); |
37
|
|
|
$writer->setPreCalculateFormulas($preCalculateFormulas); |
38
|
|
|
if ($forceFullCalc !== null) { |
39
|
|
|
$writer->setForceFullCalc($forceFullCalc); |
40
|
|
|
} |
41
|
|
|
$this->outputFile = File::temporaryFilename(); |
42
|
|
|
$writer->save($this->outputFile); |
43
|
|
|
$spreadsheet->disconnectWorksheets(); |
44
|
|
|
|
45
|
|
|
$file = 'zip://'; |
46
|
|
|
$file .= $this->outputFile; |
47
|
|
|
$file .= '#xl/workbook.xml'; |
48
|
|
|
$data = file_get_contents($file); |
49
|
|
|
if ($data === false) { |
50
|
|
|
self::fail('Unable to read file'); |
51
|
|
|
} else { |
52
|
|
|
self::assertStringContainsString($expected, $data); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function validationProvider(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
'normal case' => [true, null, 'calcMode="auto" calcCompleted="1" fullCalcOnLoad="0" forceFullCalc="0"'], |
60
|
|
|
'issue 456' => [false, null, 'calcMode="auto" calcCompleted="0" fullCalcOnLoad="1" forceFullCalc="1"'], |
61
|
|
|
'better choice for no precalc' => [false, false, 'calcMode="auto" calcCompleted="0" fullCalcOnLoad="1" forceFullCalc="0"'], |
62
|
|
|
'unlikely use case' => [true, true, 'calcMode="auto" calcCompleted="1" fullCalcOnLoad="0" forceFullCalc="1"'], |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|