1 | <?php |
||
24 | class EntityIdValueTest extends PHPUnit_Framework_TestCase { |
||
25 | |||
26 | public function testCanConstruct() { |
||
27 | $entityId = new ItemId( 'Q123' ); |
||
28 | $entityIdValue = new EntityIdValue( $entityId ); |
||
29 | $this->assertEquals( $entityId, $entityIdValue->getEntityId() ); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @dataProvider instanceProvider |
||
34 | */ |
||
35 | public function testSerialzationRoundtrip( EntityIdValue $id ) { |
||
36 | $serialized = serialize( $id ); |
||
37 | $newId = unserialize( $serialized ); |
||
38 | |||
39 | $this->assertEquals( $id, $newId ); |
||
40 | } |
||
41 | |||
42 | public function instanceProvider() { |
||
43 | $ids = [ |
||
44 | 'Q1' => new ItemId( 'Q1' ), |
||
45 | 'Q2147483647' => new ItemId( 'Q2147483647' ), |
||
46 | 'P31337' => new PropertyId( 'P31337' ), |
||
47 | 'X567' => $this->newCustomId( 'X567' ), |
||
48 | 'foo:P678' => new PropertyId( 'foo:P678' ), |
||
49 | ]; |
||
50 | |||
51 | $argLists = []; |
||
52 | |||
53 | foreach ( $ids as $k => $id ) { |
||
54 | $argLists[$k] = [ new EntityIdValue( $id ) ]; |
||
55 | } |
||
56 | |||
57 | return $argLists; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @dataProvider instanceProvider |
||
62 | */ |
||
63 | public function testGetType( EntityIdValue $id ) { |
||
64 | $this->assertEquals( 'wikibase-entityid', $id->getType() ); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @dataProvider instanceProvider |
||
69 | */ |
||
70 | public function testGetValue( EntityIdValue $id ) { |
||
71 | $this->assertEquals( $id, $id->getValue() ); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @dataProvider instanceProvider |
||
76 | */ |
||
77 | public function testGetSortKey( EntityIdValue $id ) { |
||
80 | |||
81 | public function provideGetArrayValue() { |
||
116 | |||
117 | /** |
||
118 | * @dataProvider provideGetArrayValue |
||
119 | */ |
||
120 | public function testGetArrayValue( EntityId $id, array $expected ) { |
||
128 | |||
129 | public function testSerialize() { |
||
134 | |||
135 | public function provideDeserializationCompatibility() { |
||
136 | |||
137 | $local = new EntityIdValue( new ItemId( 'Q31337' ) ); |
||
138 | $foreign = new EntityIdValue( new PropertyId( 'foo:P678' ) ); |
||
139 | $custom = new EntityIdValue( $this->newCustomId( 'X567' ) ); |
||
163 | |||
164 | /** |
||
165 | * @dataProvider provideDeserializationCompatibility |
||
166 | * |
||
167 | * @param string $serialized |
||
168 | * @param EntityId $expected |
||
169 | */ |
||
170 | public function testDeserializationCompatibility( $serialized, EntityIdValue $expected ) { |
||
174 | |||
175 | /** |
||
176 | * @dataProvider validArrayProvider |
||
177 | */ |
||
178 | public function testNewFromArrayCompatibility( array $array ) { |
||
183 | |||
184 | public function validArrayProvider() { |
||
197 | |||
198 | /** |
||
199 | * @dataProvider invalidArrayProvider |
||
200 | */ |
||
201 | public function testCannotDeserializeInvalidSerialization( $invalidArray ) { |
||
206 | |||
207 | public function invalidArrayProvider() { |
||
248 | |||
249 | /** |
||
250 | * @param string $string |
||
251 | * |
||
252 | * @return EntityId |
||
253 | */ |
||
254 | private function newCustomId( $string ) { |
||
257 | |||
258 | } |
||
259 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.