PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / webp-convert / tests / Helpers / SanityCheckTestNotReady.php

SanityCheckTestNotReady.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/rosell-dk/webp-convert/tests/Helpers/SanityCheckTestNotReady.php

277 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WebPConvert\Tests\Helpers;
4
5 use WebPConvert\Helpers\SanityCheck;
6 use WebPConvert\Exceptions\SanityException;
7
8 use PHPUnit\Framework\TestCase;
9
10 /**
11 * @coversDefaultClass WebPConvert\Helpers\SanityCheck
12 * @covers WebPConvert\Helpers\SanityCheck
13 */
14 class SanityCheckTest extends TestCase
15 {
16
17 /**
18 * @covers ::noNUL
19 */
20 public function testNoNUL()
21 {
22 $this->expectException(SanityException::class);
23
24 SanityCheck::noNUL("here it comes: \0");
25 }
26
27 /**
28 * @covers ::noNUL
29 */
30 public function testNoNUL2()
31 {
32 $this->expectException(SanityException::class);
33
34 SanityCheck::noNUL("here it comes: " . chr(0));
35 }
36
37 /**
38 * @covers ::noNUL
39 */
40 public function testNoNUL3()
41 {
42 SanityCheck::noNUL("here it does not come");
43 }
44
45 /**
46 * @covers ::noControlChars
47 */
48 public function testNoControlChars()
49 {
50 $this->expectException(SanityException::class);
51 $sanitized = SanityCheck::noControlChars("..\1..");
52 }
53
54 /**
55 * @covers ::noControlChars
56 */
57 public function testNoControlChars2()
58 {
59 $this->expectException(SanityException::class);
60 $sanitized = SanityCheck::noControlChars("..\n..");
61 }
62
63 /**
64 * @covers ::noControlChars
65 */
66 public function testNoControlChars3()
67 {
68 //$this->expectException(SanityException::class);
69 $unsanitized = urldecode("%EF%B8%8F");
70 //echo 'look:' . $unsanitized;
71 $sanitized = SanityCheck::noControlChars($unsanitized);
72 //echo $sanitized;
73 }
74
75 /**
76 * @covers ::noControlChars
77 */
78 public function testNoControlChars4()
79 {
80 //$this->expectException(SanityException::class);
81 //SanityCheck::noControlChars("Skærmbillede");
82 //SanityCheck::noControlChars("Skrm");
83 //SanityCheck::noControlChars("Skærmbillede-2018-10-12-kl.-11.26.38-e1539336533920.png.webp");
84 SanityCheck::noControlChars("Skærmbillede-2018-10-12-kl.-11.26.38-e1539336533920.png.webp");
85 $sanitized = SanityCheck::noControlChars("space is ok.");
86 echo $sanitized;
87 }
88
89
90
91 /**
92 * @covers ::notEmpty
93 */
94 public function testNotEmpty()
95 {
96 $this->expectException(SanityException::class);
97 SanityCheck::notEmpty(null);
98 }
99
100 /**
101 * @covers ::notEmpty
102 */
103 /*
104 public function testNotEmpty2()
105 {
106 $arr = [];
107 $this->expectException(SanityException::class);
108 SanityCheck::notEmpty($arr['not-exist']);
109 }
110 */
111
112 /**
113 * @covers ::notEmpty
114 */
115 public function testNotEmpty2()
116 {
117 SanityCheck::notEmpty('..');
118 }
119
120 /**
121 * @covers ::noDirectoryTraversal
122 */
123 public function testNoDirectoryTraversal()
124 {
125 $this->expectException(SanityException::class);
126 SanityCheck::noDirectoryTraversal('hello/../hi');
127 }
128
129 /**
130 * @covers ::noStreamWrappers
131 */
132 public function testNoStreamWrappers()
133 {
134 $this->expectException(SanityException::class);
135 SanityCheck::noStreamWrappers('phar://aoeu');
136 }
137
138 /**
139 * @covers ::noStreamWrappers
140 */
141 public function testNoStreamWrappers2()
142 {
143 $this->expectException(SanityException::class);
144 SanityCheck::noStreamWrappers("phar:\0//aoeu");
145 }
146
147 /**
148 * @covers ::mustBeString
149 */
150 public function testMustBeString()
151 {
152 $this->expectException(SanityException::class);
153 SanityCheck::mustBeString(0);
154 }
155
156 /**
157 * @covers ::mustBeString
158 */
159 public function testMustBeString2()
160 {
161 SanityCheck::mustBeString('');
162 SanityCheck::mustBeString('hello');
163 }
164
165 /**
166 * @covers ::isJSONArray
167 */
168 public function testIsJSONArray()
169 {
170 $this->expectException(SanityException::class);
171 SanityCheck::isJSONArray('');
172 }
173
174 /**
175 * @covers ::isJSONArray
176 */
177 public function testIsJSONArray2()
178 {
179 SanityCheck::isJSONArray('[]');
180 SanityCheck::isJSONArray('["hello", "hi"]');
181 }
182
183 /**
184 * @covers ::pregMatch
185 */
186 public function testPregMatch()
187 {
188 $this->expectException(SanityException::class);
189 SanityCheck::pregMatch('#\d#', 'a');
190 }
191
192 /**
193 * @covers ::pregMatch
194 */
195 public function testPregMatch2()
196 {
197 SanityCheck::pregMatch('#\d#', '0');
198 SanityCheck::pregMatch('#^[a-z]+$#', 'gd');
199 }
200
201 public function testPathBeginsWith()
202 {
203 SanityCheck::pathBeginsWith('/var/www/my-site/hello.php', '/var/www/');
204 }
205
206 public function testPathBeginsWith2()
207 {
208 $this->expectException(SanityException::class);
209 SanityCheck::pathBeginsWith('/var/bin/exec', '/var/www/');
210 }
211
212 public function testFindClosestExistingFolderSymLinksExpanded()
213 {
214 /*
215 $this->assertEquals(
216 '/var/www/webp-express-tests/we0/plugins-moved/webp-express',
217 SanityCheck::findClosestExistingFolderSymLinksExpanded(
218 '/var/www/webp-express-tests/we0/plugins-moved/webp-express/i/do/not/exist/test-pattern-tv.jpg'
219 )
220 );*/
221
222 //echo dirname()
223 /*
224 echo 'dir:' . SanityCheck::findClosestExistingFolderSymLinksExpanded(
225 '/var/www/webp-express-tests/we19/wp-content/webp-express/webp-images/doc-root/wp-content/plugins/webp-express/test/test-pattern-tv.jpg.webp'
226 );*/
227 }
228
229 /*
230 public function testPathBeginsWithSymLinksExpanded()
231 {
232 $this->expectException(SanityException::class);
233 SanityCheck::pathBeginsWithSymLinksExpanded(
234 '/aoeu/var/www/webp-express-tests/we19/wp-content/webp-express/webp-images/doc-root/wp-content/plugins/webp-express/test/test-pattern-tv.jpg.webp',
235 '/var/www/webp-express-tests/'
236 );
237 }
238
239 public function testPathBeginsWithSymLinksExpanded2()
240 {
241 SanityCheck::pathBeginsWithSymLinksExpanded(
242 '/var/www/webp-express-tests/we19/wp-content/webp-express/webp-images/doc-root/wp-content/plugins/webp-express/test/test-pattern-tv.jpg.webp',
243 '/var/www/webp-express-tests/'
244 );
245 }
246
247 public function testPathBeginsWithSymLinksExpanded3()
248 {
249 $this->expectException(SanityException::class);
250 SanityCheck::pathBeginsWithSymLinksExpanded(
251 'aoeu/var/www/webp-express-tests/we19/wp-content/webp-express/webp-images/doc-root/wp-content/plugins/webp-express/test/test-pattern-tv.jpg.webp',
252 '/var/www/webp-express-tests/'
253 );
254 }*/
255
256 public function testAbsPathMicrosoftStyle()
257 {
258 SanityCheck::absPathMicrosoftStyle("C:\\");
259 SanityCheck::absPathMicrosoftStyle("C:/");
260 }
261
262 public function testAbsPathMicrosoftStyle2()
263 {
264 $this->expectException(SanityException::class);
265 SanityCheck::absPathMicrosoftStyle("C:1");
266 }
267
268 public function testAbsPath()
269 {
270 SanityCheck::absPath('/var/bin/exec');
271 SanityCheck::absPath('var/bin/exec');
272 }
273
274
275
276 }
277