Passed
Push — master ( 3c6756...8b3b37 )
by Michael
14:24 queued 07:02
created

MergeTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 41
c 2
b 0
f 0
dl 0
loc 66
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMergeOpacityFull() 0 19 1
A testMergeOpacityZero() 0 19 1
A testMergeOpacityHalf() 0 21 1
1
<?php
2
	/**
3
    This file is part of WideImage.
4
		
5
    WideImage is free software; you can redistribute it and/or modify
6
    it under the terms of the GNU Lesser General Public License as published by
7
    the Free Software Foundation; either version 2.1 of the License, or
8
    (at your option) any later version.
9
		
10
    WideImage is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU Lesser General Public License for more details.
14
		
15
    You should have received a copy of the GNU Lesser General Public License
16
    along with WideImage; if not, write to the Free Software
17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
    
19
    * @package Tests
20
  **/
21
22
namespace Test\WideImage\Operation;
23
24
use WideImage\WideImage;
25
use Test\WideImage_TestCase;
26
27
/**
28
 * @package Tests
29
 * @group operation
30
 */
31
class MergeTest extends WideImage_TestCase
32
{
33
	public function testMergeOpacityZero()
34
	{
35
		$img     = WideImage::load(IMG_PATH . '100x100-color-hole.png');
36
		$overlay = WideImage::load(IMG_PATH . '100x100-square-overlay.png');
37
		
38
		$res = $img->merge($overlay, 0, 0, 0);
39
		
40
		$this->assertEquals(100, $res->getWidth());
41
		$this->assertEquals(100, $res->getHeight());
42
		
43
		$rgb = $res->getRGBAt(5, 5);
0 ignored issues
show
Unused Code introduced by
The assignment to $rgb is dead and can be removed.
Loading history...
44
		$this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 0, 'alpha' => 0));
45
		$this->assertRGBAt($res, 40, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
46
		$this->assertRGBAt($res, 95, 5, array('red' => 0, 'green' => 0, 'blue' => 255, 'alpha' => 0));
47
		$this->assertRGBAt($res, 60, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
48
		$this->assertRGBAt($res, 95, 95, array('red' => 0, 'green' => 255, 'blue' => 0, 'alpha' => 0));
49
		$this->assertRGBAt($res, 60, 60, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
50
		$this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
51
		$this->assertRGBAt($res, 40, 60, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
52
	}
53
	
54
	public function testMergeOpacityHalf()
55
	{
56
		$img     = WideImage::load(IMG_PATH . '100x100-color-hole.png');
57
		$overlay = WideImage::load(IMG_PATH . '100x100-square-overlay.png');
58
		
59
		$res = $img->merge($overlay, 0, 0, 50);
60
		
61
		$this->assertEquals(100, $res->getWidth());
62
		$this->assertEquals(100, $res->getHeight());
63
		
64
		$rgb = $res->getRGBAt(5, 5);
0 ignored issues
show
Unused Code introduced by
The assignment to $rgb is dead and can be removed.
Loading history...
65
		$this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 127, 'alpha' => 0));
66
		$this->assertRGBAt($res, 40, 40, array('red' => 127, 'green' => 127, 'blue' => 127, 'alpha' => 0));
67
		$this->assertRGBAt($res, 95, 5, array('red' => 0, 'green' => 0, 'blue' => 255, 'alpha' => 0));
68
		$this->assertRGBAt($res, 60, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
69
		$this->assertRGBAt($res, 95, 95, array('red' => 0, 'green' => 127, 'blue' => 0, 'alpha' => 0));
70
		
71
		// these two should definitely pass ...
72
		
73
		#$this->assertRGBAt($res, 60, 60, array('red' => 127, 'green' => 127, 'blue' => 127, 'alpha' => 0));
74
		$this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
75
		#$this->assertRGBAt($res, 40, 60, array('red' => 255, 'green' => 127, 'blue' => 127, 'alpha' => 0));
76
	}
77
	
78
	public function testMergeOpacityFull()
79
	{
80
		$img     = WideImage::load(IMG_PATH . '100x100-color-hole.png');
81
		$overlay = WideImage::load(IMG_PATH . '100x100-square-overlay.png');
82
		
83
		$res = $img->merge($overlay, 0, 0, 100);
84
		
85
		$this->assertEquals(100, $res->getWidth());
86
		$this->assertEquals(100, $res->getHeight());
87
		
88
		$rgb = $res->getRGBAt(5, 5);
0 ignored issues
show
Unused Code introduced by
The assignment to $rgb is dead and can be removed.
Loading history...
89
		$this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
90
		$this->assertRGBAt($res, 40, 40, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0));
91
		$this->assertRGBAt($res, 95, 5, array('red' => 0, 'green' => 0, 'blue' => 255, 'alpha' => 0));
92
		$this->assertRGBAt($res, 60, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127));
93
		$this->assertRGBAt($res, 95, 95, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0));
94
		$this->assertRGBAt($res, 60, 60, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0));
95
		$this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
96
		$this->assertRGBAt($res, 40, 60, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0));
97
	}
98
}
99