1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Queryr\Resources\Builders; |
4
|
|
|
|
5
|
|
|
use DataValues\StringValue; |
6
|
|
|
use Queryr\Resources\Builders\SimpleStatementsBuilder; |
7
|
|
|
use Queryr\Resources\SimpleStatement; |
8
|
|
|
use Wikibase\DataModel\Entity\EntityIdValue; |
9
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
10
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
11
|
|
|
use Wikibase\DataModel\Snak\PropertyValueSnak; |
12
|
|
|
use Wikibase\DataModel\Statement\Statement; |
13
|
|
|
use Wikibase\DataModel\Statement\StatementList; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers Queryr\Resources\Builders\SimpleStatementsBuilder |
17
|
|
|
* |
18
|
|
|
* @licence GNU GPL v2+ |
19
|
|
|
* @author Jeroen De Dauw < [email protected] > |
20
|
|
|
*/ |
21
|
|
|
class SimpleStatementsBuilderTest extends \PHPUnit_Framework_TestCase { |
22
|
|
|
|
23
|
|
|
public function testBuildFromSingleStatementWithPropertyValueSnak() { |
24
|
|
|
$statement = new Statement( new PropertyValueSnak( 42, new StringValue( 'kittens' ) ) ); |
25
|
|
|
$statement->setGuid( 'first guid' ); |
26
|
|
|
|
27
|
|
|
$expected = SimpleStatement::newInstance() |
28
|
|
|
->withPropertyName( 'awesome label' ) |
29
|
|
|
->withPropertyId( new PropertyId( 'P42' ) ) |
30
|
|
|
->withType( 'string' ) |
31
|
|
|
->withValues( [ new StringValue( 'kittens' ) ] ); |
32
|
|
|
|
33
|
|
|
$this->assertBuildsFrom( [ $statement ], [ $expected ] ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
private function assertBuildsFrom( array $statements, array $expected ) { |
37
|
|
|
$labelLookup = $this->getMock( 'Queryr\Resources\Builders\ResourceLabelLookup' ); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$labelLookup->expects( $this->any() ) |
40
|
|
|
->method( 'getLabelByIdAndLanguage' ) |
41
|
|
|
->will( $this->returnValue( 'awesome label' ) ); |
42
|
|
|
|
43
|
|
|
$builder = new SimpleStatementsBuilder( 'en', $labelLookup ); |
44
|
|
|
$simpleStatements = $builder->buildFromStatements( new StatementList( $statements ) ); |
45
|
|
|
|
46
|
|
|
$this->assertEquals( $expected, $simpleStatements ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testEntityIdValueGetsSimplified() { |
50
|
|
|
$statement = new Statement( new PropertyValueSnak( 42, new EntityIdValue( new ItemId( 'Q1337' ) ) ) ); |
51
|
|
|
$statement->setGuid( 'first guid' ); |
52
|
|
|
|
53
|
|
|
$expected = SimpleStatement::newInstance() |
54
|
|
|
->withPropertyName( 'awesome label' ) |
55
|
|
|
->withPropertyId( new PropertyId( 'P42' ) ) |
56
|
|
|
->withType( 'string' ) |
57
|
|
|
->withValues( [ new StringValue( 'awesome label' ) ] ); |
58
|
|
|
|
59
|
|
|
$this->assertBuildsFrom( [ $statement ], [ $expected ] ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testLabelLookupFallsBackToId() { |
63
|
|
|
$labelLookup = $this->getMock( 'Queryr\Resources\Builders\ResourceLabelLookup' ); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$labelLookup->expects( $this->any() ) |
66
|
|
|
->method( 'getLabelByIdAndLanguage' ) |
67
|
|
|
->will( $this->returnValue( null ) ); |
68
|
|
|
|
69
|
|
|
$statement = new Statement( new PropertyValueSnak( 42, new EntityIdValue( new ItemId( 'Q1337' ) ) ) ); |
70
|
|
|
$statement->setGuid( 'first guid' ); |
71
|
|
|
|
72
|
|
|
$builder = new SimpleStatementsBuilder( 'en', $labelLookup ); |
73
|
|
|
$simpleStatements = $builder->buildFromStatements( new StatementList( [ $statement ] ) ); |
74
|
|
|
|
75
|
|
|
$expected = SimpleStatement::newInstance() |
76
|
|
|
->withPropertyName( 'P42' ) |
77
|
|
|
->withPropertyId( new PropertyId( 'P42' ) ) |
78
|
|
|
->withType( 'string' ) |
79
|
|
|
->withValues( [ new StringValue( 'Q1337' ) ] ); |
80
|
|
|
|
81
|
|
|
$this->assertEquals( [ $expected ], $simpleStatements ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
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.