1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Wikibase\InternalSerialization\Deserializers; |
4
|
|
|
|
5
|
|
|
use Deserializers\Deserializer; |
6
|
|
|
use Deserializers\Exceptions\DeserializationException; |
7
|
|
|
use Wikibase\DataModel\Term\AliasGroup; |
8
|
|
|
use Wikibase\DataModel\Term\AliasGroupList; |
9
|
|
|
use Wikibase\DataModel\Term\Fingerprint; |
10
|
|
|
use Wikibase\DataModel\Term\Term; |
11
|
|
|
use Wikibase\DataModel\Term\TermList; |
12
|
|
|
use Wikibase\InternalSerialization\Deserializers\LegacyFingerprintDeserializer; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers Wikibase\InternalSerialization\Deserializers\LegacyFingerprintDeserializer |
16
|
|
|
* |
17
|
|
|
* @license GPL-2.0-or-later |
18
|
|
|
* @author Jeroen De Dauw < [email protected] > |
19
|
|
|
*/ |
20
|
|
|
class LegacyFingerprintDeserializerTest extends \PHPUnit\Framework\TestCase { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Deserializer |
24
|
|
|
*/ |
25
|
|
|
private $deserializer; |
26
|
|
|
|
27
|
|
|
protected function setUp() : void { |
28
|
|
|
$this->deserializer = new LegacyFingerprintDeserializer(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @dataProvider TermListProvider |
33
|
|
|
*/ |
34
|
|
|
public function testGivenLabels_getLabelsReturnsThem( array $labelSerialization, $expected ) { |
35
|
|
|
$fingerprint = $this->deserializer->deserialize( array( 'label' => $labelSerialization ) ); |
36
|
|
|
|
37
|
|
|
$this->assertEquals( $expected, $fingerprint->getLabels() ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function TermListProvider() { |
41
|
|
|
return array( |
42
|
|
|
array( |
43
|
|
|
array(), |
44
|
|
|
new TermList( array() ) |
45
|
|
|
), |
46
|
|
|
|
47
|
|
|
array( |
48
|
|
|
array( |
49
|
|
|
'en' => 'foo', |
50
|
|
|
'de' => 'bar', |
51
|
|
|
), |
52
|
|
|
new TermList( array( |
53
|
|
|
new Term( 'en', 'foo' ), |
54
|
|
|
new Term( 'de', 'bar' ), |
55
|
|
|
) ) |
56
|
|
|
), |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGivenNonArray_exceptionIsThrown() { |
61
|
|
|
$this->expectDeserializationException(); |
62
|
|
|
$this->deserializer->deserialize( null ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testGivenNonArrayLabels_exceptionIsThrown() { |
66
|
|
|
$this->expectDeserializationException(); |
67
|
|
|
$this->deserializer->deserialize( array( 'label' => null ) ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testGivenInvalidTermSerialization_exceptionIsThrown() { |
71
|
|
|
$this->expectDeserializationException(); |
72
|
|
|
$this->deserializer->deserialize( array( 'label' => array( null ) ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function expectDeserializationException() { |
76
|
|
|
$this->expectException( DeserializationException::class ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testGivenNonArrayDescriptions_exceptionIsThrown() { |
80
|
|
|
$this->expectDeserializationException(); |
81
|
|
|
$this->deserializer->deserialize( array( 'description' => null ) ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @dataProvider descriptionListProvider |
86
|
|
|
*/ |
87
|
|
|
public function testGivenDescriptions_getDescriptionsReturnsThem( array $descriptionSerialization, $expected ) { |
88
|
|
|
$fingerprint = $this->deserializer->deserialize( array( 'description' => $descriptionSerialization ) ); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( $expected, $fingerprint->getDescriptions() ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function descriptionListProvider() { |
94
|
|
|
return array( |
95
|
|
|
array( |
96
|
|
|
array(), |
97
|
|
|
new TermList( array() ) |
98
|
|
|
), |
99
|
|
|
|
100
|
|
|
array( |
101
|
|
|
array( |
102
|
|
|
'en' => 'foo', |
103
|
|
|
'de' => 'bar', |
104
|
|
|
), |
105
|
|
|
new TermList( array( |
106
|
|
|
new Term( 'en', 'foo' ), |
107
|
|
|
new Term( 'de', 'bar' ), |
108
|
|
|
) ) |
109
|
|
|
), |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testGivenNonArrayAliases_exceptionIsThrown() { |
114
|
|
|
$this->expectDeserializationException(); |
115
|
|
|
$this->deserializer->deserialize( array( 'aliases' => null ) ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @dataProvider aliasesListProvider |
120
|
|
|
*/ |
121
|
|
|
public function testGivenAliases_getAliasesReturnsThem( array $aliasesSerialization, $expected ) { |
122
|
|
|
/** |
123
|
|
|
* @var Fingerprint $fingerprint |
124
|
|
|
*/ |
125
|
|
|
$fingerprint = $this->deserializer->deserialize( array( 'aliases' => $aliasesSerialization ) ); |
126
|
|
|
|
127
|
|
|
$this->assertEquals( $expected, $fingerprint->getAliasGroups() ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function aliasesListProvider() { |
131
|
|
|
return array( |
132
|
|
|
array( |
133
|
|
|
array(), |
134
|
|
|
new AliasGroupList( array() ) |
135
|
|
|
), |
136
|
|
|
|
137
|
|
|
array( |
138
|
|
|
array( |
139
|
|
|
'en' => array( 'foo', 'bar' ), |
140
|
|
|
'de' => array( 'foo', 'bar', 'baz' ), |
141
|
|
|
'nl' => array( 'bah' ), |
142
|
|
|
'fr' => array(), |
143
|
|
|
), |
144
|
|
|
new AliasGroupList( array( |
145
|
|
|
new AliasGroup( 'en', array( 'foo', 'bar' ) ), |
146
|
|
|
new AliasGroup( 'de', array( 'foo', 'bar', 'baz' ) ), |
147
|
|
|
new AliasGroup( 'nl', array( 'bah' ) ), |
148
|
|
|
) ) |
149
|
|
|
), |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
} |
154
|
|
|
|