Skip to content

Commit 23cb205

Browse files
committed
ADDED : #24 : UnitTests (59.65% Lines)
1 parent 3771dd0 commit 23cb205

File tree

7 files changed

+712
-6
lines changed

7 files changed

+712
-6
lines changed

tests/PhpPowerpoint/Tests/Shape/DrawingTest.php

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,64 @@ public function testGetSetHeightWidth()
9797
$this->assertEquals(0, $object->getWidth());
9898
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Drawing', $object->setHeight());
9999
$this->assertEquals(0, $object->getHeight());
100-
100+
}
101+
/**
102+
* Value : Resize Proportional (false)
103+
*/
104+
public function testGetSetHeightWidthResizeProportionalFalse()
105+
{
101106
// Valeur : Resize Proportional (false)
107+
$object = new Drawing();
102108
$value = rand(0, 100);
103109
$object->setResizeProportional(false);
104110
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Drawing', $object->setWidth($value));
105111
$this->assertEquals($value, $object->getWidth());
106112
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Drawing', $object->setHeight($value));
107113
$this->assertEquals($value, $object->getHeight());
114+
}
115+
116+
/**
117+
* Value : Resize Proportional (true)
118+
*/
119+
public function testGetSetHeightWidthResizeProportionalTrue()
120+
{
121+
$object = new Drawing();
122+
$valueWidth = rand(1, 100);
123+
$valueHeight = rand(1, 100);
124+
$object->setResizeProportional(false);
125+
$object->setWidth($valueWidth);
126+
$object->setHeight($valueHeight);
127+
$object->setResizeProportional(true);
128+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Drawing', $object->setWidth($valueWidth));
129+
$this->assertEquals($valueWidth, $object->getWidth());
130+
$this->assertEquals(round($valueWidth * ($valueHeight / $valueWidth)), $object->getHeight());
131+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Drawing', $object->setHeight($valueHeight));
132+
$this->assertEquals($valueHeight, $object->getHeight());
133+
$this->assertEquals(round($valueHeight * ($valueWidth / $valueHeight)), $object->getWidth());
134+
}
135+
136+
public function testSetWidthAndHeight()
137+
{
138+
$object = new Drawing();
139+
$valueWidth = rand(1, 100);
140+
$valueHeight = $valueWidth / 2;
141+
$object->setResizeProportional(false);
142+
$object->setWidth($valueWidth);
143+
$object->setHeight($valueHeight);
144+
$object->setResizeProportional(true);
145+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Drawing', $object->setWidthAndHeight($valueHeight, $valueWidth));
146+
$this->assertEquals($valueHeight, $object->getWidth());
147+
$this->assertEquals(ceil($valueHeight * ($valueHeight/$valueWidth)), $object->getHeight());
108148

109-
// // Valeur : Resize Proportional (true)
110-
// $value = rand(0, 100);
111-
// $object->setResizeProportional(true);
112-
// $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Drawing', $object->setWidth($value));
113-
149+
$object = new Drawing();
150+
$valueWidth = rand(1, 100);
151+
$valueHeight = $valueWidth / 2;
152+
$object->setResizeProportional(false);
153+
$object->setWidth($valueWidth);
154+
$object->setHeight($valueHeight);
155+
$object->setResizeProportional(true);
156+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Drawing', $object->setWidthAndHeight($valueWidth, $valueHeight));
157+
$this->assertEquals($valueHeight, $object->getHeight());
158+
$this->assertEquals(ceil($valueWidth * ($valueHeight/$valueHeight)), $object->getWidth());
114159
}
115160
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPowerPoint - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPowerPoint is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPowerPoint/contributors.
12+
*
13+
* @copyright 2009-2014 PHPPowerPoint contributors
14+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
15+
* @link https://github.com/PHPOffice/PHPPowerPoint
16+
*/
17+
18+
namespace PhpOffice\PhpPowerpoint\Tests\Shape\RichText;
19+
20+
use PhpOffice\PhpPowerpoint\Shape\RichText\BreakElement;
21+
22+
/**
23+
* Test class for BreakElement element
24+
*
25+
* @coversDefaultClass PhpOffice\PhpPowerpoint\Shape\RichText\BreakElement
26+
*/
27+
class BreakElementTest extends \PHPUnit_Framework_TestCase
28+
{
29+
/**
30+
* Test can read
31+
*/
32+
public function testText()
33+
{
34+
$object = new BreakElement();
35+
$this->assertEquals("\r\n",$object->getText());
36+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\BreakElement', $object->setText());
37+
$this->assertEquals("\r\n",$object->getText());
38+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\BreakElement', $object->setText('AAA'));
39+
$this->assertEquals("\r\n",$object->getText());
40+
}
41+
42+
public function testFont ()
43+
{
44+
$object = new BreakElement();
45+
$this->assertNull($object->getFont());
46+
}
47+
48+
/**
49+
* Test get/set hash index
50+
*/
51+
public function testHashCode ()
52+
{
53+
$object = new BreakElement();
54+
$this->assertEquals(md5(get_class($object)), $object->getHashCode());
55+
}
56+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPowerPoint - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPowerPoint is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPowerPoint/contributors.
12+
*
13+
* @copyright 2009-2014 PHPPowerPoint contributors
14+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
15+
* @link https://github.com/PHPOffice/PHPPowerPoint
16+
*/
17+
18+
namespace PhpOffice\PhpPowerpoint\Tests\Shape\RichText;
19+
20+
use PhpOffice\PhpPowerpoint\Shape\RichText\Paragraph;
21+
use PhpOffice\PhpPowerpoint\Shape\RichText\TextElement;
22+
use PhpOffice\PhpPowerpoint\Style\Alignment;
23+
use PhpOffice\PhpPowerpoint\Style\Bullet;
24+
use PhpOffice\PhpPowerpoint\Style\Font;
25+
26+
/**
27+
* Test class for Paragraph element
28+
*
29+
* @coversDefaultClass PhpOffice\PhpPowerpoint\Shape\RichText\Paragraph
30+
*/
31+
class ParagraphTest extends \PHPUnit_Framework_TestCase
32+
{
33+
/**
34+
* Test can read
35+
*/
36+
public function testConstruct()
37+
{
38+
$object = new Paragraph();
39+
$this->assertEmpty($object->getRichTextElements());
40+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->getAlignment());
41+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont());
42+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Bullet', $object->getBulletStyle());
43+
}
44+
45+
public function testAlignment ()
46+
{
47+
$object = new Paragraph();
48+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->getAlignment());
49+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setAlignment(new Alignment()));
50+
}
51+
52+
/**
53+
* Test get/set bullet style
54+
*/
55+
public function testBulletStyle ()
56+
{
57+
$object = new Paragraph();
58+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Bullet', $object->getBulletStyle());
59+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setBulletStyle());
60+
$this->assertNull($object->getBulletStyle());
61+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setBulletStyle(new Bullet()));
62+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Bullet', $object->getBulletStyle());
63+
}
64+
65+
/**
66+
* Test get/set font
67+
*/
68+
public function testFont ()
69+
{
70+
$object = new Paragraph();
71+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont());
72+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setFont());
73+
$this->assertNull($object->getFont());
74+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setFont(new Font()));
75+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont());
76+
}
77+
78+
/**
79+
* Test get/set hashCode
80+
*/
81+
public function testHashCode ()
82+
{
83+
$object = new Paragraph();
84+
$oElement = new TextElement();
85+
$object->addText($oElement);
86+
$this->assertEquals(md5($oElement->getHashCode().$object->getFont()->getHashCode().get_class($object)), $object->getHashCode());
87+
}
88+
89+
/**
90+
* Test get/set hashIndex
91+
*/
92+
public function testHashIndex ()
93+
{
94+
$object = new Paragraph();
95+
$value = rand(1, 100);
96+
$object->setHashIndex($value);
97+
$this->assertEquals($value, $object->getHashIndex());
98+
}
99+
100+
/**
101+
* Test get/set richTextElements
102+
*/
103+
public function testRichTextElements ()
104+
{
105+
$object = new Paragraph();
106+
$this->assertInternalType('array', $object->getRichTextElements());
107+
$this->assertEmpty($object->getRichTextElements());
108+
$object->createBreak();
109+
$this->assertCount(1, $object->getRichTextElements());
110+
111+
$array = array(
112+
new TextElement(),
113+
new TextElement(),
114+
new TextElement(),
115+
);
116+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setRichTextElements($array));
117+
$this->assertCount(3, $object->getRichTextElements());
118+
}
119+
120+
/**
121+
* @expectedException \Exception
122+
* expectedExceptionMessage Invalid \PhpOffice\PhpPowerpoint\Shape\RichText\TextElementInterface[] array passed.
123+
*/
124+
public function testRichTextElementsException ()
125+
{
126+
$object = new Paragraph();
127+
$object->setRichTextElements(1);
128+
}
129+
130+
/**
131+
* Test text methods
132+
*/
133+
public function testText ()
134+
{
135+
$object = new Paragraph();
136+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->addText(new TextElement()));
137+
$this->assertcount(1, $object->getRichTextElements());
138+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\TextElement', $object->createText());
139+
$this->assertcount(2, $object->getRichTextElements());
140+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\TextElement', $object->createText('AAA'));
141+
$this->assertcount(3, $object->getRichTextElements());
142+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\BreakElement', $object->createBreak());
143+
$this->assertcount(4, $object->getRichTextElements());
144+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Run', $object->createTextRun());
145+
$this->assertcount(5, $object->getRichTextElements());
146+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Run', $object->createTextRun('BBB'));
147+
$this->assertcount(6, $object->getRichTextElements());
148+
$this->assertEquals('AAA'."\r\n".'BBB', $object->getPlainText());
149+
$this->assertEquals('AAA'."\r\n".'BBB', (string)$object);
150+
}
151+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPowerPoint - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPowerPoint is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPowerPoint/contributors.
12+
*
13+
* @copyright 2009-2014 PHPPowerPoint contributors
14+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
15+
* @link https://github.com/PHPOffice/PHPPowerPoint
16+
*/
17+
18+
namespace PhpOffice\PhpPowerpoint\Tests\Shape\RichText;
19+
20+
use PhpOffice\PhpPowerpoint\Shape\RichText\Run;
21+
use PhpOffice\PhpPowerpoint\Style\Font;
22+
23+
/**
24+
* Test class for Run element
25+
*
26+
* @coversDefaultClass PhpOffice\PhpPowerpoint\Shape\RichText\Run
27+
*/
28+
class RunTest extends \PHPUnit_Framework_TestCase
29+
{
30+
/**
31+
* Test can read
32+
*/
33+
public function testConstruct()
34+
{
35+
$object = new Run();
36+
$this->assertEquals('',$object->getText());
37+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont());
38+
39+
$object = new Run('BBB');
40+
$this->assertEquals('BBB', $object->getText());
41+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont());
42+
}
43+
44+
public function testFont ()
45+
{
46+
$object = new Run();
47+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Run', $object->setFont(new Font()));
48+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont());
49+
}
50+
51+
public function testText ()
52+
{
53+
$object = new Run();
54+
$this->assertEquals('',$object->getText());
55+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Run', $object->setText());
56+
$this->assertEquals('',$object->getText());
57+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Run', $object->setText('AAA'));
58+
$this->assertEquals('AAA',$object->getText());
59+
60+
$object = new Run('BBB');
61+
$this->assertEquals('BBB', $object->getText());
62+
}
63+
64+
/**
65+
* Test get/set hash index
66+
*/
67+
public function testHashCode ()
68+
{
69+
$object = new Run();
70+
$this->assertEquals(md5($object->getFont()->getHashCode().get_class($object)), $object->getHashCode());
71+
}
72+
}

0 commit comments

Comments
 (0)