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

PaletteImageTest::testCopy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 22
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 27
rs 9.568
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;
23
24
use WideImage\WideImage;
25
use WideImage\PaletteImage;
26
use WideImage\TrueColorImage;
27
use Test\WideImage_TestCase;
28
29
/**
30
 * @package Tests
31
 */
32
class PaletteImageTest extends WideImage_TestCase
33
{
34
	public function testCreate()
35
	{
36
		$img = PaletteImage::create(10, 10);
37
		$this->assertTrue($img instanceof PaletteImage);
38
		$this->assertTrue($img->isValid());
39
		$this->assertFalse($img->isTrueColor());
40
	}
41
	
42
	public function testCopy()
43
	{
44
		$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
45
		$this->assertTrue($img instanceof PaletteImage);
46
		$this->assertTrue($img->isValid());
47
		$this->assertFalse($img->isTrueColor());
48
		$this->assertTrue($img->isTransparent());
49
		$this->assertRGBEqual($img->getRGBAt(15, 15), 255, 255, 0);
50
		$this->assertRGBEqual($img->getRGBAt(85, 15), 0, 0, 255);
51
		$this->assertRGBEqual($img->getRGBAt(85, 85), 0, 255, 0);
52
		$this->assertRGBEqual($img->getRGBAt(15, 85), 255, 0, 0);
53
		$this->assertTrue($img->getTransparentColor() === $img->getColorAt(50, 50));
54
		
55
		$copy = $img->copy();
56
		$this->assertFalse($img->getHandle() === $copy->getHandle());
57
		
58
		$this->assertTrue($copy instanceof PaletteImage);
59
		$this->assertTrue($copy->isValid());
60
		$this->assertFalse($copy->isTrueColor());
61
		$this->assertTrue($copy->isTransparent());
62
		$this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 255, 0);
63
		$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 255);
64
		$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0);
65
		$this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0);
66
		$this->assertTrue($copy->getTransparentColor() === $copy->getColorAt(50, 50));
67
		
68
		$this->assertSame($img->getTransparentColorRGB(), $copy->getTransparentColorRGB());
69
	}
70
	
71
	public function testCopyNoAlpha()
72
	{
73
		$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
74
		$this->assertRGBEqual($img->getRGBAt(85, 85), 0, 255, 0);
75
		$copy = $img->copyNoAlpha();
76
		$this->assertFalse($img->getHandle() === $copy->getHandle());
77
		$this->assertTrue($copy instanceof PaletteImage);
78
		$this->assertTrue($copy->isValid());
79
		$this->assertFalse($copy->isTrueColor());
80
		$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0);
81
	}
82
	
83
	public function testAsTrueColor()
84
	{
85
		$img = WideImage::load(IMG_PATH . '100x100-color-hole.gif');
86
		$this->assertTrue($img instanceof PaletteImage);
87
		$this->assertTrue($img->isValid());
88
		
89
		$copy = $img->asTrueColor();
90
		$this->assertFalse($img->getHandle() === $copy->getHandle());
91
		
92
		$this->assertTrue($copy instanceof TrueColorImage);
93
		$this->assertTrue($copy->isValid());
94
		$this->assertTrue($copy->isTrueColor());
95
		$this->assertTrue($copy->isTransparent());
96
		$this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 255, 0);
97
		$this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 255);
98
		$this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0);
99
		$this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0);
100
		
101
		$this->assertEquals($copy->getRGBAt(50, 50), $copy->getTransparentColorRGB());
102
		$rgb = $copy->getTransparentColorRGB();
103
		$this->assertRGBEqual($img->getTransparentColorRGB(), $rgb['red'], $rgb['green'], $rgb['blue']);
104
	}
105
}
106