1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/functions.php'; |
3
|
|
|
require_once 'Intraface/modules/filemanager/FileHandler.php'; |
4
|
|
|
require_once 'Intraface/modules/filemanager/ImageHandler.php'; |
5
|
|
|
require_once 'file_functions.php'; |
6
|
|
|
|
7
|
|
|
class ImageHandlerTest extends PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
private $file_name = 'wideonball.jpg'; |
10
|
|
|
|
11
|
|
|
function setUp() |
12
|
|
|
{ |
13
|
|
|
$db = MDB2::singleton(DB_DSN); |
14
|
|
|
$db->query('TRUNCATE file_handler'); |
15
|
|
|
iht_deltree(PATH_UPLOAD.'1'); |
16
|
|
|
if (file_exists(PATH_UPLOAD.'/1/1.jpeg')) { |
17
|
|
|
unlink(PATH_UPLOAD.'/1/1.jpeg'); |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
function createKernel() |
22
|
|
|
{ |
23
|
|
|
$kernel = new Stub_Kernel; |
24
|
|
|
return $kernel; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
function createFileHandler() |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
$data = array('file_name' => $this->file_name); |
|
|
|
|
31
|
|
|
$filehandler = new FileHandler($this->createKernel()); |
32
|
|
|
copy(dirname(__FILE__) . '/'.$this->file_name, PATH_UPLOAD.$this->file_name); |
33
|
|
|
$filehandler->save(PATH_UPLOAD.$this->file_name, $this->file_name); |
34
|
|
|
$filehandler->load(); |
35
|
|
|
$this->assertEquals('', $filehandler->error->view()); |
36
|
|
|
return $filehandler; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
//////////////////////////////////////////////////////////////// |
40
|
|
|
|
41
|
|
|
function testConstruct() |
42
|
|
|
{ |
43
|
|
|
$image = new ImageHandler($this->createFileHandler()); |
44
|
|
|
$this->assertEquals('ImageHandler', get_class($image)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
View Code Duplication |
function testResizeWithRelativeSize() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
|
51
|
|
|
$image = new ImageHandler($this->createFileHandler()); |
52
|
|
|
$file = $image->resize(200, 600); |
53
|
|
|
$size = getimagesize($file); |
54
|
|
|
$this->assertEquals(200, $size[0]); |
55
|
|
|
$this->assertEquals(50, $size[1]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
function testResizeWithStrictSize() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
|
61
|
|
|
$image = new ImageHandler($this->createFileHandler()); |
62
|
|
|
$file = $image->resize(200, 300, 'strict'); |
63
|
|
|
$size = getimagesize($file); |
64
|
|
|
$this->assertEquals(200, $size[0]); |
65
|
|
|
$this->assertEquals(300, $size[1]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
function testCrop() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$image = new ImageHandler($this->createFileHandler()); |
71
|
|
|
$file = $image->crop(100, 100, 200, 20); |
72
|
|
|
$size = getimagesize($file); |
73
|
|
|
$this->assertEquals(100, $size[0]); |
74
|
|
|
$this->assertEquals(100, $size[1]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function testQualityAfterRepeatedResize() |
78
|
|
|
{ |
79
|
|
|
|
80
|
|
|
$image = new ImageHandler($this->createFileHandler()); |
81
|
|
|
$image->resize(500, 200); |
82
|
|
|
$image->resize(300, 200); |
83
|
|
|
$file1 = $image->resize(200, 200); |
84
|
|
|
|
85
|
|
|
$image = new ImageHandler($this->createFileHandler()); |
86
|
|
|
$file2 = $image->resize(200, 200); |
87
|
|
|
|
88
|
|
|
// we accept 10% fall in quality! after several resize |
89
|
|
|
$this->assertEquals(filesize($file2), filesize($file1), '', filesize($file2)/100*10); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.