1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Queryr\Resources\Builders; |
4
|
|
|
|
5
|
|
|
use Queryr\Resources\Builders\SimplePropertyBuilder; |
6
|
|
|
use Queryr\Resources\SimpleProperty; |
7
|
|
|
use Wikibase\DataModel\Entity\Property; |
8
|
|
|
use Wikibase\DataModel\Term\Fingerprint; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers Queryr\Resources\Builders\SimplePropertyBuilder |
12
|
|
|
* |
13
|
|
|
* @licence GNU GPL v2+ |
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
15
|
|
|
*/ |
16
|
|
|
class SimplePropertyBuilderTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
private function newProperty() { |
19
|
|
|
$property = Property::newFromType( 'kittens' ); |
20
|
|
|
|
21
|
|
|
$property->setId( 1337 ); |
22
|
|
|
|
23
|
|
|
$property->setFingerprint( $this->newFingerprint() ); |
24
|
|
|
|
25
|
|
|
return $property; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
private function newFingerprint() { |
29
|
|
|
$fingerprint = new Fingerprint(); |
30
|
|
|
|
31
|
|
|
$fingerprint->setLabel( 'en', 'foo' ); |
32
|
|
|
$fingerprint->setLabel( 'de', 'bar' ); |
33
|
|
|
$fingerprint->setLabel( 'nl', 'baz' ); |
34
|
|
|
|
35
|
|
|
$fingerprint->setDescription( 'de', 'de description' ); |
36
|
|
|
|
37
|
|
|
$fingerprint->setAliasGroup( 'en', [ 'first en alias', 'second en alias' ] ); |
38
|
|
|
$fingerprint->setAliasGroup( 'de', [ 'first de alias', 'second de alias' ] ); |
39
|
|
|
|
40
|
|
|
return $fingerprint; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testSerializationForDe() { |
44
|
|
|
$simpleProperty = $this->buildNewSimplePropertyForLanguage( 'de' ); |
45
|
|
|
|
46
|
|
|
$expected = new SimpleProperty(); |
47
|
|
|
$expected->ids = [ |
|
|
|
|
48
|
|
|
'wikidata' => 'P1337', |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$expected->label = 'bar'; |
52
|
|
|
$expected->description = 'de description'; |
53
|
|
|
$expected->aliases = [ 'first de alias', 'second de alias' ]; |
54
|
|
|
|
55
|
|
|
$expected->type = 'kittens'; |
56
|
|
|
|
57
|
|
|
$this->assertEquals( $expected, $simpleProperty ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function buildNewSimplePropertyForLanguage( $languageCode ) { |
61
|
|
|
$labelLookup = $this->getMock( 'Queryr\Resources\Builders\ResourceLabelLookup' ); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$labelLookup->expects( $this->any() ) |
64
|
|
|
->method( 'getLabelByIdAndLanguage' ) |
65
|
|
|
->will( $this->returnValue( 'awesome label' ) ); |
66
|
|
|
|
67
|
|
|
$propertyBuilder = new SimplePropertyBuilder( $languageCode ); |
68
|
|
|
|
69
|
|
|
return $propertyBuilder->buildFromProperty( $this->newProperty() ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testSerializationForEn() { |
73
|
|
|
$simpleProperty = $this->buildNewSimplePropertyForLanguage( 'en' ); |
74
|
|
|
|
75
|
|
|
$expected = new SimpleProperty(); |
76
|
|
|
$expected->ids = [ |
|
|
|
|
77
|
|
|
'wikidata' => 'P1337', |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
$expected->label = 'foo'; |
81
|
|
|
$expected->aliases = [ 'first en alias', 'second en alias' ]; |
82
|
|
|
|
83
|
|
|
$expected->type = 'kittens'; |
84
|
|
|
|
85
|
|
|
$this->assertEquals( $expected, $simpleProperty ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testSerializationForNl() { |
89
|
|
|
$simpleProperty = $this->buildNewSimplePropertyForLanguage( 'nl' ); |
90
|
|
|
|
91
|
|
|
$expected = new SimpleProperty(); |
92
|
|
|
$expected->ids = [ |
|
|
|
|
93
|
|
|
'wikidata' => 'P1337', |
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
$expected->label = 'baz'; |
97
|
|
|
|
98
|
|
|
$expected->type = 'kittens'; |
99
|
|
|
|
100
|
|
|
$this->assertEquals( $expected, $simpleProperty ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..