|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SWL\Tests\MediaWiki\Hooks; |
|
4
|
|
|
|
|
5
|
|
|
use SWL\MediaWiki\Hooks\GetPreferences; |
|
6
|
|
|
use SMW\DIProperty; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers \SWL\MediaWiki\Hooks\GetPreferences |
|
10
|
|
|
* |
|
11
|
|
|
* @ingroup Test |
|
12
|
|
|
* |
|
13
|
|
|
* @group SWL |
|
14
|
|
|
* @group SWLExtension |
|
15
|
|
|
* |
|
16
|
|
|
* @license GNU GPL v2+ |
|
17
|
|
|
* @since 1.0 |
|
18
|
|
|
* |
|
19
|
|
|
* @author mwjames |
|
20
|
|
|
*/ |
|
21
|
|
|
class GetPreferencesTest extends \PHPUnit_Framework_TestCase { |
|
22
|
|
|
|
|
23
|
|
|
public function testCanConstruct() { |
|
24
|
|
|
|
|
25
|
|
|
$user = $this->getMockBuilder( 'User' ) |
|
26
|
|
|
->disableOriginalConstructor() |
|
27
|
|
|
->getMock(); |
|
28
|
|
|
|
|
29
|
|
|
$language = $this->getMockBuilder( 'Language' ) |
|
30
|
|
|
->disableOriginalConstructor() |
|
31
|
|
|
->getMock(); |
|
32
|
|
|
|
|
33
|
|
|
$preferences = array(); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertInstanceOf( |
|
36
|
|
|
'\SWL\MediaWiki\Hooks\GetPreferences', |
|
37
|
|
|
new GetPreferences( $user, $language, $preferences ) |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testExecuteOnEnabledEmailNotifyPreference() { |
|
42
|
|
|
|
|
43
|
|
|
$swlGroup = array(); |
|
44
|
|
|
$preferences = array(); |
|
45
|
|
|
|
|
46
|
|
|
$configuration = array( |
|
47
|
|
|
'egSWLEnableEmailNotify' => true, |
|
48
|
|
|
'egSWLEnableTopLink' => false |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$instance = $this->acquireInstance( $configuration, $swlGroup, $preferences ); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertTrue( $instance->execute() ); |
|
54
|
|
|
$this->assertCount( 1, $preferences ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testExecuteOnEnabledTopLinkPreference() { |
|
58
|
|
|
|
|
59
|
|
|
$swlGroup = array(); |
|
60
|
|
|
$preferences = array(); |
|
61
|
|
|
|
|
62
|
|
|
$configuration = array( |
|
63
|
|
|
'egSWLEnableEmailNotify' => false, |
|
64
|
|
|
'egSWLEnableTopLink' => true |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$instance = $this->acquireInstance( $configuration, $swlGroup, $preferences ); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertTrue( $instance->execute() ); |
|
70
|
|
|
$this->assertCount( 1, $preferences ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testExecuteOnSingleCategoryGroupPreference() { |
|
74
|
|
|
|
|
75
|
|
|
$swlGroup = $this->getMockBuilder( 'SWLGroup' ) |
|
76
|
|
|
->disableOriginalConstructor() |
|
77
|
|
|
->getMock(); |
|
78
|
|
|
|
|
79
|
|
|
$swlGroup->expects( $this->once() ) |
|
80
|
|
|
->method( 'getProperties' ) |
|
81
|
|
|
->will( $this->returnValue( array( 'FooProperty' ) ) ); |
|
82
|
|
|
|
|
83
|
|
|
$swlGroup->expects( $this->exactly( 2 ) ) |
|
84
|
|
|
->method( 'getCategories' ) |
|
85
|
|
|
->will( $this->returnValue( array( 'FooCategory' ) ) ); |
|
86
|
|
|
|
|
87
|
|
|
$swlGroup->expects( $this->once() ) |
|
88
|
|
|
->method( 'getId' ) |
|
89
|
|
|
->will( $this->returnValue( 9999 ) ); |
|
90
|
|
|
|
|
91
|
|
|
$swlGroup->expects( $this->once() ) |
|
92
|
|
|
->method( 'getName' ) |
|
93
|
|
|
->will( $this->returnValue( 'Foo' ) ); |
|
94
|
|
|
|
|
95
|
|
|
$preferences = array(); |
|
96
|
|
|
|
|
97
|
|
|
$configuration = array( |
|
98
|
|
|
'egSWLEnableEmailNotify' => false, |
|
99
|
|
|
'egSWLEnableTopLink' => false |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
$instance = $this->acquireInstance( $configuration, array( $swlGroup ), $preferences ); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertTrue( $instance->execute() ); |
|
105
|
|
|
$this->assertCount( 1, $preferences ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
protected function acquireInstance( $configuration, $swlGroup, &$preferences ) { |
|
109
|
|
|
|
|
110
|
|
|
$user = $this->getMockBuilder( 'User' ) |
|
111
|
|
|
->disableOriginalConstructor() |
|
112
|
|
|
->getMock(); |
|
113
|
|
|
|
|
114
|
|
|
$language = $this->getMockBuilder( 'Language' ) |
|
115
|
|
|
->disableOriginalConstructor() |
|
116
|
|
|
->getMock(); |
|
117
|
|
|
|
|
118
|
|
|
$language->expects( $this->any() ) |
|
119
|
|
|
->method( 'getCode' ) |
|
120
|
|
|
->will( $this->returnValue( 'en' ) ); |
|
121
|
|
|
|
|
122
|
|
|
$instance = $this->getMockBuilder( '\SWL\MediaWiki\Hooks\GetPreferences' ) |
|
123
|
|
|
->setConstructorArgs( array( $user, $language, &$preferences ) ) |
|
124
|
|
|
->setMethods( array( 'getAllSwlGroups' ) ) |
|
125
|
|
|
->getMock(); |
|
126
|
|
|
|
|
127
|
|
|
$instance->expects( $this->once() ) |
|
128
|
|
|
->method( 'getAllSwlGroups' ) |
|
129
|
|
|
->will( $this->returnValue( $swlGroup ) ); |
|
130
|
|
|
|
|
131
|
|
|
$instance->setConfiguration( $configuration ); |
|
132
|
|
|
|
|
133
|
|
|
return $instance; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|