1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Test; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Shopware\Core\Content\Product\SearchKeyword\ProductSearchTermInterpreter; |
8
|
|
|
use Shopware\Core\Content\Product\SearchKeyword\ProductSearchTermInterpreterInterface; |
9
|
|
|
use Shopware\Core\Defaults; |
10
|
|
|
use Shopware\Core\Framework\Context; |
11
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Term\SearchTerm; |
12
|
|
|
use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour; |
13
|
|
|
use Shopware\Core\Framework\Uuid\Uuid; |
14
|
|
|
|
15
|
|
|
class KeywordSearchTermInterpreterTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
use IntegrationTestBehaviour; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Connection |
21
|
|
|
*/ |
22
|
|
|
private $connection; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ProductSearchTermInterpreterInterface |
26
|
|
|
*/ |
27
|
|
|
private $interpreter; |
28
|
3 |
|
|
29
|
|
|
protected function setUp(): void |
30
|
3 |
|
{ |
31
|
3 |
|
$this->connection = $this->getContainer()->get(Connection::class); |
32
|
3 |
|
$this->interpreter = $this->getContainer()->get(ProductSearchTermInterpreter::class); |
33
|
3 |
|
$this->setupKeywords(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider cases |
38
|
|
|
*/ |
39
|
|
|
public function testMatching(string $term, array $expected): void |
40
|
|
|
{ |
41
|
3 |
|
$context = Context::createDefaultContext(); |
42
|
|
|
|
43
|
3 |
|
$matches = $this->interpreter->interpret($term, $context); |
44
|
|
|
|
45
|
3 |
|
$keywords = array_map(function (SearchTerm $term) { |
46
|
|
|
return $term->getTerm(); |
47
|
|
|
}, $matches->getTerms()); |
48
|
3 |
|
|
49
|
3 |
|
sort($expected); |
50
|
|
|
sort($keywords); |
51
|
3 |
|
static::assertEquals($expected, $keywords); |
52
|
3 |
|
} |
53
|
3 |
|
|
54
|
3 |
|
public function cases(): array |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
[ |
58
|
|
|
'zeichn', |
59
|
|
|
['zeichnet', 'zeichen', 'zweichnet'], |
60
|
|
|
], |
61
|
|
|
[ |
62
|
|
|
'zeichent', |
63
|
|
|
['ausgezeichnet', 'gezeichnet', 'zeichnet'], |
64
|
|
|
], |
65
|
|
|
[ |
66
|
|
|
'Büronetz', |
67
|
|
|
['büronetzwerk'], |
68
|
|
|
], |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function setupKeywords(): void |
73
|
|
|
{ |
74
|
3 |
|
$keywords = [ |
75
|
|
|
'zeichnet', |
76
|
|
|
'zweichnet', |
77
|
3 |
|
'ausgezeichnet', |
78
|
|
|
'verkehrzeichennetzwerk', |
79
|
|
|
'gezeichnet', |
80
|
|
|
'zeichen', |
81
|
|
|
'zweideutige', |
82
|
|
|
'zweier', |
83
|
|
|
'zweite', |
84
|
|
|
'zweiteilig', |
85
|
|
|
'zweiten', |
86
|
|
|
'zweites', |
87
|
|
|
'zweiweg', |
88
|
|
|
'zweifellos', |
89
|
|
|
'büronetzwerk', |
90
|
|
|
'heimnetzwerk', |
91
|
|
|
'netzwerk', |
92
|
|
|
'netzwerkadapter', |
93
|
|
|
'netzwerkbuchse', |
94
|
|
|
'netzwerkcontroller', |
95
|
|
|
'netzwerkdrucker', |
96
|
|
|
'netzwerke', |
97
|
|
|
'netzwerken', |
98
|
|
|
'netzwerkinfrastruktur', |
99
|
|
|
'netzwerkkabel', |
100
|
|
|
'netzwerkkabels', |
101
|
|
|
'netzwerkkarte', |
102
|
|
|
'netzwerklösung', |
103
|
|
|
'netzwerkschnittstelle', |
104
|
|
|
'netzwerkschnittstellen', |
105
|
|
|
'netzwerkspeicher', |
106
|
|
|
'netzwerkspeicherlösung', |
107
|
|
|
'netzwerkspieler', |
108
|
|
|
'schwarzweiß', |
109
|
|
|
'netzwerkprotokolle', |
110
|
|
|
]; |
111
|
|
|
|
112
|
|
|
$languageId = Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM); |
113
|
|
|
|
114
|
3 |
|
foreach ($keywords as $keyword) { |
115
|
|
|
preg_match_all('/./us', $keyword, $ar); |
116
|
3 |
|
|
117
|
3 |
|
$this->connection->insert('product_keyword_dictionary', [ |
118
|
|
|
'id' => Uuid::randomBytes(), |
119
|
3 |
|
'keyword' => $keyword, |
120
|
3 |
|
'language_id' => $languageId, |
121
|
3 |
|
]); |
122
|
3 |
|
} |
123
|
3 |
|
} |
124
|
|
|
} |
125
|
|
|
|