1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types=1 ); |
4
|
|
|
|
5
|
|
|
namespace Wikibase\Repo\Tests\Hooks\Helpers; |
6
|
|
|
|
7
|
|
|
use OutputPage; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Title; |
10
|
|
|
use Wikibase\Repo\Content\EntityContentFactory; |
11
|
|
|
use Wikibase\Repo\Hooks\Helpers\OutputPageEntityViewChecker; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @covers \Wikibase\Repo\Hooks\Helpers\OutputPageEntityViewChecker |
15
|
|
|
* |
16
|
|
|
* @group Wikibase |
17
|
|
|
* |
18
|
|
|
* @license GPL-2.0-or-later |
19
|
|
|
*/ |
20
|
|
|
class OutputPageEntityViewCheckerTest extends TestCase { |
21
|
|
|
|
22
|
|
|
private const ITEM_CONTENT_MODEL = 'wikibase-item'; |
23
|
|
|
|
24
|
|
|
public function testGivenOutputPageIsEntityArticle_returnsTrue() { |
25
|
|
|
$title = $this->createMock( Title::class ); |
26
|
|
|
$title->expects( $this->once() ) |
27
|
|
|
->method( 'getContentModel' ) |
28
|
|
|
->willReturn( self::ITEM_CONTENT_MODEL ); |
29
|
|
|
|
30
|
|
|
$out = $this->createMock( OutputPage::class ); |
31
|
|
|
$out->expects( $this->once() ) |
32
|
|
|
->method( 'isArticle' ) |
33
|
|
|
->willReturn( true ); |
34
|
|
|
$out->expects( $this->once() ) |
35
|
|
|
->method( 'getTitle' ) |
36
|
|
|
->willReturn( $title ); |
37
|
|
|
|
38
|
|
|
$entityContentFactory = $this->createMock( EntityContentFactory::class ); |
39
|
|
|
$entityContentFactory->expects( $this->once() ) |
40
|
|
|
->method( 'isEntityContentModel' ) |
41
|
|
|
->with( self::ITEM_CONTENT_MODEL ) |
42
|
|
|
->willReturn( true ); |
43
|
|
|
|
44
|
|
|
$entityViewChecker = new OutputPageEntityViewChecker( $entityContentFactory ); |
45
|
|
|
|
46
|
|
|
$this->assertTrue( $entityViewChecker->hasEntityView( $out ) ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGivenOutputPageHasEntityId_returnsTrue() { |
50
|
|
|
$out = $this->createMock( OutputPage::class ); |
51
|
|
|
$out->expects( $this->once() ) |
52
|
|
|
->method( 'getJsConfigVars' ) |
53
|
|
|
->willReturn( [ 'wbEntityId' => 'Q666' ] ); |
54
|
|
|
|
55
|
|
|
$entityViewChecker = new OutputPageEntityViewChecker( $this->createMock( EntityContentFactory::class ) ); |
56
|
|
|
|
57
|
|
|
$this->assertTrue( $entityViewChecker->hasEntityView( $out ) ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGivenNotAnArticlePageAndNotHavingEntityId_returnsFalse() { |
61
|
|
|
$out = $this->createMock( OutputPage::class ); |
62
|
|
|
$out->expects( $this->once() ) |
63
|
|
|
->method( 'isArticle' ) |
64
|
|
|
->willReturn( true ); |
65
|
|
|
$out->expects( $this->once() ) |
66
|
|
|
->method( 'getJsConfigVars' ) |
67
|
|
|
->willReturn( [] ); |
68
|
|
|
|
69
|
|
|
$entityViewChecker = new OutputPageEntityViewChecker( $this->createMock( EntityContentFactory::class ) ); |
70
|
|
|
|
71
|
|
|
$this->assertFalse( $entityViewChecker->hasEntityView( $out ) ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|