From 5472c1af7efac88dc2c8a7e638a020bb72a57d82 Mon Sep 17 00:00:00 2001 From: LindaXie Date: Wed, 30 Aug 2023 16:42:35 -0700 Subject: [PATCH] PowerPoint2077 Writer : Fixed error when defining min/max bounds to 0 --- docs/changes/1.1.0.md | 3 +- .../Writer/PowerPoint2007/PptCharts.php | 4 +- .../Writer/PowerPoint2007/PptChartsTest.php | 50 +++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/docs/changes/1.1.0.md b/docs/changes/1.1.0.md index aed989f2b..a95d5ace1 100644 --- a/docs/changes/1.1.0.md +++ b/docs/changes/1.1.0.md @@ -14,4 +14,5 @@ ## Bugfixes - Fixed CI - [@Progi1984](https://github.com/Progi1984) in [#766](https://github.com/PHPOffice/PHPPresentation/pull/766) -- Fixed broken PPT Presentations due to MS Office update 2309 - [@WFarmerEthisphere](https://github.com/WFarmerEthisphere) in [#770](https://github.com/PHPOffice/PHPPresentation/pull/770) \ No newline at end of file +- PowerPoint2077 Writer : Fixed broken PPT Presentations due to MS Office update 2309 - [@WFarmerEthisphere](https://github.com/WFarmerEthisphere) in [#770](https://github.com/PHPOffice/PHPPresentation/pull/770) +- PowerPoint2077 Writer : Fixed error when defining min/max bounds to 0 - [@LilyEssence](https://github.com/LilyEssence) in [#771](https://github.com/PHPOffice/PHPPresentation/pull/771) \ No newline at end of file diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php index 132175bf4..ce0e5ff42 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php @@ -2284,13 +2284,13 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, string $ty $objWriter->writeAttribute('val', $orientation); $objWriter->endElement(); - if (null != $oAxis->getMaxBounds()) { + if (null !== $oAxis->getMaxBounds()) { $objWriter->startElement('c:max'); $objWriter->writeAttribute('val', $oAxis->getMaxBounds()); $objWriter->endElement(); } - if (null != $oAxis->getMinBounds()) { + if (null !== $oAxis->getMinBounds()) { $objWriter->startElement('c:min'); $objWriter->writeAttribute('val', $oAxis->getMinBounds()); $objWriter->endElement(); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php index db576820c..f1e5b4912 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php @@ -275,6 +275,56 @@ public function testAxisBounds(): void $this->assertIsSchemaECMA376Valid(); } + public function testAxisBoundsIfZero(): void + { + $value = 0; + + $oSeries = new Series('Downloads', $this->seriesData); + $oSeries->getFill()->setStartColor(new Color('FFAABBCC')); + $oLine = new Line(); + $oLine->addSeries($oSeries); + $oShape = $this->oPresentation->getActiveSlide()->createChartShape(); + $oShape->getPlotArea()->setType($oLine); + + $elementMax = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:scaling/c:max'; + $elementMin = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:scaling/c:min'; + + $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax); + $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin); + + $this->assertIsSchemaECMA376Valid(); + + $oShape->getPlotArea()->getAxisX()->setMinBounds($value); + $this->resetPresentationFile(); + + $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax); + $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value); + + $this->assertIsSchemaECMA376Valid(); + + $oShape->getPlotArea()->getAxisX()->setMinBounds(null); + $oShape->getPlotArea()->getAxisX()->setMaxBounds($value); + $this->resetPresentationFile(); + + $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin); + $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value); + + $this->assertIsSchemaECMA376Valid(); + + $oShape->getPlotArea()->getAxisX()->setMinBounds($value); + $oShape->getPlotArea()->getAxisX()->setMaxBounds($value); + $this->resetPresentationFile(); + + $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value); + $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value); + + $this->assertIsSchemaECMA376Valid(); + } + public function testAxisCrosses(): void { $oSeries = new Series('Downloads', $this->seriesData);