|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpOffice\PhpSpreadsheetTests\Chart; |
| 4 | + |
| 5 | +use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | + |
| 8 | +class Issue2965Test extends TestCase |
| 9 | +{ |
| 10 | + private const DIRECTORY = 'tests' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'Reader' . DIRECTORY_SEPARATOR . 'XLSX' . DIRECTORY_SEPARATOR; |
| 11 | + |
| 12 | + public function testPreliminaries(): void |
| 13 | + { |
| 14 | + $file = 'zip://'; |
| 15 | + $file .= self::DIRECTORY . 'issue.2965.xlsx'; |
| 16 | + $file .= '#xl/charts/chart1.xml'; |
| 17 | + $data = file_get_contents($file); |
| 18 | + // confirm that file contains expected namespaced xml tag |
| 19 | + if ($data === false) { |
| 20 | + self::fail('Unable to read file'); |
| 21 | + } else { |
| 22 | + self::assertStringContainsString('<c:title><c:tx><c:strRef><c:f>Sheet1!$A$1</c:f><c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>NewTitle</c:v></c:pt></c:strCache></c:strRef></c:tx>', $data); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + public function testChartTitleFormula(): void |
| 27 | + { |
| 28 | + $reader = new XlsxReader(); |
| 29 | + $reader->setIncludeCharts(true); |
| 30 | + $spreadsheet = $reader->load(self::DIRECTORY . 'issue.2965.xlsx'); |
| 31 | + $worksheet = $spreadsheet->getActiveSheet(); |
| 32 | + $charts = $worksheet->getChartCollection(); |
| 33 | + self::assertCount(1, $charts); |
| 34 | + $originalChart1 = $charts[0]; |
| 35 | + self::assertNotNull($originalChart1); |
| 36 | + $originalTitle1 = $originalChart1->getTitle(); |
| 37 | + self::assertNotNull($originalTitle1); |
| 38 | + self::assertSame('NewTitle', $originalTitle1->getCaptionText()); |
| 39 | + |
| 40 | + $spreadsheet->disconnectWorksheets(); |
| 41 | + } |
| 42 | +} |
0 commit comments