/
FilesTest.php
122 lines (115 loc) · 3.93 KB
/
FilesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace ImpressCMS\Tests\Libraries\ICMS;
class FilesTest extends \PHPUnit_Framework_TestCase {
/**
* Test if is available
*/
public function testAvailability() {
foreach ([
'icms_file_DownloadHandler' => null,
'icms_file_MediaUploadHandler' => null,
'icms_file_TarDownloader' => 'icms_file_DownloadHandler',
'icms_file_TarFileHandler' => null,
'icms_file_ZipDownloader' => 'icms_file_DownloadHandler',
'icms_file_ZipFileHandler' => null
] as $class => $must_be_instance_of) {
$this->assertTrue(class_exists($class, true), $class . " class doesn't exist");
if ($must_be_instance_of !== null) {
$instance = $this->getClassInstance($class);
$this->assertTrue( $instance instanceof $must_be_instance_of, $class . " is not instanceof " . $must_be_instance_of);
}
}
}
/**
* Gets instance of class from classname
*
* @param string $class ClassName
*
* @return object
*/
private function getClassInstance($class) {
$reflection = new \ReflectionClass($class);
if ($reflection->isAbstract()) {
$instance = $this->getMockForAbstractClass($class);
} else {
$instance = $this->getMockBuilder($class)
->disableOriginalConstructor()
->getMock();
}
return $instance;
}
/**
* Test methods availability
*/
public function testMethodsAvailability() {
foreach ([
'icms_file_DownloadHandler' => [
'addFile',
'addBinaryFile',
'addFileData',
'addBinaryFileData',
'download'
],
'icms_file_MediaUploadHandler' => [
'fetchFromURL',
'fetchMedia',
'getUploadErrorText',
'setTargetFileName',
'getMediaName',
'getMediaType',
'getMediaSize',
'getMediaTmpName',
'getSavedFileName',
'getSavedDestination',
'upload',
'checkMaxFileSize',
'checkMaxWidth',
'checkMaxHeight',
'checkMimeType',
'checkImageType',
'sanitizeMultipleExtensions',
'setErrors',
'getErrors'
],
'icms_file_TarFileHandler' => [
'openTAR',
'appendTar',
'getFile',
'getDirectory',
'containsFile',
'containsDirectory',
'addDirectory',
'addFile',
'removeFile',
'removeDirectory',
'saveTar',
'toTar',
'toTarOutput'
],
'icms_file_ZipFileHandler' => [
'addFile',
'file'
]
] as $class => $methods) {
foreach ($methods as $method) {
$this->assertTrue(method_exists($class, $method), 'Static method ' . $method . ' doesn\'t exists for class ' . $class);
}
}
}
/**
* Tests variables availability and types
*/
public function testVariables() {
foreach ([
'icms_file_TarFileHandler' => [
'numFiles' => 'null', // int
'files' => 'null' // array
]
] as $class => $variables) {
$instance = $this->getClassInstance($class);
foreach ($variables as $variable => $type) {
$this->assertInternalType($type, $instance->$variable, '$' . $variable . ' is not of type ' . $type . ' in instance of ' . $class);
}
}
}
}