1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Queryr\EntityStore; |
4
|
|
|
|
5
|
|
|
use Queryr\EntityStore\Data\EntityPageInfo; |
6
|
|
|
use Queryr\EntityStore\ItemRowFactory; |
7
|
|
|
use Wikibase\DataFixtures\Items\Berlin; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers Queryr\EntityStore\ItemRowFactory |
11
|
|
|
* |
12
|
|
|
* @licence GNU GPL v2+ |
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class ItemRowFactoryTest extends \PHPUnit_Framework_TestCase { |
16
|
|
|
|
17
|
|
|
public function testNewRowForBerlin() { |
18
|
|
|
$itemRow = $this->newFactory()->newFromItemAndPageInfo( |
19
|
|
|
( new Berlin() )->newItem(), |
20
|
|
|
$this->newPageInfo() |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
$this->assertSame( 'kittens', $itemRow->getPageTitle() ); |
24
|
|
|
$this->assertSame( '0000', $itemRow->getRevisionTime() ); |
25
|
|
|
$this->assertSame( 9001, $itemRow->getRevisionId() ); |
26
|
|
|
|
27
|
|
|
$this->assertSame( 64, $itemRow->getNumericItemId() ); |
28
|
|
|
$this->assertSame( 'Berlin', $itemRow->getEnglishLabel() ); |
29
|
|
|
$this->assertSame( 'Berlin', $itemRow->getEnglishWikipediaTitle() ); |
30
|
|
|
$this->assertSame( '["the","serialization"]', $itemRow->getItemJson() ); |
31
|
|
|
$this->assertSame( 42, $itemRow->getItemType() ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testNewRowForItemWithoutEnglishLabel() { |
35
|
|
|
$item = ( new Berlin() )->newItem(); |
36
|
|
|
$item->getFingerprint()->removeLabel( 'en' ); |
37
|
|
|
|
38
|
|
|
$itemRow = $this->newFactory()->newFromItemAndPageInfo( |
39
|
|
|
$item, |
40
|
|
|
$this->newPageInfo() |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$this->assertNull( $itemRow->getEnglishLabel() ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testNewRowForItemWithoutType() { |
47
|
|
|
$factory = new ItemRowFactory( |
48
|
|
|
$this->newStubItemSerializer(), |
49
|
|
|
$this->newStubTypeExtractor( null ) |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$itemRow = $factory->newFromItemAndPageInfo( |
53
|
|
|
( new Berlin() )->newItem(), |
54
|
|
|
$this->newPageInfo() |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$this->assertNull( $itemRow->getItemType() ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function newFactory() { |
61
|
|
|
return new ItemRowFactory( |
62
|
|
|
$this->newStubItemSerializer(), |
63
|
|
|
$this->newStubTypeExtractor( 42 ) |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function newPageInfo() { |
68
|
|
|
return ( new EntityPageInfo() ) |
69
|
|
|
->setPageTitle( 'kittens' ) |
70
|
|
|
->setRevisionTime( '0000' ) |
71
|
|
|
->setRevisionId( '9001' ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function newStubItemSerializer() { |
75
|
|
|
$serializer = $this->getMock( 'Serializers\Serializer' ); |
76
|
|
|
|
77
|
|
|
$serializer->expects( $this->any() ) |
78
|
|
|
->method( 'serialize' ) |
79
|
|
|
->will( $this->returnValue( [ 'the', 'serialization' ] ) ); |
80
|
|
|
|
81
|
|
|
return $serializer; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
private function newStubTypeExtractor( $returnValue ) { |
85
|
|
|
$extractor = $this->getMock( 'Queryr\EntityStore\ItemTypeExtractor' ); |
86
|
|
|
|
87
|
|
|
$extractor->expects( $this->any() ) |
88
|
|
|
->method( 'getTypeOfItem' ) |
89
|
|
|
->will( $this->returnValue( $returnValue ) ); |
90
|
|
|
|
91
|
|
|
return $extractor; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|