Skip to content

Commit

Permalink
PowerPoint2007 Writer : Fixed issue when first element in series is null
Browse files Browse the repository at this point in the history
  • Loading branch information
devopsadmin authored and Progi1984 committed Dec 7, 2023
1 parent ce54114 commit c807b66
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- PowerPoint2007 Writer : Fixed column indices for embedded spreadsheets - [@michael-roth](https://github.com/michael-roth) in [#773](https://github.com/PHPOffice/PHPPresentation/pull/773)
- PowerPoint2007 Reader : Load images from file only if valid - [@aelliott1485](https://github.com/aelliott1485) in [#775](https://github.com/PHPOffice/PHPPresentation/pull/775)
- PowerPoint2007 Writer : Fixed broken video file relationship - [@potofcoffee](https://github.com/potofcoffee) in [#776](https://github.com/PHPOffice/PHPPresentation/pull/776)
- PowerPoint2007 Writer : Fixed issue when first element in series is null- [@ksmeeks0001](https://github.com/ksmeeks0001) in [#778](https://github.com/PHPOffice/PHPPresentation/pull/778)

## BC Breaks
- `PhpOffice\PhpPresentation\Style\Outline` : the width is now based on pixels (before in points)
10 changes: 9 additions & 1 deletion src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,15 @@ protected function writeMultipleValuesOrReference(XMLWriter $objWriter, bool $is
// c:strLit / c:numLit
// c:strRef / c:numRef
$referenceType = ($isReference ? 'Ref' : 'Lit');
$dataType = is_numeric($values[0]) ? 'num' : 'str';

// get data type from first non-null value
$dataType = array_reduce($values, function($carry, $item) {
if (!isset($value)){

Check failure on line 353 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Variable $value in isset() is never defined.

Check failure on line 353 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.2)

Variable $value in isset() is never defined.

Check failure on line 353 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Variable $value in isset() is never defined.

Check failure on line 353 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.4)

Variable $value in isset() is never defined.

Check failure on line 353 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Variable $value in isset() is never defined.

Check failure on line 353 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.3)

Variable $value in isset() is never defined.

Check failure on line 353 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.0)

Variable $value in isset() is never defined.

Check failure on line 353 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.1)

Variable $value in isset() is never defined.
return $carry;
}
return is_numeric($item) ? 'num' : 'str';

Check failure on line 356 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.3)

Unreachable statement - code above always terminates.

Check failure on line 356 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.2)

Unreachable statement - code above always terminates.

Check failure on line 356 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.1)

Unreachable statement - code above always terminates.

Check failure on line 356 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.4)

Unreachable statement - code above always terminates.

Check failure on line 356 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.2)

Unreachable statement - code above always terminates.

Check failure on line 356 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.3)

Unreachable statement - code above always terminates.

Check failure on line 356 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (8.0)

Unreachable statement - code above always terminates.

Check failure on line 356 in src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis (7.1)

Unreachable statement - code above always terminates.
}, 'num');

$objWriter->startElement('c:' . $dataType . $referenceType);

$numValues = count($values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,76 @@ public function testChartDisplayBlankAs(): void
$this->assertIsSchemaECMA376Valid();
}

/**
* @dataProvider dataProviderIncludedSpreadsheet
*/
public function testChartIncludeSpreadsheetNullValue(string $chartType, string $chartElementName): void
{
$seriesData = array_merge(['Z' => null], $this->seriesData);

$oSlide = $this->oPresentation->getActiveSlide();
$oShape = $oSlide->createChartShape();
$oShape->setIncludeSpreadsheet(true);
/** @var AbstractType $oChart */
$oChart = new $chartType();
$oSeries = new Series('Downloads', $seriesData);
$oChart->addSeries($oSeries);
$oShape->getPlotArea()->setType($oChart);

$chartBaseXmlPath = sprintf('/c:chartSpace/c:chart/c:plotArea/%s', $chartElementName);

self::assertTrue($oShape->hasIncludedSpreadsheet());

$this->assertZipFileExists('ppt/charts/' . $oShape->getIndexedFilename());
$this->assertZipFileExists('ppt/embeddings/' . $oShape->getIndexedFilename() . '.xlsx');

$this->assertZipFileExists('ppt/charts/_rels/' . $oShape->getIndexedFilename() . '.rels');
$element = '/Relationships/Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"]';
$this->assertZipXmlElementExists('ppt/charts/_rels/' . $oShape->getIndexedFilename() . '.rels', $element);

$element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
$this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
$element = $chartBaseXmlPath;
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = $chartBaseXmlPath . '/c:ser';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlElementCount('ppt/charts/' . $oShape->getIndexedFilename(), $element, 1);
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:v';
$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:f';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Sheet1!$B$1');
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache/c:pt';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache/c:pt/c:v';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Downloads');

$element = $chartBaseXmlPath . '/c:ser/c:val/c:numRef/c:numCache/c:pt/c:v';
if ($oChart instanceof Scatter) {
$element = $chartBaseXmlPath . '/c:ser/c:yVal/c:numRef/c:numCache/c:pt/c:v';
}
$this->assertZipXmlElementCount('ppt/charts/' . $oShape->getIndexedFilename(), $element, count($seriesData));
foreach (array_values($seriesData) as $index => $value) {
$this->assertZipXmlElementAtIndexEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $index, $value);
}

$element = '/c:chartSpace/c:externalData';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeExists('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'r:id');
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'r:id', 'rId1');
$element = '/c:chartSpace/c:externalData/c:autoUpdate';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeExists('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val');
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '0');

$this->assertIsSchemaECMA376Valid();
}

/**
* @dataProvider dataProviderIncludedSpreadsheet
*/
Expand Down

0 comments on commit c807b66

Please sign in to comment.