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