|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Search\Tests\Common\FieldValueMapper; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Search\Common\FieldValueMapper\RemoteIdentifierMapper; |
|
12
|
|
|
use eZ\Publish\Core\Search\Tests\TestCase; |
|
13
|
|
|
use eZ\Publish\SPI\Search\Field; |
|
14
|
|
|
use eZ\Publish\SPI\Search\FieldType\IdentifierField; |
|
15
|
|
|
use eZ\Publish\SPI\Search\FieldType\IntegerField; |
|
16
|
|
|
use eZ\Publish\SPI\Search\FieldType\RemoteIdentifierField; |
|
17
|
|
|
use eZ\Publish\SPI\Search\FieldType\StringField; |
|
18
|
|
|
|
|
19
|
|
|
final class RemoteIdentifierMapperTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var \eZ\Publish\Core\Search\Common\FieldValueMapper\RemoteIdentifierMapper */ |
|
22
|
|
|
private $mapper; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->mapper = new RemoteIdentifierMapper(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @covers \eZ\Publish\Core\Search\Common\FieldValueMapper\RemoteIdentifierMapper::canMap |
|
31
|
|
|
* |
|
32
|
|
|
* @dataProvider getDataForTestCanMap |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testCanMap(Field $field, bool $canMap): void |
|
35
|
|
|
{ |
|
36
|
|
|
self::assertSame($canMap, $this->mapper->canMap($field)); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getDataForTestCanMap(): iterable |
|
40
|
|
|
{ |
|
41
|
|
|
yield 'can map' => [ |
|
42
|
|
|
new Field('id', 1, new RemoteIdentifierField()), |
|
43
|
|
|
true, |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
yield 'cannot map (identifier)' => [ |
|
47
|
|
|
new Field('id', 1, new IdentifierField()), |
|
48
|
|
|
false, |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
yield 'cannot map (string)' => [ |
|
52
|
|
|
new Field('name', 1, new StringField()), |
|
53
|
|
|
false, |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
|
|
yield 'cannot map (integer)' => [ |
|
57
|
|
|
new Field('number', 1, new IntegerField()), |
|
58
|
|
|
false, |
|
59
|
|
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @covers \eZ\Publish\Core\Search\Common\FieldValueMapper\IdentifierMapper::map |
|
64
|
|
|
* |
|
65
|
|
|
* @dataProvider getDataForTestMap |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testMap(Field $field, string $expectedMappedValue): void |
|
68
|
|
|
{ |
|
69
|
|
|
self::assertSame($expectedMappedValue, $this->mapper->map($field)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getDataForTestMap(): iterable |
|
73
|
|
|
{ |
|
74
|
|
|
yield 'numeric id' => [ |
|
75
|
|
|
new Field('id', 1, new IdentifierField()), |
|
76
|
|
|
1, |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
yield 'remote_id md5' => [ |
|
80
|
|
|
new Field( |
|
81
|
|
|
'remote_id', |
|
82
|
|
|
'1611729231d469e6b53c431f476926ac', |
|
83
|
|
|
new IdentifierField() |
|
84
|
|
|
), |
|
85
|
|
|
'1611729231d469e6b53c431f476926ac', |
|
86
|
|
|
]; |
|
87
|
|
|
|
|
88
|
|
|
yield 'external remote_id' => [ |
|
89
|
|
|
new Field( |
|
90
|
|
|
'location_remote_id', |
|
91
|
|
|
'external:10', |
|
92
|
|
|
new IdentifierField() |
|
93
|
|
|
), |
|
94
|
|
|
'external:10', |
|
95
|
|
|
]; |
|
96
|
|
|
|
|
97
|
|
|
yield 'section identifier' => [ |
|
98
|
|
|
new Field( |
|
99
|
|
|
'section_identifier', |
|
100
|
|
|
'my_section', |
|
101
|
|
|
new IdentifierField() |
|
102
|
|
|
), |
|
103
|
|
|
'my_section', |
|
104
|
|
|
]; |
|
105
|
|
|
|
|
106
|
|
|
yield 'path string' => [ |
|
107
|
|
|
new Field( |
|
108
|
|
|
'path_string', |
|
109
|
|
|
'/1/2/54/', |
|
110
|
|
|
new IdentifierField() |
|
111
|
|
|
), |
|
112
|
|
|
'/1/2/54/', |
|
113
|
|
|
]; |
|
114
|
|
|
|
|
115
|
|
|
yield 'identifier with national characters' => [ |
|
116
|
|
|
new Field( |
|
117
|
|
|
'some_identifier', |
|
118
|
|
|
'zażółć gęślą jaźń', |
|
119
|
|
|
new IdentifierField() |
|
120
|
|
|
), |
|
121
|
|
|
'zażółć gęślą jaźń', |
|
122
|
|
|
]; |
|
123
|
|
|
|
|
124
|
|
|
yield 'identifier with non-printable characters' => [ |
|
125
|
|
|
new Field( |
|
126
|
|
|
'identifier', |
|
127
|
|
|
utf8_decode("Non\x09Printable\x0EIdentifier"), |
|
128
|
|
|
new IdentifierField() |
|
129
|
|
|
), |
|
130
|
|
|
'Non PrintableIdentifier', |
|
131
|
|
|
]; |
|
132
|
|
|
|
|
133
|
|
|
$value = 'Emoji: ' . json_decode('"\ud83d\ude00"'); |
|
134
|
|
|
yield 'identifier with emojis' => [ |
|
135
|
|
|
new Field( |
|
136
|
|
|
'identifier', |
|
137
|
|
|
$value, |
|
138
|
|
|
new IdentifierField() |
|
139
|
|
|
), |
|
140
|
|
|
$value, |
|
141
|
|
|
]; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|