|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software; you can redistribute it and/or |
|
8
|
|
|
* modify it under the terms of the GNU General Public License |
|
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
10
|
|
|
* of the License, or (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program; if not, write to the Free Software |
|
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace App\Tests\Services\Attachments; |
|
23
|
|
|
|
|
24
|
|
|
use App\Services\Attachments\BuiltinAttachmentsFinder; |
|
25
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
26
|
|
|
|
|
27
|
|
|
class BuiltinAttachmentsFinderTest extends WebTestCase |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var BuiltinAttachmentsFinder */ |
|
30
|
|
|
protected static $service; |
|
31
|
|
|
|
|
32
|
|
|
protected static $mock_list = [ |
|
33
|
|
|
'%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS%/123.jpg', '%FOOTPRINTS%/123.jpeg', |
|
34
|
|
|
'%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt', |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
public static function setUpBeforeClass() |
|
38
|
|
|
{ |
|
39
|
|
|
//Get an service instance. |
|
40
|
|
|
self::bootKernel(); |
|
41
|
|
|
self::$service = self::$container->get(BuiltinAttachmentsFinder::class); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function dataProvider() |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
//No value should return empty array |
|
48
|
|
|
['', [], []], |
|
49
|
|
|
['', ['empty_returns_all' => true], static::$mock_list], |
|
50
|
|
|
//Basic search for keyword |
|
51
|
|
|
['test', [], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS_3D%/test.jpg']], |
|
52
|
|
|
['%FOOTPRINTS_3D%', [], ['%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt']], |
|
53
|
|
|
['.txt', [], ['%FOOTPRINTS_3D%/hallo.txt']], |
|
54
|
|
|
//Filter extensions |
|
55
|
|
|
//['test', ['allowed_extensions' => ['jpeg', 'jpg']], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/123.jpeg', '%FOOTPRINTS_3D%/test.jpg']], |
|
56
|
|
|
//['test.jpg', ['allowed_extensions' => ['jpeg', 'jpg']], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS_3D%/test.jpg']] |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @dataProvider dataProvider |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testFind($keyword, $options, $expected) |
|
64
|
|
|
{ |
|
65
|
|
|
$value = static::$service->find($keyword, $options, static::$mock_list); |
|
66
|
|
|
//$this->assertEquals($expected, static::$service->find($keyword, $options, static::$mock_list)); |
|
67
|
|
|
$this->assertEquals([], array_diff($value, $expected), 'Additional'); |
|
68
|
|
|
$this->assertEquals([], array_diff($expected, $value), 'Missing:'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|