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\Parameters; |
22
|
|
|
|
23
|
|
|
use App\Entity\Parameters\AbstractParameter; |
24
|
|
|
use App\Services\Parameters\ParameterExtractor; |
25
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
26
|
|
|
|
27
|
|
|
class ParameterExtractorTest extends WebTestCase |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
protected $service; |
31
|
|
|
|
32
|
|
|
public function setUp(): void |
33
|
|
|
{ |
34
|
|
|
parent::setUp(); |
35
|
|
|
//Get an service instance. |
36
|
|
|
self::bootKernel(); |
37
|
|
|
$this->service = self::$container->get(ParameterExtractor::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function emptyDataProvider(): array |
41
|
|
|
{ |
42
|
|
|
return [ |
43
|
|
|
[""], |
44
|
|
|
[" "], |
45
|
|
|
["\t\n"], |
46
|
|
|
[":;"], |
47
|
|
|
["NPN Transistor"], |
48
|
|
|
["=BC547 rewr"], |
49
|
|
|
["<i>For good</i>, [b]bad[/b], evil"], |
50
|
|
|
["Param:; Test"] |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @dataProvider emptyDataProvider |
56
|
|
|
*/ |
57
|
|
|
public function testShouldReturnEmpty(string $input) |
58
|
|
|
{ |
59
|
|
|
$this->assertEmpty($this->service->extractParameters($input)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testExtract() |
63
|
|
|
{ |
64
|
|
|
$parameters = $this->service->extractParameters(' Operating Voltage: 10 V; Property : Value, Ström=1A (Test)'); |
65
|
|
|
$this->assertContainsOnly(AbstractParameter::class, $parameters); |
66
|
|
|
$this->assertCount(3, $parameters); |
67
|
|
|
$this->assertSame('Operating Voltage', $parameters[0]->getName()); |
68
|
|
|
$this->assertSame('10 V', $parameters[0]->getValueText()); |
69
|
|
|
$this->assertSame('Property', $parameters[1]->getName()); |
70
|
|
|
$this->assertSame('Value', $parameters[1]->getValueText()); |
71
|
|
|
$this->assertSame('Ström', $parameters[2]->getName()); |
72
|
|
|
$this->assertSame('1A (Test)', $parameters[2]->getValueText()); |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|