PersonalUrlsTest::testExecuteOnLoggedOutUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SWL\Tests\MediaWiki\Hooks;
4
5
use SWL\MediaWiki\Hooks\PersonalUrls;
6
7
use Title;
8
9
/**
10
 * @covers \SWL\MediaWiki\Hooks\PersonalUrls
11
 *
12
 * @ingroup Test
13
 *
14
 * @group SWL
15
 * @group SWLExtension
16
 *
17
 * @license GNU GPL v2+
18
 * @since 1.0
19
 *
20
 * @author mwjames
21
 */
22
class PersonalUrlsTest extends \PHPUnit_Framework_TestCase {
23
24
	public function testCanConstruct() {
25
26
		$personalUrls = array();
27
28
		$title = $this->getMockBuilder( 'Title' )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$user = $this->getMockBuilder( 'User' )
33
			->disableOriginalConstructor()
34
			->getMock();
35
36
		$this->assertInstanceOf(
37
			'\SWL\MediaWiki\Hooks\PersonalUrls',
38
			new PersonalUrls( $personalUrls, $title, $user )
39
		);
40
	}
41
42
	public function testExecuteOnEnabledTopLink() {
43
44
		$configuration = array( 'egSWLEnableTopLink' => true );
45
		$personalUrls  = array( 'watchlist' => true );
46
47
		$title = Title::newFromText( __METHOD__ );
48
49
		$user = $this->getMockBuilder( 'User' )
50
			->disableOriginalConstructor()
51
			->getMock();
52
53
		$user->expects( $this->once() )
54
			->method( 'isLoggedIn' )
55
			->will( $this->returnValue( true ) );
56
57
		$user->expects( $this->once() )
58
			->method( 'getOption' )
59
			->with( $this->equalTo( 'swl_watchlisttoplink' ) )
60
			->will( $this->returnValue( true ) );
61
62
		$instance = new PersonalUrls( $personalUrls, $title, $user );
63
		$instance->setConfiguration( $configuration );
64
65
		$this->assertTrue( $instance->execute() );
66
		$this->assertCount( 2, $personalUrls );
67
	}
68
69
	public function testExecuteOnDisabledTopLink() {
70
71
		$configuration = array( 'egSWLEnableTopLink' => false );
72
		$personalUrls  = array();
73
74
		$title = Title::newFromText( __METHOD__ );
75
76
		$user = $this->getMockBuilder( 'User' )
77
			->disableOriginalConstructor()
78
			->getMock();
79
80
		$instance = new PersonalUrls( $personalUrls, $title, $user );
81
		$instance->setConfiguration( $configuration );
82
83
		$this->assertTrue( $instance->execute() );
84
		$this->assertEmpty( $personalUrls );
85
	}
86
87
	public function testExecuteOnLoggedOutUser() {
88
89
		$configuration = array( 'egSWLEnableTopLink' => true );
90
		$personalUrls  = array();
91
92
		$title = Title::newFromText( __METHOD__ );
93
94
		$user = $this->getMockBuilder( 'User' )
95
			->disableOriginalConstructor()
96
			->getMock();
97
98
		$user->expects( $this->once() )
99
			->method( 'isLoggedIn' )
100
			->will( $this->returnValue( false ) );
101
102
		$instance = new PersonalUrls( $personalUrls, $title, $user );
103
		$instance->setConfiguration( $configuration );
104
105
		$this->assertTrue( $instance->execute() );
106
		$this->assertEmpty( $personalUrls );
107
	}
108
109
}
110