UserSaveOptionsTest::testExecuteWithEmptyOption()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
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\UserSaveOptions;
6
7
/**
8
 * @covers \SWL\MediaWiki\Hooks\UserSaveOptions
9
 *
10
 * @group semantic-watchlist
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class UserSaveOptionsTest extends \PHPUnit_Framework_TestCase {
18
19
	public function testCanConstruct() {
20
21
		$tableUpdater = $this->getMockBuilder( '\SWL\TableUpdater' )
22
			->disableOriginalConstructor()
23
			->getMock();
24
25
		$user = $this->getMockBuilder( 'User' )
26
			->disableOriginalConstructor()
27
			->getMock();
28
29
		$options = array();
30
31
		$this->assertInstanceOf(
32
			'\SWL\MediaWiki\Hooks\UserSaveOptions',
33
			new UserSaveOptions( $tableUpdater, $user, $options )
34
		);
35
	}
36
37
	public function testExecuteWithEmptyOption() {
38
39
		$instance = $this->createUserSaveOptionsInstance(
40
			array(),
41
			array()
42
		);
43
44
		$this->assertTrue( $instance->execute() );
45
	}
46
47
	public function testExecuteWithValidSwlOption() {
48
49
		$instance = $this->createUserSaveOptionsInstance(
50
			array( 'swl_watchgroup_9999' => true ),
51
			array( 9999 )
52
		);
53
54
		$this->assertTrue( $instance->execute() );
55
	}
56
57
	public function testExecuteWithInvalidSwlOption() {
58
59
		$instance = $this->createUserSaveOptionsInstance(
60
			array( '9999' => true ),
61
			array()
62
		);
63
64
		$this->assertTrue( $instance->execute() );
65
	}
66
67
	private function createUserSaveOptionsInstance( $options, $expected ) {
68
69
		$tableUpdater = $this->getMockBuilder( '\SWL\TableUpdater' )
70
			->disableOriginalConstructor()
71
			->getMock();
72
73
		$tableUpdater->expects( $this->once() )
74
			->method( 'updateGroupIdsForUser' )
75
			->with(
76
				$this->anything(),
77
				$this->equalTo( $expected ) )
78
			->will( $this->returnValue( true ) );
79
80
		$user = $this->getMockBuilder( 'User' )
81
			->disableOriginalConstructor()
82
			->getMock();
83
84
		return new UserSaveOptions(
85
			$tableUpdater,
86
			$user,
87
			$options
88
		);
89
	}
90
91
}
92