|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Wikibase\DataModel; |
|
4
|
|
|
|
|
5
|
|
|
use DataValues\Deserializers\DataValueDeserializer; |
|
6
|
|
|
use Deserializers\Deserializer; |
|
7
|
|
|
use RecursiveDirectoryIterator; |
|
8
|
|
|
use RecursiveIteratorIterator; |
|
9
|
|
|
use SplFileInfo; |
|
10
|
|
|
use Wikibase\DataModel\DeserializerFactory; |
|
11
|
|
|
use Wikibase\DataModel\Entity\BasicEntityIdParser; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @license GPL-2.0+ |
|
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
16
|
|
|
*/ |
|
17
|
|
|
class EntityDeserializationCompatibilityTest extends \PHPUnit_Framework_TestCase { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Deserializer |
|
21
|
|
|
*/ |
|
22
|
|
|
private $deserializer; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() { |
|
25
|
|
|
$deserializerFactory = new DeserializerFactory( |
|
26
|
|
|
[ |
|
27
|
|
|
'item' => function ( DeserializerFactory $factory ) { |
|
28
|
|
|
return $factory->newItemDeserializer(); |
|
29
|
|
|
}, |
|
30
|
|
|
'property' => function ( DeserializerFactory $factory ) { |
|
31
|
|
|
return $factory->newPropertyDeserializer(); |
|
32
|
|
|
}, |
|
33
|
|
|
], |
|
34
|
|
|
new DataValueDeserializer( |
|
35
|
|
|
array( |
|
36
|
|
|
'string' => 'DataValues\StringValue', |
|
37
|
|
|
'unknown' => 'DataValues\UnknownValue', |
|
38
|
|
|
'globecoordinate' => 'DataValues\GlobeCoordinateValue', |
|
39
|
|
|
'quantity' => 'DataValues\QuantityValue', |
|
40
|
|
|
'time' => 'DataValues\TimeValue', |
|
41
|
|
|
'wikibase-entityid' => 'Wikibase\DataModel\Entity\EntityIdValue', |
|
42
|
|
|
) |
|
43
|
|
|
), |
|
44
|
|
|
new BasicEntityIdParser() |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$this->deserializer = $deserializerFactory->newEntityDeserializer(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @dataProvider entityProvider |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testGivenEntitySerialization_entityIsReturned( $fileName, $serialization ) { |
|
54
|
|
|
$entity = $this->deserializer->deserialize( $serialization ); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertInstanceOf( |
|
57
|
|
|
'Wikibase\DataModel\Entity\EntityDocument', |
|
58
|
|
|
$entity, |
|
59
|
|
|
'Deserialization of ' . $fileName . ' should lead to an EntityDocument instance' |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function entityProvider() { |
|
64
|
|
|
return $this->getEntitySerializationsFromDir( __DIR__ . '/../data/' ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function getEntitySerializationsFromDir( $dir ) { |
|
68
|
|
|
$argumentLists = array(); |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var SplFileInfo $fileInfo |
|
72
|
|
|
*/ |
|
73
|
|
|
foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir ) ) as $fileInfo ) { |
|
74
|
|
|
if ( $fileInfo->getExtension() === 'json' ) { |
|
75
|
|
|
$argumentLists[] = array( |
|
76
|
|
|
$fileInfo->getFilename(), |
|
77
|
|
|
json_decode( file_get_contents( $fileInfo->getPathname() ), true ) |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $argumentLists; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|