@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * \remarks To run this script as CLI: phpunit filename.php |
26 | 26 | */ |
27 | 27 | |
28 | -global $conf,$user,$langs,$db; |
|
28 | +global $conf, $user, $langs, $db; |
|
29 | 29 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
30 | 30 | //require_once 'PHPUnit/Autoload.php'; |
31 | 31 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $user->fetch(1); |
37 | 37 | $user->getrights(); |
38 | 38 | } |
39 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
39 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
40 | 40 | |
41 | 41 | |
42 | 42 | /** |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | parent::__construct($name); |
66 | 66 | |
67 | 67 | //$this->sharedFixture |
68 | - global $conf,$user,$langs,$db; |
|
69 | - $this->savconf=$conf; |
|
70 | - $this->savuser=$user; |
|
71 | - $this->savlangs=$langs; |
|
72 | - $this->savdb=$db; |
|
68 | + global $conf, $user, $langs, $db; |
|
69 | + $this->savconf = $conf; |
|
70 | + $this->savuser = $user; |
|
71 | + $this->savlangs = $langs; |
|
72 | + $this->savdb = $db; |
|
73 | 73 | |
74 | 74 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
75 | 75 | //print " - db ".$db->db; |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public static function setUpBeforeClass(): void |
85 | 85 | { |
86 | - global $conf,$user,$langs,$db; |
|
87 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
86 | + global $conf, $user, $langs, $db; |
|
87 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
88 | 88 | |
89 | 89 | print __METHOD__."\n"; |
90 | 90 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public static function tearDownAfterClass(): void |
98 | 98 | { |
99 | - global $conf,$user,$langs,$db; |
|
99 | + global $conf, $user, $langs, $db; |
|
100 | 100 | $db->rollback(); |
101 | 101 | |
102 | 102 | print __METHOD__."\n"; |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | */ |
110 | 110 | protected function setUp(): void |
111 | 111 | { |
112 | - global $conf,$user,$langs,$db; |
|
113 | - $conf=$this->savconf; |
|
114 | - $user=$this->savuser; |
|
115 | - $langs=$this->savlangs; |
|
116 | - $db=$this->savdb; |
|
112 | + global $conf, $user, $langs, $db; |
|
113 | + $conf = $this->savconf; |
|
114 | + $user = $this->savuser; |
|
115 | + $langs = $this->savlangs; |
|
116 | + $db = $this->savdb; |
|
117 | 117 | |
118 | 118 | print __METHOD__."\n"; |
119 | 119 | } |
@@ -135,25 +135,25 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function testDolBasename() |
137 | 137 | { |
138 | - global $conf,$user,$langs,$db; |
|
139 | - $conf=$this->savconf; |
|
140 | - $user=$this->savuser; |
|
141 | - $langs=$this->savlangs; |
|
142 | - $db=$this->savdb; |
|
138 | + global $conf, $user, $langs, $db; |
|
139 | + $conf = $this->savconf; |
|
140 | + $user = $this->savuser; |
|
141 | + $langs = $this->savlangs; |
|
142 | + $db = $this->savdb; |
|
143 | 143 | |
144 | - $result=dol_basename('adir/afile'); |
|
144 | + $result = dol_basename('adir/afile'); |
|
145 | 145 | print __METHOD__." result=".$result."\n"; |
146 | 146 | $this->assertEquals('afile', $result); |
147 | 147 | |
148 | - $result=dol_basename('adir/afile/'); |
|
148 | + $result = dol_basename('adir/afile/'); |
|
149 | 149 | print __METHOD__." result=".$result."\n"; |
150 | 150 | $this->assertEquals('afile', $result); |
151 | 151 | |
152 | - $result=dol_basename('adir/νεο'); // With cyrillic data. Here basename fails to return correct value |
|
152 | + $result = dol_basename('adir/νεο'); // With cyrillic data. Here basename fails to return correct value |
|
153 | 153 | print __METHOD__." result=".$result."\n"; |
154 | 154 | $this->assertEquals('νεο', $result); |
155 | 155 | |
156 | - $result=dol_basename('adir/νεο/'); // With cyrillic data. Here basename fails to return correct value |
|
156 | + $result = dol_basename('adir/νεο/'); // With cyrillic data. Here basename fails to return correct value |
|
157 | 157 | print __METHOD__." result=".$result."\n"; |
158 | 158 | $this->assertEquals('νεο', $result); |
159 | 159 | } |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function testDolCountNbOfLine() |
168 | 168 | { |
169 | - global $conf,$user,$langs,$db; |
|
170 | - $conf=$this->savconf; |
|
171 | - $user=$this->savuser; |
|
172 | - $langs=$this->savlangs; |
|
173 | - $db=$this->savdb; |
|
174 | - |
|
175 | - $file=dirname(__FILE__).'/Example_import_company_1.csv'; |
|
176 | - $result=dol_count_nb_of_line($file); |
|
169 | + global $conf, $user, $langs, $db; |
|
170 | + $conf = $this->savconf; |
|
171 | + $user = $this->savuser; |
|
172 | + $langs = $this->savlangs; |
|
173 | + $db = $this->savdb; |
|
174 | + |
|
175 | + $file = dirname(__FILE__).'/Example_import_company_1.csv'; |
|
176 | + $result = dol_count_nb_of_line($file); |
|
177 | 177 | print __METHOD__." result=".$result."\n"; |
178 | 178 | $this->assertEquals(3, $result); |
179 | 179 | |
@@ -187,19 +187,19 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function testDolIsFileDir() |
189 | 189 | { |
190 | - global $conf,$user,$langs,$db; |
|
191 | - $conf=$this->savconf; |
|
192 | - $user=$this->savuser; |
|
193 | - $langs=$this->savlangs; |
|
194 | - $db=$this->savdb; |
|
190 | + global $conf, $user, $langs, $db; |
|
191 | + $conf = $this->savconf; |
|
192 | + $user = $this->savuser; |
|
193 | + $langs = $this->savlangs; |
|
194 | + $db = $this->savdb; |
|
195 | 195 | |
196 | - $file=dirname(__FILE__).'/Example_import_company_1.csv'; |
|
196 | + $file = dirname(__FILE__).'/Example_import_company_1.csv'; |
|
197 | 197 | |
198 | - $result=dol_is_file($file); |
|
198 | + $result = dol_is_file($file); |
|
199 | 199 | print __METHOD__." result=".$result."\n"; |
200 | 200 | $this->assertTrue($result); |
201 | 201 | |
202 | - $result=dol_is_dir($file); |
|
202 | + $result = dol_is_dir($file); |
|
203 | 203 | print __METHOD__." result=".$result."\n"; |
204 | 204 | $this->assertFalse($result); |
205 | 205 | |
@@ -213,24 +213,24 @@ discard block |
||
213 | 213 | */ |
214 | 214 | public function testDolOther() |
215 | 215 | { |
216 | - global $conf,$user,$langs,$db; |
|
217 | - $conf=$this->savconf; |
|
218 | - $user=$this->savuser; |
|
219 | - $langs=$this->savlangs; |
|
220 | - $db=$this->savdb; |
|
221 | - |
|
222 | - $url='http://www.dolibarr.org'; |
|
223 | - $result=dol_is_url($url); |
|
216 | + global $conf, $user, $langs, $db; |
|
217 | + $conf = $this->savconf; |
|
218 | + $user = $this->savuser; |
|
219 | + $langs = $this->savlangs; |
|
220 | + $db = $this->savdb; |
|
221 | + |
|
222 | + $url = 'http://www.dolibarr.org'; |
|
223 | + $result = dol_is_url($url); |
|
224 | 224 | print __METHOD__." result=".$result."\n"; |
225 | 225 | $this->assertTrue($result); |
226 | 226 | |
227 | - $url='https://www.dolibarr.org'; |
|
228 | - $result=dol_is_url($url); |
|
227 | + $url = 'https://www.dolibarr.org'; |
|
228 | + $result = dol_is_url($url); |
|
229 | 229 | print __METHOD__." result=".$result."\n"; |
230 | 230 | $this->assertTrue($result); |
231 | 231 | |
232 | - $url='file://www.dolibarr.org/download/file.zip'; |
|
233 | - $result=dol_is_url($url); |
|
232 | + $url = 'file://www.dolibarr.org/download/file.zip'; |
|
233 | + $result = dol_is_url($url); |
|
234 | 234 | print __METHOD__." result=".$result."\n"; |
235 | 235 | $this->assertTrue($result); |
236 | 236 | |
@@ -244,41 +244,41 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function testDolMimeType() |
246 | 246 | { |
247 | - global $conf,$user,$langs,$db; |
|
248 | - $conf=$this->savconf; |
|
249 | - $user=$this->savuser; |
|
250 | - $langs=$this->savlangs; |
|
251 | - $db=$this->savdb; |
|
247 | + global $conf, $user, $langs, $db; |
|
248 | + $conf = $this->savconf; |
|
249 | + $user = $this->savuser; |
|
250 | + $langs = $this->savlangs; |
|
251 | + $db = $this->savdb; |
|
252 | 252 | |
253 | 253 | // file.png |
254 | - $result=dol_mimetype('file.png', '', 0); |
|
254 | + $result = dol_mimetype('file.png', '', 0); |
|
255 | 255 | $this->assertEquals('image/png', $result); |
256 | - $result=dol_mimetype('file.png', '', 1); |
|
256 | + $result = dol_mimetype('file.png', '', 1); |
|
257 | 257 | $this->assertEquals('png', $result); |
258 | - $result=dol_mimetype('file.png', '', 2); |
|
258 | + $result = dol_mimetype('file.png', '', 2); |
|
259 | 259 | $this->assertEquals('image.png', $result); |
260 | - $result=dol_mimetype('file.png', '', 3); |
|
260 | + $result = dol_mimetype('file.png', '', 3); |
|
261 | 261 | $this->assertEquals('', $result); |
262 | 262 | // file.odt |
263 | - $result=dol_mimetype('file.odt', '', 0); |
|
263 | + $result = dol_mimetype('file.odt', '', 0); |
|
264 | 264 | $this->assertEquals('application/vnd.oasis.opendocument.text', $result); |
265 | - $result=dol_mimetype('file.odt', '', 1); |
|
265 | + $result = dol_mimetype('file.odt', '', 1); |
|
266 | 266 | $this->assertEquals('vnd.oasis.opendocument.text', $result); |
267 | - $result=dol_mimetype('file.odt', '', 2); |
|
267 | + $result = dol_mimetype('file.odt', '', 2); |
|
268 | 268 | $this->assertEquals('ooffice.png', $result); |
269 | - $result=dol_mimetype('file.odt', '', 3); |
|
269 | + $result = dol_mimetype('file.odt', '', 3); |
|
270 | 270 | $this->assertEquals('', $result); |
271 | 271 | // file.php |
272 | - $result=dol_mimetype('file.php', '', 0); |
|
272 | + $result = dol_mimetype('file.php', '', 0); |
|
273 | 273 | $this->assertEquals('text/plain', $result); |
274 | - $result=dol_mimetype('file.php', '', 1); |
|
274 | + $result = dol_mimetype('file.php', '', 1); |
|
275 | 275 | $this->assertEquals('plain', $result); |
276 | - $result=dol_mimetype('file.php', '', 2); |
|
276 | + $result = dol_mimetype('file.php', '', 2); |
|
277 | 277 | $this->assertEquals('php.png', $result); |
278 | - $result=dol_mimetype('file.php', '', 3); |
|
278 | + $result = dol_mimetype('file.php', '', 3); |
|
279 | 279 | $this->assertEquals('php', $result); |
280 | 280 | // file.php.noexe |
281 | - $result=dol_mimetype('file.php.noexe', '', 0); |
|
281 | + $result = dol_mimetype('file.php.noexe', '', 0); |
|
282 | 282 | $this->assertEquals('text/plain', $result); |
283 | 283 | } |
284 | 284 | |
@@ -290,31 +290,31 @@ discard block |
||
290 | 290 | */ |
291 | 291 | public function testDolDeleteDir() |
292 | 292 | { |
293 | - global $conf,$user,$langs,$db; |
|
294 | - $conf=$this->savconf; |
|
295 | - $user=$this->savuser; |
|
296 | - $langs=$this->savlangs; |
|
297 | - $db=$this->savdb; |
|
293 | + global $conf, $user, $langs, $db; |
|
294 | + $conf = $this->savconf; |
|
295 | + $user = $this->savuser; |
|
296 | + $langs = $this->savlangs; |
|
297 | + $db = $this->savdb; |
|
298 | 298 | |
299 | - $dirout=$conf->admin->dir_temp.'/test'; |
|
300 | - $dirout2=$conf->admin->dir_temp.'/test2'; |
|
299 | + $dirout = $conf->admin->dir_temp.'/test'; |
|
300 | + $dirout2 = $conf->admin->dir_temp.'/test2'; |
|
301 | 301 | |
302 | - $count=0; |
|
303 | - $result=dol_delete_dir_recursive($dirout, $count); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it |
|
302 | + $count = 0; |
|
303 | + $result = dol_delete_dir_recursive($dirout, $count); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it |
|
304 | 304 | print __METHOD__." result=".$result."\n"; |
305 | 305 | $this->assertGreaterThanOrEqual(0, $result); |
306 | 306 | |
307 | - $count=0; |
|
308 | - $countdeleted=0; |
|
309 | - $result=dol_delete_dir_recursive($dirout, $count, 1, 0, $countdeleted); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it |
|
307 | + $count = 0; |
|
308 | + $countdeleted = 0; |
|
309 | + $result = dol_delete_dir_recursive($dirout, $count, 1, 0, $countdeleted); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it |
|
310 | 310 | print __METHOD__." result=".$result."\n"; |
311 | 311 | $this->assertGreaterThanOrEqual(0, $result); |
312 | 312 | $this->assertGreaterThanOrEqual(0, $countdeleted); |
313 | 313 | |
314 | 314 | dol_mkdir($dirout2); |
315 | - $count=0; |
|
316 | - $countdeleted=0; |
|
317 | - $result=dol_delete_dir_recursive($dirout2, $count, 1, 0, $countdeleted); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it |
|
315 | + $count = 0; |
|
316 | + $countdeleted = 0; |
|
317 | + $result = dol_delete_dir_recursive($dirout2, $count, 1, 0, $countdeleted); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it |
|
318 | 318 | print __METHOD__." result=".$result."\n"; |
319 | 319 | $this->assertGreaterThanOrEqual(1, $result); |
320 | 320 | $this->assertGreaterThanOrEqual(1, $countdeleted); |
@@ -328,64 +328,64 @@ discard block |
||
328 | 328 | */ |
329 | 329 | public function testDolCopyMoveDelete() |
330 | 330 | { |
331 | - global $conf,$user,$langs,$db; |
|
332 | - $conf=$this->savconf; |
|
333 | - $user=$this->savuser; |
|
334 | - $langs=$this->savlangs; |
|
335 | - $db=$this->savdb; |
|
331 | + global $conf, $user, $langs, $db; |
|
332 | + $conf = $this->savconf; |
|
333 | + $user = $this->savuser; |
|
334 | + $langs = $this->savlangs; |
|
335 | + $db = $this->savdb; |
|
336 | 336 | |
337 | - $file=dirname(__FILE__).'/Example_import_company_1.csv'; |
|
337 | + $file = dirname(__FILE__).'/Example_import_company_1.csv'; |
|
338 | 338 | |
339 | - $result=dol_copy($file, '/adir/that/does/not/exists/file.csv'); |
|
339 | + $result = dol_copy($file, '/adir/that/does/not/exists/file.csv'); |
|
340 | 340 | print __METHOD__." result=".$result."\n"; |
341 | - $this->assertLessThan(0, $result, 'copy dir that does not exists'); // We should have error |
|
341 | + $this->assertLessThan(0, $result, 'copy dir that does not exists'); // We should have error |
|
342 | 342 | |
343 | - $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 1); |
|
343 | + $result = dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 1); |
|
344 | 344 | print __METHOD__." result=".$result."\n"; |
345 | - $this->assertGreaterThanOrEqual(1, $result, 'copy file ('.$file.') into a dir that exists ('.$conf->admin->dir_temp.'/file.csv)'); // Should be 1 |
|
345 | + $this->assertGreaterThanOrEqual(1, $result, 'copy file ('.$file.') into a dir that exists ('.$conf->admin->dir_temp.'/file.csv)'); // Should be 1 |
|
346 | 346 | |
347 | 347 | // Again to test with overwriting=0 |
348 | - $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 0); |
|
348 | + $result = dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 0); |
|
349 | 349 | print __METHOD__." result=".$result."\n"; |
350 | - $this->assertEquals(0, $result, 'copy destination already exists, no overwrite'); // Should be 0 |
|
350 | + $this->assertEquals(0, $result, 'copy destination already exists, no overwrite'); // Should be 0 |
|
351 | 351 | |
352 | 352 | // Again to test with overwriting=1 |
353 | - $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 1); |
|
353 | + $result = dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 1); |
|
354 | 354 | print __METHOD__." result=".$result."\n"; |
355 | - $this->assertGreaterThanOrEqual(1, $result, 'copy destination already exists, overwrite'); // Should be 1 |
|
355 | + $this->assertGreaterThanOrEqual(1, $result, 'copy destination already exists, overwrite'); // Should be 1 |
|
356 | 356 | |
357 | 357 | // To test a move that should work |
358 | - $result=dol_move($conf->admin->dir_temp.'/file.csv', $conf->admin->dir_temp.'/file2.csv', 0, 1); |
|
358 | + $result = dol_move($conf->admin->dir_temp.'/file.csv', $conf->admin->dir_temp.'/file2.csv', 0, 1); |
|
359 | 359 | print __METHOD__." result=".$result."\n"; |
360 | 360 | $this->assertTrue($result, 'move with default mask'); |
361 | 361 | |
362 | 362 | // To test a move that should work with forced mask |
363 | - $result=dol_move($conf->admin->dir_temp.'/file2.csv', $conf->admin->dir_temp.'/file3.csv', '0754', 1); // file should be rwxr-wr-- |
|
363 | + $result = dol_move($conf->admin->dir_temp.'/file2.csv', $conf->admin->dir_temp.'/file3.csv', '0754', 1); // file should be rwxr-wr-- |
|
364 | 364 | print __METHOD__." result=".$result."\n"; |
365 | 365 | $this->assertTrue($result, 'move with forced mask'); |
366 | 366 | |
367 | 367 | // To test a delete that should success |
368 | - $result=dol_delete_file($conf->admin->dir_temp.'/file3.csv'); |
|
368 | + $result = dol_delete_file($conf->admin->dir_temp.'/file3.csv'); |
|
369 | 369 | print __METHOD__." result=".$result."\n"; |
370 | 370 | $this->assertTrue($result, 'delete file'); |
371 | 371 | |
372 | 372 | // Again to test there is error when deleting a non existing file with option disableglob |
373 | - $result=dol_delete_file($conf->admin->dir_temp.'/file3.csv', 1, 1); |
|
373 | + $result = dol_delete_file($conf->admin->dir_temp.'/file3.csv', 1, 1); |
|
374 | 374 | print __METHOD__." result=".$result."\n"; |
375 | 375 | $this->assertFalse($result, 'delete file that does not exists with disableglo must return ko'); |
376 | 376 | |
377 | 377 | // Again to test there is no error when deleting a non existing file without option disableglob |
378 | - $result=dol_delete_file($conf->admin->dir_temp.'/file3csv', 0, 1); |
|
378 | + $result = dol_delete_file($conf->admin->dir_temp.'/file3csv', 0, 1); |
|
379 | 379 | print __METHOD__." result=".$result."\n"; |
380 | 380 | $this->assertTrue($result, 'delete file that does not exists without disabling glob must return ok'); |
381 | 381 | |
382 | 382 | // Test copy with special char / delete with blob |
383 | - $result=dol_copy($file, $conf->admin->dir_temp.'/file with [x] and é.csv', 0, 1); |
|
383 | + $result = dol_copy($file, $conf->admin->dir_temp.'/file with [x] and é.csv', 0, 1); |
|
384 | 384 | print __METHOD__." result=".$result."\n"; |
385 | - $this->assertGreaterThanOrEqual(1, $result, 'copy file with special chars, overwrite'); // Should be 1 |
|
385 | + $this->assertGreaterThanOrEqual(1, $result, 'copy file with special chars, overwrite'); // Should be 1 |
|
386 | 386 | |
387 | 387 | // Try to delete using a glob criteria |
388 | - $result=dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv'); |
|
388 | + $result = dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv'); |
|
389 | 389 | print __METHOD__." result=".$result."\n"; |
390 | 390 | $this->assertTrue($result, 'delete file using glob'); |
391 | 391 | } |
@@ -397,39 +397,39 @@ discard block |
||
397 | 397 | */ |
398 | 398 | public function testDolCompressUnCompress() |
399 | 399 | { |
400 | - global $conf,$user,$langs,$db; |
|
401 | - $conf=$this->savconf; |
|
402 | - $user=$this->savuser; |
|
403 | - $langs=$this->savlangs; |
|
404 | - $db=$this->savdb; |
|
400 | + global $conf, $user, $langs, $db; |
|
401 | + $conf = $this->savconf; |
|
402 | + $user = $this->savuser; |
|
403 | + $langs = $this->savlangs; |
|
404 | + $db = $this->savdb; |
|
405 | 405 | |
406 | 406 | // Format zip |
407 | 407 | print "\n"; |
408 | 408 | print 'testDolCompressUnCompress zip'."\n"; |
409 | 409 | |
410 | - $format='zip'; |
|
411 | - $filein=dirname(__FILE__).'/Example_import_company_1.csv'; |
|
412 | - $fileout=$conf->admin->dir_temp.'/test.'.$format; |
|
413 | - $dirout=$conf->admin->dir_temp.'/testdir'.$format; |
|
410 | + $format = 'zip'; |
|
411 | + $filein = dirname(__FILE__).'/Example_import_company_1.csv'; |
|
412 | + $fileout = $conf->admin->dir_temp.'/test.'.$format; |
|
413 | + $dirout = $conf->admin->dir_temp.'/testdir'.$format; |
|
414 | 414 | |
415 | 415 | dol_delete_file($fileout); |
416 | - $count=0; |
|
416 | + $count = 0; |
|
417 | 417 | dol_delete_dir_recursive($dirout, $count, 1); |
418 | 418 | |
419 | 419 | $errorstring = ''; |
420 | 420 | |
421 | 421 | dol_mkdir($conf->admin->dir_temp); |
422 | - $conf->global->MAIN_ENABLE_LOG_TO_HTML=1; |
|
422 | + $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; |
|
423 | 423 | $conf->modules['syslog'] = 'syslog'; |
424 | - $_REQUEST['logtohtml']=1; |
|
425 | - $conf->logbuffer=array(); |
|
424 | + $_REQUEST['logtohtml'] = 1; |
|
425 | + $conf->logbuffer = array(); |
|
426 | 426 | |
427 | - $result=dol_compress_file($filein, $fileout, $format, $errorstring); |
|
427 | + $result = dol_compress_file($filein, $fileout, $format, $errorstring); |
|
428 | 428 | print __METHOD__." compress result=".$result."\n"; |
429 | 429 | print join(', ', $conf->logbuffer); |
430 | 430 | $this->assertGreaterThanOrEqual(1, $result, "Pb with dol_compress_file on ".$filein." into ".$fileout." : ".$errorstring); |
431 | 431 | |
432 | - $result=dol_uncompress($fileout, $dirout); |
|
432 | + $result = dol_uncompress($fileout, $dirout); |
|
433 | 433 | print __METHOD__." uncompress result=".join(',', $result)."\n"; |
434 | 434 | print join(', ', $conf->logbuffer); |
435 | 435 | $this->assertEquals(0, count($result), "Pb with dol_uncompress_file of file ".$fileout); |
@@ -438,29 +438,29 @@ discard block |
||
438 | 438 | print "\n"; |
439 | 439 | print 'testDolCompressUnCompress gz'."\n"; |
440 | 440 | |
441 | - $format='gz'; |
|
442 | - $filein=dirname(__FILE__).'/Example_import_company_1.csv'; |
|
443 | - $fileout=$conf->admin->dir_temp.'/test.'.$format; |
|
444 | - $dirout=$conf->admin->dir_temp.'/testdir'.$format; |
|
441 | + $format = 'gz'; |
|
442 | + $filein = dirname(__FILE__).'/Example_import_company_1.csv'; |
|
443 | + $fileout = $conf->admin->dir_temp.'/test.'.$format; |
|
444 | + $dirout = $conf->admin->dir_temp.'/testdir'.$format; |
|
445 | 445 | |
446 | 446 | dol_delete_file($fileout); |
447 | - $count=0; |
|
447 | + $count = 0; |
|
448 | 448 | dol_delete_dir_recursive($dirout, $count, 1); |
449 | 449 | |
450 | 450 | $errorstring = ''; |
451 | 451 | |
452 | 452 | dol_mkdir($conf->admin->dir_temp); |
453 | - $conf->global->MAIN_ENABLE_LOG_TO_HTML=1; |
|
453 | + $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; |
|
454 | 454 | $conf->modules['syslog'] = 'syslog'; |
455 | - $_REQUEST['logtohtml']=1; |
|
456 | - $conf->logbuffer=array(); |
|
455 | + $_REQUEST['logtohtml'] = 1; |
|
456 | + $conf->logbuffer = array(); |
|
457 | 457 | |
458 | - $result=dol_compress_file($filein, $fileout, $format, $errorstring); |
|
458 | + $result = dol_compress_file($filein, $fileout, $format, $errorstring); |
|
459 | 459 | print __METHOD__." compress result=".$result."\n"; |
460 | 460 | print join(', ', $conf->logbuffer); |
461 | 461 | $this->assertGreaterThanOrEqual(1, $result, "Pb with dol_compress_file on ".$filein." into ".$fileout." : ".$errorstring); |
462 | 462 | |
463 | - $result=dol_uncompress($fileout, $dirout); |
|
463 | + $result = dol_uncompress($fileout, $dirout); |
|
464 | 464 | print __METHOD__." uncompress result=".join(',', $result)."\n"; |
465 | 465 | print join(', ', $conf->logbuffer); |
466 | 466 | $this->assertEquals(0, count($result), "Pb with dol_uncompress_file of file ".$fileout); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | if (preg_match($excludefiles, 'a/temp/b')) { |
473 | 473 | echo '----- Regex OK -----'."\n"; |
474 | 474 | } |
475 | - $result=dol_compress_dir($dirout, $conf->admin->dir_temp.'/testcompressdirzip.zip', 'zip', $excludefiles); |
|
475 | + $result = dol_compress_dir($dirout, $conf->admin->dir_temp.'/testcompressdirzip.zip', 'zip', $excludefiles); |
|
476 | 476 | print __METHOD__." dol_compress_dir result=".$result."\n"; |
477 | 477 | print join(', ', $conf->logbuffer); |
478 | 478 | $this->assertGreaterThanOrEqual(1, $result, "Pb with dol_compress_dir of ".$dirout." into ".$conf->admin->dir_temp.'/testdir.zip'); |
@@ -485,11 +485,11 @@ discard block |
||
485 | 485 | */ |
486 | 486 | public function testDolCheckSecureAccessDocument() |
487 | 487 | { |
488 | - global $conf,$user,$langs,$db; |
|
489 | - $conf=$this->savconf; |
|
490 | - $user=$this->savuser; |
|
491 | - $langs=$this->savlangs; |
|
492 | - $db=$this->savdb; |
|
488 | + global $conf, $user, $langs, $db; |
|
489 | + $conf = $this->savconf; |
|
490 | + $user = $this->savuser; |
|
491 | + $langs = $this->savlangs; |
|
492 | + $db = $this->savdb; |
|
493 | 493 | |
494 | 494 | //$dummyuser=new User($db); |
495 | 495 | //$result=restrictedArea($dummyuser,'societe'); |
@@ -505,41 +505,41 @@ discard block |
||
505 | 505 | // Check access to SPECIMEN |
506 | 506 | $user->rights->facture->lire = 0; |
507 | 507 | $user->rights->facture->creer = 0; |
508 | - $filename='SPECIMEN.pdf'; // Filename relative to module part |
|
509 | - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); |
|
508 | + $filename = 'SPECIMEN.pdf'; // Filename relative to module part |
|
509 | + $result = dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); |
|
510 | 510 | $this->assertEquals(1, $result['accessallowed']); |
511 | 511 | |
512 | 512 | |
513 | 513 | // Check read permission |
514 | 514 | $user->rights->facture->lire = 1; |
515 | 515 | $user->rights->facture->creer = 1; |
516 | - $filename='FA010101/FA010101.pdf'; // Filename relative to module part |
|
517 | - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); |
|
516 | + $filename = 'FA010101/FA010101.pdf'; // Filename relative to module part |
|
517 | + $result = dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); |
|
518 | 518 | $this->assertEquals(1, $result['accessallowed']); |
519 | 519 | |
520 | 520 | $user->rights->facture->lire = 0; |
521 | 521 | $user->rights->facture->creer = 0; |
522 | - $filename='FA010101/FA010101.pdf'; // Filename relative to module part |
|
523 | - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); |
|
522 | + $filename = 'FA010101/FA010101.pdf'; // Filename relative to module part |
|
523 | + $result = dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); |
|
524 | 524 | $this->assertEquals(0, $result['accessallowed']); |
525 | 525 | |
526 | 526 | // Check write permission |
527 | 527 | $user->rights->facture->lire = 0; |
528 | 528 | $user->rights->facture->creer = 0; |
529 | - $filename='FA010101/FA010101.pdf'; // Filename relative to module part |
|
530 | - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); |
|
529 | + $filename = 'FA010101/FA010101.pdf'; // Filename relative to module part |
|
530 | + $result = dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); |
|
531 | 531 | $this->assertEquals(0, $result['accessallowed']); |
532 | 532 | |
533 | 533 | $user->rights->facture->lire = 1; |
534 | 534 | $user->rights->facture->creer = 1; |
535 | - $filename='FA010101/FA010101.pdf'; // Filename relative to module part |
|
536 | - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); |
|
535 | + $filename = 'FA010101/FA010101.pdf'; // Filename relative to module part |
|
536 | + $result = dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); |
|
537 | 537 | $this->assertEquals(1, $result['accessallowed']); |
538 | 538 | |
539 | 539 | $user->rights->facture->lire = 1; |
540 | 540 | $user->rights->facture->creer = 0; |
541 | - $filename='FA010101/FA010101.pdf'; // Filename relative to module part |
|
542 | - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); |
|
541 | + $filename = 'FA010101/FA010101.pdf'; // Filename relative to module part |
|
542 | + $result = dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); |
|
543 | 543 | $this->assertEquals(0, $result['accessallowed']); |
544 | 544 | |
545 | 545 | |
@@ -555,31 +555,31 @@ discard block |
||
555 | 555 | */ |
556 | 556 | public function testDolDirMove() |
557 | 557 | { |
558 | - global $conf,$user,$langs,$db; |
|
559 | - $conf=$this->savconf; |
|
560 | - $user=$this->savuser; |
|
561 | - $langs=$this->savlangs; |
|
562 | - $db=$this->savdb; |
|
558 | + global $conf, $user, $langs, $db; |
|
559 | + $conf = $this->savconf; |
|
560 | + $user = $this->savuser; |
|
561 | + $langs = $this->savlangs; |
|
562 | + $db = $this->savdb; |
|
563 | 563 | |
564 | 564 | // To test a move of empty directory that should work |
565 | 565 | $dirsrcpath = $conf->admin->dir_temp.'/directory'; |
566 | 566 | $dirdestpath = $conf->admin->dir_temp.'/directory2'; |
567 | - $file=dirname(__FILE__).'/Example_import_company_1.csv'; |
|
567 | + $file = dirname(__FILE__).'/Example_import_company_1.csv'; |
|
568 | 568 | dol_mkdir($dirsrcpath); |
569 | 569 | dol_delete_dir_recursive($dirdestpath, 0, 1); |
570 | - $result=dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
570 | + $result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
571 | 571 | print __METHOD__." result=".$result."\n"; |
572 | 572 | $this->assertTrue($result, 'move of directory with empty directory'); |
573 | 573 | |
574 | 574 | // To test a move on existing directory with overwrite |
575 | 575 | dol_mkdir($dirsrcpath); |
576 | - $result=dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
576 | + $result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
577 | 577 | print __METHOD__." result=".$result."\n"; |
578 | 578 | $this->assertTrue($result, 'move of directory on existing directory with empty directory'); |
579 | 579 | |
580 | 580 | // To test a move on existing directory without overwrite |
581 | 581 | dol_mkdir($dirsrcpath); |
582 | - $result=dol_move_dir($dirsrcpath, $dirdestpath, 0, 1, 1); |
|
582 | + $result = dol_move_dir($dirsrcpath, $dirdestpath, 0, 1, 1); |
|
583 | 583 | print __METHOD__." result=".$result."\n"; |
584 | 584 | $this->assertFalse($result, 'move of directory on existing directory without overwrite'); |
585 | 585 | |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | dol_mkdir($dirsrcpath); |
588 | 588 | dol_delete_dir_recursive($dirdestpath, 0, 1); |
589 | 589 | dol_copy($file, $dirsrcpath.'/directory_file.csv'); |
590 | - $result=dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
590 | + $result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
591 | 591 | print __METHOD__." result=".$result."\n"; |
592 | 592 | $this->assertTrue($result, 'move of directory with file in directory'); |
593 | 593 | |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | dol_mkdir($dirsrcpath); |
596 | 596 | dol_delete_dir_recursive($dirdestpath, 0, 1); |
597 | 597 | dol_copy($file, $dirsrcpath.'/file.csv'); |
598 | - $result=dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
598 | + $result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
599 | 599 | print __METHOD__." result=".$result."\n"; |
600 | 600 | $this->assertTrue($result, 'move of directory with file without rename needed in directory'); |
601 | 601 | |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | dol_mkdir($dirsrcpath); |
604 | 604 | dol_delete_dir_recursive($dirdestpath, 0, 1); |
605 | 605 | dol_mkdir($dirsrcpath.'/directory'); |
606 | - $result=dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
606 | + $result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
607 | 607 | print __METHOD__." result=".$result."\n"; |
608 | 608 | $this->assertTrue($result, 'move of directory with file with rename needed in directory'); |
609 | 609 | |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | dol_mkdir($dirsrcpath); |
612 | 612 | dol_delete_dir_recursive($dirdestpath, 0, 1); |
613 | 613 | dol_mkdir($dirsrcpath.'/notorename'); |
614 | - $result=dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
614 | + $result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1); |
|
615 | 615 | print __METHOD__." result=".$result."\n"; |
616 | 616 | $this->assertTrue($result, 'move of directory with directory without rename needed in directory'); |
617 | 617 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * \remarks To run this script as CLI: phpunit filename.php |
25 | 25 | */ |
26 | 26 | |
27 | -global $conf,$user,$langs,$db; |
|
27 | +global $conf, $user, $langs, $db; |
|
28 | 28 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
29 | 29 | //require_once 'PHPUnit/Autoload.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | $user->fetch(1); |
38 | 38 | $user->getrights(); |
39 | 39 | } |
40 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
41 | -$conf->global->MAIN_UMASK='0666'; |
|
40 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
41 | +$conf->global->MAIN_UMASK = '0666'; |
|
42 | 42 | |
43 | 43 | |
44 | 44 | /** |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | parent::__construct($name); |
70 | 70 | |
71 | 71 | //$this->sharedFixture |
72 | - global $conf,$user,$langs,$db; |
|
73 | - $this->savconf=$conf; |
|
74 | - $this->savuser=$user; |
|
75 | - $this->savlangs=$langs; |
|
76 | - $this->savdb=$db; |
|
72 | + global $conf, $user, $langs, $db; |
|
73 | + $this->savconf = $conf; |
|
74 | + $this->savuser = $user; |
|
75 | + $this->savlangs = $langs; |
|
76 | + $this->savdb = $db; |
|
77 | 77 | |
78 | 78 | if (!isModEnabled('api')) { |
79 | 79 | print __METHOD__." module api must be enabled.\n"; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public static function setUpBeforeClass(): void |
94 | 94 | { |
95 | - global $conf,$user,$langs,$db; |
|
95 | + global $conf, $user, $langs, $db; |
|
96 | 96 | $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
97 | 97 | |
98 | 98 | print __METHOD__."\n"; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public static function tearDownAfterClass(): void |
107 | 107 | { |
108 | - global $conf,$user,$langs,$db; |
|
108 | + global $conf, $user, $langs, $db; |
|
109 | 109 | $db->rollback(); |
110 | 110 | |
111 | 111 | print __METHOD__."\n"; |
@@ -118,24 +118,24 @@ discard block |
||
118 | 118 | */ |
119 | 119 | protected function setUp(): void |
120 | 120 | { |
121 | - global $conf,$user,$langs,$db; |
|
122 | - $conf=$this->savconf; |
|
123 | - $user=$this->savuser; |
|
124 | - $langs=$this->savlangs; |
|
125 | - $db=$this->savdb; |
|
121 | + global $conf, $user, $langs, $db; |
|
122 | + $conf = $this->savconf; |
|
123 | + $user = $this->savuser; |
|
124 | + $langs = $this->savlangs; |
|
125 | + $db = $this->savdb; |
|
126 | 126 | |
127 | 127 | $this->api_url = DOL_MAIN_URL_ROOT.'/api/index.php'; |
128 | 128 | |
129 | - $login='admin'; |
|
130 | - $password='admin'; |
|
131 | - $url=$this->api_url.'/login?login='.$login.'&password='.$password; |
|
129 | + $login = 'admin'; |
|
130 | + $password = 'admin'; |
|
131 | + $url = $this->api_url.'/login?login='.$login.'&password='.$password; |
|
132 | 132 | // Call the API login method to save api_key for this test class. |
133 | 133 | // At first call, if token is not defined a random value is generated and returned. |
134 | - $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); |
|
134 | + $result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); |
|
135 | 135 | print __METHOD__." result = ".var_export($result, true)."\n"; |
136 | 136 | print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; |
137 | 137 | $this->assertEquals($result['curl_error_no'], ''); |
138 | - $object = json_decode($result['content'], true); // If success content is just an id, if not an array |
|
138 | + $object = json_decode($result['content'], true); // If success content is just an id, if not an array |
|
139 | 139 | |
140 | 140 | $this->assertNotNull($object, "Parsing of json result must not be null"); |
141 | 141 | $this->assertNotEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), 'Error'.(empty($object['error']['message']) ? '' : ' '.$object['error']['message'])); |
@@ -164,28 +164,28 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function testRestGetUser() |
166 | 166 | { |
167 | - global $conf,$user,$langs,$db; |
|
167 | + global $conf, $user, $langs, $db; |
|
168 | 168 | |
169 | 169 | $url = $this->api_url.'/users/123456789?api_key='.$this->api_key; |
170 | 170 | //$addheaders=array('Content-Type: application/json'); |
171 | 171 | |
172 | 172 | print __METHOD__." Request GET url=".$url."\n"; |
173 | - $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); |
|
173 | + $result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); |
|
174 | 174 | //print __METHOD__." result for get on unexisting user: ".var_export($result, true)."\n"; |
175 | 175 | print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; |
176 | 176 | $this->assertEquals($result['curl_error_no'], ''); |
177 | - $object=json_decode($result['content'], true); |
|
177 | + $object = json_decode($result['content'], true); |
|
178 | 178 | $this->assertNotNull($object, "Parsing of json result must not be null"); |
179 | 179 | $this->assertEquals(404, (empty($object['error']['code']) ? 0 : $object['error']['code']), 'Error code is not 404'); |
180 | 180 | |
181 | 181 | $url = $this->api_url.'/users/1?api_key='.$this->api_key; |
182 | 182 | |
183 | 183 | print __METHOD__." Request GET url=".$url."\n"; |
184 | - $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); |
|
184 | + $result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); |
|
185 | 185 | print __METHOD__." result for get on an existing user: ".var_export($result, true)."\n"; |
186 | 186 | print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; |
187 | 187 | $this->assertEquals($result['curl_error_no'], ''); |
188 | - $object=json_decode($result['content'], true); |
|
188 | + $object = json_decode($result['content'], true); |
|
189 | 189 | $this->assertNotNull($object, "Parsing of json result must not be null"); |
190 | 190 | $this->assertEquals(1, $object['statut']); |
191 | 191 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | { |
205 | 205 | // attempt to create without mandatory fields : |
206 | 206 | $url = $this->api_url.'/users?api_key='.$this->api_key; |
207 | - $addheaders=array('Content-Type: application/json'); |
|
207 | + $addheaders = array('Content-Type: application/json'); |
|
208 | 208 | |
209 | 209 | $bodyobj = array( |
210 | 210 | "lastname"=>"testRestUser", |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | $body = json_encode($bodyobj); |
215 | 215 | |
216 | 216 | print __METHOD__." Request POST url=".$url."\n"; |
217 | - $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); |
|
217 | + $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); |
|
218 | 218 | //print __METHOD__." Result for creating incomplete user".var_export($result, true)."\n"; |
219 | 219 | print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; |
220 | 220 | $this->assertEquals($result['curl_error_no'], ''); |
221 | - $object=json_decode($result['content'], true); |
|
221 | + $object = json_decode($result['content'], true); |
|
222 | 222 | $this->assertNotNull($object, "Parsing of json result must no be null"); |
223 | 223 | $this->assertEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), 'Error'.(empty($object['error']['message']) ? '' : ' '.$object['error']['message'])); |
224 | 224 | |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | ); |
233 | 233 | $body = json_encode($bodyobj); |
234 | 234 | print __METHOD__." Request POST url=".$url."\n"; |
235 | - $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); |
|
235 | + $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); |
|
236 | 236 | print __METHOD__." result code for creating non existing user = ".var_export($result, true)."\n"; |
237 | 237 | print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; |
238 | 238 | $this->assertEquals($result['curl_error_no'], ''); |
239 | - $object = json_decode($result['content'], true); // If success content is just an id, if not an array |
|
239 | + $object = json_decode($result['content'], true); // If success content is just an id, if not an array |
|
240 | 240 | |
241 | 241 | $this->assertNotNull($object, "Parsing of json result must no be null"); |
242 | 242 | $this->assertNotEquals(500, ((is_scalar($object) || empty($object['error']) || empty($object['error']['code'])) ? 0 : $object['error']['code']), 'Error'.(empty($object['error']['message']) ? '' : ' '.$object['error']['message'])); |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | |
245 | 245 | // attempt to create duplicated user |
246 | 246 | print __METHOD__." Request POST url=".$url."\n"; |
247 | - $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); |
|
247 | + $result = getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); |
|
248 | 248 | //print __METHOD__." Result for creating duplicate user".var_export($result, true)."\n"; |
249 | 249 | print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; |
250 | 250 | $this->assertEquals($result['curl_error_no'], ''); |
251 | - $object=json_decode($result['content'], true); |
|
251 | + $object = json_decode($result['content'], true); |
|
252 | 252 | $this->assertNotNull($object, "Parsing of json result must no be null"); |
253 | 253 | $this->assertEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), 'Error'.(empty($object['error']['message']) ? '' : ' '.$object['error']['message'])); |
254 | 254 | } |
@@ -24,42 +24,42 @@ discard block |
||
24 | 24 | * \remarks To run this script as CLI: phpunit filename.php |
25 | 25 | */ |
26 | 26 | |
27 | -global $conf,$user,$langs,$db; |
|
27 | +global $conf, $user, $langs, $db; |
|
28 | 28 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
29 | 29 | //require_once 'PHPUnit/Autoload.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
31 | 31 | require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; |
32 | 32 | require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; |
33 | 33 | |
34 | -if (! defined('NOREQUIREUSER')) { |
|
34 | +if (!defined('NOREQUIREUSER')) { |
|
35 | 35 | define('NOREQUIREUSER', '1'); |
36 | 36 | } |
37 | -if (! defined('NOREQUIREDB')) { |
|
37 | +if (!defined('NOREQUIREDB')) { |
|
38 | 38 | define('NOREQUIREDB', '1'); |
39 | 39 | } |
40 | -if (! defined('NOREQUIRESOC')) { |
|
40 | +if (!defined('NOREQUIRESOC')) { |
|
41 | 41 | define('NOREQUIRESOC', '1'); |
42 | 42 | } |
43 | -if (! defined('NOREQUIRETRAN')) { |
|
43 | +if (!defined('NOREQUIRETRAN')) { |
|
44 | 44 | define('NOREQUIRETRAN', '1'); |
45 | 45 | } |
46 | -if (! defined('NOCSRFCHECK')) { |
|
46 | +if (!defined('NOCSRFCHECK')) { |
|
47 | 47 | define('NOCSRFCHECK', '1'); |
48 | 48 | } |
49 | -if (! defined('NOTOKENRENEWAL')) { |
|
49 | +if (!defined('NOTOKENRENEWAL')) { |
|
50 | 50 | define('NOTOKENRENEWAL', '1'); |
51 | 51 | } |
52 | -if (! defined('NOREQUIREMENU')) { |
|
52 | +if (!defined('NOREQUIREMENU')) { |
|
53 | 53 | define('NOREQUIREMENU', '1'); // If there is no menu to show |
54 | 54 | } |
55 | -if (! defined('NOREQUIREHTML')) { |
|
55 | +if (!defined('NOREQUIREHTML')) { |
|
56 | 56 | define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php |
57 | 57 | } |
58 | -if (! defined('NOREQUIREAJAX')) { |
|
58 | +if (!defined('NOREQUIREAJAX')) { |
|
59 | 59 | define('NOREQUIREAJAX', '1'); |
60 | 60 | } |
61 | -if (! defined("NOLOGIN")) { |
|
62 | - define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
61 | +if (!defined("NOLOGIN")) { |
|
62 | + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | if (empty($user->id)) { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $user->fetch(1); |
68 | 68 | $user->getrights(); |
69 | 69 | } |
70 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
70 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
71 | 71 | |
72 | 72 | |
73 | 73 | /** |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | parent::__construct($name); |
97 | 97 | |
98 | 98 | //$this->sharedFixture |
99 | - global $conf,$user,$langs,$db; |
|
100 | - $this->savconf=$conf; |
|
101 | - $this->savuser=$user; |
|
102 | - $this->savlangs=$langs; |
|
103 | - $this->savdb=$db; |
|
99 | + global $conf, $user, $langs, $db; |
|
100 | + $this->savconf = $conf; |
|
101 | + $this->savuser = $user; |
|
102 | + $this->savlangs = $langs; |
|
103 | + $this->savdb = $db; |
|
104 | 104 | |
105 | 105 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
106 | 106 | //print " - db ".$db->db; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public static function setUpBeforeClass(): void |
116 | 116 | { |
117 | - global $conf,$user,$langs,$db; |
|
117 | + global $conf, $user, $langs, $db; |
|
118 | 118 | $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
119 | 119 | |
120 | 120 | print __METHOD__."\n"; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public static function tearDownAfterClass(): void |
129 | 129 | { |
130 | - global $conf,$user,$langs,$db; |
|
130 | + global $conf, $user, $langs, $db; |
|
131 | 131 | $db->rollback(); |
132 | 132 | |
133 | 133 | print __METHOD__."\n"; |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function setUp(): void |
142 | 142 | { |
143 | - global $conf,$user,$langs,$db; |
|
144 | - $conf=$this->savconf; |
|
145 | - $user=$this->savuser; |
|
146 | - $langs=$this->savlangs; |
|
147 | - $db=$this->savdb; |
|
143 | + global $conf, $user, $langs, $db; |
|
144 | + $conf = $this->savconf; |
|
145 | + $user = $this->savuser; |
|
146 | + $langs = $this->savlangs; |
|
147 | + $db = $this->savdb; |
|
148 | 148 | |
149 | 149 | print __METHOD__."\n"; |
150 | 150 | } |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function testPHP() |
168 | 168 | { |
169 | - global $conf,$user,$langs,$db; |
|
170 | - $conf=$this->savconf; |
|
171 | - $user=$this->savuser; |
|
172 | - $langs=$this->savlangs; |
|
173 | - $db=$this->savdb; |
|
169 | + global $conf, $user, $langs, $db; |
|
170 | + $conf = $this->savconf; |
|
171 | + $user = $this->savuser; |
|
172 | + $langs = $this->savlangs; |
|
173 | + $db = $this->savdb; |
|
174 | 174 | |
175 | 175 | include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
176 | 176 | $filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname', SORT_ASC, 0, 1, '', 1); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | } |
197 | 197 | |
198 | 198 | //print 'Check php file '.$file['relativename']."\n"; |
199 | - $filecontent=file_get_contents($file['fullname']); |
|
199 | + $filecontent = file_get_contents($file['fullname']); |
|
200 | 200 | |
201 | 201 | if (preg_match('/\.class\.php/', $file['relativename']) |
202 | 202 | || preg_match('/boxes\/box_/', $file['relativename']) |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | || preg_match('/modules\/(import|mailings|printing)\//', $file['relativename']) |
205 | 205 | || in_array($file['name'], array('modules_boxes.php', 'TraceableDB.php'))) { |
206 | 206 | // Check into Class files |
207 | - if (! in_array($file['name'], array( |
|
207 | + if (!in_array($file['name'], array( |
|
208 | 208 | 'api.class.php', |
209 | 209 | 'commonobject.class.php', |
210 | 210 | 'conf.class.php', |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | 'infobox.class.php' |
217 | 217 | ))) { |
218 | 218 | // Must not find $db-> |
219 | - $ok=true; |
|
220 | - $matches=array(); |
|
219 | + $ok = true; |
|
220 | + $matches = array(); |
|
221 | 221 | // Check string $db-> inside a class.php file (it should be $this->db-> into such classes) |
222 | 222 | preg_match_all('/'.preg_quote('$db->', '/').'/', $filecontent, $matches, PREG_SET_ORDER); |
223 | 223 | foreach ($matches as $key => $val) { |
224 | - $ok=false; |
|
224 | + $ok = false; |
|
225 | 225 | break; |
226 | 226 | } |
227 | 227 | //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | } |
231 | 231 | } else { |
232 | 232 | // Check into Include files |
233 | - if (! in_array($file['name'], array( |
|
233 | + if (!in_array($file['name'], array( |
|
234 | 234 | 'objectline_view.tpl.php', |
235 | 235 | 'extrafieldsinexport.inc.php', |
236 | 236 | 'extrafieldsinimport.inc.php', |
@@ -238,12 +238,12 @@ discard block |
||
238 | 238 | 'DoliStorage.php' |
239 | 239 | ))) { |
240 | 240 | // Must not found $this->db-> |
241 | - $ok=true; |
|
242 | - $matches=array(); |
|
241 | + $ok = true; |
|
242 | + $matches = array(); |
|
243 | 243 | // Check string $this->db-> into a non class.php file (it should be $db-> into such classes) |
244 | 244 | preg_match_all('/'.preg_quote('$this->db->', '/').'/', $filecontent, $matches, PREG_SET_ORDER); |
245 | 245 | foreach ($matches as $key => $val) { |
246 | - $ok=false; |
|
246 | + $ok = false; |
|
247 | 247 | break; |
248 | 248 | } |
249 | 249 | //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | // Check we don't miss top_httphead() into any ajax pages |
256 | 256 | if (preg_match('/ajax\//', $file['relativename'])) { |
257 | 257 | print "Analyze ajax page ".$file['relativename']."\n"; |
258 | - $ok=true; |
|
259 | - $matches=array(); |
|
258 | + $ok = true; |
|
259 | + $matches = array(); |
|
260 | 260 | preg_match_all('/top_httphead/', $filecontent, $matches, PREG_SET_ORDER); |
261 | 261 | if (count($matches) == 0) { |
262 | - $ok=false; |
|
262 | + $ok = false; |
|
263 | 263 | } |
264 | 264 | //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; |
265 | 265 | $this->assertTrue($ok, 'Did not find top_httphead into the ajax page '.$file['relativename']); |
@@ -268,14 +268,14 @@ discard block |
||
268 | 268 | |
269 | 269 | // Check if a var_dump has been forgotten |
270 | 270 | if (!preg_match('/test\/phpunit/', $file['fullname'])) { |
271 | - if (! in_array($file['name'], array('class.nusoap_base.php'))) { |
|
272 | - $ok=true; |
|
273 | - $matches=array(); |
|
271 | + if (!in_array($file['name'], array('class.nusoap_base.php'))) { |
|
272 | + $ok = true; |
|
273 | + $matches = array(); |
|
274 | 274 | preg_match_all('/(.)\s*var_dump\(/', $filecontent, $matches, PREG_SET_ORDER); |
275 | 275 | //var_dump($matches); |
276 | 276 | foreach ($matches as $key => $val) { |
277 | 277 | if ($val[1] != '/' && $val[1] != '*') { |
278 | - $ok=false; |
|
278 | + $ok = false; |
|
279 | 279 | break; |
280 | 280 | } |
281 | 281 | break; |
@@ -287,11 +287,11 @@ discard block |
||
287 | 287 | } |
288 | 288 | |
289 | 289 | // Check get_class followed by __METHOD__ |
290 | - $ok=true; |
|
291 | - $matches=array(); |
|
290 | + $ok = true; |
|
291 | + $matches = array(); |
|
292 | 292 | preg_match_all('/'.preg_quote('get_class($this)."::".__METHOD__', '/').'/', $filecontent, $matches, PREG_SET_ORDER); |
293 | 293 | foreach ($matches as $key => $val) { |
294 | - $ok=false; |
|
294 | + $ok = false; |
|
295 | 295 | break; |
296 | 296 | } |
297 | 297 | //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; |
@@ -299,12 +299,12 @@ discard block |
||
299 | 299 | //exit; |
300 | 300 | |
301 | 301 | // Check string $this->db->idate without quotes |
302 | - $ok=true; |
|
303 | - $matches=array(); |
|
302 | + $ok = true; |
|
303 | + $matches = array(); |
|
304 | 304 | preg_match_all('/(..)\s*\.\s*\$this->db->idate\(/', $filecontent, $matches, PREG_SET_ORDER); |
305 | 305 | foreach ($matches as $key => $val) { |
306 | 306 | if ($val[1] != '\'"' && $val[1] != '\'\'') { |
307 | - $ok=false; |
|
307 | + $ok = false; |
|
308 | 308 | break; |
309 | 309 | } |
310 | 310 | //if ($reg[0] != 'db') $ok=false; |
@@ -316,8 +316,8 @@ discard block |
||
316 | 316 | |
317 | 317 | // Check sql string DELETE|OR|AND|WHERE|INSERT ... yyy = ".$xxx |
318 | 318 | // with xxx that is not 'thi' (for $this->db->sanitize) and 'db-' (for $db->sanitize). It means we forget a ' if string, or an (int) if int, when forging sql request. |
319 | - $ok=true; |
|
320 | - $matches=array(); |
|
319 | + $ok = true; |
|
320 | + $matches = array(); |
|
321 | 321 | preg_match_all('/(DELETE|OR|AND|WHERE|INSERT)\s.*([^\s][^\s][^\s])\s*=\s*(\'|")\s*\.\s*\$(...)/', $filecontent, $matches, PREG_SET_ORDER); |
322 | 322 | foreach ($matches as $key => $val) { |
323 | 323 | if ($val[2] == 'ity' && $val[4] == 'con') { // exclude entity = ".$conf->entity |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | continue; |
331 | 331 | } |
332 | 332 | var_dump($matches); |
333 | - $ok=false; |
|
333 | + $ok = false; |
|
334 | 334 | break; |
335 | 335 | } |
336 | 336 | //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | //exit; |
339 | 339 | |
340 | 340 | // Check that forged sql string is using ' instead of " as string PHP quotes |
341 | - $ok=true; |
|
342 | - $matches=array(); |
|
341 | + $ok = true; |
|
342 | + $matches = array(); |
|
343 | 343 | preg_match_all('/\$sql \.= \'\s*VALUES.*\$/', $filecontent, $matches, PREG_SET_ORDER); |
344 | 344 | foreach ($matches as $key => $val) { |
345 | 345 | //if ($val[1] != '\'"' && $val[1] != '\'\'') { |
346 | 346 | var_dump($matches); |
347 | - $ok=false; |
|
347 | + $ok = false; |
|
348 | 348 | break; |
349 | 349 | //} |
350 | 350 | //if ($reg[0] != 'db') $ok=false; |
@@ -354,20 +354,20 @@ discard block |
||
354 | 354 | //exit; |
355 | 355 | |
356 | 356 | // Check that forged sql string is using ' instead of " as string PHP quotes |
357 | - $ok=true; |
|
358 | - $matches=array(); |
|
357 | + $ok = true; |
|
358 | + $matches = array(); |
|
359 | 359 | preg_match_all('/\$sql \.?= \'SELECT.*\$/', $filecontent, $matches, PREG_SET_ORDER); |
360 | 360 | foreach ($matches as $key => $val) { |
361 | 361 | var_dump($matches); |
362 | - $ok=false; |
|
362 | + $ok = false; |
|
363 | 363 | break; |
364 | 364 | } |
365 | 365 | $this->assertTrue($ok, 'Found a forged SQL string that mix on same line the use of \' for PHP string and PHP variables into file '.$file['relativename'].' Use " to forge PHP string like this: $sql = "SELECT ".$myvar...'); |
366 | 366 | |
367 | 367 | // Check sql string VALUES ... , ".$xxx |
368 | 368 | // with xxx that is not 'db-' (for $db->escape). It means we forget a ' if string, or an (int) if int, when forging sql request. |
369 | - $ok=true; |
|
370 | - $matches=array(); |
|
369 | + $ok = true; |
|
370 | + $matches = array(); |
|
371 | 371 | preg_match_all('/(VALUES).*,\s*"\s*\.\s*\$(...)/', $filecontent, $matches, PREG_SET_ORDER); |
372 | 372 | foreach ($matches as $key => $val) { |
373 | 373 | if ($val[1] == 'VALUES' && $val[2] == 'db-') { // exclude $db->escape( |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | continue; |
378 | 378 | } |
379 | 379 | var_dump($matches); |
380 | - $ok=false; |
|
380 | + $ok = false; |
|
381 | 381 | break; |
382 | 382 | } |
383 | 383 | //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; |
@@ -387,12 +387,12 @@ discard block |
||
387 | 387 | // Check '".$xxx non escaped |
388 | 388 | |
389 | 389 | // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. |
390 | - $ok=true; |
|
391 | - $matches=array(); |
|
390 | + $ok = true; |
|
391 | + $matches = array(); |
|
392 | 392 | preg_match_all('/=\s*\'"\s*\.\s*\$this->(....)/', $filecontent, $matches, PREG_SET_ORDER); |
393 | 393 | foreach ($matches as $key => $val) { |
394 | 394 | if ($val[1] != 'db->' && $val[1] != 'esca') { |
395 | - $ok=false; |
|
395 | + $ok = false; |
|
396 | 396 | break; |
397 | 397 | } |
398 | 398 | } |
@@ -400,12 +400,12 @@ discard block |
||
400 | 400 | $this->assertTrue($ok, 'Found non escaped string in building of a sql request (case 1) in '.$file['relativename'].' - Bad.'); |
401 | 401 | |
402 | 402 | // Check string sql|set|WHERE|...'".$yyy->xxx with xxx that is not 'escape', 'idate', .... It means we forget a db->escape when forging sql request. |
403 | - $ok=true; |
|
404 | - $matches=array(); |
|
403 | + $ok = true; |
|
404 | + $matches = array(); |
|
405 | 405 | preg_match_all('/(sql|SET|WHERE|INSERT|VALUES|LIKE).+\s*\'"\s*\.\s*\$(.......)/', $filecontent, $matches, PREG_SET_ORDER); |
406 | 406 | foreach ($matches as $key => $val) { |
407 | - if (! in_array($val[2], array('this->d', 'this->e', 'db->esc', 'dbs->es', 'dbs->id', 'mydb->e', 'dbsessi', 'db->ida', 'escaped', 'exclude', 'include'))) { |
|
408 | - $ok=false; // This will generate error |
|
407 | + if (!in_array($val[2], array('this->d', 'this->e', 'db->esc', 'dbs->es', 'dbs->id', 'mydb->e', 'dbsessi', 'db->ida', 'escaped', 'exclude', 'include'))) { |
|
408 | + $ok = false; // This will generate error |
|
409 | 409 | break; |
410 | 410 | } |
411 | 411 | //if ($reg[0] != 'db') $ok=false; |
@@ -415,12 +415,12 @@ discard block |
||
415 | 415 | //exit; |
416 | 416 | |
417 | 417 | // Check string sql|set...'.$yyy->xxx with xxx that is not 'escape', 'idate', .... It means we forget a db->escape when forging sql request. |
418 | - $ok=true; |
|
419 | - $matches=array(); |
|
418 | + $ok = true; |
|
419 | + $matches = array(); |
|
420 | 420 | preg_match_all('/(\$sql|SET\s|WHERE\s|INSERT\s|VALUES\s|VALUES\().+\s*\'\s*\.\s*\$(.........)/', $filecontent, $matches, PREG_SET_ORDER); |
421 | 421 | foreach ($matches as $key => $val) { |
422 | - if (! in_array($val[2], array('this->db-', 'db->prefi', 'db->sanit', 'dbs->pref', 'dbs->sani', 'conf->ent', 'key : \'\')', 'key])."\')', 'excludefi', 'regexstri', ''))) { |
|
423 | - $ok=false; |
|
422 | + if (!in_array($val[2], array('this->db-', 'db->prefi', 'db->sanit', 'dbs->pref', 'dbs->sani', 'conf->ent', 'key : \'\')', 'key])."\')', 'excludefi', 'regexstri', ''))) { |
|
423 | + $ok = false; |
|
424 | 424 | var_dump($matches); |
425 | 425 | break; |
426 | 426 | } |
@@ -433,13 +433,13 @@ discard block |
||
433 | 433 | // Checks with IN |
434 | 434 | |
435 | 435 | // Check string ' IN (".xxx' or ' IN (\'.xxx' with xxx that is not '$this->db->sanitize' and not '$db->sanitize'. It means we forget a db->sanitize when forging sql request. |
436 | - $ok=true; |
|
437 | - $matches=array(); |
|
436 | + $ok = true; |
|
437 | + $matches = array(); |
|
438 | 438 | preg_match_all('/\s+IN\s*\([\'"]\s*\.\s*(.........)/i', $filecontent, $matches, PREG_SET_ORDER); |
439 | 439 | foreach ($matches as $key => $val) { |
440 | 440 | //var_dump($val); |
441 | 441 | if (!in_array($val[1], array('$db->sani', '$this->db', 'getEntity', 'WON\',\'L', 'self::STA', 'Commande:', 'CommandeF', 'Entrepot:', 'Facture::', 'FactureFo', 'ExpenseRe', 'Societe::', 'Ticket::S'))) { |
442 | - $ok=false; |
|
442 | + $ok = false; |
|
443 | 443 | break; |
444 | 444 | } |
445 | 445 | //if ($reg[0] != 'db') $ok=false; |
@@ -449,13 +449,13 @@ discard block |
||
449 | 449 | //exit; |
450 | 450 | |
451 | 451 | // Check string ' IN (\'".xxx' with xxx that is not '$this->db->sanitize' and not '$db->sanitize'. It means we forget a db->sanitize when forging sql request. |
452 | - $ok=true; |
|
453 | - $matches=array(); |
|
452 | + $ok = true; |
|
453 | + $matches = array(); |
|
454 | 454 | preg_match_all('/\s+IN\s*\(\'"\s*\.\s*(.........)/i', $filecontent, $matches, PREG_SET_ORDER); |
455 | 455 | foreach ($matches as $key => $val) { |
456 | 456 | //var_dump($val); |
457 | 457 | if (!in_array($val[1], array('$db->sani', '$this->db', 'getEntity', 'WON\',\'L', 'self::STA', 'Commande:', 'CommandeF', 'Entrepot:', 'Facture::', 'FactureFo', 'ExpenseRe', 'Societe::', 'Ticket::S'))) { |
458 | - $ok=false; |
|
458 | + $ok = false; |
|
459 | 459 | break; |
460 | 460 | } |
461 | 461 | //if ($reg[0] != 'db') $ok=false; |
@@ -465,12 +465,12 @@ discard block |
||
465 | 465 | //exit; |
466 | 466 | |
467 | 467 | // Test that output of $_SERVER\[\'QUERY_STRING\'\] is escaped. |
468 | - $ok=true; |
|
469 | - $matches=array(); |
|
468 | + $ok = true; |
|
469 | + $matches = array(); |
|
470 | 470 | preg_match_all('/(..............)\$_SERVER\[\'QUERY_STRING\'\]/', $filecontent, $matches, PREG_SET_ORDER); |
471 | 471 | foreach ($matches as $key => $val) { |
472 | 472 | if ($val[1] != 'scape_htmltag(' && $val[1] != 'ing_nohtmltag(' && $val[1] != 'dol_escape_js(') { |
473 | - $ok=false; |
|
473 | + $ok = false; |
|
474 | 474 | break; |
475 | 475 | } |
476 | 476 | } |
@@ -478,8 +478,8 @@ discard block |
||
478 | 478 | |
479 | 479 | |
480 | 480 | // Check GETPOST(... 'none'); |
481 | - $ok=true; |
|
482 | - $matches=array(); |
|
481 | + $ok = true; |
|
482 | + $matches = array(); |
|
483 | 483 | preg_match_all('/GETPOST\s*\(([^\)]+),\s*["\']none["\']/i', $filecontent, $matches, PREG_SET_ORDER); |
484 | 484 | foreach ($matches as $key => $val) { |
485 | 485 | //var_dump($val); |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | '"mysqldump"', '"postgresqldump"', |
489 | 489 | "'db_pass_root'", "'db_pass'", '"pass"', '"pass1"', '"pass2"', '"password"', "'password'", |
490 | 490 | '"MAIN_MAIL_SMTPS_PW"', '"MAIN_MAIL_SMTPS_PW_EMAILING"', '"MAIN_MAIL_SMTPS_PW_TICKET"'))) { |
491 | - $ok=false; |
|
491 | + $ok = false; |
|
492 | 492 | break; |
493 | 493 | } |
494 | 494 | //if ($reg[0] != 'db') $ok=false; |
@@ -499,24 +499,24 @@ discard block |
||
499 | 499 | |
500 | 500 | |
501 | 501 | // Test that first param of print_liste_field_titre is a translation key and not the translated value |
502 | - $ok=true; |
|
503 | - $matches=array(); |
|
502 | + $ok = true; |
|
503 | + $matches = array(); |
|
504 | 504 | // Check string ='print_liste_field_titre\(\$langs'. |
505 | 505 | preg_match_all('/print_liste_field_titre\(\$langs/', $filecontent, $matches, PREG_SET_ORDER); |
506 | 506 | foreach ($matches as $key => $val) { |
507 | - $ok=false; |
|
507 | + $ok = false; |
|
508 | 508 | break; |
509 | 509 | } |
510 | 510 | $this->assertTrue($ok, 'Found a use of print_liste_field_titre with first parameter that is a translated value instead of just the translation key in file '.$file['relativename'].'. Bad.'); |
511 | 511 | |
512 | 512 | |
513 | 513 | // Test we don't have <br /> |
514 | - $ok=true; |
|
515 | - $matches=array(); |
|
514 | + $ok = true; |
|
515 | + $matches = array(); |
|
516 | 516 | preg_match_all('/<br\s+\/>/', $filecontent, $matches, PREG_SET_ORDER); |
517 | 517 | foreach ($matches as $key => $val) { |
518 | 518 | if ($file['name'] != 'functions.lib.php') { |
519 | - $ok=false; |
|
519 | + $ok = false; |
|
520 | 520 | break; |
521 | 521 | } |
522 | 522 | } |
@@ -524,12 +524,12 @@ discard block |
||
524 | 524 | |
525 | 525 | |
526 | 526 | // Test we don't have name="token" value="'.$_SESSION['newtoken'], we must use name="token" value="'.newToken() instead. |
527 | - $ok=true; |
|
528 | - $matches=array(); |
|
527 | + $ok = true; |
|
528 | + $matches = array(); |
|
529 | 529 | preg_match_all('/name="token" value="\'\s*\.\s*\$_SESSION/', $filecontent, $matches, PREG_SET_ORDER); |
530 | 530 | foreach ($matches as $key => $val) { |
531 | 531 | if ($file['name'] != 'excludefile.php') { |
532 | - $ok=false; |
|
532 | + $ok = false; |
|
533 | 533 | break; |
534 | 534 | } |
535 | 535 | } |
@@ -537,12 +537,12 @@ discard block |
||
537 | 537 | |
538 | 538 | |
539 | 539 | // Test we don't have preg_grep with a param without preg_quote |
540 | - $ok=true; |
|
541 | - $matches=array(); |
|
540 | + $ok = true; |
|
541 | + $matches = array(); |
|
542 | 542 | preg_match_all('/preg_grep\(.*\$/', $filecontent, $matches, PREG_SET_ORDER); |
543 | 543 | foreach ($matches as $key => $val) { |
544 | 544 | if (strpos($val[0], 'preg_quote') === false) { |
545 | - $ok=false; |
|
545 | + $ok = false; |
|
546 | 546 | break; |
547 | 547 | } |
548 | 548 | } |
@@ -550,62 +550,62 @@ discard block |
||
550 | 550 | |
551 | 551 | |
552 | 552 | // Test we don't have "if ($resql >" |
553 | - $ok=true; |
|
554 | - $matches=array(); |
|
553 | + $ok = true; |
|
554 | + $matches = array(); |
|
555 | 555 | preg_match_all('/if \(\$resql >/', $filecontent, $matches, PREG_SET_ORDER); |
556 | 556 | foreach ($matches as $key => $val) { |
557 | - $ok=false; |
|
557 | + $ok = false; |
|
558 | 558 | break; |
559 | 559 | } |
560 | 560 | $this->assertTrue($ok, 'Found a if $resql with a > operator (when $resql is a boolean or resource) in file '.$file['relativename'].'. Please remove the > ... part.'); |
561 | 561 | |
562 | 562 | // Test we don't have empty($user->hasRight |
563 | - $ok=true; |
|
564 | - $matches=array(); |
|
563 | + $ok = true; |
|
564 | + $matches = array(); |
|
565 | 565 | preg_match_all('/empty\(\$user->hasRight/', $filecontent, $matches, PREG_SET_ORDER); |
566 | 566 | foreach ($matches as $key => $val) { |
567 | - $ok=false; |
|
567 | + $ok = false; |
|
568 | 568 | break; |
569 | 569 | } |
570 | 570 | $this->assertTrue($ok, 'Found code empty($user->hasRight in file '.$file['relativename'].'. empty() must not be used on a var not on a function.'); |
571 | 571 | |
572 | 572 | // Test we don't have empty(DolibarrApiAccess::$user->hasRight |
573 | - $ok=true; |
|
574 | - $matches=array(); |
|
573 | + $ok = true; |
|
574 | + $matches = array(); |
|
575 | 575 | preg_match_all('/empty\(DolibarrApiAccess::\$user->hasRight/', $filecontent, $matches, PREG_SET_ORDER); |
576 | 576 | foreach ($matches as $key => $val) { |
577 | - $ok=false; |
|
577 | + $ok = false; |
|
578 | 578 | break; |
579 | 579 | } |
580 | 580 | $this->assertTrue($ok, 'Found code empty(DolibarrApiAccess::$user->hasRight in file '.$file['relativename'].'. empty() must not be used on a var not on a function.'); |
581 | 581 | |
582 | 582 | // Test we don't have empty($user->hasRight |
583 | - $ok=true; |
|
584 | - $matches=array(); |
|
583 | + $ok = true; |
|
584 | + $matches = array(); |
|
585 | 585 | preg_match_all('/empty\(getDolGlobal/', $filecontent, $matches, PREG_SET_ORDER); |
586 | 586 | foreach ($matches as $key => $val) { |
587 | - $ok=false; |
|
587 | + $ok = false; |
|
588 | 588 | break; |
589 | 589 | } |
590 | 590 | $this->assertTrue($ok, 'Found code empty(getDolGlobal... in file '.$file['relativename'].'. empty() must be used on a var not on a function.'); |
591 | 591 | |
592 | 592 | // Test we don't have @var array( |
593 | - $ok=true; |
|
594 | - $matches=array(); |
|
593 | + $ok = true; |
|
594 | + $matches = array(); |
|
595 | 595 | preg_match_all('/@var\s+array\(/', $filecontent, $matches, PREG_SET_ORDER); |
596 | 596 | foreach ($matches as $key => $val) { |
597 | - $ok=false; |
|
597 | + $ok = false; |
|
598 | 598 | break; |
599 | 599 | } |
600 | 600 | $this->assertTrue($ok, 'Found a declaration @var array() instead of @var array in file '.$file['relativename'].'.'); |
601 | 601 | |
602 | 602 | |
603 | 603 | // Test we don't have CURDATE() |
604 | - $ok=true; |
|
605 | - $matches=array(); |
|
604 | + $ok = true; |
|
605 | + $matches = array(); |
|
606 | 606 | preg_match_all('/CURDATE\(\)/', $filecontent, $matches, PREG_SET_ORDER); |
607 | 607 | foreach ($matches as $key => $val) { |
608 | - $ok=false; |
|
608 | + $ok = false; |
|
609 | 609 | break; |
610 | 610 | } |
611 | 611 | $this->assertTrue($ok, 'Found a CURDATE\(\) into code. Do not use this SQL method in file '.$file['relativename'].'. You must use the PHP function dol_now() instead.'); |
@@ -24,41 +24,41 @@ discard block |
||
24 | 24 | * \remarks To run this script as CLI: phpunit filename.php |
25 | 25 | */ |
26 | 26 | |
27 | -global $conf,$user,$langs,$db; |
|
27 | +global $conf, $user, $langs, $db; |
|
28 | 28 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
29 | 29 | //require_once 'PHPUnit/Autoload.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
31 | 31 | require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php'; |
32 | 32 | |
33 | -if (! defined('NOREQUIREUSER')) { |
|
33 | +if (!defined('NOREQUIREUSER')) { |
|
34 | 34 | define('NOREQUIREUSER', '1'); |
35 | 35 | } |
36 | -if (! defined('NOREQUIREDB')) { |
|
36 | +if (!defined('NOREQUIREDB')) { |
|
37 | 37 | define('NOREQUIREDB', '1'); |
38 | 38 | } |
39 | -if (! defined('NOREQUIRESOC')) { |
|
39 | +if (!defined('NOREQUIRESOC')) { |
|
40 | 40 | define('NOREQUIRESOC', '1'); |
41 | 41 | } |
42 | -if (! defined('NOREQUIRETRAN')) { |
|
42 | +if (!defined('NOREQUIRETRAN')) { |
|
43 | 43 | define('NOREQUIRETRAN', '1'); |
44 | 44 | } |
45 | -if (! defined('NOCSRFCHECK')) { |
|
45 | +if (!defined('NOCSRFCHECK')) { |
|
46 | 46 | define('NOCSRFCHECK', '1'); |
47 | 47 | } |
48 | -if (! defined('NOTOKENRENEWAL')) { |
|
48 | +if (!defined('NOTOKENRENEWAL')) { |
|
49 | 49 | define('NOTOKENRENEWAL', '1'); |
50 | 50 | } |
51 | -if (! defined('NOREQUIREMENU')) { |
|
51 | +if (!defined('NOREQUIREMENU')) { |
|
52 | 52 | define('NOREQUIREMENU', '1'); // If there is no menu to show |
53 | 53 | } |
54 | -if (! defined('NOREQUIREHTML')) { |
|
54 | +if (!defined('NOREQUIREHTML')) { |
|
55 | 55 | define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php |
56 | 56 | } |
57 | -if (! defined('NOREQUIREAJAX')) { |
|
57 | +if (!defined('NOREQUIREAJAX')) { |
|
58 | 58 | define('NOREQUIREAJAX', '1'); |
59 | 59 | } |
60 | -if (! defined("NOLOGIN")) { |
|
61 | - define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
60 | +if (!defined("NOLOGIN")) { |
|
61 | + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | if (empty($user->id)) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $user->fetch(1); |
67 | 67 | $user->getrights(); |
68 | 68 | } |
69 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
69 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
70 | 70 | |
71 | 71 | |
72 | 72 | /** |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | parent::__construct($name); |
96 | 96 | |
97 | 97 | //$this->sharedFixture |
98 | - global $conf,$user,$langs,$db; |
|
99 | - $this->savconf=$conf; |
|
100 | - $this->savuser=$user; |
|
101 | - $this->savlangs=$langs; |
|
102 | - $this->savdb=$db; |
|
98 | + global $conf, $user, $langs, $db; |
|
99 | + $this->savconf = $conf; |
|
100 | + $this->savuser = $user; |
|
101 | + $this->savlangs = $langs; |
|
102 | + $this->savdb = $db; |
|
103 | 103 | |
104 | 104 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
105 | 105 | //print " - db ".$db->db; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public static function setUpBeforeClass(): void |
115 | 115 | { |
116 | - global $conf,$user,$langs,$db; |
|
116 | + global $conf, $user, $langs, $db; |
|
117 | 117 | $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
118 | 118 | |
119 | 119 | print __METHOD__."\n"; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function tearDownAfterClass(): void |
128 | 128 | { |
129 | - global $conf,$user,$langs,$db; |
|
129 | + global $conf, $user, $langs, $db; |
|
130 | 130 | $db->rollback(); |
131 | 131 | |
132 | 132 | print __METHOD__."\n"; |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function setUp(): void |
141 | 141 | { |
142 | - global $conf,$user,$langs,$db; |
|
143 | - $conf=$this->savconf; |
|
144 | - $user=$this->savuser; |
|
145 | - $langs=$this->savlangs; |
|
146 | - $db=$this->savdb; |
|
142 | + global $conf, $user, $langs, $db; |
|
143 | + $conf = $this->savconf; |
|
144 | + $user = $this->savuser; |
|
145 | + $langs = $this->savlangs; |
|
146 | + $db = $this->savdb; |
|
147 | 147 | |
148 | 148 | print __METHOD__."\n"; |
149 | 149 | } |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function testJqueryOnce() |
170 | 170 | { |
171 | - global $conf,$user,$langs,$db; |
|
171 | + global $conf, $user, $langs, $db; |
|
172 | 172 | |
173 | 173 | // Scan dir to guarantee we don't have library jquery twice |
174 | - $foundfiles=dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.js', array('ckeditor')); |
|
174 | + $foundfiles = dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.js', array('ckeditor')); |
|
175 | 175 | print __METHOD__." count(founddirs)=".count($foundfiles)."\n"; |
176 | 176 | $this->assertEquals(1, count($foundfiles), 'We found jquery lib (jquery.js) twice'); |
177 | 177 | |
178 | 178 | // Scan dir to guarantee we don't have library jquery twice |
179 | - $foundfiles=dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.min\.js', array('ckeditor')); |
|
179 | + $foundfiles = dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.min\.js', array('ckeditor')); |
|
180 | 180 | print __METHOD__." count(founddirs)=".count($foundfiles)."\n"; |
181 | 181 | $this->assertEquals(1, count($foundfiles), 'We found jquery lib (jquery.min.js) twice '.(empty($foundfiles[0]) ? '' : $foundfiles[0]['fullname']).' '.(empty($foundfiles[1]) ? '' : $foundfiles[1]['fullname'])); |
182 | 182 | } |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function testRepository() |
191 | 191 | { |
192 | - global $conf,$user,$langs,$db; |
|
193 | - $conf=$this->savconf; |
|
194 | - $user=$this->savuser; |
|
195 | - $langs=$this->savlangs; |
|
196 | - $db=$this->savdb; |
|
192 | + global $conf, $user, $langs, $db; |
|
193 | + $conf = $this->savconf; |
|
194 | + $user = $this->savuser; |
|
195 | + $langs = $this->savlangs; |
|
196 | + $db = $this->savdb; |
|
197 | 197 | |
198 | 198 | include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
199 | 199 | $filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'directories', 1, '', array('\/custom\/'), 'fullname', SORT_ASC, 0, 1, '', 1); |
@@ -24,42 +24,42 @@ discard block |
||
24 | 24 | * \remarks To run this script as CLI: phpunit filename.php |
25 | 25 | */ |
26 | 26 | |
27 | -global $conf,$user,$langs,$db; |
|
27 | +global $conf, $user, $langs, $db; |
|
28 | 28 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
29 | 29 | //require_once 'PHPUnit/Autoload.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
31 | 31 | require_once dirname(__FILE__).'/../../htdocs/exports/class/export.class.php'; |
32 | 32 | require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php'; |
33 | 33 | |
34 | -if (! defined('NOREQUIREUSER')) { |
|
34 | +if (!defined('NOREQUIREUSER')) { |
|
35 | 35 | define('NOREQUIREUSER', '1'); |
36 | 36 | } |
37 | -if (! defined('NOREQUIREDB')) { |
|
37 | +if (!defined('NOREQUIREDB')) { |
|
38 | 38 | define('NOREQUIREDB', '1'); |
39 | 39 | } |
40 | -if (! defined('NOREQUIRESOC')) { |
|
40 | +if (!defined('NOREQUIRESOC')) { |
|
41 | 41 | define('NOREQUIRESOC', '1'); |
42 | 42 | } |
43 | -if (! defined('NOREQUIRETRAN')) { |
|
43 | +if (!defined('NOREQUIRETRAN')) { |
|
44 | 44 | define('NOREQUIRETRAN', '1'); |
45 | 45 | } |
46 | -if (! defined('NOCSRFCHECK')) { |
|
46 | +if (!defined('NOCSRFCHECK')) { |
|
47 | 47 | define('NOCSRFCHECK', '1'); |
48 | 48 | } |
49 | -if (! defined('NOTOKENRENEWAL')) { |
|
49 | +if (!defined('NOTOKENRENEWAL')) { |
|
50 | 50 | define('NOTOKENRENEWAL', '1'); |
51 | 51 | } |
52 | -if (! defined('NOREQUIREMENU')) { |
|
52 | +if (!defined('NOREQUIREMENU')) { |
|
53 | 53 | define('NOREQUIREMENU', '1'); // If there is no menu to show |
54 | 54 | } |
55 | -if (! defined('NOREQUIREHTML')) { |
|
55 | +if (!defined('NOREQUIREHTML')) { |
|
56 | 56 | define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php |
57 | 57 | } |
58 | -if (! defined('NOREQUIREAJAX')) { |
|
58 | +if (!defined('NOREQUIREAJAX')) { |
|
59 | 59 | define('NOREQUIREAJAX', '1'); |
60 | 60 | } |
61 | -if (! defined("NOLOGIN")) { |
|
62 | - define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
61 | +if (!defined("NOLOGIN")) { |
|
62 | + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | parent::__construct($name); |
90 | 90 | |
91 | 91 | //$this->sharedFixture |
92 | - global $conf,$user,$langs,$db; |
|
93 | - $this->savconf=$conf; |
|
94 | - $this->savuser=$user; |
|
95 | - $this->savlangs=$langs; |
|
96 | - $this->savdb=$db; |
|
92 | + global $conf, $user, $langs, $db; |
|
93 | + $this->savconf = $conf; |
|
94 | + $this->savuser = $user; |
|
95 | + $this->savlangs = $langs; |
|
96 | + $this->savdb = $db; |
|
97 | 97 | |
98 | 98 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
99 | 99 | //print " - db ".$db->db; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public static function setUpBeforeClass(): void |
109 | 109 | { |
110 | - global $conf,$user,$langs,$db; |
|
110 | + global $conf, $user, $langs, $db; |
|
111 | 111 | //$db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
112 | 112 | |
113 | 113 | print __METHOD__."\n"; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public static function tearDownAfterClass(): void |
122 | 122 | { |
123 | - global $conf,$user,$langs,$db; |
|
123 | + global $conf, $user, $langs, $db; |
|
124 | 124 | //$db->rollback(); |
125 | 125 | |
126 | 126 | print __METHOD__."\n"; |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function setUp(): void |
135 | 135 | { |
136 | - global $conf,$user,$langs,$db; |
|
137 | - $conf=$this->savconf; |
|
138 | - $user=$this->savuser; |
|
139 | - $langs=$this->savlangs; |
|
140 | - $db=$this->savdb; |
|
136 | + global $conf, $user, $langs, $db; |
|
137 | + $conf = $this->savconf; |
|
138 | + $user = $this->savuser; |
|
139 | + $langs = $this->savlangs; |
|
140 | + $db = $this->savdb; |
|
141 | 141 | |
142 | 142 | print __METHOD__."\n"; |
143 | 143 | } |
@@ -158,15 +158,15 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function testExportCsvUtf() |
160 | 160 | { |
161 | - global $conf,$user,$langs,$db; |
|
161 | + global $conf, $user, $langs, $db; |
|
162 | 162 | |
163 | - $model='csvutf8'; |
|
163 | + $model = 'csvutf8'; |
|
164 | 164 | |
165 | 165 | $conf->global->EXPORT_CSV_SEPARATOR_TO_USE = ','; |
166 | - print 'EXPORT_CSV_SEPARATOR_TO_USE = ' . getDolGlobalString('EXPORT_CSV_SEPARATOR_TO_USE'); |
|
166 | + print 'EXPORT_CSV_SEPARATOR_TO_USE = '.getDolGlobalString('EXPORT_CSV_SEPARATOR_TO_USE'); |
|
167 | 167 | |
168 | 168 | // Creation of class to export using model ExportXXX |
169 | - $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; |
|
169 | + $dir = DOL_DOCUMENT_ROOT."/core/modules/export/"; |
|
170 | 170 | $file = "export_".$model.".modules.php"; |
171 | 171 | $classname = "Export".$model; |
172 | 172 | require_once $dir.$file; |
@@ -175,31 +175,31 @@ discard block |
||
175 | 175 | // First test without option USE_STRICT_CSV_RULES |
176 | 176 | unset($conf->global->USE_STRICT_CSV_RULES); |
177 | 177 | |
178 | - $valtotest='A simple string'; |
|
178 | + $valtotest = 'A simple string'; |
|
179 | 179 | print __METHOD__." valtotest=".$valtotest."\n"; |
180 | 180 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
181 | 181 | print __METHOD__." result=".$result."\n"; |
182 | 182 | $this->assertEquals($result, 'A simple string'); |
183 | 183 | |
184 | - $valtotest='A string with , and ; inside'; |
|
184 | + $valtotest = 'A string with , and ; inside'; |
|
185 | 185 | print __METHOD__." valtotest=".$valtotest."\n"; |
186 | 186 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
187 | 187 | print __METHOD__." result=".$result."\n"; |
188 | 188 | $this->assertEquals($result, '"A string with , and ; inside"', 'Error in csvClean for '.$file); |
189 | 189 | |
190 | - $valtotest='A string with " inside'; |
|
190 | + $valtotest = 'A string with " inside'; |
|
191 | 191 | print __METHOD__." valtotest=".$valtotest."\n"; |
192 | 192 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
193 | 193 | print __METHOD__." result=".$result."\n"; |
194 | 194 | $this->assertEquals($result, '"A string with "" inside"'); |
195 | 195 | |
196 | - $valtotest='A string with " inside and '."\r\n".' carriage returns'; |
|
196 | + $valtotest = 'A string with " inside and '."\r\n".' carriage returns'; |
|
197 | 197 | print __METHOD__." valtotest=".$valtotest."\n"; |
198 | 198 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
199 | 199 | print __METHOD__." result=".$result."\n"; |
200 | 200 | $this->assertEquals($result, '"A string with "" inside and \n carriage returns"'); |
201 | 201 | |
202 | - $valtotest='A string with <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n"; |
|
202 | + $valtotest = 'A string with <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n"; |
|
203 | 203 | print __METHOD__." valtotest=".$valtotest."\n"; |
204 | 204 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
205 | 205 | print __METHOD__." result=".$result."\n"; |
@@ -208,31 +208,31 @@ discard block |
||
208 | 208 | // Same tests with strict mode |
209 | 209 | $conf->global->USE_STRICT_CSV_RULES = 1; |
210 | 210 | |
211 | - $valtotest='A simple string'; |
|
211 | + $valtotest = 'A simple string'; |
|
212 | 212 | print __METHOD__." valtotest=".$valtotest."\n"; |
213 | 213 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
214 | 214 | print __METHOD__." result=".$result."\n"; |
215 | 215 | $this->assertEquals($result, 'A simple string'); |
216 | 216 | |
217 | - $valtotest='A string with , and ; inside'; |
|
217 | + $valtotest = 'A string with , and ; inside'; |
|
218 | 218 | print __METHOD__." valtotest=".$valtotest."\n"; |
219 | 219 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
220 | 220 | print __METHOD__." result=".$result."\n"; |
221 | 221 | $this->assertEquals($result, '"A string with , and ; inside"'); |
222 | 222 | |
223 | - $valtotest='A string with " inside'; |
|
223 | + $valtotest = 'A string with " inside'; |
|
224 | 224 | print __METHOD__." valtotest=".$valtotest."\n"; |
225 | 225 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
226 | 226 | print __METHOD__." result=".$result."\n"; |
227 | 227 | $this->assertEquals($result, '"A string with "" inside"'); |
228 | 228 | |
229 | - $valtotest='A string with " inside and '."\r\n".' carriage returns'; |
|
229 | + $valtotest = 'A string with " inside and '."\r\n".' carriage returns'; |
|
230 | 230 | print __METHOD__." valtotest=".$valtotest."\n"; |
231 | 231 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
232 | 232 | print __METHOD__." result=".$result."\n"; |
233 | 233 | $this->assertEquals($result, "\"A string with \"\" inside and \r\n carriage returns\""); |
234 | 234 | |
235 | - $valtotest='A string with <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n"; |
|
235 | + $valtotest = 'A string with <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n"; |
|
236 | 236 | print __METHOD__." valtotest=".$valtotest."\n"; |
237 | 237 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
238 | 238 | print __METHOD__." result=".$result."\n"; |
@@ -247,15 +247,15 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function testExportOther() |
249 | 249 | { |
250 | - global $conf,$user,$langs,$db; |
|
250 | + global $conf, $user, $langs, $db; |
|
251 | 251 | |
252 | - $model='csviso'; |
|
252 | + $model = 'csviso'; |
|
253 | 253 | |
254 | 254 | $conf->global->EXPORT_CSV_SEPARATOR_TO_USE = ','; |
255 | - print 'EXPORT_CSV_SEPARATOR_TO_USE = ' . getDolGlobalString('EXPORT_CSV_SEPARATOR_TO_USE'); |
|
255 | + print 'EXPORT_CSV_SEPARATOR_TO_USE = '.getDolGlobalString('EXPORT_CSV_SEPARATOR_TO_USE'); |
|
256 | 256 | |
257 | 257 | // Creation of class to export using model ExportXXX |
258 | - $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; |
|
258 | + $dir = DOL_DOCUMENT_ROOT."/core/modules/export/"; |
|
259 | 259 | $file = "export_".$model.".modules.php"; |
260 | 260 | $classname = "Export".$model; |
261 | 261 | require_once $dir.$file; |
@@ -264,31 +264,31 @@ discard block |
||
264 | 264 | // First test without option USE_STRICT_CSV_RULES |
265 | 265 | unset($conf->global->USE_STRICT_CSV_RULES); |
266 | 266 | |
267 | - $valtotest='A simple string'; |
|
267 | + $valtotest = 'A simple string'; |
|
268 | 268 | print __METHOD__." valtotest=".$valtotest."\n"; |
269 | 269 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
270 | 270 | print __METHOD__." result=".$result."\n"; |
271 | 271 | $this->assertEquals($result, 'A simple string'); |
272 | 272 | |
273 | - $valtotest='A string with , and ; inside'; |
|
273 | + $valtotest = 'A string with , and ; inside'; |
|
274 | 274 | print __METHOD__." valtotest=".$valtotest."\n"; |
275 | 275 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
276 | 276 | print __METHOD__." result=".$result."\n"; |
277 | 277 | $this->assertEquals($result, '"A string with , and ; inside"', 'Error in csvClean for '.$file); |
278 | 278 | |
279 | - $valtotest='A string with " inside'; |
|
279 | + $valtotest = 'A string with " inside'; |
|
280 | 280 | print __METHOD__." valtotest=".$valtotest."\n"; |
281 | 281 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
282 | 282 | print __METHOD__." result=".$result."\n"; |
283 | 283 | $this->assertEquals($result, '"A string with "" inside"'); |
284 | 284 | |
285 | - $valtotest='A string with " inside and '."\r\n".' carriage returns'; |
|
285 | + $valtotest = 'A string with " inside and '."\r\n".' carriage returns'; |
|
286 | 286 | print __METHOD__." valtotest=".$valtotest."\n"; |
287 | 287 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
288 | 288 | print __METHOD__." result=".$result."\n"; |
289 | 289 | $this->assertEquals($result, '"A string with "" inside and \n carriage returns"'); |
290 | 290 | |
291 | - $valtotest='A string with <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n"; |
|
291 | + $valtotest = 'A string with <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n"; |
|
292 | 292 | print __METHOD__." valtotest=".$valtotest."\n"; |
293 | 293 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
294 | 294 | print __METHOD__." result=".$result."\n"; |
@@ -297,31 +297,31 @@ discard block |
||
297 | 297 | // Same tests with strict mode |
298 | 298 | $conf->global->USE_STRICT_CSV_RULES = 1; |
299 | 299 | |
300 | - $valtotest='A simple string'; |
|
300 | + $valtotest = 'A simple string'; |
|
301 | 301 | print __METHOD__." valtotest=".$valtotest."\n"; |
302 | 302 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
303 | 303 | print __METHOD__." result=".$result."\n"; |
304 | 304 | $this->assertEquals($result, 'A simple string'); |
305 | 305 | |
306 | - $valtotest='A string with , and ; inside'; |
|
306 | + $valtotest = 'A string with , and ; inside'; |
|
307 | 307 | print __METHOD__." valtotest=".$valtotest."\n"; |
308 | 308 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
309 | 309 | print __METHOD__." result=".$result."\n"; |
310 | 310 | $this->assertEquals($result, '"A string with , and ; inside"'); |
311 | 311 | |
312 | - $valtotest='A string with " inside'; |
|
312 | + $valtotest = 'A string with " inside'; |
|
313 | 313 | print __METHOD__." valtotest=".$valtotest."\n"; |
314 | 314 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
315 | 315 | print __METHOD__." result=".$result."\n"; |
316 | 316 | $this->assertEquals($result, '"A string with "" inside"'); |
317 | 317 | |
318 | - $valtotest='A string with " inside and '."\r\n".' carriage returns'; |
|
318 | + $valtotest = 'A string with " inside and '."\r\n".' carriage returns'; |
|
319 | 319 | print __METHOD__." valtotest=".$valtotest."\n"; |
320 | 320 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
321 | 321 | print __METHOD__." result=".$result."\n"; |
322 | 322 | $this->assertEquals($result, "\"A string with \"\" inside and \r\n carriage returns\""); |
323 | 323 | |
324 | - $valtotest='A string with <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n"; |
|
324 | + $valtotest = 'A string with <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n"; |
|
325 | 325 | print __METHOD__." valtotest=".$valtotest."\n"; |
326 | 326 | $result = $objmodel->csvClean($valtotest, $langs->charset_output); |
327 | 327 | print __METHOD__." result=".$result."\n"; |
@@ -336,54 +336,54 @@ discard block |
||
336 | 336 | */ |
337 | 337 | public function testExportPersonalizedExport() |
338 | 338 | { |
339 | - global $conf,$user,$langs,$db; |
|
339 | + global $conf, $user, $langs, $db; |
|
340 | 340 | |
341 | 341 | $sql = "SELECT f.ref as f_ref, f.total_ht as f_total, f.total_tva as f_tva FROM ".MAIN_DB_PREFIX."facture f"; |
342 | 342 | |
343 | - $objexport=new Export($db); |
|
343 | + $objexport = new Export($db); |
|
344 | 344 | //$objexport->load_arrays($user,$datatoexport); |
345 | 345 | |
346 | 346 | // Define properties |
347 | - $datatoexport='test'; |
|
347 | + $datatoexport = 'test'; |
|
348 | 348 | $array_selected = array("f.ref"=>1, "f.total"=>2, "f.tva"=>3); |
349 | 349 | $array_export_fields = array("f.ref"=>"FacNumber", "f.total"=>"FacTotal", "f.tva"=>"FacVat"); |
350 | 350 | $array_alias = array("f_ref"=>"ref", "f_total"=>"total", "f_tva"=>"tva"); |
351 | - $objexport->array_export_fields[0]=$array_export_fields; |
|
352 | - $objexport->array_export_alias[0]=$array_alias; |
|
351 | + $objexport->array_export_fields[0] = $array_export_fields; |
|
352 | + $objexport->array_export_alias[0] = $array_alias; |
|
353 | 353 | |
354 | 354 | dol_mkdir($conf->export->dir_temp); |
355 | 355 | |
356 | - $model='csviso'; |
|
356 | + $model = 'csviso'; |
|
357 | 357 | |
358 | 358 | // Build export file |
359 | 359 | print "Process build_file for model = ".$model."\n"; |
360 | - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
360 | + $result = $objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
361 | 361 | $expectedresult = 1; |
362 | 362 | $this->assertEquals($expectedresult, $result, 'Error in CSV export'); |
363 | 363 | |
364 | - $model='csvutf8'; |
|
364 | + $model = 'csvutf8'; |
|
365 | 365 | |
366 | 366 | // Build export file |
367 | 367 | print "Process build_file for model = ".$model."\n"; |
368 | - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
368 | + $result = $objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
369 | 369 | $expectedresult = 1; |
370 | 370 | $this->assertEquals($expectedresult, $result, 'Error in CSV export'); |
371 | 371 | |
372 | - $model='tsv'; |
|
372 | + $model = 'tsv'; |
|
373 | 373 | |
374 | 374 | // Build export file |
375 | 375 | print "Process build_file for model = ".$model."\n"; |
376 | - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
377 | - $expectedresult=1; |
|
376 | + $result = $objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
377 | + $expectedresult = 1; |
|
378 | 378 | $this->assertEquals($expectedresult, $result, 'Error in TSV export'); |
379 | 379 | |
380 | - $model='excel2007'; |
|
380 | + $model = 'excel2007'; |
|
381 | 381 | |
382 | 382 | // Build export file |
383 | 383 | /* ko on php 7.4 on travis (zip not available) */ |
384 | 384 | print "Process build_file for model = ".$model."\n"; |
385 | - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
386 | - $expectedresult=1; |
|
385 | + $result = $objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
386 | + $expectedresult = 1; |
|
387 | 387 | $this->assertEquals($expectedresult, $result, 'Error in Excel2007 export'); |
388 | 388 | |
389 | 389 | return true; |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | */ |
398 | 398 | public function testExportPersonalizedWithFilter() |
399 | 399 | { |
400 | - global $conf,$user,$langs,$db; |
|
400 | + global $conf, $user, $langs, $db; |
|
401 | 401 | /* |
402 | 402 | $sql = "SELECT f.ref as f_ref, f.total_ht as f_total_ht, f.total_tva as f_total_tva FROM ".MAIN_DB_PREFIX."facture f"; |
403 | 403 | |
@@ -449,38 +449,38 @@ discard block |
||
449 | 449 | */ |
450 | 450 | public function testExportModulesDatasets() |
451 | 451 | { |
452 | - global $conf,$user,$langs,$db; |
|
452 | + global $conf, $user, $langs, $db; |
|
453 | 453 | |
454 | - $model='csviso'; |
|
454 | + $model = 'csviso'; |
|
455 | 455 | |
456 | - $filterdatatoexport=''; |
|
456 | + $filterdatatoexport = ''; |
|
457 | 457 | //$filterdatatoexport=''; |
458 | 458 | //$array_selected = array("s.rowid"=>1, "s.nom"=>2); // Must be fields found into declaration of dataset |
459 | 459 | |
460 | 460 | // Load properties of arrays to make export |
461 | - $objexport=new Export($db); |
|
462 | - $result=$objexport->load_arrays($user, $filterdatatoexport); // This load ->array_export_xxx properties for datatoexport |
|
461 | + $objexport = new Export($db); |
|
462 | + $result = $objexport->load_arrays($user, $filterdatatoexport); // This load ->array_export_xxx properties for datatoexport |
|
463 | 463 | |
464 | 464 | // Loop on each dataset |
465 | 465 | foreach ($objexport->array_export_code as $key => $datatoexport) { |
466 | - $exportfile=$conf->export->dir_temp.'/'.$user->id.'/export_'.$datatoexport.'.csv'; |
|
466 | + $exportfile = $conf->export->dir_temp.'/'.$user->id.'/export_'.$datatoexport.'.csv'; |
|
467 | 467 | print "Process export for dataset ".$datatoexport." into ".$exportfile."\n"; |
468 | 468 | dol_delete_file($exportfile); |
469 | 469 | |
470 | 470 | // Generate $array_selected |
471 | - $i=0; |
|
472 | - $array_selected=array(); |
|
471 | + $i = 0; |
|
472 | + $array_selected = array(); |
|
473 | 473 | foreach ($objexport->array_export_fields[$key] as $key => $val) { |
474 | - $array_selected[$key]=$i++; |
|
474 | + $array_selected[$key] = $i++; |
|
475 | 475 | } |
476 | 476 | //var_dump($array_selected); |
477 | 477 | |
478 | 478 | // Build export file |
479 | 479 | $sql = ""; |
480 | - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
480 | + $result = $objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); |
|
481 | 481 | $expectedresult = 1; |
482 | 482 | $this->assertEquals($expectedresult, $result, "Call build_file() to export ".$exportfile.' failed: '.$objexport->error); |
483 | - $result=dol_is_file($exportfile); |
|
483 | + $result = dol_is_file($exportfile); |
|
484 | 484 | $this->assertTrue($result, 'File '.$exportfile.' not found'); |
485 | 485 | } |
486 | 486 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * \remarks To run this script as CLI: phpunit filename.php |
25 | 25 | */ |
26 | 26 | |
27 | -global $conf,$user,$langs,$db; |
|
27 | +global $conf, $user, $langs, $db; |
|
28 | 28 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
29 | 29 | //require_once 'PHPUnit/Autoload.php'; |
30 | 30 | require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $user->fetch(1); |
35 | 35 | $user->getrights(); |
36 | 36 | } |
37 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
37 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
38 | 38 | |
39 | 39 | |
40 | 40 | /** |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | parent::__construct($name); |
64 | 64 | |
65 | 65 | //$this->sharedFixture |
66 | - global $conf,$user,$langs,$db; |
|
67 | - $this->savconf=$conf; |
|
68 | - $this->savuser=$user; |
|
69 | - $this->savlangs=$langs; |
|
70 | - $this->savdb=$db; |
|
66 | + global $conf, $user, $langs, $db; |
|
67 | + $this->savconf = $conf; |
|
68 | + $this->savuser = $user; |
|
69 | + $this->savlangs = $langs; |
|
70 | + $this->savdb = $db; |
|
71 | 71 | |
72 | 72 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
73 | 73 | //print " - db ".$db->db; |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public static function setUpBeforeClass(): void |
83 | 83 | { |
84 | - global $conf,$user,$langs,$db; |
|
84 | + global $conf, $user, $langs, $db; |
|
85 | 85 | |
86 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
86 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
87 | 87 | |
88 | 88 | print __METHOD__."\n"; |
89 | 89 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public static function tearDownAfterClass(): void |
97 | 97 | { |
98 | - global $conf,$user,$langs,$db; |
|
98 | + global $conf, $user, $langs, $db; |
|
99 | 99 | $db->rollback(); |
100 | 100 | |
101 | 101 | print __METHOD__."\n"; |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function setUp(): void |
110 | 110 | { |
111 | - global $conf,$user,$langs,$db; |
|
112 | - $conf=$this->savconf; |
|
113 | - $user=$this->savuser; |
|
114 | - $langs=$this->savlangs; |
|
115 | - $db=$this->savdb; |
|
111 | + global $conf, $user, $langs, $db; |
|
112 | + $conf = $this->savconf; |
|
113 | + $user = $this->savuser; |
|
114 | + $langs = $this->savlangs; |
|
115 | + $db = $this->savdb; |
|
116 | 116 | |
117 | 117 | print __METHOD__."\n"; |
118 | 118 | } |
@@ -134,527 +134,527 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function testFactureMercure() |
136 | 136 | { |
137 | - global $conf,$user,$langs,$db,$mysoc; |
|
138 | - $conf=$this->savconf; |
|
139 | - $user=$this->savuser; |
|
140 | - $langs=$this->savlangs; |
|
141 | - $db=$this->savdb; |
|
137 | + global $conf, $user, $langs, $db, $mysoc; |
|
138 | + $conf = $this->savconf; |
|
139 | + $user = $this->savuser; |
|
140 | + $langs = $this->savlangs; |
|
141 | + $db = $this->savdb; |
|
142 | 142 | |
143 | 143 | require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; |
144 | 144 | require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/mod_facture_mercure.php'; |
145 | 145 | |
146 | 146 | // First we try with a simple mask, with no reset |
147 | 147 | // and we test counter is still increase second year. |
148 | - $conf->global->FACTURE_ADDON='mercure'; |
|
149 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}-{0000}'; |
|
150 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000}'; |
|
151 | - $conf->global->FACTURE_MERCURE_MASK_DEPOSIT='{yyyy}-{0000}'; |
|
152 | - $conf->global->FACTURE_MERCURE_MASK_REPLACEMENT='{yyyy}-{0000}'; |
|
153 | - $conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED=0; |
|
154 | - |
|
155 | - $localobject=new Facture($db); |
|
148 | + $conf->global->FACTURE_ADDON = 'mercure'; |
|
149 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}-{0000}'; |
|
150 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}-{0000}'; |
|
151 | + $conf->global->FACTURE_MERCURE_MASK_DEPOSIT = '{yyyy}-{0000}'; |
|
152 | + $conf->global->FACTURE_MERCURE_MASK_REPLACEMENT = '{yyyy}-{0000}'; |
|
153 | + $conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED = 0; |
|
154 | + |
|
155 | + $localobject = new Facture($db); |
|
156 | 156 | $localobject->initAsSpecimen(); |
157 | 157 | $localobject->fetch_thirdparty(); |
158 | 158 | |
159 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1915); // we use year 1915 to be sure to not have existing invoice for this year (useful only if numbering is {0000@1} |
|
160 | - $numbering=new mod_facture_mercure(); |
|
161 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
159 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1915); // we use year 1915 to be sure to not have existing invoice for this year (useful only if numbering is {0000@1} |
|
160 | + $numbering = new mod_facture_mercure(); |
|
161 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
162 | 162 | print __METHOD__." result=".$result."\n"; |
163 | - $this->assertEquals('1915-0001', $result, 'Test for {yyyy}-{0000}, 1st invoice'); // counter must start to 1 |
|
164 | - $result2=$localobject->create($user, 1); |
|
163 | + $this->assertEquals('1915-0001', $result, 'Test for {yyyy}-{0000}, 1st invoice'); // counter must start to 1 |
|
164 | + $result2 = $localobject->create($user, 1); |
|
165 | 165 | print __METHOD__." result2=".$result."\n"; |
166 | - $result3=$localobject->validate($user, $result); // create invoice by forcing ref |
|
166 | + $result3 = $localobject->validate($user, $result); // create invoice by forcing ref |
|
167 | 167 | print __METHOD__." result3=".$result."\n"; |
168 | - $this->assertEquals(1, $result3, 'Test validation of invoice with forced ref is ok'); // counter must start to 1 |
|
169 | - $result=$localobject->is_erasable(); |
|
168 | + $this->assertEquals(1, $result3, 'Test validation of invoice with forced ref is ok'); // counter must start to 1 |
|
169 | + $result = $localobject->is_erasable(); |
|
170 | 170 | print __METHOD__." is_erasable=".$result."\n"; |
171 | - $this->assertGreaterThanOrEqual(1, $result, 'Test for is_erasable, 1st invoice'); // Can be deleted |
|
171 | + $this->assertGreaterThanOrEqual(1, $result, 'Test for is_erasable, 1st invoice'); // Can be deleted |
|
172 | 172 | |
173 | - $localobject2=new Facture($db); |
|
173 | + $localobject2 = new Facture($db); |
|
174 | 174 | $localobject2->initAsSpecimen(); |
175 | 175 | $localobject2->fetch_thirdparty(); |
176 | 176 | |
177 | - $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask) |
|
178 | - $numbering=new mod_facture_mercure(); |
|
179 | - $result=$numbering->getNextValue($mysoc, $localobject2, 'last'); |
|
177 | + $localobject2->date = dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask) |
|
178 | + $numbering = new mod_facture_mercure(); |
|
179 | + $result = $numbering->getNextValue($mysoc, $localobject2, 'last'); |
|
180 | 180 | print __METHOD__." result=".$result."\n"; |
181 | 181 | $this->assertEquals('1915-0001', $result, "Test to get last value with param 'last'"); |
182 | - $result=$numbering->getNextValue($mysoc, $localobject2); |
|
182 | + $result = $numbering->getNextValue($mysoc, $localobject2); |
|
183 | 183 | print __METHOD__." result=".$result."\n"; |
184 | - $this->assertEquals('1916-0002', $result); // counter must be now 2 (not reset) |
|
185 | - $result2=$localobject2->create($user, 1); |
|
184 | + $this->assertEquals('1916-0002', $result); // counter must be now 2 (not reset) |
|
185 | + $result2 = $localobject2->create($user, 1); |
|
186 | 186 | print __METHOD__." result2=".$result."\n"; |
187 | - $result3=$localobject2->validate($user, $result); // create invoice by forcing ref |
|
187 | + $result3 = $localobject2->validate($user, $result); // create invoice by forcing ref |
|
188 | 188 | print __METHOD__." result3=".$result."\n"; |
189 | - $this->assertEquals(1, $result3, 'Test validation of invoice with forced ref is ok'); // counter must start to 1 |
|
190 | - $result=$localobject2->is_erasable(); |
|
189 | + $this->assertEquals(1, $result3, 'Test validation of invoice with forced ref is ok'); // counter must start to 1 |
|
190 | + $result = $localobject2->is_erasable(); |
|
191 | 191 | print __METHOD__." is_erasable=".$result."\n"; |
192 | - $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
193 | - $result=$localobject->is_erasable(); |
|
192 | + $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
193 | + $result = $localobject->is_erasable(); |
|
194 | 194 | print __METHOD__." is_erasable=".$result."\n"; |
195 | - $this->assertLessThanOrEqual(0, $result, 'Test for {yyyy}-{0000} that is_erasable is 0 for 1st invoice'); // 1 can no more be deleted (2 is more recent) |
|
195 | + $this->assertLessThanOrEqual(0, $result, 'Test for {yyyy}-{0000} that is_erasable is 0 for 1st invoice'); // 1 can no more be deleted (2 is more recent) |
|
196 | 196 | |
197 | 197 | // Now we try with a reset |
198 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000@1}'; |
|
199 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}-{0000@1}'; |
|
198 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}-{0000@1}'; |
|
199 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}-{0000@1}'; |
|
200 | 200 | |
201 | - $localobject=new Facture($db); |
|
201 | + $localobject = new Facture($db); |
|
202 | 202 | $localobject->initAsSpecimen(); |
203 | 203 | $localobject->fetch_thirdparty(); |
204 | 204 | |
205 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1910); // we use year 1910 to be sure to not have existing invoice for this year |
|
206 | - $numbering=new mod_facture_mercure(); |
|
207 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
208 | - $result2=$localobject->create($user, 1); |
|
209 | - $result3=$localobject->validate($user, $result); |
|
205 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1910); // we use year 1910 to be sure to not have existing invoice for this year |
|
206 | + $numbering = new mod_facture_mercure(); |
|
207 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
208 | + $result2 = $localobject->create($user, 1); |
|
209 | + $result3 = $localobject->validate($user, $result); |
|
210 | 210 | print __METHOD__." result=".$result."\n"; |
211 | - $this->assertEquals('1910-0001', $result, 'Test for {yyyy}-{0000@1} 1st invoice'); // counter must start to 1 |
|
211 | + $this->assertEquals('1910-0001', $result, 'Test for {yyyy}-{0000@1} 1st invoice'); // counter must start to 1 |
|
212 | 212 | |
213 | - $localobject2=new Facture($db); |
|
213 | + $localobject2 = new Facture($db); |
|
214 | 214 | $localobject2->initAsSpecimen(); |
215 | 215 | $localobject2->fetch_thirdparty(); |
216 | 216 | |
217 | - $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1910); // we use same year for second invoice (and there is a reset required) |
|
218 | - $numbering=new mod_facture_mercure(); |
|
219 | - $result=$numbering->getNextValue($mysoc, $localobject2); |
|
217 | + $localobject2->date = dol_mktime(12, 0, 0, 1, 1, 1910); // we use same year for second invoice (and there is a reset required) |
|
218 | + $numbering = new mod_facture_mercure(); |
|
219 | + $result = $numbering->getNextValue($mysoc, $localobject2); |
|
220 | 220 | print __METHOD__." result=".$result."\n"; |
221 | - $this->assertEquals('1910-0002', $result, 'Test for {yyyy}-{0000@1} 2nd invoice, same day'); // counter must be now 2 |
|
221 | + $this->assertEquals('1910-0002', $result, 'Test for {yyyy}-{0000@1} 2nd invoice, same day'); // counter must be now 2 |
|
222 | 222 | |
223 | - $localobject3=new Facture($db); |
|
223 | + $localobject3 = new Facture($db); |
|
224 | 224 | $localobject3->initAsSpecimen(); |
225 | 225 | $localobject3->fetch_thirdparty(); |
226 | 226 | |
227 | - $localobject3->date=dol_mktime(12, 0, 0, 1, 1, 1911); // we use next year for third invoice (and there is a reset required) |
|
228 | - $numbering=new mod_facture_mercure(); |
|
229 | - $result=$numbering->getNextValue($mysoc, $localobject3); |
|
227 | + $localobject3->date = dol_mktime(12, 0, 0, 1, 1, 1911); // we use next year for third invoice (and there is a reset required) |
|
228 | + $numbering = new mod_facture_mercure(); |
|
229 | + $result = $numbering->getNextValue($mysoc, $localobject3); |
|
230 | 230 | print __METHOD__." result=".$result."\n"; |
231 | - $this->assertEquals('1911-0001', $result, 'Test for {yyyy}-{0000@1} 3rd invoice, same day'); // counter must be now 1 |
|
231 | + $this->assertEquals('1911-0001', $result, 'Test for {yyyy}-{0000@1} 3rd invoice, same day'); // counter must be now 1 |
|
232 | 232 | |
233 | 233 | // Same but we add month after year |
234 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@1}'; |
|
235 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@1}'; |
|
234 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}{mm}-{0000@1}'; |
|
235 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}{mm}-{0000@1}'; |
|
236 | 236 | |
237 | - $localobject=new Facture($db); |
|
237 | + $localobject = new Facture($db); |
|
238 | 238 | $localobject->initAsSpecimen(); |
239 | 239 | $localobject->fetch_thirdparty(); |
240 | 240 | |
241 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1920); // we use year 1920 to be sure to not have existing invoice for this year |
|
242 | - $numbering=new mod_facture_mercure(); |
|
243 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
244 | - $result2=$localobject->create($user, 1); |
|
245 | - $result3=$localobject->validate($user, $result); |
|
241 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1920); // we use year 1920 to be sure to not have existing invoice for this year |
|
242 | + $numbering = new mod_facture_mercure(); |
|
243 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
244 | + $result2 = $localobject->create($user, 1); |
|
245 | + $result3 = $localobject->validate($user, $result); |
|
246 | 246 | print __METHOD__." result=".$result."\n"; |
247 | - $this->assertEquals('192001-0001', $result, 'Test for {yyyy}{mm}-{0000@1} 1st invoice'); // counter must start to 1 |
|
248 | - $result=$localobject->is_erasable(); |
|
247 | + $this->assertEquals('192001-0001', $result, 'Test for {yyyy}{mm}-{0000@1} 1st invoice'); // counter must start to 1 |
|
248 | + $result = $localobject->is_erasable(); |
|
249 | 249 | print __METHOD__." is_erasable=".$result."\n"; |
250 | - $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
250 | + $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
251 | 251 | |
252 | - $localobject2=new Facture($db); |
|
252 | + $localobject2 = new Facture($db); |
|
253 | 253 | $localobject2->initAsSpecimen(); |
254 | 254 | $localobject2->fetch_thirdparty(); |
255 | 255 | |
256 | - $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice (and there is a reset required) |
|
257 | - $numbering=new mod_facture_mercure(); |
|
258 | - $result=$numbering->getNextValue($mysoc, $localobject2); |
|
259 | - $result2=$localobject2->create($user, 1); |
|
260 | - $result3=$localobject2->validate($user, $result); |
|
256 | + $localobject2->date = dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice (and there is a reset required) |
|
257 | + $numbering = new mod_facture_mercure(); |
|
258 | + $result = $numbering->getNextValue($mysoc, $localobject2); |
|
259 | + $result2 = $localobject2->create($user, 1); |
|
260 | + $result3 = $localobject2->validate($user, $result); |
|
261 | 261 | print __METHOD__." result=".$result."\n"; |
262 | - $this->assertEquals('192101-0001', $result); // counter must be reset to 1 |
|
263 | - $result=$localobject2->is_erasable(); |
|
262 | + $this->assertEquals('192101-0001', $result); // counter must be reset to 1 |
|
263 | + $result = $localobject2->is_erasable(); |
|
264 | 264 | print __METHOD__." is_erasable=".$result."\n"; |
265 | - $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
266 | - $result=$localobject->is_erasable(); |
|
265 | + $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
266 | + $result = $localobject->is_erasable(); |
|
267 | 267 | print __METHOD__." is_erasable=".$result."\n"; |
268 | - $this->assertGreaterThanOrEqual(1, $result); // Case 1 can be deleted (because there was a reset for case 2) |
|
268 | + $this->assertGreaterThanOrEqual(1, $result); // Case 1 can be deleted (because there was a reset for case 2) |
|
269 | 269 | |
270 | 270 | // Same but we add month before year and use a year on 2 digits |
271 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='[mm}{yy}-{0000@1}'; |
|
272 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{mm}{yy}-{0000@1}'; |
|
273 | - $localobject=new Facture($db); |
|
271 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '[mm}{yy}-{0000@1}'; |
|
272 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{mm}{yy}-{0000@1}'; |
|
273 | + $localobject = new Facture($db); |
|
274 | 274 | $localobject->initAsSpecimen(); |
275 | 275 | $localobject->fetch_thirdparty(); |
276 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1925); // we use year 1925 to be sure to not have existing invoice for this year |
|
277 | - $numbering=new mod_facture_mercure(); |
|
278 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
279 | - $result2=$localobject->create($user, 1); |
|
280 | - $result3=$localobject->validate($user, $result); |
|
281 | - print __METHOD__." result=".$result."\n"; |
|
282 | - $this->assertEquals('0125-0001', $result, 'Test for {mm}{yy}-{0000@1} 1st invoice'); // counter must start to 1 |
|
283 | - $result=$localobject->is_erasable(); // This call get getNextNumRef with param 'last' |
|
276 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1925); // we use year 1925 to be sure to not have existing invoice for this year |
|
277 | + $numbering = new mod_facture_mercure(); |
|
278 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
279 | + $result2 = $localobject->create($user, 1); |
|
280 | + $result3 = $localobject->validate($user, $result); |
|
281 | + print __METHOD__." result=".$result."\n"; |
|
282 | + $this->assertEquals('0125-0001', $result, 'Test for {mm}{yy}-{0000@1} 1st invoice'); // counter must start to 1 |
|
283 | + $result = $localobject->is_erasable(); // This call get getNextNumRef with param 'last' |
|
284 | 284 | print __METHOD__." is_erasable=".$result."\n"; |
285 | - $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
285 | + $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
286 | 286 | |
287 | - $localobject2=new Facture($db); |
|
287 | + $localobject2 = new Facture($db); |
|
288 | 288 | $localobject2->initAsSpecimen(); |
289 | 289 | $localobject2->fetch_thirdparty(); |
290 | - $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1925); // we use same year 1925 for second invoice (and there is a reset required) |
|
291 | - $numbering=new mod_facture_mercure(); |
|
292 | - $result=$numbering->getNextValue($mysoc, $localobject2); |
|
293 | - $result2=$localobject2->create($user, 1); |
|
294 | - $result3=$localobject2->validate($user, $result); |
|
295 | - print __METHOD__." result=".$result."\n"; |
|
296 | - $this->assertEquals('0125-0002', $result, 'Test for {mm}{yy}-{0000@1} 2nd invoice'); // counter must be now 2 |
|
297 | - $result=$localobject2->is_erasable(); |
|
290 | + $localobject2->date = dol_mktime(12, 0, 0, 1, 1, 1925); // we use same year 1925 for second invoice (and there is a reset required) |
|
291 | + $numbering = new mod_facture_mercure(); |
|
292 | + $result = $numbering->getNextValue($mysoc, $localobject2); |
|
293 | + $result2 = $localobject2->create($user, 1); |
|
294 | + $result3 = $localobject2->validate($user, $result); |
|
295 | + print __METHOD__." result=".$result."\n"; |
|
296 | + $this->assertEquals('0125-0002', $result, 'Test for {mm}{yy}-{0000@1} 2nd invoice'); // counter must be now 2 |
|
297 | + $result = $localobject2->is_erasable(); |
|
298 | 298 | print __METHOD__." is_erasable=".$result."\n"; |
299 | - $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
300 | - $result=$localobject->is_erasable(); |
|
299 | + $this->assertGreaterThanOrEqual(1, $result); // Can be deleted |
|
300 | + $result = $localobject->is_erasable(); |
|
301 | 301 | print __METHOD__." is_erasable=".$result."\n"; |
302 | - $this->assertLessThanOrEqual(0, $result); // Case 1 can not be deleted (because there is an invoice 2) |
|
302 | + $this->assertLessThanOrEqual(0, $result); // Case 1 can not be deleted (because there is an invoice 2) |
|
303 | 303 | |
304 | - $localobject3=new Facture($db); |
|
304 | + $localobject3 = new Facture($db); |
|
305 | 305 | $localobject3->initAsSpecimen(); |
306 | 306 | $localobject3->fetch_thirdparty(); |
307 | - $localobject3->date=dol_mktime(12, 0, 0, 1, 1, 1926); // we use following year for third invoice (and there is a reset required) |
|
308 | - $numbering=new mod_facture_mercure(); |
|
309 | - $result=$numbering->getNextValue($mysoc, $localobject3); |
|
307 | + $localobject3->date = dol_mktime(12, 0, 0, 1, 1, 1926); // we use following year for third invoice (and there is a reset required) |
|
308 | + $numbering = new mod_facture_mercure(); |
|
309 | + $result = $numbering->getNextValue($mysoc, $localobject3); |
|
310 | 310 | print __METHOD__." result=".$result."\n"; |
311 | - $this->assertEquals('0126-0001', $result, 'Test for {mm}{yy}-{0000@1} 3rd invoice'); // counter must be now 1 |
|
311 | + $this->assertEquals('0126-0001', $result, 'Test for {mm}{yy}-{0000@1} 3rd invoice'); // counter must be now 1 |
|
312 | 312 | |
313 | 313 | // Try an offset when an invoice already exists |
314 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000+9990}'; |
|
315 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000+9990}'; |
|
316 | - $result=$numbering->getNextValue($mysoc, $localobject2); |
|
314 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}{mm}-{0000+9990}'; |
|
315 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}{mm}-{0000+9990}'; |
|
316 | + $result = $numbering->getNextValue($mysoc, $localobject2); |
|
317 | 317 | |
318 | 318 | // Now we try with a different fiscal month (forced by mask) |
319 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@6}'; |
|
320 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@6}'; |
|
319 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}{mm}-{0000@6}'; |
|
320 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}{mm}-{0000@6}'; |
|
321 | 321 | |
322 | - $localobject=new Facture($db); |
|
322 | + $localobject = new Facture($db); |
|
323 | 323 | $localobject->initAsSpecimen(); |
324 | 324 | $localobject->fetch_thirdparty(); |
325 | 325 | |
326 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1930); // we use year 1930 to be sure to not have existing invoice for this year |
|
327 | - $numbering=new mod_facture_mercure(); |
|
328 | - $result=$numbering->getNextValue($mysoc, $localobject, 'last'); |
|
326 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1930); // we use year 1930 to be sure to not have existing invoice for this year |
|
327 | + $numbering = new mod_facture_mercure(); |
|
328 | + $result = $numbering->getNextValue($mysoc, $localobject, 'last'); |
|
329 | 329 | print __METHOD__." result for last=".$result."\n"; |
330 | - $this->assertEquals('', $result); // no existing ref into reset range |
|
331 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
332 | - $result2=$localobject->create($user, 1); |
|
333 | - $result3=$localobject->validate($user, $result); |
|
330 | + $this->assertEquals('', $result); // no existing ref into reset range |
|
331 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
332 | + $result2 = $localobject->create($user, 1); |
|
333 | + $result3 = $localobject->validate($user, $result); |
|
334 | 334 | print __METHOD__." result=".$result."\n"; |
335 | - $this->assertEquals('193001-0001', $result); // counter must start to 1 |
|
336 | - $result=$numbering->getNextValue($mysoc, $localobject, 'last'); |
|
335 | + $this->assertEquals('193001-0001', $result); // counter must start to 1 |
|
336 | + $result = $numbering->getNextValue($mysoc, $localobject, 'last'); |
|
337 | 337 | print __METHOD__." result for last=".$result."\n"; |
338 | - $this->assertEquals('193001-0001', $result); // last ref into reset range should be same than last created |
|
338 | + $this->assertEquals('193001-0001', $result); // last ref into reset range should be same than last created |
|
339 | 339 | |
340 | - $localobject=new Facture($db); |
|
340 | + $localobject = new Facture($db); |
|
341 | 341 | $localobject->initAsSpecimen(); |
342 | 342 | $localobject->fetch_thirdparty(); |
343 | 343 | |
344 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1930); // we use same year but fiscal month after |
|
345 | - $numbering=new mod_facture_mercure(); |
|
346 | - $result=$numbering->getNextValue($mysoc, $localobject, 'last'); |
|
344 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1930); // we use same year but fiscal month after |
|
345 | + $numbering = new mod_facture_mercure(); |
|
346 | + $result = $numbering->getNextValue($mysoc, $localobject, 'last'); |
|
347 | 347 | print __METHOD__." result for last=".$result."\n"; |
348 | - $this->assertEquals('', $result); // last ref into reset range should be '' |
|
349 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
350 | - $result2=$localobject->create($user, 1); |
|
351 | - $result3=$localobject->validate($user, $result); |
|
348 | + $this->assertEquals('', $result); // last ref into reset range should be '' |
|
349 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
350 | + $result2 = $localobject->create($user, 1); |
|
351 | + $result3 = $localobject->validate($user, $result); |
|
352 | 352 | print __METHOD__." result=".$result."\n"; |
353 | - $this->assertEquals('193012-0001', $result); // counter must be reset to 1 |
|
353 | + $this->assertEquals('193012-0001', $result); // counter must be reset to 1 |
|
354 | 354 | |
355 | - $localobject=new Facture($db); |
|
355 | + $localobject = new Facture($db); |
|
356 | 356 | $localobject->initAsSpecimen(); |
357 | 357 | $localobject->fetch_thirdparty(); |
358 | 358 | |
359 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1931); // we use same fiscal year but different year |
|
360 | - $numbering=new mod_facture_mercure(); |
|
361 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
362 | - $result2=$localobject->create($user, 1); |
|
363 | - $result3=$localobject->validate($user, $result); |
|
359 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1931); // we use same fiscal year but different year |
|
360 | + $numbering = new mod_facture_mercure(); |
|
361 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
362 | + $result2 = $localobject->create($user, 1); |
|
363 | + $result3 = $localobject->validate($user, $result); |
|
364 | 364 | print __METHOD__." result=".$result."\n"; |
365 | - $this->assertEquals('193101-0002', $result); // counter must be 2 |
|
365 | + $this->assertEquals('193101-0002', $result); // counter must be 2 |
|
366 | 366 | |
367 | - $localobject=new Facture($db); |
|
367 | + $localobject = new Facture($db); |
|
368 | 368 | $localobject->initAsSpecimen(); |
369 | 369 | $localobject->fetch_thirdparty(); |
370 | 370 | |
371 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1931); // we use different fiscal year but same year |
|
372 | - $numbering=new mod_facture_mercure(); |
|
373 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
371 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1931); // we use different fiscal year but same year |
|
372 | + $numbering = new mod_facture_mercure(); |
|
373 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
374 | 374 | print __METHOD__." result=".$result."\n"; |
375 | - $this->assertEquals('193112-0001', $result); // counter must be reset to 1 |
|
375 | + $this->assertEquals('193112-0001', $result); // counter must be reset to 1 |
|
376 | 376 | |
377 | 377 | |
378 | 378 | // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) |
379 | - $conf->global->SOCIETE_FISCAL_MONTH_START=6; |
|
380 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@0}'; |
|
381 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@0}'; |
|
379 | + $conf->global->SOCIETE_FISCAL_MONTH_START = 6; |
|
380 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}{mm}-{0000@0}'; |
|
381 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}{mm}-{0000@0}'; |
|
382 | 382 | |
383 | - $localobject=new Facture($db); |
|
383 | + $localobject = new Facture($db); |
|
384 | 384 | $localobject->initAsSpecimen(); |
385 | 385 | $localobject->fetch_thirdparty(); |
386 | 386 | |
387 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1940); // we use year 1940 to be sure to not have existing invoice for this year |
|
388 | - $numbering=new mod_facture_mercure(); |
|
389 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
390 | - $result2=$localobject->create($user, 1); |
|
391 | - $result3=$localobject->validate($user, $result); |
|
387 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1940); // we use year 1940 to be sure to not have existing invoice for this year |
|
388 | + $numbering = new mod_facture_mercure(); |
|
389 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
390 | + $result2 = $localobject->create($user, 1); |
|
391 | + $result3 = $localobject->validate($user, $result); |
|
392 | 392 | print __METHOD__." result=".$result."\n"; |
393 | - $this->assertEquals('194001-0001', $result); // counter must start to 1 |
|
393 | + $this->assertEquals('194001-0001', $result); // counter must start to 1 |
|
394 | 394 | |
395 | - $localobject=new Facture($db); |
|
395 | + $localobject = new Facture($db); |
|
396 | 396 | $localobject->initAsSpecimen(); |
397 | 397 | $localobject->fetch_thirdparty(); |
398 | 398 | |
399 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1940); // we use same year but fiscal month after |
|
400 | - $numbering=new mod_facture_mercure(); |
|
401 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
402 | - $result2=$localobject->create($user, 1); |
|
403 | - $result3=$localobject->validate($user, $result); |
|
399 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1940); // we use same year but fiscal month after |
|
400 | + $numbering = new mod_facture_mercure(); |
|
401 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
402 | + $result2 = $localobject->create($user, 1); |
|
403 | + $result3 = $localobject->validate($user, $result); |
|
404 | 404 | print __METHOD__." result=".$result."\n"; |
405 | - $this->assertEquals('194012-0001', $result); // counter must be reset to 1 |
|
405 | + $this->assertEquals('194012-0001', $result); // counter must be reset to 1 |
|
406 | 406 | |
407 | - $localobject=new Facture($db); |
|
407 | + $localobject = new Facture($db); |
|
408 | 408 | $localobject->initAsSpecimen(); |
409 | 409 | $localobject->fetch_thirdparty(); |
410 | 410 | |
411 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1941); // we use same fiscal year but different year |
|
412 | - $numbering=new mod_facture_mercure(); |
|
413 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
414 | - $result2=$localobject->create($user, 1); |
|
415 | - $result3=$localobject->validate($user, $result); |
|
411 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1941); // we use same fiscal year but different year |
|
412 | + $numbering = new mod_facture_mercure(); |
|
413 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
414 | + $result2 = $localobject->create($user, 1); |
|
415 | + $result3 = $localobject->validate($user, $result); |
|
416 | 416 | print __METHOD__." result=".$result."\n"; |
417 | - $this->assertEquals('194101-0002', $result); // counter must be 2 |
|
417 | + $this->assertEquals('194101-0002', $result); // counter must be 2 |
|
418 | 418 | |
419 | - $localobject=new Facture($db); |
|
419 | + $localobject = new Facture($db); |
|
420 | 420 | $localobject->initAsSpecimen(); |
421 | 421 | $localobject->fetch_thirdparty(); |
422 | 422 | |
423 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1941); // we use different discal year but same year |
|
424 | - $numbering=new mod_facture_mercure(); |
|
425 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
423 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1941); // we use different discal year but same year |
|
424 | + $numbering = new mod_facture_mercure(); |
|
425 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
426 | 426 | print __METHOD__." result=".$result."\n"; |
427 | - $this->assertEquals('194112-0001', $result); // counter must be reset to 1 |
|
427 | + $this->assertEquals('194112-0001', $result); // counter must be reset to 1 |
|
428 | 428 | |
429 | 429 | |
430 | 430 | // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want year of element |
431 | - $conf->global->SOCIETE_FISCAL_MONTH_START=6; |
|
432 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@=}'; |
|
433 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@=}'; |
|
431 | + $conf->global->SOCIETE_FISCAL_MONTH_START = 6; |
|
432 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}{mm}-{0000@=}'; |
|
433 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}{mm}-{0000@=}'; |
|
434 | 434 | |
435 | - $localobject=new Facture($db); |
|
435 | + $localobject = new Facture($db); |
|
436 | 436 | $localobject->initAsSpecimen(); |
437 | 437 | $localobject->fetch_thirdparty(); |
438 | 438 | |
439 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1950); // we use year 1950 to be sure to not have existing invoice for this year |
|
440 | - $numbering=new mod_facture_mercure(); |
|
441 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
442 | - $result2=$localobject->create($user, 1); |
|
443 | - $result3=$localobject->validate($user, $result); |
|
439 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1950); // we use year 1950 to be sure to not have existing invoice for this year |
|
440 | + $numbering = new mod_facture_mercure(); |
|
441 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
442 | + $result2 = $localobject->create($user, 1); |
|
443 | + $result3 = $localobject->validate($user, $result); |
|
444 | 444 | print __METHOD__." result=".$result."\n"; |
445 | - $this->assertEquals('195001-0001', $result); // counter must start to 1 |
|
445 | + $this->assertEquals('195001-0001', $result); // counter must start to 1 |
|
446 | 446 | |
447 | - $localobject=new Facture($db); |
|
447 | + $localobject = new Facture($db); |
|
448 | 448 | $localobject->initAsSpecimen(); |
449 | 449 | $localobject->fetch_thirdparty(); |
450 | 450 | |
451 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1950); // we use same year but fiscal month after |
|
452 | - $numbering=new mod_facture_mercure(); |
|
453 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
454 | - $result2=$localobject->create($user, 1); |
|
455 | - $result3=$localobject->validate($user, $result); |
|
451 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1950); // we use same year but fiscal month after |
|
452 | + $numbering = new mod_facture_mercure(); |
|
453 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
454 | + $result2 = $localobject->create($user, 1); |
|
455 | + $result3 = $localobject->validate($user, $result); |
|
456 | 456 | print __METHOD__." result=".$result."\n"; |
457 | - $this->assertEquals('195012-0001', $result); // counter must be reset to 1 |
|
457 | + $this->assertEquals('195012-0001', $result); // counter must be reset to 1 |
|
458 | 458 | |
459 | - $localobject=new Facture($db); |
|
459 | + $localobject = new Facture($db); |
|
460 | 460 | $localobject->initAsSpecimen(); |
461 | 461 | $localobject->fetch_thirdparty(); |
462 | 462 | |
463 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1951); // we use same fiscal year but different year |
|
464 | - $numbering=new mod_facture_mercure(); |
|
465 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
466 | - $result2=$localobject->create($user, 1); |
|
467 | - $result3=$localobject->validate($user, $result); |
|
463 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1951); // we use same fiscal year but different year |
|
464 | + $numbering = new mod_facture_mercure(); |
|
465 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
466 | + $result2 = $localobject->create($user, 1); |
|
467 | + $result3 = $localobject->validate($user, $result); |
|
468 | 468 | print __METHOD__." result=".$result."\n"; |
469 | - $this->assertEquals('195101-0002', $result); // counter must be 2 |
|
469 | + $this->assertEquals('195101-0002', $result); // counter must be 2 |
|
470 | 470 | |
471 | - $localobject=new Facture($db); |
|
471 | + $localobject = new Facture($db); |
|
472 | 472 | $localobject->initAsSpecimen(); |
473 | 473 | $localobject->fetch_thirdparty(); |
474 | 474 | |
475 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1951); // we use different discal year but same year |
|
476 | - $numbering=new mod_facture_mercure(); |
|
477 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
475 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1951); // we use different discal year but same year |
|
476 | + $numbering = new mod_facture_mercure(); |
|
477 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
478 | 478 | print __METHOD__." result=".$result."\n"; |
479 | - $this->assertEquals('195112-0001', $result); // counter must be reset to 1 |
|
479 | + $this->assertEquals('195112-0001', $result); // counter must be reset to 1 |
|
480 | 480 | |
481 | 481 | |
482 | 482 | // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want start year |
483 | - $conf->global->SOCIETE_FISCAL_MONTH_START=6; |
|
484 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@-}'; |
|
485 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@-}'; |
|
483 | + $conf->global->SOCIETE_FISCAL_MONTH_START = 6; |
|
484 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}{mm}-{0000@-}'; |
|
485 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}{mm}-{0000@-}'; |
|
486 | 486 | |
487 | - $localobject=new Facture($db); |
|
487 | + $localobject = new Facture($db); |
|
488 | 488 | $localobject->initAsSpecimen(); |
489 | 489 | $localobject->fetch_thirdparty(); |
490 | 490 | |
491 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1960); // we use year 1960 to be sure to not have existing invoice for this year |
|
492 | - $numbering=new mod_facture_mercure(); |
|
493 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
494 | - $result2=$localobject->create($user, 1); |
|
495 | - $result3=$localobject->validate($user, $result); |
|
491 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1960); // we use year 1960 to be sure to not have existing invoice for this year |
|
492 | + $numbering = new mod_facture_mercure(); |
|
493 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
494 | + $result2 = $localobject->create($user, 1); |
|
495 | + $result3 = $localobject->validate($user, $result); |
|
496 | 496 | print __METHOD__." result=".$result."\n"; |
497 | - $this->assertEquals('195901-0001', $result); // counter must start to 1 |
|
497 | + $this->assertEquals('195901-0001', $result); // counter must start to 1 |
|
498 | 498 | |
499 | - $localobject=new Facture($db); |
|
499 | + $localobject = new Facture($db); |
|
500 | 500 | $localobject->initAsSpecimen(); |
501 | 501 | $localobject->fetch_thirdparty(); |
502 | 502 | |
503 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1960); // we use same year but fiscal month after |
|
504 | - $numbering=new mod_facture_mercure(); |
|
505 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
506 | - $result2=$localobject->create($user, 1); |
|
507 | - $result3=$localobject->validate($user, $result); |
|
503 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1960); // we use same year but fiscal month after |
|
504 | + $numbering = new mod_facture_mercure(); |
|
505 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
506 | + $result2 = $localobject->create($user, 1); |
|
507 | + $result3 = $localobject->validate($user, $result); |
|
508 | 508 | print __METHOD__." result=".$result."\n"; |
509 | - $this->assertEquals('196012-0001', $result); // counter must be reset to 1 |
|
509 | + $this->assertEquals('196012-0001', $result); // counter must be reset to 1 |
|
510 | 510 | |
511 | - $localobject=new Facture($db); |
|
511 | + $localobject = new Facture($db); |
|
512 | 512 | $localobject->initAsSpecimen(); |
513 | 513 | $localobject->fetch_thirdparty(); |
514 | 514 | |
515 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1961); // we use same fiscal year but different year |
|
516 | - $numbering=new mod_facture_mercure(); |
|
517 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
518 | - $result2=$localobject->create($user, 1); |
|
519 | - $result3=$localobject->validate($user, $result); |
|
515 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1961); // we use same fiscal year but different year |
|
516 | + $numbering = new mod_facture_mercure(); |
|
517 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
518 | + $result2 = $localobject->create($user, 1); |
|
519 | + $result3 = $localobject->validate($user, $result); |
|
520 | 520 | print __METHOD__." result=".$result."\n"; |
521 | - $this->assertEquals('196001-0002', $result); // counter must be 2 |
|
521 | + $this->assertEquals('196001-0002', $result); // counter must be 2 |
|
522 | 522 | |
523 | - $localobject=new Facture($db); |
|
523 | + $localobject = new Facture($db); |
|
524 | 524 | $localobject->initAsSpecimen(); |
525 | 525 | $localobject->fetch_thirdparty(); |
526 | 526 | |
527 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1961); // we use different discal year but same year |
|
528 | - $numbering=new mod_facture_mercure(); |
|
529 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
527 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1961); // we use different discal year but same year |
|
528 | + $numbering = new mod_facture_mercure(); |
|
529 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
530 | 530 | print __METHOD__." result=".$result."\n"; |
531 | - $this->assertEquals('196112-0001', $result); // counter must be reset to 1 |
|
531 | + $this->assertEquals('196112-0001', $result); // counter must be reset to 1 |
|
532 | 532 | |
533 | 533 | |
534 | 534 | // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want end year |
535 | - $conf->global->SOCIETE_FISCAL_MONTH_START=6; |
|
536 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@+}'; |
|
537 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@+}'; |
|
535 | + $conf->global->SOCIETE_FISCAL_MONTH_START = 6; |
|
536 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}{mm}-{0000@+}'; |
|
537 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}{mm}-{0000@+}'; |
|
538 | 538 | |
539 | - $localobject=new Facture($db); |
|
539 | + $localobject = new Facture($db); |
|
540 | 540 | $localobject->initAsSpecimen(); |
541 | 541 | $localobject->fetch_thirdparty(); |
542 | 542 | |
543 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1970); // we use year 1970 to be sure to not have existing invoice for this year |
|
544 | - $numbering=new mod_facture_mercure(); |
|
545 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
546 | - $result2=$localobject->create($user, 1); |
|
547 | - $result3=$localobject->validate($user, $result); |
|
543 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1970); // we use year 1970 to be sure to not have existing invoice for this year |
|
544 | + $numbering = new mod_facture_mercure(); |
|
545 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
546 | + $result2 = $localobject->create($user, 1); |
|
547 | + $result3 = $localobject->validate($user, $result); |
|
548 | 548 | print __METHOD__." result=".$result."\n"; |
549 | - $this->assertEquals('197001-0001', $result); // counter must start to 1 |
|
549 | + $this->assertEquals('197001-0001', $result); // counter must start to 1 |
|
550 | 550 | |
551 | - $localobject=new Facture($db); |
|
551 | + $localobject = new Facture($db); |
|
552 | 552 | $localobject->initAsSpecimen(); |
553 | 553 | $localobject->fetch_thirdparty(); |
554 | 554 | |
555 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1970); // we use same year but fiscal month after |
|
556 | - $numbering=new mod_facture_mercure(); |
|
557 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
558 | - $result2=$localobject->create($user, 1); |
|
559 | - $result3=$localobject->validate($user, $result); |
|
555 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1970); // we use same year but fiscal month after |
|
556 | + $numbering = new mod_facture_mercure(); |
|
557 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
558 | + $result2 = $localobject->create($user, 1); |
|
559 | + $result3 = $localobject->validate($user, $result); |
|
560 | 560 | print __METHOD__." result=".$result."\n"; |
561 | - $this->assertEquals('197112-0001', $result); // counter must be reset to 1 |
|
561 | + $this->assertEquals('197112-0001', $result); // counter must be reset to 1 |
|
562 | 562 | |
563 | - $localobject=new Facture($db); |
|
563 | + $localobject = new Facture($db); |
|
564 | 564 | $localobject->initAsSpecimen(); |
565 | 565 | $localobject->fetch_thirdparty(); |
566 | 566 | |
567 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1971); // we use same fiscal year but different year |
|
568 | - $numbering=new mod_facture_mercure(); |
|
569 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
570 | - $result2=$localobject->create($user, 1); |
|
571 | - $result3=$localobject->validate($user, $result); |
|
567 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1971); // we use same fiscal year but different year |
|
568 | + $numbering = new mod_facture_mercure(); |
|
569 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
570 | + $result2 = $localobject->create($user, 1); |
|
571 | + $result3 = $localobject->validate($user, $result); |
|
572 | 572 | print __METHOD__." result=".$result."\n"; |
573 | - $this->assertEquals('197101-0002', $result); // counter must be 2 |
|
573 | + $this->assertEquals('197101-0002', $result); // counter must be 2 |
|
574 | 574 | |
575 | - $localobject=new Facture($db); |
|
575 | + $localobject = new Facture($db); |
|
576 | 576 | $localobject->initAsSpecimen(); |
577 | 577 | $localobject->fetch_thirdparty(); |
578 | 578 | |
579 | - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1971); // we use different fiscal year but same year |
|
580 | - $numbering=new mod_facture_mercure(); |
|
581 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
579 | + $localobject->date = dol_mktime(12, 0, 0, 12, 1, 1971); // we use different fiscal year but same year |
|
580 | + $numbering = new mod_facture_mercure(); |
|
581 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
582 | 582 | print __METHOD__." result=".$result."\n"; |
583 | - $this->assertEquals('197212-0001', $result); // counter must be reset to 1 |
|
583 | + $this->assertEquals('197212-0001', $result); // counter must be reset to 1 |
|
584 | 584 | |
585 | 585 | // Now we try with a reset every month (@99) |
586 | - $conf->global->SOCIETE_FISCAL_MONTH_START=6; |
|
587 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@99}'; |
|
588 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@99}'; |
|
586 | + $conf->global->SOCIETE_FISCAL_MONTH_START = 6; |
|
587 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{yyyy}{mm}-{0000@99}'; |
|
588 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{yyyy}{mm}-{0000@99}'; |
|
589 | 589 | |
590 | - $localobject=new Facture($db); |
|
590 | + $localobject = new Facture($db); |
|
591 | 591 | $localobject->initAsSpecimen(); |
592 | 592 | $localobject->fetch_thirdparty(); |
593 | 593 | |
594 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year |
|
595 | - $numbering=new mod_facture_mercure(); |
|
596 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
597 | - $result2=$localobject->create($user, 1); |
|
598 | - $result3=$localobject->validate($user, $result); |
|
594 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year |
|
595 | + $numbering = new mod_facture_mercure(); |
|
596 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
597 | + $result2 = $localobject->create($user, 1); |
|
598 | + $result3 = $localobject->validate($user, $result); |
|
599 | 599 | print __METHOD__." result=".$result."\n"; |
600 | - $this->assertEquals('198001-0001', $result); // counter must start to 1 |
|
600 | + $this->assertEquals('198001-0001', $result); // counter must start to 1 |
|
601 | 601 | |
602 | - $localobject=new Facture($db); |
|
602 | + $localobject = new Facture($db); |
|
603 | 603 | $localobject->initAsSpecimen(); |
604 | 604 | $localobject->fetch_thirdparty(); |
605 | 605 | |
606 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year |
|
607 | - $numbering=new mod_facture_mercure(); |
|
608 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
609 | - $result2=$localobject->create($user, 1); |
|
610 | - $result3=$localobject->validate($user, $result); |
|
606 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year |
|
607 | + $numbering = new mod_facture_mercure(); |
|
608 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
609 | + $result2 = $localobject->create($user, 1); |
|
610 | + $result3 = $localobject->validate($user, $result); |
|
611 | 611 | print __METHOD__." result=".$result."\n"; |
612 | - $this->assertEquals('198001-0002', $result); // counter must start to 2 |
|
612 | + $this->assertEquals('198001-0002', $result); // counter must start to 2 |
|
613 | 613 | |
614 | - $localobject=new Facture($db); |
|
614 | + $localobject = new Facture($db); |
|
615 | 615 | $localobject->initAsSpecimen(); |
616 | 616 | $localobject->fetch_thirdparty(); |
617 | 617 | |
618 | - $localobject->date=dol_mktime(12, 0, 0, 2, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year |
|
619 | - $numbering=new mod_facture_mercure(); |
|
620 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
621 | - $result2=$localobject->create($user, 1); |
|
622 | - $result3=$localobject->validate($user, $result); |
|
618 | + $localobject->date = dol_mktime(12, 0, 0, 2, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year |
|
619 | + $numbering = new mod_facture_mercure(); |
|
620 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
621 | + $result2 = $localobject->create($user, 1); |
|
622 | + $result3 = $localobject->validate($user, $result); |
|
623 | 623 | print __METHOD__." result=".$result."\n"; |
624 | - $this->assertEquals('198002-0001', $result); // counter must start to 1 |
|
624 | + $this->assertEquals('198002-0001', $result); // counter must start to 1 |
|
625 | 625 | |
626 | - $localobject=new Facture($db); |
|
626 | + $localobject = new Facture($db); |
|
627 | 627 | $localobject->initAsSpecimen(); |
628 | 628 | $localobject->fetch_thirdparty(); |
629 | 629 | |
630 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1981); // we use year 1981 to be sure to not have existing invoice for this year |
|
631 | - $numbering=new mod_facture_mercure(); |
|
632 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
633 | - $result2=$localobject->create($user, 1); |
|
634 | - $result3=$localobject->validate($user, $result); |
|
630 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1981); // we use year 1981 to be sure to not have existing invoice for this year |
|
631 | + $numbering = new mod_facture_mercure(); |
|
632 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
633 | + $result2 = $localobject->create($user, 1); |
|
634 | + $result3 = $localobject->validate($user, $result); |
|
635 | 635 | print __METHOD__." result=".$result."\n"; |
636 | - $this->assertEquals('198101-0001', $result); // counter must start to 1 |
|
636 | + $this->assertEquals('198101-0001', $result); // counter must start to 1 |
|
637 | 637 | |
638 | 638 | // Test with {t} tag |
639 | - $conf->global->SOCIETE_FISCAL_MONTH_START=1; |
|
640 | - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{t}{yyyy}{mm}-{0000}'; |
|
641 | - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{t}{yyyy}{mm}-{0000}'; |
|
639 | + $conf->global->SOCIETE_FISCAL_MONTH_START = 1; |
|
640 | + $conf->global->FACTURE_MERCURE_MASK_CREDIT = '{t}{yyyy}{mm}-{0000}'; |
|
641 | + $conf->global->FACTURE_MERCURE_MASK_INVOICE = '{t}{yyyy}{mm}-{0000}'; |
|
642 | 642 | |
643 | - $tmpthirdparty=new Societe($db); |
|
643 | + $tmpthirdparty = new Societe($db); |
|
644 | 644 | $tmpthirdparty->initAsSpecimen(); |
645 | 645 | $tmpthirdparty->typent_code = 'TE_ABC'; |
646 | 646 | |
647 | - $localobject=new Facture($db); |
|
647 | + $localobject = new Facture($db); |
|
648 | 648 | $localobject->initAsSpecimen(); |
649 | 649 | $localobject->fetch_thirdparty(); |
650 | 650 | |
651 | - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1982); // we use year 1982 to be sure to not have existing invoice for this year |
|
652 | - $numbering=new mod_facture_mercure(); |
|
653 | - $result=$numbering->getNextValue($tmpthirdparty, $localobject); |
|
654 | - $result2=$localobject->create($user, 1); |
|
655 | - $result3=$localobject->validate($user, $result); |
|
651 | + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 1982); // we use year 1982 to be sure to not have existing invoice for this year |
|
652 | + $numbering = new mod_facture_mercure(); |
|
653 | + $result = $numbering->getNextValue($tmpthirdparty, $localobject); |
|
654 | + $result2 = $localobject->create($user, 1); |
|
655 | + $result3 = $localobject->validate($user, $result); |
|
656 | 656 | print __METHOD__." result=".$result."\n"; |
657 | - $this->assertEquals('A198201-0001', $result); // counter must start to 1 |
|
657 | + $this->assertEquals('A198201-0001', $result); // counter must start to 1 |
|
658 | 658 | |
659 | 659 | |
660 | 660 | return $result; |
@@ -668,24 +668,24 @@ discard block |
||
668 | 668 | */ |
669 | 669 | public function testShipmentSafor() |
670 | 670 | { |
671 | - global $conf,$user,$langs,$db,$mysoc; |
|
672 | - $conf=$this->savconf; |
|
673 | - $user=$this->savuser; |
|
674 | - $langs=$this->savlangs; |
|
675 | - $db=$this->savdb; |
|
671 | + global $conf, $user, $langs, $db, $mysoc; |
|
672 | + $conf = $this->savconf; |
|
673 | + $user = $this->savuser; |
|
674 | + $langs = $this->savlangs; |
|
675 | + $db = $this->savdb; |
|
676 | 676 | |
677 | 677 | require_once dirname(__FILE__).'/../../htdocs/expedition/class/expedition.class.php'; |
678 | 678 | require_once dirname(__FILE__).'/../../htdocs/core/modules/expedition/mod_expedition_safor.php'; |
679 | 679 | |
680 | - $localobject=new Expedition($db); |
|
680 | + $localobject = new Expedition($db); |
|
681 | 681 | $localobject->initAsSpecimen(); |
682 | 682 | $localobject->fetch_thirdparty(); |
683 | 683 | |
684 | - $localobject->date_creation = dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1915 to be sure to not have existing invoice for this year (useful only if numbering is {0000@1} |
|
685 | - $numbering=new mod_expedition_safor(); |
|
686 | - $result=$numbering->getNextValue($mysoc, $localobject); |
|
684 | + $localobject->date_creation = dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1915 to be sure to not have existing invoice for this year (useful only if numbering is {0000@1} |
|
685 | + $numbering = new mod_expedition_safor(); |
|
686 | + $result = $numbering->getNextValue($mysoc, $localobject); |
|
687 | 687 | |
688 | 688 | print __METHOD__." result=".$result."\n"; |
689 | - $this->assertEquals('SH8001-0003', $result); // counter must start to 1 |
|
689 | + $this->assertEquals('SH8001-0003', $result); // counter must start to 1 |
|
690 | 690 | } |
691 | 691 | } |
@@ -24,32 +24,32 @@ discard block |
||
24 | 24 | * \remarks To run this script as CLI: phpunit filename.php |
25 | 25 | */ |
26 | 26 | |
27 | -global $conf,$user,$langs,$db; |
|
27 | +global $conf, $user, $langs, $db; |
|
28 | 28 | //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver |
29 | 29 | //require_once 'PHPUnit/Autoload.php'; |
30 | 30 | |
31 | -if (! defined('NOREQUIRESOC')) { |
|
31 | +if (!defined('NOREQUIRESOC')) { |
|
32 | 32 | define('NOREQUIRESOC', '1'); |
33 | 33 | } |
34 | -if (! defined('NOCSRFCHECK')) { |
|
34 | +if (!defined('NOCSRFCHECK')) { |
|
35 | 35 | define('NOCSRFCHECK', '1'); |
36 | 36 | } |
37 | -if (! defined('NOTOKENRENEWAL')) { |
|
37 | +if (!defined('NOTOKENRENEWAL')) { |
|
38 | 38 | define('NOTOKENRENEWAL', '1'); |
39 | 39 | } |
40 | -if (! defined('NOREQUIREMENU')) { |
|
40 | +if (!defined('NOREQUIREMENU')) { |
|
41 | 41 | define('NOREQUIREMENU', '1'); // If there is no menu to show |
42 | 42 | } |
43 | -if (! defined('NOREQUIREHTML')) { |
|
43 | +if (!defined('NOREQUIREHTML')) { |
|
44 | 44 | define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php |
45 | 45 | } |
46 | -if (! defined('NOREQUIREAJAX')) { |
|
46 | +if (!defined('NOREQUIREAJAX')) { |
|
47 | 47 | define('NOREQUIREAJAX', '1'); |
48 | 48 | } |
49 | -if (! defined("NOLOGIN")) { |
|
50 | - define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
49 | +if (!defined("NOLOGIN")) { |
|
50 | + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
51 | 51 | } |
52 | -if (! defined("NOSESSION")) { |
|
52 | +if (!defined("NOSESSION")) { |
|
53 | 53 | define("NOSESSION", '1'); |
54 | 54 | } |
55 | 55 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $user->fetch(1); |
64 | 64 | $user->getrights(); |
65 | 65 | } |
66 | -$conf->global->MAIN_DISABLE_ALL_MAILS=1; |
|
66 | +$conf->global->MAIN_DISABLE_ALL_MAILS = 1; |
|
67 | 67 | |
68 | 68 | |
69 | 69 | /** |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | parent::__construct($name); |
93 | 93 | |
94 | 94 | //$this->sharedFixture |
95 | - global $conf,$user,$langs,$db; |
|
96 | - $this->savconf=$conf; |
|
97 | - $this->savuser=$user; |
|
98 | - $this->savlangs=$langs; |
|
99 | - $this->savdb=$db; |
|
95 | + global $conf, $user, $langs, $db; |
|
96 | + $this->savconf = $conf; |
|
97 | + $this->savuser = $user; |
|
98 | + $this->savlangs = $langs; |
|
99 | + $this->savdb = $db; |
|
100 | 100 | |
101 | 101 | print __METHOD__." db->type=".$db->type." user->id=".$user->id; |
102 | 102 | //print " - db ".$db->db; |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public static function setUpBeforeClass(): void |
112 | 112 | { |
113 | - global $conf,$user,$langs,$db; |
|
114 | - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
113 | + global $conf, $user, $langs, $db; |
|
114 | + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. |
|
115 | 115 | |
116 | 116 | print __METHOD__."\n"; |
117 | 117 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public static function tearDownAfterClass(): void |
125 | 125 | { |
126 | - global $conf,$user,$langs,$db; |
|
126 | + global $conf, $user, $langs, $db; |
|
127 | 127 | $db->rollback(); |
128 | 128 | |
129 | 129 | // Restore value to a neutral value (it was set to a test value by some tests) |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function setUp(): void |
141 | 141 | { |
142 | - global $conf,$user,$langs,$db; |
|
143 | - $conf=$this->savconf; |
|
144 | - $user=$this->savuser; |
|
145 | - $langs=$this->savlangs; |
|
146 | - $db=$this->savdb; |
|
142 | + global $conf, $user, $langs, $db; |
|
143 | + $conf = $this->savconf; |
|
144 | + $user = $this->savuser; |
|
145 | + $langs = $this->savlangs; |
|
146 | + $db = $this->savdb; |
|
147 | 147 | |
148 | 148 | print __METHOD__."\n"; |
149 | 149 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public function testSetLang() |
167 | 167 | { |
168 | 168 | global $conf; |
169 | - $conf=$this->savconf; |
|
169 | + $conf = $this->savconf; |
|
170 | 170 | |
171 | 171 | $tmplangs = new Translate('', $conf); |
172 | 172 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet |
189 | 189 | |
190 | 190 | // Should be OK |
191 | - $expectedresult=0; |
|
191 | + $expectedresult = 0; |
|
192 | 192 | |
193 | 193 | /* |
194 | 194 | $test = ''; |
@@ -196,107 +196,107 @@ discard block |
||
196 | 196 | $this->assertGreaterThanOrEqual(0, $result, 'Error on testSqlAndScriptInject kkk'); |
197 | 197 | */ |
198 | 198 | |
199 | - $_SERVER["PHP_SELF"]='/DIR WITH SPACE/htdocs/admin/index.php'; |
|
200 | - $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); |
|
199 | + $_SERVER["PHP_SELF"] = '/DIR WITH SPACE/htdocs/admin/index.php'; |
|
200 | + $result = testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); |
|
201 | 201 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for PHP_SELF that should be ok'); |
202 | 202 | |
203 | 203 | $test = 'This is a < inside string with < and > also and tag like <a> before the >'; |
204 | - $result=testSqlAndScriptInject($test, 0); |
|
204 | + $result = testSqlAndScriptInject($test, 0); |
|
205 | 205 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject expected 0b'); |
206 | 206 | |
207 | 207 | $test = 'This is the union of all for the selection of the best'; |
208 | - $result=testSqlAndScriptInject($test, 0); |
|
208 | + $result = testSqlAndScriptInject($test, 0); |
|
209 | 209 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject expected 0c'); |
210 | 210 | |
211 | - $test='/user/perms.php?id=1&action=addrights&entity=1&rights=123&confirm=yes&token=123456789&updatedmodulename=lmscoursetracking'; |
|
212 | - $result=testSqlAndScriptInject($test, 1); |
|
211 | + $test = '/user/perms.php?id=1&action=addrights&entity=1&rights=123&confirm=yes&token=123456789&updatedmodulename=lmscoursetracking'; |
|
212 | + $result = testSqlAndScriptInject($test, 1); |
|
213 | 213 | print "test=".$test." result=".$result."\n"; |
214 | 214 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject with a valid url'); |
215 | 215 | |
216 | 216 | // Should detect attack |
217 | - $expectedresult=1; |
|
217 | + $expectedresult = 1; |
|
218 | 218 | |
219 | - $_SERVER["PHP_SELF"]='/DIR WITH SPACE/htdocs/admin/index.php/<svg>'; |
|
220 | - $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); |
|
219 | + $_SERVER["PHP_SELF"] = '/DIR WITH SPACE/htdocs/admin/index.php/<svg>'; |
|
220 | + $result = testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); |
|
221 | 221 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject for PHP_SELF that should detect XSS'); |
222 | 222 | |
223 | 223 | $test = 'select @@version'; |
224 | - $result=testSqlAndScriptInject($test, 0); |
|
224 | + $result = testSqlAndScriptInject($test, 0); |
|
225 | 225 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for SQL1a. Should find an attack on POST param and did not.'); |
226 | 226 | |
227 | 227 | $test = 'select @@version'; |
228 | - $result=testSqlAndScriptInject($test, 1); |
|
228 | + $result = testSqlAndScriptInject($test, 1); |
|
229 | 229 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for SQL1b. Should find an attack on GET param and did not.'); |
230 | 230 | |
231 | 231 | $test = '... update ... set ... ='; |
232 | - $result=testSqlAndScriptInject($test, 1); |
|
232 | + $result = testSqlAndScriptInject($test, 1); |
|
233 | 233 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for SQL2a. Should find an attack on GET param and did not.'); |
234 | 234 | |
235 | 235 | $test = "delete\nfrom"; |
236 | - $result=testSqlAndScriptInject($test, 1); |
|
236 | + $result = testSqlAndScriptInject($test, 1); |
|
237 | 237 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for SQL2b. Should find an attack on GET param and did not.'); |
238 | 238 | |
239 | 239 | $test = 'action=update& ... set ... ='; |
240 | - $result=testSqlAndScriptInject($test, 1); |
|
240 | + $result = testSqlAndScriptInject($test, 1); |
|
241 | 241 | $this->assertEquals(0, $result, 'Error on testSqlAndScriptInject for SQL2b. Should not find an attack on GET param and did.'); |
242 | 242 | |
243 | 243 | $test = '... union ... selection '; |
244 | - $result=testSqlAndScriptInject($test, 1); |
|
244 | + $result = testSqlAndScriptInject($test, 1); |
|
245 | 245 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for SQL2c. Should find an attack on GET param and did not.'); |
246 | 246 | |
247 | 247 | $test = 'javascript:'; |
248 | - $result=testSqlAndScriptInject($test, 0); |
|
248 | + $result = testSqlAndScriptInject($test, 0); |
|
249 | 249 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for javascript1. Should find an attack and did not.'); |
250 | 250 | |
251 | 251 | $test = 'javascript:'; |
252 | - $result=testSqlAndScriptInject($test, 0); |
|
252 | + $result = testSqlAndScriptInject($test, 0); |
|
253 | 253 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for javascript2. Should find an attack and did not.'); |
254 | 254 | |
255 | 255 | $test = 'javascript&colon;alert(1)'; |
256 | - $result=testSqlAndScriptInject($test, 0); |
|
256 | + $result = testSqlAndScriptInject($test, 0); |
|
257 | 257 | $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for javascript2'); |
258 | 258 | |
259 | - $test="<img src='1.jpg' onerror =javascript:alert('XSS')>"; |
|
260 | - $result=testSqlAndScriptInject($test, 0); |
|
259 | + $test = "<img src='1.jpg' onerror =javascript:alert('XSS')>"; |
|
260 | + $result = testSqlAndScriptInject($test, 0); |
|
261 | 261 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa1'); |
262 | 262 | |
263 | - $test="<img src='1.jpg' onerror =javascript:alert('XSS')>"; |
|
264 | - $result=testSqlAndScriptInject($test, 2); |
|
263 | + $test = "<img src='1.jpg' onerror =javascript:alert('XSS')>"; |
|
264 | + $result = testSqlAndScriptInject($test, 2); |
|
265 | 265 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa2'); |
266 | 266 | |
267 | - $test='<IMG SRC=# onmouseover="alert(1)">'; |
|
268 | - $result=testSqlAndScriptInject($test, 0); |
|
267 | + $test = '<IMG SRC=# onmouseover="alert(1)">'; |
|
268 | + $result = testSqlAndScriptInject($test, 0); |
|
269 | 269 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa3'); |
270 | - $test='<IMG SRC onmouseover="alert(1)">'; |
|
271 | - $result=testSqlAndScriptInject($test, 0); |
|
270 | + $test = '<IMG SRC onmouseover="alert(1)">'; |
|
271 | + $result = testSqlAndScriptInject($test, 0); |
|
272 | 272 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa4'); |
273 | - $test='<IMG onmouseover="alert(1)">'; |
|
274 | - $result=testSqlAndScriptInject($test, 0); |
|
273 | + $test = '<IMG onmouseover="alert(1)">'; |
|
274 | + $result = testSqlAndScriptInject($test, 0); |
|
275 | 275 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa5'); |
276 | - $test='<IMG SRC=/ onerror="alert(1)">'; |
|
277 | - $result=testSqlAndScriptInject($test, 0); |
|
276 | + $test = '<IMG SRC=/ onerror="alert(1)">'; |
|
277 | + $result = testSqlAndScriptInject($test, 0); |
|
278 | 278 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa6'); |
279 | - $test='<IMG SRC="  javascript:alert(1);">'; |
|
280 | - $result=testSqlAndScriptInject($test, 0); |
|
279 | + $test = '<IMG SRC="  javascript:alert(1);">'; |
|
280 | + $result = testSqlAndScriptInject($test, 0); |
|
281 | 281 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa7'); |
282 | 282 | |
283 | - $test='<IMG SRC=javascript:alert('XSS')>'; |
|
284 | - $result=testSqlAndScriptInject($test, 0); |
|
283 | + $test = '<IMG SRC=javascript:alert('XSS')>'; |
|
284 | + $result = testSqlAndScriptInject($test, 0); |
|
285 | 285 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject bbb'); |
286 | 286 | |
287 | - $test='<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>'; |
|
288 | - $result=testSqlAndScriptInject($test, 0); |
|
287 | + $test = '<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>'; |
|
288 | + $result = testSqlAndScriptInject($test, 0); |
|
289 | 289 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ccc'); |
290 | 290 | |
291 | - $test='<IMG SRC="javascript:alert(\'XSS\');">'; |
|
292 | - $result=testSqlAndScriptInject($test, 1); |
|
291 | + $test = '<IMG SRC="javascript:alert(\'XSS\');">'; |
|
292 | + $result = testSqlAndScriptInject($test, 1); |
|
293 | 293 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ddd'); |
294 | 294 | |
295 | - $test='<IMG """><SCRIPT>alert("XSS")</SCRIPT>">'; |
|
296 | - $result=testSqlAndScriptInject($test, 0); |
|
295 | + $test = '<IMG """><SCRIPT>alert("XSS")</SCRIPT>">'; |
|
296 | + $result = testSqlAndScriptInject($test, 0); |
|
297 | 297 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); |
298 | 298 | |
299 | - $test='<!-- Google analytics --> |
|
299 | + $test = '<!-- Google analytics --> |
|
300 | 300 | <script> |
301 | 301 | (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){ |
302 | 302 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
@@ -307,60 +307,60 @@ discard block |
||
307 | 307 | ga(\'send\', \'pageview\'); |
308 | 308 | |
309 | 309 | </script>'; |
310 | - $result=testSqlAndScriptInject($test, 0); |
|
310 | + $result = testSqlAndScriptInject($test, 0); |
|
311 | 311 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); |
312 | 312 | |
313 | - $test="<IMG SRC=\"jav\tascript:alert('XSS');\">"; // Is locked by some browser like chrome because the default directive no-referrer-when-downgrade is sent when requesting the SRC and then refused because of browser protection on img src load without referrer. |
|
314 | - $test="<IMG SRC=\"jav
ascript:alert('XSS');\">"; // Same |
|
313 | + $test = "<IMG SRC=\"jav\tascript:alert('XSS');\">"; // Is locked by some browser like chrome because the default directive no-referrer-when-downgrade is sent when requesting the SRC and then refused because of browser protection on img src load without referrer. |
|
314 | + $test = "<IMG SRC=\"jav
ascript:alert('XSS');\">"; // Same |
|
315 | 315 | |
316 | - $test='<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
317 | - $result=testSqlAndScriptInject($test, 0); |
|
316 | + $test = '<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
317 | + $result = testSqlAndScriptInject($test, 0); |
|
318 | 318 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff1'); |
319 | - $test='<SCRIPT/SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
320 | - $result=testSqlAndScriptInject($test, 0); |
|
319 | + $test = '<SCRIPT/SRC="http://xss.rocks/xss.js"></SCRIPT>'; |
|
320 | + $result = testSqlAndScriptInject($test, 0); |
|
321 | 321 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff2'); |
322 | 322 | |
323 | 323 | // This case seems to be filtered by browsers now. |
324 | - $test='<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert(1)>'; |
|
324 | + $test = '<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert(1)>'; |
|
325 | 325 | //$result=testSqlAndScriptInject($test, 0); |
326 | 326 | //$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ggg'); |
327 | 327 | |
328 | - $test='<iframe src=http://xss.rocks/scriptlet.html <'; |
|
329 | - $result=testSqlAndScriptInject($test, 0); |
|
328 | + $test = '<iframe src=http://xss.rocks/scriptlet.html <'; |
|
329 | + $result = testSqlAndScriptInject($test, 0); |
|
330 | 330 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject hhh'); |
331 | 331 | |
332 | - $test='Set.constructor`alert\x281\x29```'; |
|
333 | - $result=testSqlAndScriptInject($test, 0); |
|
332 | + $test = 'Set.constructor`alert\x281\x29```'; |
|
333 | + $result = testSqlAndScriptInject($test, 0); |
|
334 | 334 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject iii'); |
335 | 335 | |
336 | - $test="on<!-- ab\nc -->error=alert(1)"; |
|
337 | - $result=testSqlAndScriptInject($test, 0); |
|
336 | + $test = "on<!-- ab\nc -->error=alert(1)"; |
|
337 | + $result = testSqlAndScriptInject($test, 0); |
|
338 | 338 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject jjj'); |
339 | 339 | |
340 | - $test="<img src=x one<a>rror=alert(document.location)"; |
|
341 | - $result=testSqlAndScriptInject($test, 0); |
|
340 | + $test = "<img src=x one<a>rror=alert(document.location)"; |
|
341 | + $result = testSqlAndScriptInject($test, 0); |
|
342 | 342 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject kkk'); |
343 | 343 | |
344 | - $test="<a onpointerdown=alert(document.domain)>XSS</a>"; |
|
345 | - $result=testSqlAndScriptInject($test, 0); |
|
344 | + $test = "<a onpointerdown=alert(document.domain)>XSS</a>"; |
|
345 | + $result = testSqlAndScriptInject($test, 0); |
|
346 | 346 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject lll'); |
347 | 347 | |
348 | - $test='<a onscrollend=alert(1) style="display:block;overflow:auto;border:1px+dashed;width:500px;height:100px;"><br><br><br><br><br><span+id=x>test</span></a>'; // Add the char %F6 into the variable |
|
349 | - $result=testSqlAndScriptInject($test, 0); |
|
348 | + $test = '<a onscrollend=alert(1) style="display:block;overflow:auto;border:1px+dashed;width:500px;height:100px;"><br><br><br><br><br><span+id=x>test</span></a>'; // Add the char %F6 into the variable |
|
349 | + $result = testSqlAndScriptInject($test, 0); |
|
350 | 350 | //print "test=".$test." result=".$result."\n"; |
351 | 351 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject mmm'); |
352 | 352 | |
353 | 353 | |
354 | - $test="Text with ' encoded with the numeric html entity converted into text entity ' (like when submitted by CKEditor)"; |
|
355 | - $result=testSqlAndScriptInject($test, 0); // result must be 0 |
|
354 | + $test = "Text with ' encoded with the numeric html entity converted into text entity ' (like when submitted by CKEditor)"; |
|
355 | + $result = testSqlAndScriptInject($test, 0); // result must be 0 |
|
356 | 356 | $this->assertEquals(0, $result, 'Error on testSqlAndScriptInject mmm, result should be 0 and is not'); |
357 | 357 | |
358 | - $test ='<a href="j	a	v	asc
ri	pt:(a	l	e	r	t	(document.cookie))">XSS</a>'; |
|
359 | - $result=testSqlAndScriptInject($test, 0); |
|
358 | + $test = '<a href="j	a	v	asc
ri	pt:(a	l	e	r	t	(document.cookie))">XSS</a>'; |
|
359 | + $result = testSqlAndScriptInject($test, 0); |
|
360 | 360 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject nnn, result should be >= 1 and is not'); |
361 | 361 | |
362 | - $test="/dolibarr/htdocs/index.php/".chr('246')."abc"; // Add the char %F6 into the variable |
|
363 | - $result=testSqlAndScriptInject($test, 2); |
|
362 | + $test = "/dolibarr/htdocs/index.php/".chr('246')."abc"; // Add the char %F6 into the variable |
|
363 | + $result = testSqlAndScriptInject($test, 2); |
|
364 | 364 | //print "test=".$test." result=".$result."\n"; |
365 | 365 | $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject with a non valid UTF8 char'); |
366 | 366 | } |
@@ -372,11 +372,11 @@ discard block |
||
372 | 372 | */ |
373 | 373 | public function testGETPOST() |
374 | 374 | { |
375 | - global $conf,$user,$langs,$db; |
|
376 | - $conf=$this->savconf; |
|
377 | - $user=$this->savuser; |
|
378 | - $langs=$this->savlangs; |
|
379 | - $db=$this->savdb; |
|
375 | + global $conf, $user, $langs, $db; |
|
376 | + $conf = $this->savconf; |
|
377 | + $user = $this->savuser; |
|
378 | + $langs = $this->savlangs; |
|
379 | + $db = $this->savdb; |
|
380 | 380 | |
381 | 381 | // Force default mode |
382 | 382 | $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 0; |
@@ -384,206 +384,206 @@ discard block |
||
384 | 384 | $conf->global->MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES = 0; |
385 | 385 | $conf->global->MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 0; |
386 | 386 | |
387 | - $_COOKIE["id"]=111; |
|
388 | - $_POST["param0"]='A real string with <a href="rrr" title="aa"bb">aaa</a> and " and \' and & inside content'; |
|
389 | - $_GET["param1"]="222"; |
|
390 | - $_POST["param1"]="333"; |
|
391 | - $_GET["param2"]='a/b#e(pr)qq-rr\cc'; |
|
392 | - $_GET["param3"]='"na/b#e(pr)qq-rr\cc'; // Same than param2 + " and n |
|
393 | - $_GET["param4a"]='../../dir'; |
|
394 | - $_GET["param4b"]='..\..\dirwindows'; |
|
395 | - $_GET["param5"]="a_1-b"; |
|
396 | - $_POST["param6"]=""><svg onload='console.log("123")'>"; |
|
397 | - $_POST["param6b"]='<<<../>../>../svg><<<../>../>../animate =alert(1)>abc'; |
|
398 | - $_GET["param7"]='"c:\this is a path~1\aaan &#x110;" abc<bad>def</bad>'; |
|
399 | - $_POST["param8a"]="Hacker<svg onload='console.log("123")'"; // html tag is not closed so it is not detected as html tag but is still harmfull |
|
400 | - $_POST['param8b']='<img src=x onerror=alert(document.location) t='; // this is html obfuscated by non closing tag |
|
401 | - $_POST['param8c']='< with space after is ok'; |
|
402 | - $_POST['param8d']='<abc123 is html to clean'; |
|
403 | - $_POST['param8e']='<123abc is not html to clean'; // other similar case: '<2021-12-12' |
|
404 | - $_POST['param8f']='abc<<svg <><<animate onbegin=alert(document.domain) a'; |
|
405 | - $_POST["param9"]='is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : \'objnotdefined\''; |
|
406 | - $_POST["param10"]='is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : \'<abc>objnotdefined\''; |
|
407 | - $_POST["param11"]=' Name <[email protected]> '; |
|
408 | - $_POST["param12"]='<!DOCTYPE html><html>aaa</html>'; |
|
409 | - $_POST["param13"]='n n > < " <a href=\"javascript:alert(document.domain)\">XSS</a>'; |
|
410 | - $_POST["param13b"]='n n > < " <a href=\"javascript:alert(document.domain)\">XSS</a>'; |
|
411 | - $_POST["param14"]="Text with ' encoded with the numeric html entity converted into text entity ' (like when submitted by CKEditor)"; |
|
412 | - $_POST["param15"]="<img onerror<=alert(document.domain)> src=>0xbeefed"; |
|
387 | + $_COOKIE["id"] = 111; |
|
388 | + $_POST["param0"] = 'A real string with <a href="rrr" title="aa"bb">aaa</a> and " and \' and & inside content'; |
|
389 | + $_GET["param1"] = "222"; |
|
390 | + $_POST["param1"] = "333"; |
|
391 | + $_GET["param2"] = 'a/b#e(pr)qq-rr\cc'; |
|
392 | + $_GET["param3"] = '"na/b#e(pr)qq-rr\cc'; // Same than param2 + " and n |
|
393 | + $_GET["param4a"] = '../../dir'; |
|
394 | + $_GET["param4b"] = '..\..\dirwindows'; |
|
395 | + $_GET["param5"] = "a_1-b"; |
|
396 | + $_POST["param6"] = ""><svg onload='console.log("123")'>"; |
|
397 | + $_POST["param6b"] = '<<<../>../>../svg><<<../>../>../animate =alert(1)>abc'; |
|
398 | + $_GET["param7"] = '"c:\this is a path~1\aaan &#x110;" abc<bad>def</bad>'; |
|
399 | + $_POST["param8a"] = "Hacker<svg onload='console.log("123")'"; // html tag is not closed so it is not detected as html tag but is still harmfull |
|
400 | + $_POST['param8b'] = '<img src=x onerror=alert(document.location) t='; // this is html obfuscated by non closing tag |
|
401 | + $_POST['param8c'] = '< with space after is ok'; |
|
402 | + $_POST['param8d'] = '<abc123 is html to clean'; |
|
403 | + $_POST['param8e'] = '<123abc is not html to clean'; // other similar case: '<2021-12-12' |
|
404 | + $_POST['param8f'] = 'abc<<svg <><<animate onbegin=alert(document.domain) a'; |
|
405 | + $_POST["param9"] = 'is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : \'objnotdefined\''; |
|
406 | + $_POST["param10"] = 'is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : \'<abc>objnotdefined\''; |
|
407 | + $_POST["param11"] = ' Name <[email protected]> '; |
|
408 | + $_POST["param12"] = '<!DOCTYPE html><html>aaa</html>'; |
|
409 | + $_POST["param13"] = 'n n > < " <a href=\"javascript:alert(document.domain)\">XSS</a>'; |
|
410 | + $_POST["param13b"] = 'n n > < " <a href=\"javascript:alert(document.domain)\">XSS</a>'; |
|
411 | + $_POST["param14"] = "Text with ' encoded with the numeric html entity converted into text entity ' (like when submitted by CKEditor)"; |
|
412 | + $_POST["param15"] = "<img onerror<=alert(document.domain)> src=>0xbeefed"; |
|
413 | 413 | //$_POST["param15b"]="<html><head><title>Example HTML</title></head><body><div><p>This is a paragraph.</div><ul><li>Item 1</li><li>Item 2</li></ol></body><html>"; |
414 | - $_POST["param16"]='<a style="z-index: 1000">abc</a>'; |
|
415 | - $_POST["param17"]='<span style="background-image: url(logout.php)">abc</span>'; |
|
416 | - $_POST["param18"]='<span style="background-image: url(...?...action=aaa)">abc</span>'; |
|
417 | - $_POST["param19"]='<a href="j	a	v	asc
ri	pt:(alert(document.cookie))">XSS</a>'; |
|
414 | + $_POST["param16"] = '<a style="z-index: 1000">abc</a>'; |
|
415 | + $_POST["param17"] = '<span style="background-image: url(logout.php)">abc</span>'; |
|
416 | + $_POST["param18"] = '<span style="background-image: url(...?...action=aaa)">abc</span>'; |
|
417 | + $_POST["param19"] = '<a href="j	a	v	asc
ri	pt:(alert(document.cookie))">XSS</a>'; |
|
418 | 418 | //$_POST["param19"]='<a href="javascript:alert(document.cookie)">XSS</a>'; |
419 | 419 | |
420 | 420 | |
421 | 421 | |
422 | - $result=GETPOST('id', 'int'); // Must return nothing |
|
422 | + $result = GETPOST('id', 'int'); // Must return nothing |
|
423 | 423 | print __METHOD__." result=".$result."\n"; |
424 | 424 | $this->assertEquals('', $result); |
425 | 425 | |
426 | - $result=GETPOST("param1", 'int'); |
|
426 | + $result = GETPOST("param1", 'int'); |
|
427 | 427 | print __METHOD__." result=".$result."\n"; |
428 | 428 | $this->assertEquals(222, $result, 'Test on param1 with no 3rd param'); |
429 | 429 | |
430 | - $result=GETPOST("param1", 'int', 2); |
|
430 | + $result = GETPOST("param1", 'int', 2); |
|
431 | 431 | print __METHOD__." result=".$result."\n"; |
432 | 432 | $this->assertEquals(333, $result, 'Test on param1 with 3rd param = 2'); |
433 | 433 | |
434 | 434 | // Test with alpha |
435 | 435 | |
436 | - $result=GETPOST("param0", 'alpha'); // a simple format, so " completely removed |
|
436 | + $result = GETPOST("param0", 'alpha'); // a simple format, so " completely removed |
|
437 | 437 | $resultexpected = 'A real string with aaa and and \' and & inside content'; |
438 | 438 | print __METHOD__." result=".$result."\n"; |
439 | 439 | $this->assertEquals($resultexpected, $result, 'Test on param0'); |
440 | 440 | |
441 | - $result=GETPOST("param2", 'alpha'); |
|
441 | + $result = GETPOST("param2", 'alpha'); |
|
442 | 442 | print __METHOD__." result=".$result."\n"; |
443 | 443 | $this->assertEquals($result, $_GET["param2"], 'Test on param2'); |
444 | 444 | |
445 | - $result=GETPOST("param3", 'alpha'); // Must return string sanitized from char " |
|
445 | + $result = GETPOST("param3", 'alpha'); // Must return string sanitized from char " |
|
446 | 446 | print __METHOD__." result=".$result."\n"; |
447 | 447 | $this->assertEquals($result, 'na/b#e(pr)qq-rr\cc', 'Test on param3'); |
448 | 448 | |
449 | - $result=GETPOST("param4a", 'alpha'); // Must return string sanitized from ../ |
|
449 | + $result = GETPOST("param4a", 'alpha'); // Must return string sanitized from ../ |
|
450 | 450 | print __METHOD__." result=".$result."\n"; |
451 | 451 | $this->assertEquals($result, 'dir'); |
452 | 452 | |
453 | - $result=GETPOST("param4b", 'alpha'); // Must return string sanitized from ../ |
|
453 | + $result = GETPOST("param4b", 'alpha'); // Must return string sanitized from ../ |
|
454 | 454 | print __METHOD__." result=".$result."\n"; |
455 | 455 | $this->assertEquals($result, 'dirwindows'); |
456 | 456 | |
457 | 457 | // Test with aZ09 |
458 | 458 | |
459 | - $result=GETPOST("param1", 'aZ09'); |
|
459 | + $result = GETPOST("param1", 'aZ09'); |
|
460 | 460 | print __METHOD__." result=".$result."\n"; |
461 | 461 | $this->assertEquals($result, $_GET["param1"]); |
462 | 462 | |
463 | - $result=GETPOST("param2", 'aZ09'); // Must return '' as string contains car not in aZ09 definition |
|
463 | + $result = GETPOST("param2", 'aZ09'); // Must return '' as string contains car not in aZ09 definition |
|
464 | 464 | print __METHOD__." result=".$result."\n"; |
465 | 465 | $this->assertEquals($result, ''); |
466 | 466 | |
467 | - $result=GETPOST("param3", 'aZ09'); // Must return '' as string contains car not in aZ09 definition |
|
467 | + $result = GETPOST("param3", 'aZ09'); // Must return '' as string contains car not in aZ09 definition |
|
468 | 468 | print __METHOD__." result=".$result."\n"; |
469 | 469 | $this->assertEquals($result, ''); |
470 | 470 | |
471 | - $result=GETPOST("param4a", 'aZ09'); // Must return '' as string contains car not in aZ09 definition |
|
471 | + $result = GETPOST("param4a", 'aZ09'); // Must return '' as string contains car not in aZ09 definition |
|
472 | 472 | print __METHOD__." result=".$result."\n"; |
473 | 473 | $this->assertEquals('', $result); |
474 | 474 | |
475 | - $result=GETPOST("param4b", 'aZ09'); // Must return '' as string contains car not in aZ09 definition |
|
475 | + $result = GETPOST("param4b", 'aZ09'); // Must return '' as string contains car not in aZ09 definition |
|
476 | 476 | print __METHOD__." result=".$result."\n"; |
477 | 477 | $this->assertEquals('', $result); |
478 | 478 | |
479 | - $result=GETPOST("param5", 'aZ09'); |
|
479 | + $result = GETPOST("param5", 'aZ09'); |
|
480 | 480 | print __METHOD__." result=".$result."\n"; |
481 | 481 | $this->assertEquals($_GET["param5"], $result); |
482 | 482 | |
483 | 483 | // Test with nohtml |
484 | 484 | |
485 | - $result=GETPOST("param6", 'nohtml'); |
|
485 | + $result = GETPOST("param6", 'nohtml'); |
|
486 | 486 | print __METHOD__." result6=".$result."\n"; |
487 | 487 | $this->assertEquals('">', $result); |
488 | 488 | |
489 | 489 | // Test with alpha = alphanohtml. We must convert the html entities like n and disable all entities |
490 | 490 | |
491 | - $result=GETPOST("param6", 'alphanohtml'); |
|
491 | + $result = GETPOST("param6", 'alphanohtml'); |
|
492 | 492 | print __METHOD__." result=".$result."\n"; |
493 | 493 | $this->assertEquals('>', $result); |
494 | 494 | |
495 | - $result=GETPOST("param6b", 'alphanohtml'); |
|
495 | + $result = GETPOST("param6b", 'alphanohtml'); |
|
496 | 496 | print __METHOD__." result=".$result."\n"; |
497 | 497 | $this->assertEquals('abc', $result); |
498 | 498 | |
499 | - $result=GETPOST("param8a", 'alphanohtml'); |
|
499 | + $result = GETPOST("param8a", 'alphanohtml'); |
|
500 | 500 | print __METHOD__." result=".$result."\n"; |
501 | 501 | $this->assertEquals("Hackersvg onload='console.log(123)'", $result); |
502 | 502 | |
503 | - $result=GETPOST("param8b", 'alphanohtml'); |
|
503 | + $result = GETPOST("param8b", 'alphanohtml'); |
|
504 | 504 | print __METHOD__." result=".$result."\n"; |
505 | 505 | $this->assertEquals('img src=x onerror=alert(document.location) t=', $result, 'Test a string with non closing html tag with alphanohtml'); |
506 | 506 | |
507 | - $result=GETPOST("param8c", 'alphanohtml'); |
|
507 | + $result = GETPOST("param8c", 'alphanohtml'); |
|
508 | 508 | print __METHOD__." result=".$result."\n"; |
509 | 509 | $this->assertEquals($_POST['param8c'], $result, 'Test a string with non closing html tag with alphanohtml'); |
510 | 510 | |
511 | - $result=GETPOST("param8d", 'alphanohtml'); |
|
511 | + $result = GETPOST("param8d", 'alphanohtml'); |
|
512 | 512 | print __METHOD__." result=".$result."\n"; |
513 | 513 | $this->assertEquals('abc123 is html to clean', $result, 'Test a string with non closing html tag with alphanohtml'); |
514 | 514 | |
515 | - $result=GETPOST("param8e", 'alphanohtml'); |
|
515 | + $result = GETPOST("param8e", 'alphanohtml'); |
|
516 | 516 | print __METHOD__." result=".$result."\n"; |
517 | 517 | $this->assertEquals($_POST['param8e'], $result, 'Test a string with non closing html tag with alphanohtml'); |
518 | 518 | |
519 | - $result=GETPOST("param8f", 'alphanohtml'); |
|
519 | + $result = GETPOST("param8f", 'alphanohtml'); |
|
520 | 520 | print __METHOD__." result=".$result."\n"; |
521 | 521 | $this->assertEquals('abcsvg animate onbegin=alert(document.domain) a', $result, 'Test a string with html tag open with several <'); |
522 | 522 | |
523 | - $result=GETPOST("param9", 'alphanohtml'); |
|
523 | + $result = GETPOST("param9", 'alphanohtml'); |
|
524 | 524 | print __METHOD__." result=".$result."\n"; |
525 | 525 | $this->assertEquals($_POST["param9"], $result); |
526 | 526 | |
527 | - $result=GETPOST("param10", 'alphanohtml'); |
|
527 | + $result = GETPOST("param10", 'alphanohtml'); |
|
528 | 528 | print __METHOD__." result=".$result."\n"; |
529 | 529 | $this->assertEquals($_POST["param9"], $result, 'We should get param9 after processing param10'); |
530 | 530 | |
531 | - $result=GETPOST("param11", 'alphanohtml'); |
|
531 | + $result = GETPOST("param11", 'alphanohtml'); |
|
532 | 532 | print __METHOD__." result=".$result."\n"; |
533 | 533 | $this->assertEquals("Name", $result, 'Test an email string with alphanohtml'); |
534 | 534 | |
535 | - $result=GETPOST("param13", 'alphanohtml'); |
|
535 | + $result = GETPOST("param13", 'alphanohtml'); |
|
536 | 536 | print __METHOD__." result=".$result."\n"; |
537 | 537 | $this->assertEquals('n n > < XSS', $result, 'Test that html entities are decoded with alpha'); |
538 | 538 | |
539 | 539 | |
540 | 540 | // Test with alphawithlgt |
541 | 541 | |
542 | - $result=GETPOST("param11", 'alphawithlgt'); |
|
542 | + $result = GETPOST("param11", 'alphawithlgt'); |
|
543 | 543 | print __METHOD__." result=".$result."\n"; |
544 | 544 | $this->assertEquals(trim($_POST["param11"]), $result, 'Test an email string with alphawithlgt'); |
545 | 545 | |
546 | 546 | |
547 | 547 | // Test with restricthtml: we must remove html open/close tag and content but not htmlentities (we can decode html entities for ascii chars like n) |
548 | 548 | |
549 | - $result=GETPOST("param0", 'restricthtml'); |
|
549 | + $result = GETPOST("param0", 'restricthtml'); |
|
550 | 550 | $resultexpected = 'A real string with <a href="rrr" title="aa"bb">aaa</a> and " and \' and & inside content'; |
551 | 551 | print __METHOD__." result=".$result."\n"; |
552 | 552 | $this->assertEquals($resultexpected, $result, 'Test on param0'); |
553 | 553 | |
554 | - $result=GETPOST("param6", 'restricthtml'); |
|
554 | + $result = GETPOST("param6", 'restricthtml'); |
|
555 | 555 | print __METHOD__." result for param6=".$result." - before=".$_POST["param6"]."\n"; |
556 | 556 | $this->assertEquals('">', $result); |
557 | 557 | |
558 | - $result=GETPOST("param7", 'restricthtml'); |
|
558 | + $result = GETPOST("param7", 'restricthtml'); |
|
559 | 559 | print __METHOD__." result param7 = ".$result."\n"; |
560 | 560 | $this->assertEquals('"c:\this is a path~1\aaan &#x;;;;" abcdef', $result); |
561 | 561 | |
562 | - $result=GETPOST("param8e", 'restricthtml'); |
|
562 | + $result = GETPOST("param8e", 'restricthtml'); |
|
563 | 563 | print __METHOD__." result param8e = ".$result."\n"; |
564 | 564 | $this->assertEquals('', $result); |
565 | 565 | |
566 | - $result=GETPOST("param12", 'restricthtml'); |
|
566 | + $result = GETPOST("param12", 'restricthtml'); |
|
567 | 567 | print __METHOD__." result=".$result."\n"; |
568 | 568 | $this->assertEquals(trim($_POST["param12"]), $result, 'Test a string with DOCTYPE and restricthtml'); |
569 | 569 | |
570 | - $result=GETPOST("param13", 'restricthtml'); |
|
570 | + $result = GETPOST("param13", 'restricthtml'); |
|
571 | 571 | print __METHOD__." result=".$result."\n"; |
572 | 572 | $this->assertEquals('n n > < " <a href=\"alert(document.domain)\">XSS</a>', $result, 'Test 13 that HTML entities are decoded with restricthtml, but only for common alpha chars'); |
573 | 573 | |
574 | - $result=GETPOST("param13b", 'restricthtml'); |
|
574 | + $result = GETPOST("param13b", 'restricthtml'); |
|
575 | 575 | print __METHOD__." result=".$result."\n"; |
576 | 576 | $this->assertEquals('n n > < " <a href=\"alert(document.domain)\">XSS</a>', $result, 'Test 13b that HTML entities are decoded with restricthtml, but only for common alpha chars'); |
577 | 577 | |
578 | - $result=GETPOST("param14", 'restricthtml'); |
|
578 | + $result = GETPOST("param14", 'restricthtml'); |
|
579 | 579 | print __METHOD__." result=".$result."\n"; |
580 | 580 | $this->assertEquals("Text with ' encoded with the numeric html entity converted into text entity ' (like when submitted by CKEditor)", $result, 'Test 14'); |
581 | 581 | |
582 | - $result=GETPOST("param15", 'restricthtml'); // param15 = <img onerror<=alert(document.domain)> src=>0xbeefed that is a dangerous string |
|
582 | + $result = GETPOST("param15", 'restricthtml'); // param15 = <img onerror<=alert(document.domain)> src=>0xbeefed that is a dangerous string |
|
583 | 583 | print __METHOD__." result=".$result."\n"; |
584 | - $this->assertEquals("<img onerror=alert(document.domain) src=>0xbeefed", $result, 'Test 15'); // The GETPOST return a harmull string |
|
584 | + $this->assertEquals("<img onerror=alert(document.domain) src=>0xbeefed", $result, 'Test 15'); // The GETPOST return a harmull string |
|
585 | 585 | |
586 | - $result=GETPOST("param19", 'restricthtml'); |
|
586 | + $result = GETPOST("param19", 'restricthtml'); |
|
587 | 587 | print __METHOD__." result=".$result."\n"; |
588 | 588 | $this->assertEquals('<a href="(alert(document.cookie))">XSS</a>', $result, 'Test 19'); |
589 | 589 | |
@@ -594,22 +594,22 @@ discard block |
||
594 | 594 | $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 0; |
595 | 595 | |
596 | 596 | //$_POST["param0"] = 'A real string with <a href="rrr" title="aabb">aaa</a> and " inside content'; |
597 | - $result=GETPOST("param0", 'restricthtml'); |
|
597 | + $result = GETPOST("param0", 'restricthtml'); |
|
598 | 598 | $resultexpected = 'A real string with <a href="rrr" title=\'aa"bb\'>aaa</a> and " and \' and & inside content'; |
599 | 599 | print __METHOD__." result for param0=".$result."\n"; |
600 | 600 | $this->assertEquals($resultexpected, $result, 'Test on param0'); |
601 | 601 | |
602 | - $result=GETPOST("param15", 'restricthtml'); // param15 = <img onerror<=alert(document.domain)> src=>0xbeefed that is a dangerous string |
|
602 | + $result = GETPOST("param15", 'restricthtml'); // param15 = <img onerror<=alert(document.domain)> src=>0xbeefed that is a dangerous string |
|
603 | 603 | print __METHOD__." result for param15=".$result."\n"; |
604 | 604 | //$this->assertEquals('InvalidHTMLStringCantBeCleaned', $result, 'Test 15b'); // With some PHP and libxml version, we got this result when parsing invalid HTML, but ... |
605 | 605 | //$this->assertEquals('<img onerror> src=>0xbeefed', $result, 'Test 15b'); // ... on other PHP and libxml versions, we got a HTML that has been cleaned |
606 | 606 | |
607 | - $result=GETPOST("param6", 'restricthtml'); // param6 = ""><svg onload='console.log("123")'>" |
|
607 | + $result = GETPOST("param6", 'restricthtml'); // param6 = ""><svg onload='console.log("123")'>" |
|
608 | 608 | print __METHOD__." result for param6=".$result." - before=".$_POST["param6"]."\n"; |
609 | 609 | //$this->assertEquals('InvalidHTMLStringCantBeCleaned', $result, 'Test 15b'); // With some PHP and libxml version, we got this result when parsing invalid HTML, but ... |
610 | 610 | //$this->assertEquals('">', $result); // ... on other PHP and libxml versions, we got a HTML that has been cleaned |
611 | 611 | |
612 | - $result=GETPOST("param7", 'restricthtml'); // param7 = "c:\this is a path~1\aaan &#x110;" abc<bad>def</bad> |
|
612 | + $result = GETPOST("param7", 'restricthtml'); // param7 = "c:\this is a path~1\aaan &#x110;" abc<bad>def</bad> |
|
613 | 613 | print __METHOD__." result param7 = ".$result."\n"; |
614 | 614 | //$this->assertEquals('InvalidHTMLStringCantBeCleaned', $result, 'Test 15b'); // With some PHP and libxml version, we got this result when parsing invalid HTML, but ... |
615 | 615 | //$this->assertEquals('"c:\this is a path~1\aaan 110;" abcdef', $result); // ... on other PHP and libxml versions, we got a HTML that has been cleaned |
@@ -621,19 +621,19 @@ discard block |
||
621 | 621 | $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 0; |
622 | 622 | $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 1; |
623 | 623 | |
624 | - $result=GETPOST("param0", 'restricthtml'); |
|
624 | + $result = GETPOST("param0", 'restricthtml'); |
|
625 | 625 | $resultexpected = 'A real string with <a href="rrr" title="aa"bb">aaa</a> and " and \' and & inside content'; |
626 | 626 | print __METHOD__." result for param0=".$result."\n"; |
627 | 627 | $this->assertEquals($resultexpected, $result, 'Test on param0'); |
628 | 628 | |
629 | - $result=GETPOST("param15", 'restricthtml'); // param15 = <img onerror<=alert(document.domain)> src=>0xbeefed that is a dangerous string |
|
629 | + $result = GETPOST("param15", 'restricthtml'); // param15 = <img onerror<=alert(document.domain)> src=>0xbeefed that is a dangerous string |
|
630 | 630 | print __METHOD__." result=".$result."\n"; |
631 | 631 | |
632 | - $result=GETPOST("param6", 'restricthtml'); |
|
632 | + $result = GETPOST("param6", 'restricthtml'); |
|
633 | 633 | print __METHOD__." result for param6=".$result." - before=".$_POST["param6"]."\n"; |
634 | 634 | $this->assertEquals('">', $result); |
635 | 635 | |
636 | - $result=GETPOST("param7", 'restricthtml'); |
|
636 | + $result = GETPOST("param7", 'restricthtml'); |
|
637 | 637 | print __METHOD__." result param7 = ".$result."\n"; |
638 | 638 | $this->assertEquals('"c:\this is a path~1\aaan &#x110;" abcdef', $result); |
639 | 639 | } |
@@ -645,19 +645,19 @@ discard block |
||
645 | 645 | $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 1; |
646 | 646 | $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 1; |
647 | 647 | |
648 | - $result=GETPOST("param0", 'restricthtml'); |
|
648 | + $result = GETPOST("param0", 'restricthtml'); |
|
649 | 649 | $resultexpected = 'A real string with <a href="rrr" title=\'aa"bb\'>aaa</a> and " and \' and & inside content'; |
650 | 650 | print __METHOD__." result for param0=".$result."\n"; |
651 | 651 | $this->assertEquals($resultexpected, $result, 'Test on param0'); |
652 | 652 | |
653 | - $result=GETPOST("param15", 'restricthtml'); // param15 = <img onerror<=alert(document.domain)> src=>0xbeefed that is a dangerous string |
|
653 | + $result = GETPOST("param15", 'restricthtml'); // param15 = <img onerror<=alert(document.domain)> src=>0xbeefed that is a dangerous string |
|
654 | 654 | print __METHOD__." result=".$result."\n"; |
655 | 655 | |
656 | - $result=GETPOST("param6", 'restricthtml'); |
|
656 | + $result = GETPOST("param6", 'restricthtml'); |
|
657 | 657 | print __METHOD__." result for param6=".$result." - before=".$_POST["param6"]."\n"; |
658 | 658 | $this->assertEquals('">', $result); |
659 | 659 | |
660 | - $result=GETPOST("param7", 'restricthtml'); |
|
660 | + $result = GETPOST("param7", 'restricthtml'); |
|
661 | 661 | print __METHOD__." result param7 = ".$result."\n"; |
662 | 662 | $this->assertEquals('"c:\this is a path~1\aaan 110;" abcdef', $result); |
663 | 663 | } |
@@ -669,19 +669,19 @@ discard block |
||
669 | 669 | unset($conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY); |
670 | 670 | $conf->global->MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES = 1; |
671 | 671 | |
672 | - $result=GETPOST("param15", 'restricthtml'); |
|
672 | + $result = GETPOST("param15", 'restricthtml'); |
|
673 | 673 | print __METHOD__." result=".$result."\n"; |
674 | 674 | $this->assertEquals('<img src="">0xbeefed', $result, 'Test 15c'); |
675 | 675 | |
676 | - $result=GETPOST('param16', 'restricthtml'); |
|
676 | + $result = GETPOST('param16', 'restricthtml'); |
|
677 | 677 | print __METHOD__." result=".$result."\n"; |
678 | 678 | $this->assertEquals('<a style=" 1000">abc</a>', $result, 'Test tag a with forbidden attribute z-index'); |
679 | 679 | |
680 | - $result=GETPOST('param17', 'restricthtml'); |
|
680 | + $result = GETPOST('param17', 'restricthtml'); |
|
681 | 681 | print __METHOD__." result=".$result."\n"; |
682 | 682 | $this->assertEquals('<span style="background-image: url()">abc</span>', $result, 'Test anytag with a forbidden value for attribute'); |
683 | 683 | |
684 | - $result=GETPOST('param18', 'restricthtml'); |
|
684 | + $result = GETPOST('param18', 'restricthtml'); |
|
685 | 685 | print __METHOD__." result=".$result."\n"; |
686 | 686 | $this->assertEquals('<span style="background-image: url(...?...aaa)">abc</span>', $result, 'Test anytag with a forbidden value for attribute'); |
687 | 687 | |
@@ -690,75 +690,75 @@ discard block |
||
690 | 690 | |
691 | 691 | // Special test for GETPOST of backtopage, backtolist or backtourl parameter |
692 | 692 | |
693 | - $_POST["backtopage"]='//www.google.com'; |
|
694 | - $result=GETPOST("backtopage"); |
|
693 | + $_POST["backtopage"] = '//www.google.com'; |
|
694 | + $result = GETPOST("backtopage"); |
|
695 | 695 | print __METHOD__." result=".$result."\n"; |
696 | 696 | $this->assertEquals('www.google.com', $result, 'Test for backtopage param'); |
697 | 697 | |
698 | - $_POST["backtopage"]='https:https://www.google.com'; |
|
699 | - $result=GETPOST("backtopage"); |
|
698 | + $_POST["backtopage"] = 'https:https://www.google.com'; |
|
699 | + $result = GETPOST("backtopage"); |
|
700 | 700 | print __METHOD__." result=".$result."\n"; |
701 | 701 | $this->assertEquals('www.google.com', $result, 'Test for backtopage param'); |
702 | 702 | |
703 | - $_POST["backtolist"]='::HTTPS://www.google.com'; |
|
704 | - $result=GETPOST("backtolist"); |
|
703 | + $_POST["backtolist"] = '::HTTPS://www.google.com'; |
|
704 | + $result = GETPOST("backtolist"); |
|
705 | 705 | print __METHOD__." result=".$result."\n"; |
706 | 706 | $this->assertEquals('www.google.com', $result, 'Test for backtopage param'); |
707 | 707 | |
708 | - $_POST["backtopage"]='http:www.google.com'; |
|
709 | - $result=GETPOST("backtopage"); |
|
708 | + $_POST["backtopage"] = 'http:www.google.com'; |
|
709 | + $result = GETPOST("backtopage"); |
|
710 | 710 | print __METHOD__." result=".$result."\n"; |
711 | 711 | $this->assertEquals('httpwww.google.com', $result, 'Test for backtopage param'); |
712 | 712 | |
713 | - $_POST["backtopage"]='/mydir/mypage.php?aa=a%10a'; |
|
714 | - $result=GETPOST("backtopage"); |
|
713 | + $_POST["backtopage"] = '/mydir/mypage.php?aa=a%10a'; |
|
714 | + $result = GETPOST("backtopage"); |
|
715 | 715 | print __METHOD__." result=".$result."\n"; |
716 | 716 | $this->assertEquals('/mydir/mypage.php?aa=a%10a', $result, 'Test for backtopage param'); |
717 | 717 | |
718 | - $_POST["backtopage"]='javascripT&javascript#javascriptxjavascript3a alert(1)'; |
|
719 | - $result=GETPOST("backtopage"); |
|
718 | + $_POST["backtopage"] = 'javascripT&javascript#javascriptxjavascript3a alert(1)'; |
|
719 | + $result = GETPOST("backtopage"); |
|
720 | 720 | print __METHOD__." result=".$result."\n"; |
721 | 721 | $this->assertEquals('x3aalert(1)', $result, 'Test for backtopage param'); |
722 | 722 | |
723 | 723 | |
724 | 724 | $conf->global->MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT = 3; |
725 | - $_POST["pagecontentwithlinks"]='<img src="aaa"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>'; |
|
726 | - $result=GETPOST("pagecontentwithlinks", 'restricthtml'); |
|
725 | + $_POST["pagecontentwithlinks"] = '<img src="aaa"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>'; |
|
726 | + $result = GETPOST("pagecontentwithlinks", 'restricthtml'); |
|
727 | 727 | print __METHOD__." result=".$result."\n"; |
728 | 728 | $this->assertEquals('ErrorTooManyLinksIntoHTMLString', $result, 'Test on limit on GETPOST fails'); |
729 | 729 | |
730 | 730 | // Test that img src="data:..." is excluded from the count of external links |
731 | 731 | $conf->global->MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT = 3; |
732 | - $_POST["pagecontentwithlinks"]='<img src="data:abc"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>'; |
|
733 | - $result=GETPOST("pagecontentwithlinks", 'restricthtml'); |
|
732 | + $_POST["pagecontentwithlinks"] = '<img src="data:abc"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>'; |
|
733 | + $result = GETPOST("pagecontentwithlinks", 'restricthtml'); |
|
734 | 734 | print __METHOD__." result=".$result."\n"; |
735 | 735 | $this->assertEquals('<img src="data:abc"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>', $result, 'Test on limit on GETPOST fails'); |
736 | 736 | |
737 | 737 | $conf->global->MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 2; |
738 | 738 | |
739 | 739 | // Test that no links is allowed |
740 | - $_POST["pagecontentwithlinks"]='<img src="data:abc"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>'; |
|
741 | - $result=GETPOST("pagecontentwithlinks", 'restricthtml'); |
|
740 | + $_POST["pagecontentwithlinks"] = '<img src="data:abc"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>'; |
|
741 | + $result = GETPOST("pagecontentwithlinks", 'restricthtml'); |
|
742 | 742 | print __METHOD__." result=".$result."\n"; |
743 | 743 | $this->assertEquals('ErrorHTMLLinksNotAllowed', $result, 'Test on limit on MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 2 (no links allowed)'); |
744 | 744 | |
745 | 745 | $conf->global->MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 1; |
746 | 746 | |
747 | 747 | // Test that links on wrapper or local url are allowed |
748 | - $_POST["pagecontentwithnowrapperlinks"]='<img src="data:abc"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>'; |
|
749 | - $result=GETPOST("pagecontentwithnowrapperlinks", 'restricthtml'); |
|
748 | + $_POST["pagecontentwithnowrapperlinks"] = '<img src="data:abc"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>'; |
|
749 | + $result = GETPOST("pagecontentwithnowrapperlinks", 'restricthtml'); |
|
750 | 750 | print __METHOD__." result=".$result."\n"; |
751 | 751 | $this->assertEquals('<img src="data:abc"><img src="bbb"><img src="/ccc"><span style="background: url(/ddd)"></span>', $result, 'Test on MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 1 (links on data or relative links ar allowed)'); |
752 | 752 | |
753 | 753 | // Test that links not on wrapper and not data are disallowed |
754 | - $_POST["pagecontentwithnowrapperlinks"]='<img src="https://aaa">'; |
|
755 | - $result=GETPOST("pagecontentwithnowrapperlinks", 'restricthtml'); |
|
754 | + $_POST["pagecontentwithnowrapperlinks"] = '<img src="https://aaa">'; |
|
755 | + $result = GETPOST("pagecontentwithnowrapperlinks", 'restricthtml'); |
|
756 | 756 | print __METHOD__." result=".$result."\n"; |
757 | 757 | $this->assertEquals('ErrorHTMLExternalLinksNotAllowed', $result, 'Test on MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 1 (no links to http allowed)'); |
758 | 758 | |
759 | 759 | // Test that links not on wrapper and not data are disallowed |
760 | - $_POST["pagecontentwithnowrapperlinks"]='<span style="background: url(http://ddd)"></span>'; |
|
761 | - $result=GETPOST("pagecontentwithnowrapperlinks", 'restricthtml'); |
|
760 | + $_POST["pagecontentwithnowrapperlinks"] = '<span style="background: url(http://ddd)"></span>'; |
|
761 | + $result = GETPOST("pagecontentwithnowrapperlinks", 'restricthtml'); |
|
762 | 762 | print __METHOD__." result=".$result."\n"; |
763 | 763 | $this->assertEquals('ErrorHTMLExternalLinksNotAllowed', $result, 'Test on MAIN_DISALLOW_URL_INTO_DESCRIPTIONS = 1 (no links to http allowed)'); |
764 | 764 | |
@@ -772,15 +772,15 @@ discard block |
||
772 | 772 | */ |
773 | 773 | public function testEncodeDecode() |
774 | 774 | { |
775 | - $stringtotest="This is a string to test encode/decode. This is a string to test encode/decode. This is a string to test encode/decode."; |
|
775 | + $stringtotest = "This is a string to test encode/decode. This is a string to test encode/decode. This is a string to test encode/decode."; |
|
776 | 776 | |
777 | - $encodedstring=dol_encode($stringtotest); |
|
778 | - $decodedstring=dol_decode($encodedstring); |
|
777 | + $encodedstring = dol_encode($stringtotest); |
|
778 | + $decodedstring = dol_decode($encodedstring); |
|
779 | 779 | print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n"; |
780 | 780 | $this->assertEquals($stringtotest, $decodedstring, 'Use dol_encode/decode with no parameter'); |
781 | 781 | |
782 | - $encodedstring=dol_encode($stringtotest, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
783 | - $decodedstring=dol_decode($encodedstring, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
782 | + $encodedstring = dol_encode($stringtotest, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
783 | + $decodedstring = dol_decode($encodedstring, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
784 | 784 | print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n"; |
785 | 785 | $this->assertEquals($stringtotest, $decodedstring, 'Use dol_encode/decode with a key parameter'); |
786 | 786 | |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | $this->assertEquals('a : b " c \' d ' e é', $decodedstring, 'Function did not sanitize correclty'); |
800 | 800 | |
801 | 801 | $stringtotest = 'a : b " c ' d ' e é'; |
802 | - $decodedstring = dol_html_entity_decode($stringtotest, ENT_QUOTES|ENT_HTML5); |
|
802 | + $decodedstring = dol_html_entity_decode($stringtotest, ENT_QUOTES | ENT_HTML5); |
|
803 | 803 | $this->assertEquals('a : b " c \' d \' e é', $decodedstring, 'Function did not sanitize correclty'); |
804 | 804 | |
805 | 805 | return 0; |
@@ -863,21 +863,21 @@ discard block |
||
863 | 863 | { |
864 | 864 | global $conf; |
865 | 865 | |
866 | - $genpass1=getRandomPassword(true); // Should be a string return by dol_hash (if no option set, will be md5) |
|
866 | + $genpass1 = getRandomPassword(true); // Should be a string return by dol_hash (if no option set, will be md5) |
|
867 | 867 | print __METHOD__." genpass1=".$genpass1."\n"; |
868 | 868 | $this->assertEquals(strlen($genpass1), 32); |
869 | 869 | |
870 | - $genpass1=getRandomPassword(true, array('I')); // Should be a string return by dol_hash (if no option set, will be md5) |
|
870 | + $genpass1 = getRandomPassword(true, array('I')); // Should be a string return by dol_hash (if no option set, will be md5) |
|
871 | 871 | print __METHOD__." genpass1=".$genpass1."\n"; |
872 | 872 | $this->assertEquals(strlen($genpass1), 32); |
873 | 873 | |
874 | - $conf->global->USER_PASSWORD_GENERATED='None'; |
|
875 | - $genpass2=getRandomPassword(false); // Should return an empty string |
|
874 | + $conf->global->USER_PASSWORD_GENERATED = 'None'; |
|
875 | + $genpass2 = getRandomPassword(false); // Should return an empty string |
|
876 | 876 | print __METHOD__." genpass2=".$genpass2."\n"; |
877 | 877 | $this->assertEquals($genpass2, ''); |
878 | 878 | |
879 | - $conf->global->USER_PASSWORD_GENERATED='Standard'; |
|
880 | - $genpass3=getRandomPassword(false); // Should return a password of 12 chars |
|
879 | + $conf->global->USER_PASSWORD_GENERATED = 'Standard'; |
|
880 | + $genpass3 = getRandomPassword(false); // Should return a password of 12 chars |
|
881 | 881 | print __METHOD__." genpass3=".$genpass3."\n"; |
882 | 882 | $this->assertEquals(strlen($genpass3), 12); |
883 | 883 | |
@@ -891,16 +891,16 @@ discard block |
||
891 | 891 | */ |
892 | 892 | public function testRestrictedArea() |
893 | 893 | { |
894 | - global $conf,$user,$langs,$db; |
|
895 | - $conf=$this->savconf; |
|
896 | - $user=$this->savuser; |
|
897 | - $langs=$this->savlangs; |
|
898 | - $db=$this->savdb; |
|
894 | + global $conf, $user, $langs, $db; |
|
895 | + $conf = $this->savconf; |
|
896 | + $user = $this->savuser; |
|
897 | + $langs = $this->savlangs; |
|
898 | + $db = $this->savdb; |
|
899 | 899 | |
900 | 900 | //$dummyuser=new User($db); |
901 | 901 | //$result=restrictedArea($dummyuser,'societe'); |
902 | 902 | |
903 | - $result=restrictedArea($user, 'societe'); |
|
903 | + $result = restrictedArea($user, 'societe'); |
|
904 | 904 | $this->assertEquals(1, $result); |
905 | 905 | } |
906 | 906 | |
@@ -918,42 +918,42 @@ discard block |
||
918 | 918 | $url = 'ftp://mydomain.com'; |
919 | 919 | $tmp = getURLContent($url); |
920 | 920 | print __METHOD__." url=".$url."\n"; |
921 | - $this->assertGreaterThan(0, strpos($tmp['curl_error_msg'], 'not supported')); // Test error if return does not contains 'not supported' |
|
921 | + $this->assertGreaterThan(0, strpos($tmp['curl_error_msg'], 'not supported')); // Test error if return does not contains 'not supported' |
|
922 | 922 | |
923 | - $url = 'https://www.dolibarr.fr'; // This is a redirect 301 page |
|
924 | - $tmp = getURLContent($url, 'GET', '', 0); // We do NOT follow |
|
923 | + $url = 'https://www.dolibarr.fr'; // This is a redirect 301 page |
|
924 | + $tmp = getURLContent($url, 'GET', '', 0); // We do NOT follow |
|
925 | 925 | print __METHOD__." url=".$url."\n"; |
926 | 926 | $this->assertEquals(301, $tmp['http_code'], 'Should GET url 301 response and stop here'); |
927 | 927 | |
928 | - $url = 'https://www.dolibarr.fr'; // This is a redirect 301 page |
|
929 | - $tmp = getURLContent($url); // We DO follow a page with return 300 so result should be 200 |
|
928 | + $url = 'https://www.dolibarr.fr'; // This is a redirect 301 page |
|
929 | + $tmp = getURLContent($url); // We DO follow a page with return 300 so result should be 200 |
|
930 | 930 | print __METHOD__." url=".$url."\n"; |
931 | 931 | $this->assertEquals(200, $tmp['http_code'], 'Should GET url 301 with a follow -> 200 but we get '.$tmp['http_code']); |
932 | 932 | |
933 | 933 | $url = 'http://localhost'; |
934 | - $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
934 | + $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
935 | 935 | print __METHOD__." url=".$url."\n"; |
936 | - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that resolves to a local URL'); // Test we receive an error because localtest.me is not an external URL |
|
936 | + $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that resolves to a local URL'); // Test we receive an error because localtest.me is not an external URL |
|
937 | 937 | |
938 | 938 | $url = 'http://127.0.0.1'; |
939 | - $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
939 | + $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
940 | 940 | print __METHOD__." url=".$url."\n"; |
941 | - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 127.0.0.1 is not an external URL |
|
941 | + $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 127.0.0.1 is not an external URL |
|
942 | 942 | |
943 | 943 | $url = 'http://127.0.2.1'; |
944 | - $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
944 | + $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
945 | 945 | print __METHOD__." url=".$url."\n"; |
946 | - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 127.0.2.1 is not an external URL |
|
946 | + $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 127.0.2.1 is not an external URL |
|
947 | 947 | |
948 | 948 | $url = 'https://169.254.0.1'; |
949 | - $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
949 | + $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
950 | 950 | print __METHOD__." url=".$url."\n"; |
951 | - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 169.254.0.1 is not an external URL |
|
951 | + $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because 169.254.0.1 is not an external URL |
|
952 | 952 | |
953 | 953 | $url = 'http://[::1]'; |
954 | - $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
954 | + $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
|
955 | 955 | print __METHOD__." url=".$url."\n"; |
956 | - $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because [::1] is not an external URL |
|
956 | + $this->assertEquals(400, $tmp['http_code'], 'Should GET url to '.$url.' that is a local URL'); // Test we receive an error because [::1] is not an external URL |
|
957 | 957 | |
958 | 958 | /*$url = 'localtest.me'; |
959 | 959 | $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL |
@@ -962,9 +962,9 @@ discard block |
||
962 | 962 | */ |
963 | 963 | |
964 | 964 | $url = 'http://192.0.0.192'; |
965 | - $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL but on an IP in blacklist |
|
965 | + $tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0); // Only external URL but on an IP in blacklist |
|
966 | 966 | print __METHOD__." url=".$url." tmp['http_code'] = ".$tmp['http_code']."\n"; |
967 | - $this->assertEquals(400, $tmp['http_code'], 'Access should be refused and was not'); // Test we receive an error because ip is in blacklist |
|
967 | + $this->assertEquals(400, $tmp['http_code'], 'Access should be refused and was not'); // Test we receive an error because ip is in blacklist |
|
968 | 968 | |
969 | 969 | return 0; |
970 | 970 | } |
@@ -976,22 +976,22 @@ discard block |
||
976 | 976 | */ |
977 | 977 | public function testDolSanitizeUrl() |
978 | 978 | { |
979 | - global $conf,$user,$langs,$db; |
|
980 | - $conf=$this->savconf; |
|
981 | - $user=$this->savuser; |
|
982 | - $langs=$this->savlangs; |
|
983 | - $db=$this->savdb; |
|
979 | + global $conf, $user, $langs, $db; |
|
980 | + $conf = $this->savconf; |
|
981 | + $user = $this->savuser; |
|
982 | + $langs = $this->savlangs; |
|
983 | + $db = $this->savdb; |
|
984 | 984 | |
985 | 985 | $test = 'javascripT&javascript#x3a alert(1)'; |
986 | - $result=dol_sanitizeUrl($test); |
|
986 | + $result = dol_sanitizeUrl($test); |
|
987 | 987 | $this->assertEquals('x3a alert(1)', $result, 'Test on dol_sanitizeUrl A'); |
988 | 988 | |
989 | 989 | $test = 'javajavascriptscript&cjavascriptolon;alert(1)'; |
990 | - $result=dol_sanitizeUrl($test); |
|
990 | + $result = dol_sanitizeUrl($test); |
|
991 | 991 | $this->assertEquals('alert(1)', $result, 'Test on dol_sanitizeUrl B'); |
992 | 992 | |
993 | 993 | $test = '/javas:cript/google.com'; |
994 | - $result=dol_sanitizeUrl($test); |
|
994 | + $result = dol_sanitizeUrl($test); |
|
995 | 995 | $this->assertEquals('google.com', $result, 'Test on dol_sanitizeUrl C'); |
996 | 996 | } |
997 | 997 | |
@@ -1002,26 +1002,26 @@ discard block |
||
1002 | 1002 | */ |
1003 | 1003 | public function testDolSanitizeEmail() |
1004 | 1004 | { |
1005 | - global $conf,$user,$langs,$db; |
|
1006 | - $conf=$this->savconf; |
|
1007 | - $user=$this->savuser; |
|
1008 | - $langs=$this->savlangs; |
|
1009 | - $db=$this->savdb; |
|
1005 | + global $conf, $user, $langs, $db; |
|
1006 | + $conf = $this->savconf; |
|
1007 | + $user = $this->savuser; |
|
1008 | + $langs = $this->savlangs; |
|
1009 | + $db = $this->savdb; |
|
1010 | 1010 | |
1011 | 1011 | $test = '[email protected] <My name>, [email protected] <Another name>'; |
1012 | - $result=dol_sanitizeEmail($test); |
|
1012 | + $result = dol_sanitizeEmail($test); |
|
1013 | 1013 | $this->assertEquals($test, $result, 'Test on dol_sanitizeEmail A'); |
1014 | 1014 | |
1015 | 1015 | $test = "[email protected] <My name>,\[email protected] <Another name>"; |
1016 | - $result=dol_sanitizeEmail($test); |
|
1016 | + $result = dol_sanitizeEmail($test); |
|
1017 | 1017 | $this->assertEquals('[email protected] <My name>,[email protected] <Another name>', $result, 'Test on dol_sanitizeEmail B'); |
1018 | 1018 | |
1019 | 1019 | $test = '[email protected] <My name>,\[email protected] <Another name>'; |
1020 | - $result=dol_sanitizeEmail($test); |
|
1020 | + $result = dol_sanitizeEmail($test); |
|
1021 | 1021 | $this->assertEquals('[email protected] <My name>,[email protected] <Another name>', $result, 'Test on dol_sanitizeEmail C'); |
1022 | 1022 | |
1023 | 1023 | $test = '[email protected] <My name>, "bcc:bbb"@mycompany.com <Another name>'; |
1024 | - $result=dol_sanitizeEmail($test); |
|
1024 | + $result = dol_sanitizeEmail($test); |
|
1025 | 1025 | $this->assertEquals('[email protected] <My name>, [email protected] <Another name>', $result, 'Test on dol_sanitizeEmail D'); |
1026 | 1026 | } |
1027 | 1027 | |
@@ -1032,19 +1032,19 @@ discard block |
||
1032 | 1032 | */ |
1033 | 1033 | public function testDolSanitizeFileName() |
1034 | 1034 | { |
1035 | - global $conf,$user,$langs,$db; |
|
1036 | - $conf=$this->savconf; |
|
1037 | - $user=$this->savuser; |
|
1038 | - $langs=$this->savlangs; |
|
1039 | - $db=$this->savdb; |
|
1035 | + global $conf, $user, $langs, $db; |
|
1036 | + $conf = $this->savconf; |
|
1037 | + $user = $this->savuser; |
|
1038 | + $langs = $this->savlangs; |
|
1039 | + $db = $this->savdb; |
|
1040 | 1040 | |
1041 | 1041 | //$dummyuser=new User($db); |
1042 | 1042 | //$result=restrictedArea($dummyuser,'societe'); |
1043 | 1043 | |
1044 | - $result=dol_sanitizeFileName('bad file | evilaction'); |
|
1044 | + $result = dol_sanitizeFileName('bad file | evilaction'); |
|
1045 | 1045 | $this->assertEquals('bad file _ evilaction', $result); |
1046 | 1046 | |
1047 | - $result=dol_sanitizeFileName('bad file -evilparam --evilparam ---evilparam ----evilparam'); |
|
1047 | + $result = dol_sanitizeFileName('bad file -evilparam --evilparam ---evilparam ----evilparam'); |
|
1048 | 1048 | $this->assertEquals('bad file _evilparam _evilparam _evilparam _evilparam', $result); |
1049 | 1049 | } |
1050 | 1050 | |
@@ -1055,17 +1055,17 @@ discard block |
||
1055 | 1055 | */ |
1056 | 1056 | public function testDolEval() |
1057 | 1057 | { |
1058 | - global $conf,$user,$langs,$db; |
|
1059 | - $conf=$this->savconf; |
|
1060 | - $user=$this->savuser; |
|
1061 | - $langs=$this->savlangs; |
|
1062 | - $db=$this->savdb; |
|
1058 | + global $conf, $user, $langs, $db; |
|
1059 | + $conf = $this->savconf; |
|
1060 | + $user = $this->savuser; |
|
1061 | + $langs = $this->savlangs; |
|
1062 | + $db = $this->savdb; |
|
1063 | 1063 | |
1064 | - $result=dol_eval('1==1', 1, 0); |
|
1064 | + $result = dol_eval('1==1', 1, 0); |
|
1065 | 1065 | print "result1 = ".$result."\n"; |
1066 | 1066 | $this->assertTrue($result); |
1067 | 1067 | |
1068 | - $result=dol_eval('1==2', 1, 0); |
|
1068 | + $result = dol_eval('1==2', 1, 0); |
|
1069 | 1069 | print "result2 = ".$result."\n"; |
1070 | 1070 | $this->assertFalse($result); |
1071 | 1071 | |
@@ -1073,7 +1073,7 @@ discard block |
||
1073 | 1073 | include_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; |
1074 | 1074 | |
1075 | 1075 | $s = '(($reloadedobj = new Task($db)) && ($reloadedobj->fetchNoCompute($object->id) > 0) && ($secondloadedobj = new Project($db)) && ($secondloadedobj->fetchNoCompute($reloadedobj->fk_project) > 0)) ? $secondloadedobj->ref : "Parent project not found"'; |
1076 | - $result=dol_eval($s, 1, 1, '2'); |
|
1076 | + $result = dol_eval($s, 1, 1, '2'); |
|
1077 | 1077 | print "result3 = ".$result."\n"; |
1078 | 1078 | $this->assertEquals('Parent project not found', $result); |
1079 | 1079 | |
@@ -1114,48 +1114,48 @@ discard block |
||
1114 | 1114 | print "result12 = ".$result."\n"; |
1115 | 1115 | $this->assertStringContainsString('Bad string syntax to evaluate', $result); |
1116 | 1116 | |
1117 | - $result=dol_eval("90402.38+267678+0", 1, 1, 1); |
|
1117 | + $result = dol_eval("90402.38+267678+0", 1, 1, 1); |
|
1118 | 1118 | print "result13 = ".$result."\n"; |
1119 | 1119 | $this->assertEquals('358080.38', $result); |
1120 | 1120 | |
1121 | - global $leftmenu; // Used into strings to eval |
|
1121 | + global $leftmenu; // Used into strings to eval |
|
1122 | 1122 | |
1123 | 1123 | $leftmenu = 'AAA'; |
1124 | - $result=dol_eval('$conf->currency && preg_match(\'/^(AAA|BBB)/\',$leftmenu)', 1, 1, '1'); |
|
1124 | + $result = dol_eval('$conf->currency && preg_match(\'/^(AAA|BBB)/\',$leftmenu)', 1, 1, '1'); |
|
1125 | 1125 | print "result = ".$result."\n"; |
1126 | 1126 | $this->assertTrue($result); |
1127 | 1127 | |
1128 | 1128 | // Same with a value that does not match |
1129 | 1129 | $leftmenu = 'XXX'; |
1130 | - $result=dol_eval('$conf->currency && preg_match(\'/^(AAA|BBB)/\',$leftmenu)', 1, 1, '1'); |
|
1130 | + $result = dol_eval('$conf->currency && preg_match(\'/^(AAA|BBB)/\',$leftmenu)', 1, 1, '1'); |
|
1131 | 1131 | print "result14 = ".$result."\n"; |
1132 | 1132 | $this->assertFalse($result); |
1133 | 1133 | |
1134 | 1134 | $leftmenu = 'AAA'; |
1135 | - $result=dol_eval('$conf->currency && isStringVarMatching(\'leftmenu\', \'(AAA|BBB)\')', 1, 1, '1'); |
|
1135 | + $result = dol_eval('$conf->currency && isStringVarMatching(\'leftmenu\', \'(AAA|BBB)\')', 1, 1, '1'); |
|
1136 | 1136 | print "result15 = ".$result."\n"; |
1137 | 1137 | $this->assertTrue($result); |
1138 | 1138 | |
1139 | 1139 | $leftmenu = 'XXX'; |
1140 | - $result=dol_eval('$conf->currency && isStringVarMatching(\'leftmenu\', \'(AAA|BBB)\')', 1, 1, '1'); |
|
1140 | + $result = dol_eval('$conf->currency && isStringVarMatching(\'leftmenu\', \'(AAA|BBB)\')', 1, 1, '1'); |
|
1141 | 1141 | print "result16 = ".$result."\n"; |
1142 | 1142 | $this->assertFalse($result); |
1143 | 1143 | |
1144 | 1144 | $string = '(isModEnabled("agenda") || isModEnabled("resource")) && getDolGlobalInt("MAIN_FEATURES_LEVEL") >= 0 && preg_match(\'/^(admintools|all|XXX)/\', $leftmenu)'; |
1145 | - $result=dol_eval($string, 1, 1, '1'); |
|
1145 | + $result = dol_eval($string, 1, 1, '1'); |
|
1146 | 1146 | print "result17 = ".$result."\n"; |
1147 | 1147 | $this->assertTrue($result); |
1148 | 1148 | |
1149 | - $result=dol_eval('1 && getDolGlobalInt("doesnotexist1") && $conf->global->MAIN_FEATURES_LEVEL', 1, 0); // Should return false and not a 'Bad string syntax to evaluate ...' |
|
1149 | + $result = dol_eval('1 && getDolGlobalInt("doesnotexist1") && $conf->global->MAIN_FEATURES_LEVEL', 1, 0); // Should return false and not a 'Bad string syntax to evaluate ...' |
|
1150 | 1150 | print "result18 = ".$result."\n"; |
1151 | 1151 | $this->assertFalse($result); |
1152 | 1152 | |
1153 | - $a='ab'; |
|
1153 | + $a = 'ab'; |
|
1154 | 1154 | $result = (string) dol_eval("(\$a.'s')", 1, 0); |
1155 | 1155 | print "result19 = ".$result."\n"; |
1156 | 1156 | $this->assertStringContainsString('Bad string syntax to evaluate', $result); |
1157 | 1157 | |
1158 | - $leftmenu='abs'; |
|
1158 | + $leftmenu = 'abs'; |
|
1159 | 1159 | $result = (string) dol_eval('$leftmenu(-5)', 1, 0); |
1160 | 1160 | print "result20 = ".$result."\n"; |
1161 | 1161 | $this->assertStringContainsString('Bad string syntax to evaluate', $result); |
@@ -1173,12 +1173,12 @@ discard block |
||
1173 | 1173 | global $conf; |
1174 | 1174 | |
1175 | 1175 | // Set options for cleaning data |
1176 | - $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 0; // disabled, does not work on HTML5 and some libxml versions |
|
1176 | + $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML = 0; // disabled, does not work on HTML5 and some libxml versions |
|
1177 | 1177 | // Enabled option MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY if possible |
1178 | 1178 | if (extension_loaded('tidy') && class_exists("tidy")) { |
1179 | 1179 | $conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 1; |
1180 | 1180 | } |
1181 | - $conf->global->MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES = 0; // disabled, does not work on HTML5 and some libxml versions |
|
1181 | + $conf->global->MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES = 0; // disabled, does not work on HTML5 and some libxml versions |
|
1182 | 1182 | |
1183 | 1183 | |
1184 | 1184 | |
@@ -1191,7 +1191,7 @@ discard block |
||
1191 | 1191 | //$result = dol_escape_htmltag(dol_htmlwithnojs(dol_string_onlythesehtmltags(dol_htmlentitiesbr($stringtotest), 1, 1, 1, 0)), 1, 1, 'common', 0, 1); |
1192 | 1192 | $result = dolPrintHTML($stringtotest); |
1193 | 1193 | print __METHOD__." result=".$result."\n"; |
1194 | - $this->assertEquals($stringfixed, $result, 'Error'); // Expected '' because should failed because login 'auto' does not exists |
|
1194 | + $this->assertEquals($stringfixed, $result, 'Error'); // Expected '' because should failed because login 'auto' does not exists |
|
1195 | 1195 | |
1196 | 1196 | |
1197 | 1197 | // For a string that is already HTML (contains HTML tags) with special tags but badly formatted |
@@ -1240,24 +1240,24 @@ discard block |
||
1240 | 1240 | */ |
1241 | 1241 | public function testCheckLoginPassEntity() |
1242 | 1242 | { |
1243 | - $login=checkLoginPassEntity('loginbidon', 'passwordbidon', 1, array('dolibarr')); |
|
1243 | + $login = checkLoginPassEntity('loginbidon', 'passwordbidon', 1, array('dolibarr')); |
|
1244 | 1244 | print __METHOD__." login=".$login."\n"; |
1245 | 1245 | $this->assertEquals($login, ''); |
1246 | 1246 | |
1247 | - $login=checkLoginPassEntity('admin', 'passwordbidon', 1, array('dolibarr')); |
|
1247 | + $login = checkLoginPassEntity('admin', 'passwordbidon', 1, array('dolibarr')); |
|
1248 | 1248 | print __METHOD__." login=".$login."\n"; |
1249 | 1249 | $this->assertEquals($login, ''); |
1250 | 1250 | |
1251 | - $login=checkLoginPassEntity('admin', 'admin', 1, array('dolibarr')); // Should works because admin/admin exists |
|
1251 | + $login = checkLoginPassEntity('admin', 'admin', 1, array('dolibarr')); // Should works because admin/admin exists |
|
1252 | 1252 | print __METHOD__." login=".$login."\n"; |
1253 | 1253 | $this->assertEquals($login, 'admin', 'The test to check if pass of user "admin" is "admin" has failed'); |
1254 | 1254 | |
1255 | - $login=checkLoginPassEntity('admin', 'admin', 1, array('http','dolibarr')); // Should work because of second authentication method |
|
1255 | + $login = checkLoginPassEntity('admin', 'admin', 1, array('http', 'dolibarr')); // Should work because of second authentication method |
|
1256 | 1256 | print __METHOD__." login=".$login."\n"; |
1257 | 1257 | $this->assertEquals($login, 'admin'); |
1258 | 1258 | |
1259 | - $login=checkLoginPassEntity('admin', 'admin', 1, array('forceuser')); |
|
1259 | + $login = checkLoginPassEntity('admin', 'admin', 1, array('forceuser')); |
|
1260 | 1260 | print __METHOD__." login=".$login."\n"; |
1261 | - $this->assertEquals('', $login, 'Error'); // Expected '' because should failed because login 'auto' does not exists |
|
1261 | + $this->assertEquals('', $login, 'Error'); // Expected '' because should failed because login 'auto' does not exists |
|
1262 | 1262 | } |
1263 | 1263 | } |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | |
21 | 21 | $sapi_type = php_sapi_name(); |
22 | 22 | $script_file = basename(__FILE__); |
23 | -$path=dirname(__FILE__).'/'; |
|
23 | +$path = dirname(__FILE__).'/'; |
|
24 | 24 | |
25 | -$web=0; |
|
25 | +$web = 0; |
|
26 | 26 | |
27 | 27 | // Test if batch mode |
28 | 28 | if (substr($sapi_type, 0, 3) == 'cgi') { |
29 | - $web=1; |
|
29 | + $web = 1; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | exit; |
113 | 113 | } |
114 | 114 | |
115 | -$dups=array(); |
|
116 | -$exludefiles = array('.','..','README'); |
|
115 | +$dups = array(); |
|
116 | +$exludefiles = array('.', '..', 'README'); |
|
117 | 117 | $files = array_diff($files, $exludefiles); |
118 | 118 | // To force a file: $files=array('myfile.lang'); |
119 | 119 | if (isset($argv[2])) { |
@@ -124,18 +124,18 @@ discard block |
||
124 | 124 | foreach ($files as $file) { |
125 | 125 | $path_file = pathinfo($file); |
126 | 126 | // we're only interested in .lang files |
127 | - if ($path_file['extension']=='lang') { |
|
127 | + if ($path_file['extension'] == 'lang') { |
|
128 | 128 | $content = file($workdir.$file); |
129 | 129 | foreach ($content as $line => $row) { |
130 | 130 | // don't want comment lines |
131 | 131 | if (substr($row, 0, 1) !== '#') { |
132 | 132 | // don't want lines without the separator (why should those even be here, anyway...) |
133 | - if (strpos($row, '=')!==false) { |
|
134 | - $row_array = explode('=', $row); // $row_array[0] = key |
|
135 | - $langstrings_3d[$path_file['basename']][$line+1]=$row_array[0]; |
|
136 | - $langstrings_3dtrans[$path_file['basename']][$line+1]=$row_array[1]; |
|
137 | - $langstrings_full[]=$row_array[0]; |
|
138 | - $langstrings_dist[$row_array[0]]=$row; |
|
133 | + if (strpos($row, '=') !== false) { |
|
134 | + $row_array = explode('=', $row); // $row_array[0] = key |
|
135 | + $langstrings_3d[$path_file['basename']][$line + 1] = $row_array[0]; |
|
136 | + $langstrings_3dtrans[$path_file['basename']][$line + 1] = $row_array[1]; |
|
137 | + $langstrings_full[] = $row_array[0]; |
|
138 | + $langstrings_dist[$row_array[0]] = $row; |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | foreach ($langstrings_3d as $filename => $file) { |
146 | 146 | foreach ($file as $linenum => $value) { |
147 | 147 | $keys = array_keys($langstrings_full, $value); |
148 | - if (count($keys)>1) { |
|
148 | + if (count($keys) > 1) { |
|
149 | 149 | foreach ($keys as $key) { |
150 | 150 | $dups[$value][$filename][$linenum] = trim($langstrings_3dtrans[$filename][$linenum]); |
151 | 151 | } |
@@ -167,76 +167,76 @@ discard block |
||
167 | 167 | echo "<tbody>\n"; |
168 | 168 | } |
169 | 169 | |
170 | -$sduplicateinsamefile=''; |
|
171 | -$sinmainandother=''; |
|
172 | -$sininstallandadmin=''; |
|
173 | -$sother=''; |
|
170 | +$sduplicateinsamefile = ''; |
|
171 | +$sinmainandother = ''; |
|
172 | +$sininstallandadmin = ''; |
|
173 | +$sother = ''; |
|
174 | 174 | |
175 | 175 | $count = 0; |
176 | 176 | foreach ($dups as $string => $pages) { |
177 | 177 | $count++; |
178 | - $s=''; |
|
178 | + $s = ''; |
|
179 | 179 | |
180 | 180 | // Keyword $string |
181 | 181 | if ($web) { |
182 | - $s.="<tr>"; |
|
182 | + $s .= "<tr>"; |
|
183 | 183 | } |
184 | 184 | if ($web) { |
185 | - $s.="<td align=\"center\">"; |
|
185 | + $s .= "<td align=\"center\">"; |
|
186 | 186 | } |
187 | 187 | if ($web) { |
188 | - $s.=$count; |
|
188 | + $s .= $count; |
|
189 | 189 | } |
190 | 190 | if ($web) { |
191 | - $s.="</td>"; |
|
191 | + $s .= "</td>"; |
|
192 | 192 | } |
193 | 193 | if ($web) { |
194 | - $s.="<td>"; |
|
194 | + $s .= "<td>"; |
|
195 | 195 | } |
196 | - $s.=$string; |
|
196 | + $s .= $string; |
|
197 | 197 | if ($web) { |
198 | - $s.="</td>"; |
|
198 | + $s .= "</td>"; |
|
199 | 199 | } |
200 | 200 | if ($web) { |
201 | - $s.="<td>"; |
|
201 | + $s .= "<td>"; |
|
202 | 202 | } |
203 | - if (! $web) { |
|
204 | - $s.= ' : '; |
|
203 | + if (!$web) { |
|
204 | + $s .= ' : '; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | // Loop on each files keyword was found |
208 | - $duplicateinsamefile=0; |
|
209 | - $inmain=0; |
|
210 | - $inadmin=0; |
|
208 | + $duplicateinsamefile = 0; |
|
209 | + $inmain = 0; |
|
210 | + $inadmin = 0; |
|
211 | 211 | foreach ($pages as $file => $lines) { |
212 | 212 | if ($file == 'main.lang') { |
213 | - $inmain=1; |
|
214 | - $inadmin=0; |
|
213 | + $inmain = 1; |
|
214 | + $inadmin = 0; |
|
215 | 215 | } |
216 | - if ($file == 'admin.lang' && ! $inmain) { |
|
217 | - $inadmin=1; |
|
216 | + if ($file == 'admin.lang' && !$inmain) { |
|
217 | + $inadmin = 1; |
|
218 | 218 | } |
219 | 219 | |
220 | - $s.=$file." "; |
|
220 | + $s .= $file." "; |
|
221 | 221 | |
222 | 222 | // Loop on each line keyword was found into file. |
223 | - $listoffilesforthisentry=array(); |
|
223 | + $listoffilesforthisentry = array(); |
|
224 | 224 | foreach ($lines as $line => $translatedvalue) { |
225 | 225 | if (!empty($listoffilesforthisentry[$file])) { |
226 | - $duplicateinsamefile=1; |
|
226 | + $duplicateinsamefile = 1; |
|
227 | 227 | } |
228 | - $listoffilesforthisentry[$file]=1; |
|
228 | + $listoffilesforthisentry[$file] = 1; |
|
229 | 229 | |
230 | - $s.= "(".$line." - ".htmlentities($translatedvalue).") "; |
|
230 | + $s .= "(".$line." - ".htmlentities($translatedvalue).") "; |
|
231 | 231 | } |
232 | 232 | if ($web) { |
233 | - $s.="<br>"; |
|
233 | + $s .= "<br>"; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | if ($web) { |
237 | - $s.="</td></tr>"; |
|
237 | + $s .= "</td></tr>"; |
|
238 | 238 | } |
239 | - $s.="\n"; |
|
239 | + $s .= "\n"; |
|
240 | 240 | |
241 | 241 | if ($duplicateinsamefile) { |
242 | 242 | $sduplicateinsamefile .= $s; |
@@ -249,47 +249,47 @@ discard block |
||
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | -if (! $web) { |
|
252 | +if (!$web) { |
|
253 | 253 | print "\n***** Entries duplicated in same file\n"; |
254 | 254 | } |
255 | 255 | print $sduplicateinsamefile; |
256 | -if (! $web && empty($sduplicateinsamefile)) { |
|
256 | +if (!$web && empty($sduplicateinsamefile)) { |
|
257 | 257 | print "None\n"; |
258 | 258 | } |
259 | -if (! $web) { |
|
259 | +if (!$web) { |
|
260 | 260 | print "\n"; |
261 | 261 | } |
262 | 262 | |
263 | -if (! $web) { |
|
263 | +if (!$web) { |
|
264 | 264 | print "***** Entries in main and another (keep only entry in main)\n"; |
265 | 265 | } |
266 | 266 | print $sinmainandother; |
267 | -if (! $web && empty($sinmainandother)) { |
|
267 | +if (!$web && empty($sinmainandother)) { |
|
268 | 268 | print "None\n"; |
269 | 269 | } |
270 | -if (! $web) { |
|
270 | +if (!$web) { |
|
271 | 271 | print "\n"; |
272 | 272 | } |
273 | 273 | |
274 | -if (! $web) { |
|
274 | +if (!$web) { |
|
275 | 275 | print "***** Entries in admin and another\n"; |
276 | 276 | } |
277 | 277 | print $sininstallandadmin; |
278 | -if (! $web && empty($sininstallandadmin)) { |
|
278 | +if (!$web && empty($sininstallandadmin)) { |
|
279 | 279 | print "None\n"; |
280 | 280 | } |
281 | -if (! $web) { |
|
281 | +if (!$web) { |
|
282 | 282 | print "\n"; |
283 | 283 | } |
284 | 284 | |
285 | -if (! $web) { |
|
285 | +if (!$web) { |
|
286 | 286 | print "***** Other\n"; |
287 | 287 | } |
288 | 288 | print $sother; |
289 | -if (! $web && empty($sother)) { |
|
289 | +if (!$web && empty($sother)) { |
|
290 | 290 | print "None\n"; |
291 | 291 | } |
292 | -if (! $web) { |
|
292 | +if (!$web) { |
|
293 | 293 | print "\n"; |
294 | 294 | } |
295 | 295 | |
@@ -301,265 +301,265 @@ discard block |
||
301 | 301 | |
302 | 302 | // STEP 2 - Search key not used |
303 | 303 | |
304 | -if ((!empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($argv[1]) && $argv[1]=='unused=true')) { |
|
304 | +if ((!empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($argv[1]) && $argv[1] == 'unused=true')) { |
|
305 | 305 | print "***** Strings in en_US that are never used:\n"; |
306 | 306 | |
307 | - $unused=array(); |
|
307 | + $unused = array(); |
|
308 | 308 | foreach ($langstrings_dist as $value => $line) { |
309 | - $qualifiedforclean=1; |
|
309 | + $qualifiedforclean = 1; |
|
310 | 310 | // Check if we must keep this key to be into file for removal |
311 | 311 | if (preg_match('/^Module\d+/', $value)) { |
312 | - $qualifiedforclean=0; |
|
312 | + $qualifiedforclean = 0; |
|
313 | 313 | } |
314 | 314 | if (preg_match('/^Permission\d+/', $value)) { |
315 | - $qualifiedforclean=0; |
|
315 | + $qualifiedforclean = 0; |
|
316 | 316 | } |
317 | 317 | if (preg_match('/^PermissionAdvanced\d+/', $value)) { |
318 | - $qualifiedforclean=0; |
|
318 | + $qualifiedforclean = 0; |
|
319 | 319 | } |
320 | 320 | if (preg_match('/^ProfId\d+/', $value)) { |
321 | - $qualifiedforclean=0; |
|
321 | + $qualifiedforclean = 0; |
|
322 | 322 | } |
323 | 323 | if (preg_match('/^Delays_/', $value)) { |
324 | - $qualifiedforclean=0; |
|
324 | + $qualifiedforclean = 0; |
|
325 | 325 | } |
326 | 326 | if (preg_match('/^BarcodeDesc/', $value)) { |
327 | - $qualifiedforclean=0; |
|
327 | + $qualifiedforclean = 0; |
|
328 | 328 | } |
329 | 329 | if (preg_match('/^Extrafield/', $value)) { |
330 | - $qualifiedforclean=0; |
|
330 | + $qualifiedforclean = 0; |
|
331 | 331 | } |
332 | 332 | if (preg_match('/^LocalTax/', $value)) { |
333 | - $qualifiedforclean=0; |
|
333 | + $qualifiedforclean = 0; |
|
334 | 334 | } |
335 | 335 | if (preg_match('/^Country/', $value)) { |
336 | - $qualifiedforclean=0; |
|
336 | + $qualifiedforclean = 0; |
|
337 | 337 | } |
338 | 338 | if (preg_match('/^Civility/', $value)) { |
339 | - $qualifiedforclean=0; |
|
339 | + $qualifiedforclean = 0; |
|
340 | 340 | } |
341 | 341 | if (preg_match('/^Currency/', $value)) { |
342 | - $qualifiedforclean=0; |
|
342 | + $qualifiedforclean = 0; |
|
343 | 343 | } |
344 | 344 | if (preg_match('/^DemandReasonTypeSRC/', $value)) { |
345 | - $qualifiedforclean=0; |
|
345 | + $qualifiedforclean = 0; |
|
346 | 346 | } |
347 | 347 | if (preg_match('/^PaperFormat/', $value)) { |
348 | - $qualifiedforclean=0; |
|
348 | + $qualifiedforclean = 0; |
|
349 | 349 | } |
350 | 350 | if (preg_match('/^Duration/', $value)) { |
351 | - $qualifiedforclean=0; |
|
351 | + $qualifiedforclean = 0; |
|
352 | 352 | } |
353 | 353 | if (preg_match('/^AmountLT/', $value)) { |
354 | - $qualifiedforclean=0; |
|
354 | + $qualifiedforclean = 0; |
|
355 | 355 | } |
356 | 356 | if (preg_match('/^TotalLT/', $value)) { |
357 | - $qualifiedforclean=0; |
|
357 | + $qualifiedforclean = 0; |
|
358 | 358 | } |
359 | 359 | if (preg_match('/^Month/', $value)) { |
360 | - $qualifiedforclean=0; |
|
360 | + $qualifiedforclean = 0; |
|
361 | 361 | } |
362 | 362 | if (preg_match('/^MonthShort/', $value)) { |
363 | - $qualifiedforclean=0; |
|
363 | + $qualifiedforclean = 0; |
|
364 | 364 | } |
365 | 365 | if (preg_match('/^Day\d/', $value)) { |
366 | - $qualifiedforclean=0; |
|
366 | + $qualifiedforclean = 0; |
|
367 | 367 | } |
368 | 368 | if (preg_match('/^Short/', $value)) { |
369 | - $qualifiedforclean=0; |
|
369 | + $qualifiedforclean = 0; |
|
370 | 370 | } |
371 | 371 | if (preg_match('/^ExportDataset_/', $value)) { |
372 | - $qualifiedforclean=0; |
|
372 | + $qualifiedforclean = 0; |
|
373 | 373 | } |
374 | 374 | if (preg_match('/^ImportDataset_/', $value)) { |
375 | - $qualifiedforclean=0; |
|
375 | + $qualifiedforclean = 0; |
|
376 | 376 | } |
377 | 377 | if (preg_match('/^ActionAC_/', $value)) { |
378 | - $qualifiedforclean=0; |
|
378 | + $qualifiedforclean = 0; |
|
379 | 379 | } |
380 | 380 | if (preg_match('/^TypeLocaltax/', $value)) { |
381 | - $qualifiedforclean=0; |
|
381 | + $qualifiedforclean = 0; |
|
382 | 382 | } |
383 | 383 | if (preg_match('/^StatusProspect/', $value)) { |
384 | - $qualifiedforclean=0; |
|
384 | + $qualifiedforclean = 0; |
|
385 | 385 | } |
386 | 386 | if (preg_match('/^PL_/', $value)) { |
387 | - $qualifiedforclean=0; |
|
387 | + $qualifiedforclean = 0; |
|
388 | 388 | } |
389 | 389 | if (preg_match('/^TE_/', $value)) { |
390 | - $qualifiedforclean=0; |
|
390 | + $qualifiedforclean = 0; |
|
391 | 391 | } |
392 | 392 | if (preg_match('/^JuridicalStatus/', $value)) { |
393 | - $qualifiedforclean=0; |
|
393 | + $qualifiedforclean = 0; |
|
394 | 394 | } |
395 | 395 | if (preg_match('/^CalcMode/', $value)) { |
396 | - $qualifiedforclean=0; |
|
396 | + $qualifiedforclean = 0; |
|
397 | 397 | } |
398 | 398 | if (preg_match('/^newLT/', $value)) { |
399 | - $qualifiedforclean=0; |
|
399 | + $qualifiedforclean = 0; |
|
400 | 400 | } |
401 | 401 | if (preg_match('/^LT[0-9]/', $value)) { |
402 | - $qualifiedforclean=0; |
|
402 | + $qualifiedforclean = 0; |
|
403 | 403 | } |
404 | 404 | if (preg_match('/^TypeContact_contrat_/', $value)) { |
405 | - $qualifiedforclean=0; |
|
405 | + $qualifiedforclean = 0; |
|
406 | 406 | } |
407 | 407 | if (preg_match('/^ErrorPriceExpression/', $value)) { |
408 | - $qualifiedforclean=0; |
|
408 | + $qualifiedforclean = 0; |
|
409 | 409 | } |
410 | 410 | if (preg_match('/^Language_/', $value)) { |
411 | - $qualifiedforclean=0; |
|
411 | + $qualifiedforclean = 0; |
|
412 | 412 | } |
413 | 413 | if (preg_match('/^DescADHERENT_/', $value)) { |
414 | - $qualifiedforclean=0; |
|
414 | + $qualifiedforclean = 0; |
|
415 | 415 | } |
416 | 416 | if (preg_match('/^SubmitTranslation/', $value)) { |
417 | - $qualifiedforclean=0; |
|
417 | + $qualifiedforclean = 0; |
|
418 | 418 | } |
419 | 419 | if (preg_match('/^ModuleCompanyCode/', $value)) { |
420 | - $qualifiedforclean=0; |
|
420 | + $qualifiedforclean = 0; |
|
421 | 421 | } |
422 | 422 | if (preg_match('/InDolibarr$/', $value)) { |
423 | - $qualifiedforclean=0; |
|
423 | + $qualifiedforclean = 0; |
|
424 | 424 | } |
425 | 425 | // admin.lang |
426 | 426 | if (preg_match('/^DAV_ALLOW_PUBLIC_DIR/i', $value)) { |
427 | - $qualifiedforclean=0; |
|
427 | + $qualifiedforclean = 0; |
|
428 | 428 | } |
429 | 429 | if (preg_match('/^DAV_ALLOW_ECM_DIR/i', $value)) { |
430 | - $qualifiedforclean=0; |
|
430 | + $qualifiedforclean = 0; |
|
431 | 431 | } |
432 | 432 | // boxes.lang |
433 | 433 | if (preg_match('/^BoxTitleLast/', $value)) { |
434 | - $qualifiedforclean=0; |
|
434 | + $qualifiedforclean = 0; |
|
435 | 435 | } |
436 | 436 | if (preg_match('/^BoxTitleLatest/', $value)) { |
437 | - $qualifiedforclean=0; |
|
437 | + $qualifiedforclean = 0; |
|
438 | 438 | } |
439 | 439 | // install.lang |
440 | 440 | if (preg_match('/^KeepDefaultValues/', $value)) { |
441 | - $qualifiedforclean=0; |
|
441 | + $qualifiedforclean = 0; |
|
442 | 442 | } |
443 | 443 | // mail.lang |
444 | 444 | if (preg_match('/MailingModuleDesc/i', $value)) { |
445 | - $qualifiedforclean=0; |
|
445 | + $qualifiedforclean = 0; |
|
446 | 446 | } |
447 | 447 | // main.lang |
448 | 448 | if (preg_match('/^Duration/', $value)) { |
449 | - $qualifiedforclean=0; |
|
449 | + $qualifiedforclean = 0; |
|
450 | 450 | } |
451 | 451 | if (preg_match('/^FormatDate/', $value)) { |
452 | - $qualifiedforclean=0; |
|
452 | + $qualifiedforclean = 0; |
|
453 | 453 | } |
454 | 454 | if (preg_match('/^DateFormat/', $value)) { |
455 | - $qualifiedforclean=0; |
|
455 | + $qualifiedforclean = 0; |
|
456 | 456 | } |
457 | 457 | if (preg_match('/^.b$/', $value)) { |
458 | - $qualifiedforclean=0; |
|
458 | + $qualifiedforclean = 0; |
|
459 | 459 | } |
460 | 460 | if (preg_match('/^.*Bytes$/', $value)) { |
461 | - $qualifiedforclean=0; |
|
461 | + $qualifiedforclean = 0; |
|
462 | 462 | } |
463 | 463 | if (preg_match('/^NoteSomeFeaturesAreDisabled/', $value)) { |
464 | - $qualifiedforclean=0; |
|
464 | + $qualifiedforclean = 0; |
|
465 | 465 | } |
466 | 466 | if (preg_match('/^(DoTest|Under|Limits|Cards|CurrentValue|DateLimit|DateAndHour|NbOfLines|NbOfObjects|NbOfReferes|TotalTTCShort|VATs)/', $value)) { |
467 | - $qualifiedforclean=0; |
|
467 | + $qualifiedforclean = 0; |
|
468 | 468 | } |
469 | 469 | // modulebuilder |
470 | 470 | if (preg_match('/^ModuleBuilderDesc/', $value)) { |
471 | - $qualifiedforclean=0; |
|
471 | + $qualifiedforclean = 0; |
|
472 | 472 | } |
473 | 473 | // orders |
474 | 474 | if (preg_match('/^OrderSource/', $value)) { |
475 | - $qualifiedforclean=0; |
|
475 | + $qualifiedforclean = 0; |
|
476 | 476 | } |
477 | 477 | if (preg_match('/^TypeContact_/', $value)) { |
478 | - $qualifiedforclean=0; |
|
478 | + $qualifiedforclean = 0; |
|
479 | 479 | } |
480 | 480 | // other.lang |
481 | 481 | if (preg_match('/^Notify_/', $value)) { |
482 | - $qualifiedforclean=0; |
|
482 | + $qualifiedforclean = 0; |
|
483 | 483 | } |
484 | 484 | if (preg_match('/^PredefinedMail/', $value)) { |
485 | - $qualifiedforclean=0; |
|
485 | + $qualifiedforclean = 0; |
|
486 | 486 | } |
487 | 487 | if (preg_match('/^DemoCompany/', $value)) { |
488 | - $qualifiedforclean=0; |
|
488 | + $qualifiedforclean = 0; |
|
489 | 489 | } |
490 | 490 | if (preg_match('/^WeightUnit/', $value)) { |
491 | - $qualifiedforclean=0; |
|
491 | + $qualifiedforclean = 0; |
|
492 | 492 | } |
493 | 493 | if (preg_match('/^LengthUnit/', $value)) { |
494 | - $qualifiedforclean=0; |
|
494 | + $qualifiedforclean = 0; |
|
495 | 495 | } |
496 | 496 | if (preg_match('/^SurfaceUnit/', $value)) { |
497 | - $qualifiedforclean=0; |
|
497 | + $qualifiedforclean = 0; |
|
498 | 498 | } |
499 | 499 | if (preg_match('/^VolumeUnit/', $value)) { |
500 | - $qualifiedforclean=0; |
|
500 | + $qualifiedforclean = 0; |
|
501 | 501 | } |
502 | 502 | if (preg_match('/^SizeUnit/', $value)) { |
503 | - $qualifiedforclean=0; |
|
503 | + $qualifiedforclean = 0; |
|
504 | 504 | } |
505 | 505 | if (preg_match('/^EMailText/', $value)) { |
506 | - $qualifiedforclean=0; |
|
506 | + $qualifiedforclean = 0; |
|
507 | 507 | } |
508 | 508 | if (preg_match('/ById$/', $value)) { |
509 | - $qualifiedforclean=0; |
|
509 | + $qualifiedforclean = 0; |
|
510 | 510 | } |
511 | 511 | if (preg_match('/ByLogin$/', $value)) { |
512 | - $qualifiedforclean=0; |
|
512 | + $qualifiedforclean = 0; |
|
513 | 513 | } |
514 | 514 | // printing |
515 | 515 | if (preg_match('/PrintingDriverDesc$/', $value)) { |
516 | - $qualifiedforclean=0; |
|
516 | + $qualifiedforclean = 0; |
|
517 | 517 | } |
518 | 518 | if (preg_match('/PrintTestDesc$/', $value)) { |
519 | - $qualifiedforclean=0; |
|
519 | + $qualifiedforclean = 0; |
|
520 | 520 | } |
521 | 521 | // products |
522 | 522 | if (preg_match('/GlobalVariableUpdaterType$/', $value)) { |
523 | - $qualifiedforclean=0; |
|
523 | + $qualifiedforclean = 0; |
|
524 | 524 | } |
525 | 525 | if (preg_match('/GlobalVariableUpdaterHelp$/', $value)) { |
526 | - $qualifiedforclean=0; |
|
526 | + $qualifiedforclean = 0; |
|
527 | 527 | } |
528 | 528 | if (preg_match('/OppStatus/', $value)) { |
529 | - $qualifiedforclean=0; |
|
529 | + $qualifiedforclean = 0; |
|
530 | 530 | } |
531 | 531 | if (preg_match('/AvailabilityType/', $value)) { |
532 | - $qualifiedforclean=0; |
|
532 | + $qualifiedforclean = 0; |
|
533 | 533 | } |
534 | 534 | if (preg_match('/CardProduct/', $value)) { |
535 | - $qualifiedforclean=0; |
|
535 | + $qualifiedforclean = 0; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | if (preg_match('/sms/i', $value)) { |
539 | - $qualifiedforclean=0; |
|
539 | + $qualifiedforclean = 0; |
|
540 | 540 | } |
541 | 541 | if (preg_match('/TF_/i', $value)) { |
542 | - $qualifiedforclean=0; |
|
542 | + $qualifiedforclean = 0; |
|
543 | 543 | } |
544 | 544 | if (preg_match('/WithBankUsing/i', $value)) { |
545 | - $qualifiedforclean=0; |
|
545 | + $qualifiedforclean = 0; |
|
546 | 546 | } |
547 | 547 | if (preg_match('/descWORKFLOW_/i', $value)) { |
548 | - $qualifiedforclean=0; |
|
548 | + $qualifiedforclean = 0; |
|
549 | 549 | } |
550 | 550 | |
551 | - if (! $qualifiedforclean) { |
|
551 | + if (!$qualifiedforclean) { |
|
552 | 552 | continue; |
553 | 553 | } |
554 | 554 | |
555 | 555 | //$search = '\'trans("'.$value.'")\''; |
556 | 556 | $search = '-e "\''.$value.'\'" -e \'"'.$value.'"\' -e "('.$value.')" -e "('.$value.',"'; |
557 | - $string = 'grep -R -m 1 -F --exclude=includes/* --include=*.php '.$search.' '.$htdocs.'* '.$scripts.'*'; |
|
557 | + $string = 'grep -R -m 1 -F --exclude=includes/* --include=*.php '.$search.' '.$htdocs.'* '.$scripts.'*'; |
|
558 | 558 | //print $string."<br>\n"; |
559 | 559 | exec($string, $output); |
560 | 560 | if (empty($output)) { |
561 | 561 | $unused[$value] = $line; |
562 | - echo $line; // $trad contains the \n |
|
562 | + echo $line; // $trad contains the \n |
|
563 | 563 | } else { |
564 | 564 | unset($output); |
565 | 565 | //print 'X'.$output.'Y'; |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | if (empty($unused)) { |
570 | 570 | print "No string not used found.\n"; |
571 | 571 | } else { |
572 | - $filetosave='/tmp/'.($argv[2] ? $argv[2] : "").'notused.lang'; |
|
572 | + $filetosave = '/tmp/'.($argv[2] ? $argv[2] : "").'notused.lang'; |
|
573 | 573 | print "Strings in en_US that are never used are saved into file ".$filetosave.":\n"; |
574 | 574 | file_put_contents($filetosave, implode("", $unused)); |
575 | 575 | print "To remove from original file, run command :\n"; |