1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Wikibase\DataModel\Serializers; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Serializers\Exceptions\UnsupportedObjectException; |
7
|
|
|
use Wikibase\DataModel\Serializers\AliasGroupSerializer; |
8
|
|
|
use Wikibase\DataModel\Term\AliasGroup; |
9
|
|
|
use Wikibase\DataModel\Term\AliasGroupFallback; |
10
|
|
|
use Wikibase\DataModel\Term\AliasGroupList; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers Wikibase\DataModel\Serializers\AliasGroupSerializer |
14
|
|
|
* |
15
|
|
|
* @license GPL-2.0-or-later |
16
|
|
|
* @author Bene* < [email protected] > |
17
|
|
|
*/ |
18
|
|
|
class AliasGroupSerializerTest extends TestCase { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @dataProvider nonSerializableProvider |
22
|
|
|
*/ |
23
|
|
|
public function testSerializeThrowsUnsupportedObjectException( $nonSerializable ) { |
24
|
|
|
$serializer = new AliasGroupSerializer(); |
25
|
|
|
|
26
|
|
|
$this->expectException( UnsupportedObjectException::class ); |
27
|
|
|
$serializer->serialize( $nonSerializable ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function nonSerializableProvider() { |
31
|
|
|
return [ |
32
|
|
|
[ |
33
|
|
|
5 |
34
|
|
|
], |
35
|
|
|
[ |
36
|
|
|
[] |
37
|
|
|
], |
38
|
|
|
[ |
39
|
|
|
new AliasGroupList() |
40
|
|
|
] |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @dataProvider serializationProvider |
46
|
|
|
*/ |
47
|
|
|
public function testSerialization( $serialization, $object ) { |
48
|
|
|
$serializer = new AliasGroupSerializer(); |
49
|
|
|
$this->assertSame( $serialization, $serializer->serialize( $object ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function serializationProvider() { |
53
|
|
|
return [ |
54
|
|
|
[ |
55
|
|
|
[], |
56
|
|
|
new AliasGroup( 'en', [] ) |
57
|
|
|
], |
58
|
|
|
[ |
59
|
|
|
[ |
60
|
|
|
[ 'language' => 'en', 'value' => 'One' ] |
61
|
|
|
], |
62
|
|
|
new AliasGroup( 'en', [ 'One' ] ) |
63
|
|
|
], |
64
|
|
|
[ |
65
|
|
|
[ |
66
|
|
|
[ 'language' => 'en', 'value' => 'One' ], |
67
|
|
|
[ 'language' => 'en', 'value' => 'Pony' ] |
68
|
|
|
], |
69
|
|
|
new AliasGroup( 'en', [ 'One', 'Pony' ] ) |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
[ |
73
|
|
|
[ 'language' => 'de', 'value' => 'One', 'source' => 'fr' ], |
74
|
|
|
[ 'language' => 'de', 'value' => 'Pony', 'source' => 'fr' ], |
75
|
|
|
], |
76
|
|
|
new AliasGroupFallback( 'en', [ 'One', 'Pony' ], 'de', 'fr' ) |
77
|
|
|
] |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|