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; |
22
|
|
|
|
23
|
|
|
use App\Entity\Base\AbstractDBElement; |
24
|
|
|
use App\Entity\LabelSystem\LabelOptions; |
25
|
|
|
use App\Entity\Parts\Part; |
26
|
|
|
use App\Entity\Parts\PartLot; |
27
|
|
|
use App\Entity\Parts\Storelocation; |
28
|
|
|
use App\Services\LabelSystem\LabelGenerator; |
29
|
|
|
use PHPUnit\Framework\TestCase; |
30
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
31
|
|
|
|
32
|
|
|
class LabelGeneratorTest extends WebTestCase |
33
|
|
|
{ |
34
|
|
|
/** @var LabelGenerator */ |
35
|
|
|
protected $service; |
36
|
|
|
|
37
|
|
|
public function setUp(): void |
38
|
|
|
{ |
39
|
|
|
self::bootKernel(); |
40
|
|
|
$this->service = self::$container->get(LabelGenerator::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function supportsDataProvider(): array |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
['part', Part::class], |
47
|
|
|
['part_lot', PartLot::class], |
48
|
|
|
['storelocation', Storelocation::class] |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @dataProvider supportsDataProvider |
54
|
|
|
*/ |
55
|
|
|
public function testSupports(string $type, string $class) |
56
|
|
|
{ |
57
|
|
|
$options = new LabelOptions(); |
58
|
|
|
$options->setSupportedElement($type); |
59
|
|
|
|
60
|
|
|
//Ensure that the given class is supported |
61
|
|
|
$this->assertTrue($this->service->supports($options, new $class())); |
62
|
|
|
|
63
|
|
|
//Ensure that another class is not supported |
64
|
|
|
$not_supported = new class extends AbstractDBElement { |
65
|
|
|
|
66
|
|
|
public function getIDString(): string |
67
|
|
|
{ |
68
|
|
|
return "not_important"; |
69
|
|
|
} |
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
$this->assertFalse($this->service->supports($options, $not_supported)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testMmToPointsArray() |
76
|
|
|
{ |
77
|
|
|
$this->assertSame( |
78
|
|
|
[0.0, 0.0, 141.7325, 85.0395], |
79
|
|
|
$this->service->mmToPointsArray(50.0, 30.0) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testGenerateLabel() |
84
|
|
|
{ |
85
|
|
|
$part = new Part(); |
86
|
|
|
$options = new LabelOptions(); |
87
|
|
|
$options->setLines('Test'); |
88
|
|
|
$options->setSupportedElement('part'); |
89
|
|
|
|
90
|
|
|
//Test for a single passed element: |
91
|
|
|
$pdf = $this->service->generateLabel($options, $part); |
92
|
|
|
//Just a simple check if a PDF is returned |
93
|
|
|
$this->assertStringStartsWith('%PDF-', $pdf); |
94
|
|
|
|
95
|
|
|
//Test for an array of elements |
96
|
|
|
$pdf = $this->service->generateLabel($options, [$part, $part]); |
97
|
|
|
//Just a simple check if a PDF is returned |
98
|
|
|
$this->assertStringStartsWith('%PDF-', $pdf); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|