|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Integration\Wikibase\InternalSerialization; |
|
4
|
|
|
|
|
5
|
|
|
use Deserializers\Deserializer; |
|
6
|
|
|
use RecursiveDirectoryIterator; |
|
7
|
|
|
use RecursiveIteratorIterator; |
|
8
|
|
|
use SplFileInfo; |
|
9
|
|
|
use Wikibase\DataModel\Entity\Item; |
|
10
|
|
|
use Wikibase\DataModel\Entity\Property; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @covers Wikibase\InternalSerialization\DeserializerFactory |
|
14
|
|
|
* |
|
15
|
|
|
* @license GPL-2.0-or-later |
|
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
17
|
|
|
*/ |
|
18
|
|
|
class RealEntitiesTest extends \PHPUnit\Framework\TestCase { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var Deserializer |
|
22
|
|
|
*/ |
|
23
|
|
|
private $deserializer; |
|
24
|
|
|
|
|
25
|
|
|
protected function setUp() : void { |
|
26
|
|
|
$this->deserializer = TestFactoryBuilder::newDeserializerFactoryWithDataValueSupport()->newEntityDeserializer(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @dataProvider itemLegacySerializationProvider |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testGivenLegacyItem_DeserializationReturnsItem( $fileName, $serialization ) { |
|
33
|
|
|
$item = $this->deserializer->deserialize( $serialization ); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertInstanceOf( |
|
36
|
|
|
Item::class, |
|
37
|
|
|
$item, |
|
38
|
|
|
$fileName . ' should deserialize into an Item' |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function itemLegacySerializationProvider() { |
|
43
|
|
|
return $this->getEntitySerializationsFromDir( __DIR__ . '/../data/items/legacy/' ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private function getEntitySerializationsFromDir( $dir ) { |
|
47
|
|
|
$argumentLists = array(); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var SplFileInfo $fileInfo |
|
51
|
|
|
*/ |
|
52
|
|
|
foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir ) ) as $fileInfo ) { |
|
53
|
|
|
if ( $fileInfo->getExtension() === 'json' ) { |
|
54
|
|
|
$argumentLists[] = array( |
|
55
|
|
|
$fileInfo->getFilename(), |
|
56
|
|
|
json_decode( file_get_contents( $fileInfo->getPathname() ), true ) |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $argumentLists; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function propertyLegacySerializationProvider() { |
|
65
|
|
|
return $this->getEntitySerializationsFromDir( __DIR__ . '/../data/properties/legacy/' ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @dataProvider propertyLegacySerializationProvider |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testGivenLegacyProperty_DeserializationReturnsProperty( $fileName, $serialization ) { |
|
72
|
|
|
$property = $this->deserializer->deserialize( $serialization ); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertInstanceOf( |
|
75
|
|
|
Property::class, |
|
76
|
|
|
$property, |
|
77
|
|
|
$fileName . ' should deserialize into a Property' |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @dataProvider currentEntitySerializationProvider |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testGivenCurrentEntities_DeserializationReturnsCorrectEntity( $fileName, $serialization ) { |
|
85
|
|
|
$entity = $this->deserializer->deserialize( $serialization ); |
|
86
|
|
|
|
|
87
|
|
|
$expectedEntity = TestFactoryBuilder::newCurrentDeserializerFactory() |
|
88
|
|
|
->newEntityDeserializer()->deserialize( $serialization ); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertTrue( |
|
91
|
|
|
$entity->equals( $expectedEntity ), |
|
92
|
|
|
$fileName . ' should be deserialized into the same entity by both deserializers' |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function currentEntitySerializationProvider() { |
|
97
|
|
|
return $this->getEntitySerializationsFromDir( __DIR__ . '/../data/items/current/' ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|