|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Wikibase\DataModel\Deserializers; |
|
4
|
|
|
|
|
5
|
|
|
use Wikibase\DataModel\Deserializers\SiteLinkDeserializer; |
|
6
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
7
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
|
8
|
|
|
use Wikibase\DataModel\SiteLink; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers Wikibase\DataModel\Deserializers\SiteLinkDeserializer |
|
12
|
|
|
* |
|
13
|
|
|
* @licence GNU GPL v2+ |
|
14
|
|
|
* @author Thomas Pellissier Tanon |
|
15
|
|
|
*/ |
|
16
|
|
|
class SiteLinkDeserializerTest extends DeserializerBaseTest { |
|
17
|
|
|
|
|
18
|
|
|
public function buildDeserializer() { |
|
19
|
|
|
$entityIdDeserializerMock = $this->getMock( '\Deserializers\Deserializer' ); |
|
20
|
|
|
$entityIdDeserializerMock->expects( $this->any() ) |
|
21
|
|
|
->method( 'deserialize' ) |
|
22
|
|
|
->with( $this->equalTo( 'Q42' ) ) |
|
23
|
|
|
->will( $this->returnValue( new ItemId( 'Q42' ) ) ); |
|
24
|
|
|
|
|
25
|
|
|
return new SiteLinkDeserializer( $entityIdDeserializerMock ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function deserializableProvider() { |
|
29
|
|
|
return array( array() ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function nonDeserializableProvider() { |
|
33
|
|
|
return array( |
|
34
|
|
|
array( |
|
35
|
|
|
42 |
|
36
|
|
|
), |
|
37
|
|
|
array( |
|
38
|
|
|
array() |
|
39
|
|
|
), |
|
40
|
|
|
array( |
|
41
|
|
|
array( |
|
42
|
|
|
'id' => 'P10' |
|
43
|
|
|
) |
|
44
|
|
|
), |
|
45
|
|
|
array( |
|
46
|
|
|
array( |
|
47
|
|
|
'site' => '42value' |
|
48
|
|
|
) |
|
49
|
|
|
), |
|
50
|
|
|
array( |
|
51
|
|
|
array( |
|
52
|
|
|
'title' => '42value' |
|
53
|
|
|
) |
|
54
|
|
|
), |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function deserializationProvider() { |
|
59
|
|
|
return array( |
|
60
|
|
|
array( |
|
61
|
|
|
new SiteLink( 'enwiki', 'Nyan Cat' ), |
|
62
|
|
|
array( |
|
63
|
|
|
'site' => 'enwiki', |
|
64
|
|
|
'title' => 'Nyan Cat' |
|
65
|
|
|
) |
|
66
|
|
|
), |
|
67
|
|
|
array( |
|
68
|
|
|
new SiteLink( 'enwiki', 'Nyan Cat', array( |
|
69
|
|
|
new ItemId( 'Q42' ) |
|
70
|
|
|
) ), |
|
71
|
|
|
array( |
|
72
|
|
|
'site' => 'enwiki', |
|
73
|
|
|
'title' => 'Nyan Cat', |
|
74
|
|
|
'badges' => array( 'Q42' ) |
|
75
|
|
|
) |
|
76
|
|
|
), |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testDeserializeItemIdFilterPropertyId() { |
|
81
|
|
|
$entityIdDeserializerMock = $this->getMock( '\Deserializers\Deserializer' ); |
|
82
|
|
|
$entityIdDeserializerMock->expects( $this->any() ) |
|
83
|
|
|
->method( 'deserialize' ) |
|
84
|
|
|
->with( $this->equalTo( 'P42' ) ) |
|
85
|
|
|
->will( $this->returnValue( new PropertyId( 'P42' ) ) ); |
|
86
|
|
|
$deserializer = new SiteLinkDeserializer( $entityIdDeserializerMock ); |
|
87
|
|
|
|
|
88
|
|
|
$this->setExpectedException( '\Deserializers\Exceptions\InvalidAttributeException' ); |
|
89
|
|
|
$deserializer->deserialize( array( |
|
90
|
|
|
'site' => 'frwikisource', |
|
91
|
|
|
'title' => 'Nyan Cat', |
|
92
|
|
|
'badges' => array( 'P42' ) |
|
93
|
|
|
) ); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testAssertBadgesIsArray() { |
|
97
|
|
|
$entityIdDeserializerMock = $this->getMock( '\Deserializers\Deserializer' ); |
|
98
|
|
|
$deserializer = new SiteLinkDeserializer( $entityIdDeserializerMock ); |
|
99
|
|
|
|
|
100
|
|
|
$this->setExpectedException( '\Deserializers\Exceptions\InvalidAttributeException' ); |
|
101
|
|
|
$deserializer->deserialize( array( |
|
102
|
|
|
'site' => 'frwikisource', |
|
103
|
|
|
'title' => 'Nyan Cat', |
|
104
|
|
|
'badges' => 'Q42' |
|
105
|
|
|
) ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|