1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Grandstream-XMLApp |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* |
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace mrcnpdlk\Grandstream\XMLApp; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Application\ModelConstant; |
19
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Helper\Color; |
20
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Helper\Font; |
21
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Helper\Point; |
22
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Helper\Rectangle; |
23
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Helper\Vector; |
24
|
|
|
|
25
|
|
|
class HelperTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
public function testColor() |
28
|
|
|
{ |
29
|
|
|
$oColor = new Color(); |
30
|
|
|
$this->assertEquals('None', $oColor->get()); |
31
|
|
|
$oColor = new Color(0); |
32
|
|
|
$this->assertEquals('White', $oColor->get()); |
33
|
|
|
$oColor = new Color(100); |
34
|
|
|
$this->assertEquals('Black', $oColor->get()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testColorOutOfRange() |
38
|
|
|
{ |
39
|
|
|
$oColor = new Color(-1); |
40
|
|
|
$this->assertEquals('White', $oColor->get()); |
41
|
|
|
$oColor = new Color(101); |
42
|
|
|
$this->assertEquals('Black', $oColor->get()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testFont() |
46
|
|
|
{ |
47
|
|
|
$oFont = new Font(); |
48
|
|
|
$this->assertEquals('Black', $oFont->getColor()->get()); |
49
|
|
|
$this->assertEquals(ModelConstant::FONT_UNIFONT, $oFont->getType()); |
50
|
|
|
$this->assertEquals(ModelConstant::HORIZONTAL_ALIGN_LEFT, $oFont->getHorizontalAlign()); |
51
|
|
|
|
52
|
|
|
$this->assertEquals(ModelConstant::HORIZONTAL_ALIGN_CENTER, |
53
|
|
|
$oFont->setHorizontalAlign(ModelConstant::HORIZONTAL_ALIGN_CENTER)->getHorizontalAlign()); |
54
|
|
|
$this->assertInstanceOf(Color::class, |
55
|
|
|
$oFont->setColor(new Color(100))->getColor()); |
56
|
|
|
$this->assertEquals(ModelConstant::FONT_BOLD, |
57
|
|
|
$oFont->setType(ModelConstant::FONT_BOLD)->getType()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testPoint() |
61
|
|
|
{ |
62
|
|
|
$oPoint = new Point(3, 4); |
63
|
|
|
$this->assertEquals(3, $oPoint->getX()); |
64
|
|
|
$this->assertEquals(4, $oPoint->getY()); |
65
|
|
|
|
66
|
|
|
$movedPoint = $oPoint->move(new Vector(-4, -5)); |
67
|
|
|
$this->assertEquals(-1, $movedPoint->getX()); |
68
|
|
|
$this->assertEquals(-1, $movedPoint->getY()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testVector() |
72
|
|
|
{ |
73
|
|
|
$oVector = new Vector(3, 4); |
74
|
|
|
$this->assertEquals(5, $oVector->getLength()); |
75
|
|
|
$this->assertEquals(3, $oVector->getDeltaX()); |
76
|
|
|
$this->assertEquals(4, $oVector->getDeltaY()); |
77
|
|
|
|
78
|
|
|
$newVector = $oVector->add(new Vector(-7, -7)); |
79
|
|
|
$this->assertEquals(5, $newVector->getLength()); |
80
|
|
|
$this->assertEquals(-4, $newVector->getDeltaX()); |
81
|
|
|
$this->assertEquals(-3, $newVector->getDeltaY()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
public function testRectangle() |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$oRectangle = new Rectangle(5, 2); |
87
|
|
|
$this->assertEquals(10, $oRectangle->getArea()); |
88
|
|
|
$this->assertEquals(5, $oRectangle->getWidth()); |
89
|
|
|
$this->assertEquals(2, $oRectangle->getHeight()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
View Code Duplication |
public function testRectangleSquare() |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$oRectangle = new Rectangle(5); |
95
|
|
|
$this->assertEquals(25, $oRectangle->getArea()); |
96
|
|
|
$this->assertEquals(5, $oRectangle->getWidth()); |
97
|
|
|
$this->assertEquals(5, $oRectangle->getHeight()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
View Code Duplication |
public function testRectangleOutOfRange() |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$oRectangle = new Rectangle(-5, -2); |
103
|
|
|
$this->assertEquals(0, $oRectangle->getArea()); |
104
|
|
|
$this->assertEquals(0, $oRectangle->getWidth()); |
105
|
|
|
$this->assertEquals(0, $oRectangle->getHeight()); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.