-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFilesValidatorTest.php
155 lines (144 loc) · 4.97 KB
/
FilesValidatorTest.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/*
* This file is part of Aplus Framework Validation Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests\Validation;
use Framework\Validation\FilesValidator;
use PHPUnit\Framework\TestCase;
final class FilesValidatorTest extends TestCase
{
protected function setUp() : void
{
$_FILES = [
'foo' => [
'name' => ['a' => 'logo-circle.png'],
'type' => ['a' => 'image/png'],
'tmp_name' => ['a' => __DIR__ . '/files/logo-circle.png'],
'error' => ['a' => 0],
'size' => ['a' => 18688],
],
'bar' => [
'name' => 'desenhando.svg',
'type' => 'image/svg+xml',
'tmp_name' => __DIR__ . '/files/desenhando.svg',
'error' => 0,
'size' => 1960,
],
'baz' => [
'name' => [
'x' => [
'y' => 'logo-circle.png',
],
],
'type' => [
'x' => [
'y' => 'image/png',
],
],
'tmp_name' => [
'x' => [
'y' => '/tmp/phplXINR3',
],
],
'error' => [
'x' => [
'y' => 0,
],
],
'size' => [
'x' => [
'y' => 18688,
],
],
],
];
}
public function testOrganizedFiles() : void
{
self::assertSame([
'foo' => [
'a' => [
'name' => 'logo-circle.png',
'type' => 'image/png',
'tmp_name' => __DIR__ . '/files/logo-circle.png',
'error' => 0,
'size' => 18688,
],
],
'bar' => [
'name' => 'desenhando.svg',
'type' => 'image/svg+xml',
'tmp_name' => __DIR__ . '/files/desenhando.svg',
'error' => 0,
'size' => 1960,
],
'baz' => [
'x' => [
'y' => [
'name' => 'logo-circle.png',
'type' => 'image/png',
'tmp_name' => '/tmp/phplXINR3',
'error' => 0,
'size' => 18688,
],
],
],
], FilesValidatorMock::getOrganizedFiles());
}
public function testUploaded() : void
{
self::assertFalse(FilesValidator::uploaded('foo[a]'));
self::assertFalse(FilesValidator::uploaded('bar'));
self::assertFalse(FilesValidator::uploaded('unknown'));
}
public function testMaxSize() : void
{
self::assertFalse(FilesValidatorMock::maxSize('foo[a]', [], 10));
self::assertTrue(FilesValidatorMock::maxSize('foo[a]', [], 40));
self::assertFalse(FilesValidator::maxSize('foo[a]', [], 40));
}
public function testMimeTypes() : void
{
self::assertFalse(FilesValidatorMock::mimes('foo[a]', [], 'application/json'));
self::assertTrue(
FilesValidatorMock::mimes('foo[a]', [], 'application/json', 'image/png')
);
self::assertFalse(
FilesValidator::mimes('foo[a]', [], 'application/json', 'image/png')
);
}
public function testExtensions() : void
{
self::assertFalse(FilesValidatorMock::ext('foo[a]', [], 'pdf', 'svg'));
self::assertTrue(FilesValidatorMock::ext('foo[a]', [], 'pdf', 'png'));
self::assertFalse(FilesValidator::ext('foo[a]', [], 'pdf', 'png'));
}
public function testImage() : void
{
self::assertTrue(FilesValidatorMock::image('foo[a]'));
self::assertFalse(FilesValidator::image('foo[a]'));
}
public function testMaxDimensions() : void
{
self::assertFalse(FilesValidatorMock::maxDim('foo[a]', [], 200, 200));
self::assertTrue(FilesValidatorMock::maxDim('foo[a]', [], 400, 500));
self::assertFalse(FilesValidator::maxDim('foo[a]', [], 400, 500));
}
public function testMinDimensions() : void
{
self::assertFalse(FilesValidatorMock::minDim('foo[a]', [], 500, 500));
self::assertTrue(FilesValidatorMock::minDim('foo[a]', [], 300, 400));
self::assertFalse(FilesValidator::minDim('foo[a]', [], 300, 500));
}
public function testDimensions() : void
{
self::assertFalse(FilesValidatorMock::dim('foo[a]', [], 500, 500));
self::assertTrue(FilesValidatorMock::dim('foo[a]', [], 400, 400));
self::assertFalse(FilesValidator::dim('foo[a]', [], 300, 500));
}
}