1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\View\Tests; |
4
|
|
|
|
5
|
|
|
use Wikibase\DataModel\Entity\EntityId; |
6
|
|
|
use Wikibase\DataModel\Entity\Item; |
7
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
8
|
|
|
use Wikibase\DataModel\Statement\Statement; |
9
|
|
|
use Wikibase\DataModel\Statement\StatementList; |
10
|
|
|
use Wikibase\View\CacheableEntityTermsView; |
11
|
|
|
use Wikibase\View\ItemView; |
12
|
|
|
use Wikibase\View\LanguageDirectionalityLookup; |
13
|
|
|
use Wikibase\View\LocalizedTextProvider; |
14
|
|
|
use Wikibase\View\SiteLinksView; |
15
|
|
|
use Wikibase\View\StatementSectionsView; |
16
|
|
|
use Wikibase\View\Template\TemplateFactory; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @covers \Wikibase\View\ItemView |
20
|
|
|
* @covers \Wikibase\View\EntityView |
21
|
|
|
* |
22
|
|
|
* @uses \Wikibase\View\Template\Template |
23
|
|
|
* @uses \Wikibase\View\Template\TemplateFactory |
24
|
|
|
* @uses \Wikibase\View\Template\TemplateRegistry |
25
|
|
|
* |
26
|
|
|
* @group Wikibase |
27
|
|
|
* @group WikibaseView |
28
|
|
|
* |
29
|
|
|
* @license GPL-2.0-or-later |
30
|
|
|
* @author Daniel Kinzler |
31
|
|
|
*/ |
32
|
|
|
class ItemViewTest extends EntityViewTestCase { |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param EntityId|ItemId $id |
36
|
|
|
* @param Statement[] $statements |
37
|
|
|
* |
38
|
|
|
* @return Item |
39
|
|
|
*/ |
40
|
|
|
protected function makeEntity( EntityId $id, array $statements = [] ) { |
41
|
|
|
$item = new Item( $id ); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$item->setLabel( 'en', "label:$id" ); |
44
|
|
|
$item->setDescription( 'en', "description:$id" ); |
45
|
|
|
|
46
|
|
|
$item->setStatements( new StatementList( $statements ) ); |
47
|
|
|
|
48
|
|
|
return $item; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Generates a suitable entity ID based on $n. |
53
|
|
|
* |
54
|
|
|
* @param int|string $n |
55
|
|
|
* |
56
|
|
|
* @return ItemId |
57
|
|
|
*/ |
58
|
|
|
protected function makeEntityId( $n ) { |
59
|
|
|
return new ItemId( "Q$n" ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function provideTestGetHtml() { |
63
|
|
|
$itemView = $this->newItemView(); |
64
|
|
|
|
65
|
|
|
return [ |
66
|
|
|
[ |
67
|
|
|
$itemView, |
68
|
|
|
$this->newEntityForStatements( [] ), |
69
|
|
|
'/wb-item/' |
70
|
|
|
] |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testTermsViewPlaceholdersArePropagated() { |
75
|
|
|
$placeholders = [ 'a' => 'b' ]; |
76
|
|
|
$itemView = $this->newItemView( $placeholders ); |
77
|
|
|
|
78
|
|
|
$view = $itemView->getContent( $this->makeEntity( $this->makeEntityId( 42 ) ), 4711 ); |
79
|
|
|
|
80
|
|
|
$this->assertSame( $placeholders, $view->getPlaceholders() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function newItemView( $placeholders = [] ) { |
84
|
|
|
$templateFactory = TemplateFactory::getDefaultInstance(); |
85
|
|
|
|
86
|
|
|
$termsView = $this->createMock( CacheableEntityTermsView::class ); |
87
|
|
|
$termsView->method( 'getPlaceholders' )->willReturn( $placeholders ); |
88
|
|
|
|
89
|
|
|
return new ItemView( |
90
|
|
|
$templateFactory, |
91
|
|
|
$termsView, |
92
|
|
|
$this->createMock( LanguageDirectionalityLookup::class ), |
93
|
|
|
$this->getMockBuilder( StatementSectionsView::class ) |
94
|
|
|
->disableOriginalConstructor() |
95
|
|
|
->getMock(), |
96
|
|
|
'en', |
97
|
|
|
$this->getMockBuilder( SiteLinksView::class ) |
98
|
|
|
->disableOriginalConstructor() |
99
|
|
|
->getMock(), |
100
|
|
|
[], |
101
|
|
|
$this->createMock( LocalizedTextProvider::class ) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: