mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-25 16:28:18 +00:00
68158c8120
These changes have already been implemented twice, and been regressed twice. I'll try once more (with a different approach), then give up ... As configured, Phpstan running under Php7 reports no errors. However, running under Php8, it reports 100 (!) errors. The vast majority of these are due to two reasons: - renaming parameters in Php builtin functions in preparation for named parameters. - using the new class GdImage rather than type resource as the argument type for many image-based functions. Regardless of the cause, this will be a problem sooner or later. This PR is an attempt to get ahead of that problem. For source members, it mostly adds annotations or updates doc-blocks. Only 2 members have changes to executable code, and these are very minor - BitWise and Writer/Xlsx. For test members, all baseline errors are deleted and the code is fixed. Php7 and Php8 both report no errors with this configuration.
65 lines
2.6 KiB
PHP
65 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\Title;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ChartsTitleTest extends TestCase
|
|
{
|
|
private static function getTitleText(?Title $title): string
|
|
{
|
|
return ($title === null) ? '' : $title->getCaptionText();
|
|
}
|
|
|
|
public function testChartTitles(): void
|
|
{
|
|
$filename = 'tests/data/Reader/XLSX/excelChartsTest.xlsx';
|
|
$reader = IOFactory::createReader('Xlsx')->setIncludeCharts(true);
|
|
$spreadsheet = $reader->load($filename);
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
|
|
$charts = $worksheet->getChartCollection();
|
|
self::assertEquals(5, $worksheet->getChartCount());
|
|
self::assertCount(5, $charts);
|
|
|
|
// No title or axis labels
|
|
$chart1 = $charts[0];
|
|
self::assertNotNull($chart1);
|
|
$title = self::getTitleText($chart1->getTitle());
|
|
self::assertEmpty($title);
|
|
self::assertEmpty(self::getTitleText($chart1->getXAxisLabel()));
|
|
self::assertEmpty(self::getTitleText($chart1->getYAxisLabel()));
|
|
|
|
// Title, no axis labels
|
|
$chart2 = $charts[1];
|
|
self::assertNotNull($chart2);
|
|
|
|
self::assertEquals('Chart with Title and no Axis Labels', self::getTitleText($chart2->getTitle()));
|
|
self::assertEmpty(self::getTitleText($chart2->getXAxisLabel()));
|
|
self::assertEmpty(self::getTitleText($chart2->getYAxisLabel()));
|
|
|
|
// No title, only horizontal axis label
|
|
$chart3 = $charts[2];
|
|
self::assertNotNull($chart3);
|
|
self::assertEmpty(self::getTitleText($chart3->getTitle()));
|
|
self::assertEquals('Horizontal Axis Title Only', self::getTitleText($chart3->getXAxisLabel()));
|
|
self::assertEmpty(self::getTitleText($chart3->getYAxisLabel()));
|
|
|
|
// No title, only vertical axis label
|
|
$chart4 = $charts[3];
|
|
self::assertNotNull($chart4);
|
|
self::assertEmpty(self::getTitleText($chart4->getTitle()));
|
|
self::assertEquals('Vertical Axis Title Only', self::getTitleText($chart4->getYAxisLabel()));
|
|
self::assertEmpty(self::getTitleText($chart4->getXAxisLabel()));
|
|
|
|
// Title and both axis labels
|
|
$chart5 = $charts[4];
|
|
self::assertNotNull($chart5);
|
|
self::assertEquals('Complete Annotations', self::getTitleText($chart5->getTitle()));
|
|
self::assertEquals('Horizontal Axis Title', self::getTitleText($chart5->getXAxisLabel()));
|
|
self::assertEquals('Vertical Axis Title', self::getTitleText($chart5->getYAxisLabel()));
|
|
}
|
|
}
|