Skip to content

Commit f46c79c

Browse files
committed
fixing bug in assigning relationship ids in master slide
1 parent 2549058 commit f46c79c

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ protected function writeDrawingRelations(AbstractSlideAlias $pSlideMaster, $objW
108108
$iterator->next();
109109
}
110110
}
111+
112+
return $relId;
111113
}
112114

113115
/**

src/PhpPresentation/Writer/PowerPoint2007/PptSlideMasters.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ public function writeSlideMasterRelationships(SlideMaster $oMasterSlide)
5454
// Save the used relationId
5555
$slideLayout->relationId = 'rId' . $relId;
5656
}
57+
5758
// Write drawing relationships?
58-
$this->writeDrawingRelations($oMasterSlide, $objWriter, ++$relId);
59+
$relId = $this->writeDrawingRelations($oMasterSlide, $objWriter, ++$relId);
60+
5961
// TODO: Write hyperlink relationships?
6062
// TODO: Write comment relationships
6163
// Relationship theme/theme1.xml
62-
$this->writeRelationship($objWriter, ++$relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', '../theme/theme' . $oMasterSlide->getRelsIndex() . '.xml');
64+
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', '../theme/theme' . $oMasterSlide->getRelsIndex() . '.xml');
6365
$objWriter->endElement();
6466
// Return
6567
return $objWriter->getData();

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlideMastersTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpOffice\PhpPresentation\Writer\PowerPoint2007\PptSlideMasters;
66
use PhpOffice\PhpPresentation\Slide\SlideLayout;
7+
use PhpOffice\PhpPresentation\Shape\Drawing\File as ShapeDrawingFile;
78

89
/**
910
* Test class for PowerPoint2007
@@ -25,10 +26,30 @@ public function testWriteSlideMasterRelationships()
2526
->method('getAllSlideLayouts')
2627
->will($this->returnValue($layouts));
2728

29+
$collection = new \ArrayObject();
30+
$collection[] = new ShapeDrawingFile();
31+
$collection[] = new ShapeDrawingFile();
32+
$collection[] = new ShapeDrawingFile();
33+
2834
$slideMaster->expects($this->exactly(2))
2935
->method('getShapeCollection')
30-
->will($this->returnValue(new \ArrayObject()));
36+
->will($this->returnValue($collection));
3137

3238
$data = $writer->writeSlideMasterRelationships($slideMaster);
39+
40+
$dom = new \DomDocument();
41+
$dom->loadXml($data);
42+
43+
$xpath = new \DomXpath($dom);
44+
$xpath->registerNamespace('r', 'http://schemas.openxmlformats.org/package/2006/relationships');
45+
$list = $xpath->query('//r:Relationship');
46+
47+
$this->assertEquals(5, $list->length);
48+
49+
$this->assertEquals('rId1', $list->item(0)->getAttribute('Id'));
50+
$this->assertEquals('rId2', $list->item(1)->getAttribute('Id'));
51+
$this->assertEquals('rId3', $list->item(2)->getAttribute('Id'));
52+
$this->assertEquals('rId4', $list->item(3)->getAttribute('Id'));
53+
$this->assertEquals('rId5', $list->item(4)->getAttribute('Id'));
3354
}
3455
}

0 commit comments

Comments
 (0)