Skip to content

Commit e012bc1

Browse files
committed
createDrawingShape has no container defined
1 parent 7c3d2f5 commit e012bc1

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

docs/changes/1.2.0.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
- Word2007 Reader: Fixed cast of color by [@Progi1984](https://github.com/Progi1984) fixing [#826](https://github.com/PHPOffice/PHPPresentation/pull/826) in [#840](https://github.com/PHPOffice/PHPPresentation/pull/840)
1717
- Word2007 Reader: Fixed panose with 20 characters by [@Progi1984](https://github.com/Progi1984) fixing [#798](https://github.com/PHPOffice/PHPPresentation/pull/798) in [#842](https://github.com/PHPOffice/PHPPresentation/pull/842)
1818
- `Gd::setImageResource()` : Fixed when imagecreatetruecolor returns false by [@jaapdh](https://github.com/jaapdh) in [#843](https://github.com/PHPOffice/PHPPresentation/pull/843)
19-
- Word2007 Writer: LineChart supports LabelPosition for Series by [@pal-software](https://github.com/jaapdh) fixing [#606](https://github.com/PHPOffice/PHPPresentation/pull/606) in [#8434](https://github.com/PHPOffice/PHPPresentation/pull/844)
19+
- Word2007 Writer: LineChart supports LabelPosition for Series by [@pal-software](https://github.com/pal-software) fixing [#606](https://github.com/PHPOffice/PHPPresentation/pull/606) in [#8434](https://github.com/PHPOffice/PHPPresentation/pull/844)
20+
- `createDrawingShape` has no container defined by [@Progi1984](https://github.com/Progi1984) fixing [#820](https://github.com/PHPOffice/PHPPresentation/pull/820) in [#845](https://github.com/PHPOffice/PHPPresentation/pull/845)
2021

2122
## Miscellaneous
2223

src/PhpPresentation/Traits/ShapeCollection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace PhpOffice\PhpPresentation\Traits;
2222

2323
use PhpOffice\PhpPresentation\AbstractShape;
24+
use PhpOffice\PhpPresentation\ShapeContainerInterface;
2425

2526
trait ShapeCollection
2627
{
@@ -80,7 +81,11 @@ public function setShapeCollection(array $shapeCollection = []): self
8081
*/
8182
public function addShape(AbstractShape $shape)
8283
{
83-
$this->shapeCollection[] = $shape;
84+
if (!$shape->getContainer() && $this instanceof ShapeContainerInterface) {
85+
$shape->setContainer($this);
86+
} else {
87+
$this->shapeCollection[] = $shape;
88+
}
8489

8590
return $this;
8691
}

tests/PhpPresentation/Tests/Slide/AbstractSlideTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class AbstractSlideTest extends TestCase
3636
public function testCollection(): void
3737
{
3838
/** @var AbstractSlide $stub */
39-
$stub = $this->getMockForAbstractClass('PhpOffice\\PhpPresentation\\Slide\\AbstractSlide');
39+
$stub = $this->getMockForAbstractClass(AbstractSlide::class);
4040

4141
$array = [];
42-
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\AbstractSlide', $stub->setShapeCollection($array));
42+
self::assertInstanceOf(AbstractSlide::class, $stub->setShapeCollection($array));
4343
self::assertIsArray($stub->getShapeCollection());
4444
self::assertCount(count($array), $stub->getShapeCollection());
4545

@@ -48,22 +48,22 @@ public function testCollection(): void
4848
new RichText(),
4949
new RichText(),
5050
];
51-
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\AbstractSlide', $stub->setShapeCollection($array));
51+
self::assertInstanceOf(AbstractSlide::class, $stub->setShapeCollection($array));
5252
self::assertIsArray($stub->getShapeCollection());
5353
self::assertCount(count($array), $stub->getShapeCollection());
5454
}
5555

56-
public function testsearchShapes(): void
56+
public function testSearchShapes(): void
5757
{
5858
/** @var AbstractSlide $stub */
59-
$stub = $this->getMockForAbstractClass('PhpOffice\\PhpPresentation\\Slide\\AbstractSlide');
59+
$stub = $this->getMockForAbstractClass(AbstractSlide::class);
6060

6161
$array = [
6262
(new RichText())->setName('AAA'),
6363
(new Table())->setName('BBB'),
6464
(new Chart())->setName('AAA'),
6565
];
66-
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\AbstractSlide', $stub->setShapeCollection($array));
66+
self::assertInstanceOf(AbstractSlide::class, $stub->setShapeCollection($array));
6767

6868
// Search by Name
6969
$result = $stub->searchShapes('AAA', null);

tests/PhpPresentation/Tests/SlideTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
namespace PhpOffice\PhpPresentation\Tests;
2222

2323
use PhpOffice\PhpPresentation\PhpPresentation;
24+
use PhpOffice\PhpPresentation\ShapeContainerInterface;
25+
use PhpOffice\PhpPresentation\Shape\Drawing\File;
2426
use PhpOffice\PhpPresentation\Slide;
2527
use PhpOffice\PhpPresentation\Slide\AbstractBackground;
2628
use PhpOffice\PhpPresentation\Slide\Animation;
@@ -143,4 +145,40 @@ public function testVisible(): void
143145
self::assertInstanceOf(Slide::class, $object->setIsVisible());
144146
self::assertTrue($object->isVisible());
145147
}
148+
149+
public function testAddShape(): void
150+
{
151+
$slide = new Slide();
152+
self::assertInstanceOf(ShapeContainerInterface::class, $slide);
153+
$shape = new File();
154+
155+
self::assertIsArray($slide->getShapeCollection());
156+
self::assertCount(0, $slide->getShapeCollection());
157+
158+
$slide->addShape($shape);
159+
self::assertInstanceOf(File::class, $shape);
160+
self::assertEquals($slide, $shape->getContainer());
161+
self::assertInstanceOf(Slide::class, $shape->getContainer());
162+
163+
self::assertIsArray($slide->getShapeCollection());
164+
self::assertCount(1, $slide->getShapeCollection());
165+
self::assertEquals([$shape], $slide->getShapeCollection());
166+
}
167+
168+
public function testCreateDrawingShape(): void
169+
{
170+
$slide = new Slide();
171+
172+
self::assertIsArray($slide->getShapeCollection());
173+
self::assertCount(0, $slide->getShapeCollection());
174+
175+
$shape = $slide->createDrawingShape();
176+
self::assertInstanceOf(File::class, $shape);
177+
self::assertEquals($slide, $shape->getContainer());
178+
self::assertInstanceOf(Slide::class, $shape->getContainer());
179+
180+
self::assertIsArray($slide->getShapeCollection());
181+
self::assertCount(1, $slide->getShapeCollection());
182+
self::assertEquals([$shape], $slide->getShapeCollection());
183+
}
146184
}

0 commit comments

Comments
 (0)