Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Writer/Xlsx/Issue4269Test.php
T
oleibman 95213bf50a Breaking Change - 3 Defaults
Fix #4092. Change default value for Csv Reader autodetect line endings. Prior behavior can be enabled via `setTestAutodetect(true)`.

Change default value for Html Writer "better boolean" logic. Prior behavior can be explicitly enabled via `setBetterBoolean(false)`.

Change default for Xlsx Writer forceFullCalc option. Prior behavior can be explicitly enabled via `setForceFullCalc(null)`.
2025-02-04 06:58:31 -08:00

71 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class Issue4269Test extends TestCase
{
private string $outputFile = '';
private static bool $alwaysFalse = false;
protected function tearDown(): void
{
if ($this->outputFile !== '') {
unlink($this->outputFile);
$this->outputFile = '';
}
}
#[DataProvider('validationProvider')]
public function testWriteArrayFormulaTextJoin(
bool $preCalculateFormulas,
?bool $forceFullCalc,
string $expected
): void {
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', '=A2*2');
$sheet->setCellValue('A2', 0);
$writer = new XlsxWriter($spreadsheet);
$writer->setPreCalculateFormulas($preCalculateFormulas);
$writer->setForceFullCalc($forceFullCalc);
$this->outputFile = File::temporaryFilename();
$writer->save($this->outputFile);
$spreadsheet->disconnectWorksheets();
$file = 'zip://';
$file .= $this->outputFile;
$file .= '#xl/workbook.xml';
$data = file_get_contents($file);
if ($data === false) {
self::fail('Unable to read file');
} else {
self::assertStringContainsString($expected, $data);
}
}
public static function validationProvider(): array
{
return [
'normal case' => [true, null, 'calcMode="auto" calcCompleted="1" fullCalcOnLoad="0" forceFullCalc="0"'],
'issue 456' => [false, null, 'calcMode="auto" calcCompleted="0" fullCalcOnLoad="1" forceFullCalc="1"'],
'better choice for no precalc' => [false, false, 'calcMode="auto" calcCompleted="0" fullCalcOnLoad="1" forceFullCalc="0"'],
'unlikely use case' => [true, true, 'calcMode="auto" calcCompleted="1" fullCalcOnLoad="0" forceFullCalc="1"'],
];
}
public function testDefault(): void
{
self::assertSame(self::$alwaysFalse, XlsxWriter::DEFAULT_FORCE_FULL_CALC);
}
}