1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (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 Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace App\Tests\Services\LabelSystem\PlaceholderProviders; |
22
|
|
|
|
23
|
|
|
use App\Entity\Contracts\NamedElementInterface; |
24
|
|
|
use App\Entity\Parts\Part; |
25
|
|
|
use App\Entity\Parts\PartLot; |
26
|
|
|
use App\Entity\Parts\Storelocation; |
27
|
|
|
use App\Services\LabelSystem\PlaceholderProviders\NamedElementProvider; |
28
|
|
|
use App\Services\LabelSystem\PlaceholderProviders\PartLotProvider; |
29
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
30
|
|
|
|
31
|
|
|
class PartLotProviderTest extends WebTestCase |
32
|
|
|
{ |
33
|
|
|
/** @var PartLotProvider */ |
34
|
|
|
protected $service; |
35
|
|
|
|
36
|
|
|
protected $target; |
37
|
|
|
|
38
|
|
|
public function setUp(): void |
39
|
|
|
{ |
40
|
|
|
self::bootKernel(); |
41
|
|
|
\Locale::setDefault('en'); |
42
|
|
|
$this->service = self::$container->get(PartLotProvider::class); |
43
|
|
|
$this->target = new PartLot(); |
44
|
|
|
$this->target->setDescription('Lot description'); |
45
|
|
|
$this->target->setComment('Lot comment'); |
46
|
|
|
$this->target->setExpirationDate(new \DateTime('1999-04-13')); |
47
|
|
|
$this->target->setInstockUnknown(true); |
48
|
|
|
|
49
|
|
|
$location = new Storelocation(); |
50
|
|
|
$location->setName('Location'); |
51
|
|
|
$location->setParent((new Storelocation())->setName('Parent')); |
52
|
|
|
$this->target->setStorageLocation($location); |
53
|
|
|
|
54
|
|
|
$part = new Part(); |
55
|
|
|
$part->setName('Part'); |
56
|
|
|
$part->setDescription('Part description'); |
57
|
|
|
$this->target->setPart($part); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function dataProvider(): array |
61
|
|
|
{ |
62
|
|
|
return [ |
63
|
|
|
['unknown', '[[LOT_ID]]'], |
64
|
|
|
['Lot description', '[[LOT_NAME]]'], |
65
|
|
|
['Lot comment', '[[LOT_COMMENT]]'], |
66
|
|
|
['4/13/99', '[[EXPIRATION_DATE]]'], |
67
|
|
|
['?', '[[AMOUNT]]'], |
68
|
|
|
['Location', '[[LOCATION]]'], |
69
|
|
|
['Parent → Location', '[[LOCATION_FULL]]'], |
70
|
|
|
//Test part inheritance |
71
|
|
|
['Part', '[[NAME]]'], |
72
|
|
|
['Part description', '[[DESCRIPTION]]'], |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @dataProvider dataProvider |
78
|
|
|
*/ |
79
|
|
|
public function testReplace(string $expected, string $placeholder): void |
80
|
|
|
{ |
81
|
|
|
$this->assertSame($expected, $this->service->replace($placeholder, $this->target)); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|