forked from PHPOffice/PHPPresentation
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutoShapeTest.php
More file actions
125 lines (103 loc) · 4.16 KB
/
Copy pathAutoShapeTest.php
File metadata and controls
125 lines (103 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
declare(strict_types=1);
namespace PhpOffice\PhpPresentation\Tests\Shape;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\AutoShape;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Fill;
use PhpOffice\PhpPresentation\Style\Outline;
use PhpOffice\PhpPresentation\Writer\PowerPoint2007;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ZipArchive;
class AutoShapeTest extends TestCase
{
public function testConstruct(): void
{
$object = new AutoShape();
self::assertEquals(AutoShape::TYPE_HEART, $object->getType());
self::assertEquals('', $object->getText());
self::assertInstanceOf(Outline::class, $object->getOutline());
self::assertNotEmpty($object->getHashCode());
}
public function testOutline(): void
{
/** @var MockObject&Outline $mock */
$mock = $this->getMockBuilder(Outline::class)->getMock();
$object = new AutoShape();
self::assertInstanceOf(Outline::class, $object->getOutline());
self::assertInstanceOf(AutoShape::class, $object->setOutline($mock));
self::assertInstanceOf(Outline::class, $object->getOutline());
}
public function testText(): void
{
$object = new AutoShape();
self::assertEquals('', $object->getText());
self::assertInstanceOf(AutoShape::class, $object->setText('Text'));
self::assertEquals('Text', $object->getText());
}
public function testType(): void
{
$object = new AutoShape();
self::assertEquals(AutoShape::TYPE_HEART, $object->getType());
self::assertInstanceOf(AutoShape::class, $object->setType(AutoShape::TYPE_HEXAGON));
self::assertEquals(AutoShape::TYPE_HEXAGON, $object->getType());
}
public function testNoRadiusByDefaultIsNull(): void
{
$shape = new AutoShape();
self::assertNull($shape->getRoundRectCorner());
}
public function testWriterEmitsAdjGuideForRoundRect(): void
{
$ppt = new PhpPresentation();
$slide = $ppt->getActiveSlide();
$width = 200;
$height = 100;
$padding = 5;
$minHalf = (int) floor(min($width, $height) / 2);
$expectedAdj = (int) round($padding / $minHalf * 50000); // 5000
$shape = (new AutoShape())
->setType(AutoShape::TYPE_ROUNDED_RECTANGLE)
->setWidth($width)->setHeight($height)
->setRoundRectCorner($padding);
// Give it a fill so it's an obvious shape
$shape->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFFFFFFF'));
$slide->addShape($shape);
$tmpFile = tempnam(sys_get_temp_dir(), 'pptx_');
$writer = new PowerPoint2007($ppt);
$writer->save($tmpFile);
// Open the pptx and read slide1.xml
$zip = new ZipArchive();
self::assertTrue($zip->open($tmpFile) === true, 'Failed to open pptx zip');
$xml = $zip->getFromName('ppt/slides/slide1.xml');
$zip->close();
@unlink($tmpFile);
self::assertIsString($xml);
// Must contain roundRect geometry and the adj guide with expected value
self::assertStringContainsString('<a:prstGeom prst="roundRect">', $xml);
// fmla="val N" (there is a space after 'val' in writer)
self::assertSame(
1,
preg_match(
sprintf('/<a:gd[^>]+name="adj"[^>]+fmla="val %d"/', $expectedAdj),
(string) $xml
)
);
}
}