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

testResizeCanvasPositionsCenter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9332
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
// WideImage_OperationFactory::get('ResizeCanvas');
28
29
/**
30
 * @package Tests
31
 */
32
class ResizeCanvasTest extends WideImage_TestCase
33
{
34
	public function testResizeCanvasUp()
35
	{
36
		$img = WideImage::createTrueColorImage(160, 120);
37
		$resized = $img->resizeCanvas(180, 180, 0, 0);
38
		$this->assertDimensions($resized, 180, 180);
39
	}
40
	
41
	public function testResizeCanvasDown()
42
	{
43
		$img = WideImage::createTrueColorImage(160, 120);
44
		$resized = $img->resizeCanvas(30, 100, 0, 0);
45
		$this->assertDimensions($resized, 30, 100);
46
	}
47
	
48
	public function testResizeCanvasPositionsCenter()
49
	{
50
		$img = WideImage::createTrueColorImage(20, 20);
51
		$black = $img->allocateColor(0, 0, 0);
52
		$white = $img->allocateColor(255, 255, 255);
53
		$img->fill(0, 0, $black);
54
		
55
		$res = $img->resizeCanvas(40, 40, 'center', 'center', $white);
56
		$this->assertRGBAt($res, 5, 5, $white);
57
		$this->assertRGBAt($res, 35, 35, $white);
58
		$this->assertRGBAt($res, 5, 35, $white);
59
		$this->assertRGBAt($res, 35, 5, $white);
60
		$this->assertRGBAt($res, 20, 20, $black);
61
	}
62
	
63
	public function testResizeCanvasPositionsCorner()
64
	{
65
		$img = WideImage::createTrueColorImage(20, 20);
66
		$black = $img->allocateColor(0, 0, 0);
67
		$white = $img->allocateColor(255, 255, 255);
68
		$img->fill(0, 0, $black);
69
		
70
		$res = $img->resizeCanvas(40, 40, 'bottom', 'right', $white);
71
		$this->assertRGBAt($res, 5, 5, $white);
72
		$this->assertRGBAt($res, 35, 35, $black);
73
		$this->assertRGBAt($res, 5, 35, $white);
74
		$this->assertRGBAt($res, 35, 5, $white);
75
	}
76
}
77