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

GD2Test::testSaveToString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9666
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\Mapper;
23
24
use WideImage\WideImage;
25
use WideImage\MapperFactory;
26
use Test\WideImage_TestCase;
27
28
/**
29
 * @package Tests
30
 */
31
class GD2Test extends WideImage_TestCase
32
{
33
	protected $mapper;
34
	
35
	public function setup()
36
	{
37
		$this->mapper = MapperFactory::selectMapper(null, 'gd2');
38
	}
39
	
40
	public function teardown()
41
	{
42
		$this->mapper = null;
43
		
44
		if (file_exists(IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.gd2')) {
45
			unlink(IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.gd2');
46
		}
47
	}
48
	
49
	public function testSaveToString()
50
	{
51
		$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
52
		ob_start();
53
		$this->mapper->save($handle);
54
		$string = ob_get_clean();
55
		$this->assertTrue(strlen($string) > 0);
56
		imagedestroy($handle);
57
		
58
		// string contains valid image data
59
		$handle = imagecreatefromstring($string);
60
		$this->assertTrue(WideImage::isValidImageHandle($handle));
61
		imagedestroy($handle);
62
	}
63
	
64
	public function testSaveToFile()
65
	{
66
		$handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
67
		$this->mapper->save($handle, IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.gd2');
68
		$this->assertTrue(filesize(IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.gd2') > 0);
69
		imagedestroy($handle);
70
		
71
		// file is a valid image
72
		$handle = imagecreatefromgd2(IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.gd2');
73
		$this->assertTrue(WideImage::isValidImageHandle($handle));
74
		imagedestroy($handle);
75
	}
76
}
77