1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\Repo\Tests\ParserOutput; |
4
|
|
|
|
5
|
|
|
use ExtensionRegistry; |
6
|
|
|
use MobileContext; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Wikibase\Lib\SettingsArray; |
9
|
|
|
use Wikibase\Repo\ParserOutput\TermboxFlag; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \Wikibase\Repo\ParserOutput\TermboxFlag |
13
|
|
|
* |
14
|
|
|
* @group Wikibase |
15
|
|
|
* |
16
|
|
|
* @license GPL-2.0-or-later |
17
|
|
|
*/ |
18
|
|
|
class TermboxFlagTest extends TestCase { |
19
|
|
|
|
20
|
|
|
public function testGetInstance() { |
21
|
|
|
$this->assertInstanceOf( TermboxFlag::class, TermboxFlag::getInstance() ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testGivenDesktopFeatureFlagSetFalse_shouldRenderTermboxReturnsFalse() { |
25
|
|
|
$flag = new TermboxFlag( |
26
|
|
|
$this->newSettingsWithFeatureFlag( false, true ), |
27
|
|
|
$this->createMock( ExtensionRegistry::class ) |
28
|
|
|
); |
29
|
|
|
$this->assertFalse( $flag->shouldRenderTermbox() ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGivenDesktopFeatureFlagSetTrue_shouldRenderTermboxReturnsTrue() { |
33
|
|
|
$flag = new TermboxFlag( |
34
|
|
|
$this->newSettingsWithFeatureFlag( true, true ), |
35
|
|
|
$this->createMock( ExtensionRegistry::class ) |
36
|
|
|
); |
37
|
|
|
$this->assertTrue( $flag->shouldRenderTermbox() ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGivenFeatureFlagSetFalse_shouldRenderTermboxReturnsFalse() { |
41
|
|
|
$flag = new TermboxFlag( |
42
|
|
|
$this->newSettingsWithFeatureFlag( false ), |
43
|
|
|
$this->createMock( ExtensionRegistry::class ) |
44
|
|
|
); |
45
|
|
|
$this->assertFalse( $flag->shouldRenderTermbox() ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGivenMobileExtensionNotLoaded_shouldRenderTermboxReturnsFalse() { |
49
|
|
|
$flag = new TermboxFlag( |
50
|
|
|
$this->newSettingsWithFeatureFlag( true ), |
51
|
|
|
$this->newExtensionRegistryWithMobileExtension( false ) |
52
|
|
|
); |
53
|
|
|
$this->assertFalse( $flag->shouldRenderTermbox() ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testAllTrue_shouldRenderTermboxReturnsTrue() { |
57
|
|
|
if ( !ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) { |
58
|
|
|
$this->markTestSkipped(); |
59
|
|
|
} |
60
|
|
|
$flag = new TermboxFlag( |
61
|
|
|
$this->newSettingsWithFeatureFlag( true ), |
62
|
|
|
$this->newExtensionRegistryWithMobileExtension( true ) |
63
|
|
|
); |
64
|
|
|
$this->assertSame( MobileContext::singleton()->shouldDisplayMobileView(), $flag->shouldRenderTermbox() ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function newSettingsWithFeatureFlag( $setting, $desktop = false ) { |
68
|
|
|
$settings = $this->createMock( SettingsArray::class ); |
69
|
|
|
$settings->expects( $this->atMost( 2 ) ) |
70
|
|
|
->method( 'getSetting' ) |
71
|
|
|
->with( $this->logicalOr( |
72
|
|
|
$this->equalTo( TermboxFlag::TERMBOX_DESKTOP_FLAG ), |
73
|
|
|
$this->equalTo( TermboxFlag::TERMBOX_FLAG ) |
74
|
|
|
) ) |
75
|
|
|
->willReturnCallback( function ( $key ) use ( $setting, $desktop ) { |
76
|
|
|
if ( |
77
|
|
|
( $key === TermboxFlag::TERMBOX_DESKTOP_FLAG && $desktop ) || |
78
|
|
|
( $key === TermboxFlag::TERMBOX_FLAG && !$desktop ) |
79
|
|
|
) { |
80
|
|
|
return $setting; |
81
|
|
|
} |
82
|
|
|
return false; |
83
|
|
|
} ); |
84
|
|
|
|
85
|
|
|
return $settings; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
private function newExtensionRegistryWithMobileExtension( $isEnabled ) { |
89
|
|
|
$registry = $this->createMock( ExtensionRegistry::class ); |
90
|
|
|
$registry->expects( $this->atMost( 2 ) ) |
91
|
|
|
->method( 'isLoaded' ) |
92
|
|
|
->with( 'MobileFrontend' ) |
93
|
|
|
->willReturn( $isEnabled ); |
94
|
|
|
|
95
|
|
|
return $registry; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|