|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SixtyNine\Cloud\Tests\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Imagine\Gd\Image; |
|
6
|
|
|
use Imagine\Image\Point; |
|
7
|
|
|
use SixtyNine\Cloud\Factory\FontsFactory; |
|
8
|
|
|
use SixtyNine\Cloud\Factory\PlacerFactory; |
|
9
|
|
|
use SixtyNine\Cloud\Model\Box; |
|
10
|
|
|
use SixtyNine\Cloud\Usher; |
|
11
|
|
|
|
|
12
|
|
|
class BoxTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testConstructor() |
|
15
|
|
|
{ |
|
16
|
|
|
$box = new Box(1, 2, 3, 4); |
|
17
|
|
|
$this->assertInstanceOf(Box::class, $box); |
|
18
|
|
|
$this->assertAttributeEquals(1, 'x', $box); |
|
19
|
|
|
$this->assertAttributeEquals(2, 'y', $box); |
|
20
|
|
|
$this->assertAttributeEquals(3, 'width', $box); |
|
21
|
|
|
$this->assertAttributeEquals(4, 'height', $box); |
|
22
|
|
|
$this->assertAttributeEquals(1, 'left', $box); |
|
23
|
|
|
$this->assertAttributeEquals(4, 'right', $box); |
|
24
|
|
|
$this->assertAttributeEquals(2, 'top', $box); |
|
25
|
|
|
$this->assertAttributeEquals(6, 'bottom', $box); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testConstructFromImagine() |
|
29
|
|
|
{ |
|
30
|
|
|
$p = new Point(10, 20); |
|
31
|
|
|
$b = new \Imagine\Image\Box(100, 200); |
|
32
|
|
|
$box = Box::constructFromImagine($p, $b); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertInstanceOf(Box::class, $box); |
|
35
|
|
|
$this->assertAttributeEquals(10, 'x', $box); |
|
36
|
|
|
$this->assertAttributeEquals(20, 'y', $box); |
|
37
|
|
|
$this->assertAttributeEquals(100, 'width', $box); |
|
38
|
|
|
$this->assertAttributeEquals(200, 'height', $box); |
|
39
|
|
|
$this->assertAttributeEquals(10, 'left', $box); |
|
40
|
|
|
$this->assertAttributeEquals(110, 'right', $box); |
|
41
|
|
|
$this->assertAttributeEquals(20, 'top', $box); |
|
42
|
|
|
$this->assertAttributeEquals(220, 'bottom', $box); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @dataProvider boxesProvider |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testIntersect(Box $b1, Box $b2, $shouldCollide) |
|
49
|
|
|
{ |
|
50
|
|
|
$collide = $b1->intersects($b2); |
|
51
|
|
|
|
|
52
|
|
|
if ($collide && !$shouldCollide) { |
|
53
|
|
|
$this->fail('Collision not expected'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (!$collide && $shouldCollide) { |
|
57
|
|
|
$this->fail('Collision expected'); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function boxesProvider() |
|
62
|
|
|
{ |
|
63
|
|
|
return array( |
|
64
|
|
|
array(new Box(1, 1, 1, 1), new Box(2, 2, 1, 1), false), |
|
65
|
|
|
array(new Box(1, 1, 1, 1), new Box(1, 1, 1, 1), true), |
|
66
|
|
|
array(new Box(10, 10, 100, 50), new Box(5, 5, 5, 50), false), |
|
67
|
|
|
array(new Box(10, 10, 100, 50), new Box(5, 5, 50, 50), true), |
|
68
|
|
|
array(new Box(0, 10, 100, 10), new Box(10, 0, 10, 100), true), |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|