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