File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
tests/PhpPresentation/Tests Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -312,11 +312,26 @@ public function copy(): self
312
312
$ copied = clone $ this ;
313
313
314
314
$ slideCount = count ($ this ->slideCollection );
315
+
316
+ // Because the rebindParent() method on AbstractSlide removes the slide
317
+ // from the parent (current $this which we're cloning) presentation, we
318
+ // save the collection. This way, after the copying has finished, we can
319
+ // return the slides to the original presentation.
320
+ $ oldSlideCollection = $ this ->slideCollection ;
321
+ $ newSlideCollection = [];
322
+
315
323
for ($ i = 0 ; $ i < $ slideCount ; ++$ i ) {
316
- $ this -> slideCollection [$ i ] = $ this -> slideCollection [$ i ]->copy ();
317
- $ this -> slideCollection [$ i ]->rebindParent ($ this );
324
+ $ newSlideCollection [$ i ] = $ oldSlideCollection [$ i ]->copy ();
325
+ $ newSlideCollection [$ i ]->rebindParent ($ copied );
318
326
}
319
327
328
+ // Give the copied presentation a copied slide collection which the
329
+ // copied slides have been rebind to the copied presentation.
330
+ $ copied ->slideCollection = $ newSlideCollection ;
331
+
332
+ // Return the original slides to the original presentation.
333
+ $ this ->slideCollection = $ oldSlideCollection ;
334
+
320
335
return $ copied ;
321
336
}
322
337
Original file line number Diff line number Diff line change @@ -86,7 +86,12 @@ public function testAddExternalSlide(): void
86
86
public function testCopy (): void
87
87
{
88
88
$ object = new PhpPresentation ();
89
- self ::assertInstanceOf ('PhpOffice \\PhpPresentation \\PhpPresentation ' , $ object ->copy ());
89
+ $ object ->createSlide ();
90
+
91
+ $ copy = $ object ->copy ();
92
+
93
+ self ::assertInstanceOf ('PhpOffice \\PhpPresentation \\PhpPresentation ' , $ copy );
94
+ self ::assertEquals (2 , $ copy ->getSlideCount ());
90
95
}
91
96
92
97
/**
You can’t perform that action at this time.
0 commit comments