outputFileName !== '') { unlink($this->outputFileName); $this->outputFileName = ''; } } /** * @dataProvider providerScatterCharts */ public function testBezierCount(int $expectedCount, string $inputFile): void { $file = self::DIRECTORY . $inputFile; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $writer = new XlsxWriter($spreadsheet); $writer->setIncludeCharts(true); $this->outputFileName = File::temporaryFilename(); $writer->save($this->outputFileName); $spreadsheet->disconnectWorksheets(); $file = 'zip://'; $file .= $this->outputFileName; $file .= '#xl/charts/chart2.xml'; $data = file_get_contents($file); // confirm that file contains expected tags if ($data === false) { self::fail('Unable to read file'); } else { self::assertSame(1, substr_count($data, '')); self::assertSame($expectedCount, substr_count($data, '')); } } public function providerScatterCharts(): array { return [ 'no line' => [0, '32readwriteScatterChart1.xlsx'], 'smooth line (Bezier)' => [3, '32readwriteScatterChart2.xlsx'], 'straight line' => [0, '32readwriteScatterChart3.xlsx'], ]; } public function testAreaPercentageNoCat(): void { $file = self::DIRECTORY . '32readwriteAreaPercentageChart1.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $writer = new XlsxWriter($spreadsheet); $writer->setIncludeCharts(true); $this->outputFileName = File::temporaryFilename(); $writer->save($this->outputFileName); $spreadsheet->disconnectWorksheets(); $file = 'zip://'; $file .= $this->outputFileName; $file .= '#xl/charts/chart1.xml'; $data = file_get_contents($file); // confirm that file contains expected tags if ($data === false) { self::fail('Unable to read file'); } else { self::assertSame(0, substr_count($data, '')); } } /** * @dataProvider providerCatAxValAx */ public function testCatAxValAx(?bool $numeric): void { $file = self::DIRECTORY . '32readwriteScatterChart1.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $xAxis = $chart->getChartAxisX(); self::assertSame(Properties::FORMAT_CODE_GENERAL, $xAxis->getAxisNumberFormat()); if (is_bool($numeric)) { $xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_GENERAL, true); } $yAxis = $chart->getChartAxisY(); self::assertSame(Properties::FORMAT_CODE_GENERAL, $yAxis->getAxisNumberFormat()); if (is_bool($numeric)) { $xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_GENERAL, $numeric); $yAxis->setAxisNumberProperties(Properties::FORMAT_CODE_GENERAL, $numeric); } $writer = new XlsxWriter($spreadsheet); $writer->setIncludeCharts(true); $this->outputFileName = File::temporaryFilename(); $writer->save($this->outputFileName); $spreadsheet->disconnectWorksheets(); $file = 'zip://'; $file .= $this->outputFileName; $file .= '#xl/charts/chart2.xml'; $data = file_get_contents($file); // confirm that file contains expected tags if ($data === false) { self::fail('Unable to read file'); } elseif ($numeric === true) { self::assertSame(0, substr_count($data, '')); self::assertSame(2, substr_count($data, '')); } else { self::assertSame(1, substr_count($data, '')); self::assertSame(1, substr_count($data, '')); } } public function providerCatAxValAx(): array { return [ [true], [false], [null], ]; } }