Skip to content

Commit bfca92d

Browse files
committed
IMPROVED : #24 : PHPUnit tests
1 parent c69e6f2 commit bfca92d

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* PHPPowerPoint
4+
*
5+
* @link https://github.com/PHPOffice/PHPPowerPoint
6+
* @copyright 2014 PHPPowerPoint
7+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
8+
*/
9+
10+
namespace PhpOffice\PhpPowerpoint\Tests;
11+
12+
use PhpOffice\PhpPowerpoint\Style\Alignment;
13+
14+
/**
15+
* Test class for PhpPowerpoint
16+
*
17+
* @coversDefaultClass PhpOffice\PhpPowerpoint\PhpPowerpoint
18+
*/
19+
class AlignmentTest
20+
extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* Test create new instance
24+
*/
25+
public function testConstruct ()
26+
{
27+
$object = new Alignment();
28+
$this->assertEquals(Alignment::HORIZONTAL_LEFT, $object->getHorizontal());
29+
$this->assertEquals(Alignment::VERTICAL_BASE, $object->getVertical());
30+
$this->assertEquals(0, $object->getLevel());
31+
$this->assertEquals(0, $object->getIndent());
32+
$this->assertEquals(0, $object->getMarginLeft());
33+
$this->assertEquals(0, $object->getMarginRight());
34+
}
35+
36+
public function testSetGetHorizontal ()
37+
{
38+
$object = new Alignment();
39+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setHorizontal(''));
40+
$this->assertEquals(Alignment::HORIZONTAL_LEFT, $object->getHorizontal());
41+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setHorizontal(Alignment::HORIZONTAL_GENERAL));
42+
$this->assertEquals(Alignment::HORIZONTAL_GENERAL, $object->getHorizontal());
43+
}
44+
45+
public function testSetGetVertical ()
46+
{
47+
$object = new Alignment();
48+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setVertical(''));
49+
$this->assertEquals(Alignment::VERTICAL_BASE, $object->getVertical());
50+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setVertical(Alignment::VERTICAL_AUTO));
51+
$this->assertEquals(Alignment::VERTICAL_AUTO, $object->getVertical());
52+
}
53+
54+
public function testSetGetLevelExceptionMin ()
55+
{
56+
$object = new Alignment();
57+
$this->setExpectedException('\Exception', 'Invalid value: shoul be range 0 - 8.');
58+
$object->setLevel(-1);
59+
}
60+
61+
public function testSetGetLevelExceptionMax ()
62+
{
63+
$object = new Alignment();
64+
$this->setExpectedException('\Exception', 'Invalid value: shoul be range 0 - 8.');
65+
$object->setLevel(9);
66+
}
67+
68+
public function testSetGetLevel ()
69+
{
70+
$object = new Alignment();
71+
$value = rand(1, 8);
72+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setLevel($value));
73+
$this->assertEquals($value, $object->getLevel());
74+
}
75+
76+
public function testSetGetIndent ()
77+
{
78+
$object = new Alignment();
79+
// != Alignment::HORIZONTAL_GENERAL
80+
$object->setHorizontal(Alignment::HORIZONTAL_CENTER);
81+
$value = rand(1, 100);
82+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setIndent($value));
83+
$this->assertEquals(0, $object->getIndent());
84+
$value = rand(-100, 0);
85+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setIndent($value));
86+
$this->assertEquals($value, $object->getIndent());
87+
88+
89+
$object->setHorizontal(Alignment::HORIZONTAL_GENERAL);
90+
$value = rand(1, 100);
91+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setIndent($value));
92+
$this->assertEquals($value, $object->getIndent());
93+
$value = rand(-100, 0);
94+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setIndent($value));
95+
$this->assertEquals($value, $object->getIndent());
96+
}
97+
98+
public function testSetGetMarginLeft ()
99+
{
100+
$object = new Alignment();
101+
// != Alignment::HORIZONTAL_GENERAL
102+
$object->setHorizontal(Alignment::HORIZONTAL_CENTER);
103+
$value = rand(1, 100);
104+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setMarginLeft($value));
105+
$this->assertEquals(0, $object->getMarginLeft());
106+
$value = rand(-100, 0);
107+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setMarginLeft($value));
108+
$this->assertEquals($value, $object->getMarginLeft());
109+
110+
111+
$object->setHorizontal(Alignment::HORIZONTAL_GENERAL);
112+
$value = rand(1, 100);
113+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setMarginLeft($value));
114+
$this->assertEquals($value, $object->getMarginLeft());
115+
$value = rand(-100, 0);
116+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setMarginLeft($value));
117+
$this->assertEquals($value, $object->getMarginLeft());
118+
}
119+
120+
public function testSetGetMarginRight ()
121+
{
122+
$object = new Alignment();
123+
// != Alignment::HORIZONTAL_GENERAL
124+
$object->setHorizontal(Alignment::HORIZONTAL_CENTER);
125+
$value = rand(1, 100);
126+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setMarginRight($value));
127+
$this->assertEquals(0, $object->getMarginRight());
128+
$value = rand(-100, 0);
129+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setMarginRight($value));
130+
$this->assertEquals($value, $object->getMarginRight());
131+
132+
133+
$object->setHorizontal(Alignment::HORIZONTAL_GENERAL);
134+
$value = rand(1, 100);
135+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setMarginRight($value));
136+
$this->assertEquals($value, $object->getMarginRight());
137+
$value = rand(-100, 0);
138+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->setMarginRight($value));
139+
$this->assertEquals($value, $object->getMarginRight());
140+
}
141+
142+
public function testSetGetHashIndex ()
143+
{
144+
$value = md5(rand(1, 100));
145+
146+
$object = new Alignment();
147+
$object->setHashIndex($value);
148+
$this->assertEquals($value, $object->getHashIndex());
149+
}
150+
151+
public function testClone ()
152+
{
153+
$object = new Alignment();
154+
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', clone $object);
155+
}
156+
}

0 commit comments

Comments
 (0)