1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/functions.php'; |
3
|
|
|
require_once 'Intraface/modules/filemanager/FileHandler.php'; |
4
|
|
|
require_once 'Intraface/modules/filemanager/InstanceManager.php'; |
5
|
|
|
require_once 'file_functions.php'; |
6
|
|
|
|
7
|
|
|
class InstanceHandlerTest extends PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
function setUp() |
10
|
|
|
{ |
11
|
|
|
$db = MDB2::singleton(DB_DSN); |
12
|
|
|
$db->query('TRUNCATE file_handler'); |
13
|
|
|
$db->query('TRUNCATE file_handler_instance'); |
14
|
|
|
$db->query('TRUNCATE file_handler_instance_type'); |
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
|
|
|
return new FileHandler($this->createKernel()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function createFile($file) |
33
|
|
|
{ |
34
|
|
|
$data = array('file_name' => $file); |
|
|
|
|
35
|
|
|
$filehandler = $this->createFileHandler(); |
36
|
|
|
copy(dirname(__FILE__) . '/'.$file, PATH_UPLOAD.$file); |
37
|
|
|
$filehandler->save(PATH_UPLOAD.$file, $file); |
38
|
|
|
$filehandler->load(); |
39
|
|
|
$this->assertEquals('', $filehandler->error->view()); |
40
|
|
|
return $filehandler; |
41
|
|
|
} |
42
|
|
|
//////////////////////////////////////////////////////////////// |
43
|
|
|
|
44
|
|
|
function testCreateFile() |
45
|
|
|
{ |
46
|
|
|
$file = $this->createFile('wideonball.jpg'); |
47
|
|
|
|
48
|
|
|
$this->assertEquals('wideonball.jpg', $file->get('file_name')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function testConstructWithoutParameters() |
52
|
|
|
{ |
53
|
|
|
$filehandler = $this->createFile('wideonball.jpg'); |
54
|
|
|
$filehandler->createInstance(); |
55
|
|
|
$this->assertTrue(is_object($filehandler->instance)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function testConstructWithTypeSquare() |
59
|
|
|
{ |
60
|
|
|
$filehandler = $this->createFile('wideonball.jpg'); |
61
|
|
|
$filehandler->createInstance('square'); |
62
|
|
|
|
63
|
|
|
$this->assertEquals(3846, $filehandler->instance->get('file_size'), '', 10); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function testConstructWithTypeSquareAndCropParams() |
67
|
|
|
{ |
68
|
|
|
$filehandler = $this->createFile('wideonball.jpg'); |
69
|
|
|
|
70
|
|
|
$crop = array('crop_offset_x' => 200, |
71
|
|
|
'crop_offset_y' => 20, |
72
|
|
|
'crop_width' => 100, |
73
|
|
|
'crop_height' => 100); |
74
|
|
|
|
75
|
|
|
$filehandler->createInstance('square', $crop); |
76
|
|
|
// we add 10 bytes delta |
77
|
|
|
$this->assertEquals(3644, filesize($filehandler->instance->get('file_path')), '', 10); |
78
|
|
|
$size = getimagesize($filehandler->instance->get('file_path')); |
79
|
|
|
$this->assertEquals(75, $size[0]); |
80
|
|
|
$this->assertEquals(75, $size[1]); |
81
|
|
|
|
82
|
|
|
// $this->assertEquals('c6fc157c4d2d56ad8be50a71af684fab', md5(file_get_contents($filehandler->instance->get('file_path')))); |
|
|
|
|
83
|
|
|
|
84
|
|
|
// instance handler does not return the crop parameter, so we just find it in the database! |
85
|
|
|
$db = MDB2::singleton(DB_DSN); |
86
|
|
|
$result = $db->query('SELECT crop_parameter FROM file_handler_instance WHERE id = '.$filehandler->instance->get('id')); |
87
|
|
|
$row = $result->fetchRow(MDB2_FETCHMODE_ASSOC); |
88
|
|
|
$this->assertEquals($crop, unserialize($row['crop_parameter'])); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
function testCreateCustomInstanceCreaterThanImage() |
92
|
|
|
{ |
93
|
|
|
$this->markTestSkipped( |
94
|
|
|
'This test has not been implemented yet.' |
95
|
|
|
); |
96
|
|
|
$im = new InstanceManager($this->createKernel()); |
97
|
|
|
|
98
|
|
|
$this->assertEquals(1000, $im->save(array('name' => 'wide', 'max_height' => 280, 'max_width' => 720, 'resize_type' => 'strict'))); |
99
|
|
|
|
100
|
|
|
$filehandler = $this->createFile('idraetshoejskolen9.jpg'); |
101
|
|
|
$filehandler->createInstance('wide'); |
102
|
|
|
// we add 20 bytes delta |
103
|
|
|
$this->assertEquals(54510, filesize($filehandler->instance->get('file_path')), '', 20); |
104
|
|
|
$size = getimagesize($filehandler->instance->get('file_path')); |
105
|
|
|
$this->assertEquals(720, $size[0]); |
106
|
|
|
$this->assertEquals(280, $size[1]); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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.