|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SWL\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SWL\HookRegistry; |
|
6
|
|
|
use SMW\DIWikiPage; |
|
7
|
|
|
use Title; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \SWL\HookRegistry |
|
11
|
|
|
* @group semantic-watchlist |
|
12
|
|
|
* |
|
13
|
|
|
* @license GNU GPL v2+ |
|
14
|
|
|
* @since 1.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @author mwjames |
|
17
|
|
|
*/ |
|
18
|
|
|
class HookRegistryTest extends \PHPUnit_Framework_TestCase { |
|
19
|
|
|
|
|
20
|
|
|
public function testCanConstruct() { |
|
21
|
|
|
|
|
22
|
|
|
$this->assertInstanceOf( |
|
23
|
|
|
'\SWL\HookRegistry', |
|
24
|
|
|
new HookRegistry( array() ) |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testRegister() { |
|
29
|
|
|
|
|
30
|
|
|
$language = $this->getMockBuilder( '\Language' ) |
|
31
|
|
|
->disableOriginalConstructor() |
|
32
|
|
|
->getMock(); |
|
33
|
|
|
|
|
34
|
|
|
$language->expects( $this->any() ) |
|
35
|
|
|
->method( 'getCode' ) |
|
36
|
|
|
->will( $this->returnValue( 'en' ) ); |
|
37
|
|
|
|
|
38
|
|
|
$user = $this->getMockBuilder( '\User' ) |
|
39
|
|
|
->disableOriginalConstructor() |
|
40
|
|
|
->getMock(); |
|
41
|
|
|
|
|
42
|
|
|
$configuration = array( |
|
43
|
|
|
'egSWLEnableTopLink' => false, |
|
44
|
|
|
'egSWLEnableEmailNotify' => false, |
|
45
|
|
|
'egSwlSqlDatabaseSchemaPath' => '../foo', |
|
46
|
|
|
'wgLang' => $language |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$wgHooks = array(); |
|
50
|
|
|
|
|
51
|
|
|
$instance = new HookRegistry( $configuration ); |
|
52
|
|
|
$instance->register( $wgHooks ); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertNotEmpty( |
|
55
|
|
|
$wgHooks |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$this->doTestPersonalUrls( $wgHooks, $user ); |
|
59
|
|
|
$this->doTestUserSaveOptions( $wgHooks, $user ); |
|
60
|
|
|
$this->doTestLoadExtensionSchemaUpdates( $wgHooks ); |
|
61
|
|
|
$this->doTestGetPreferences( $wgHooks, $user ); |
|
62
|
|
|
$this->doTestStoreUpdate( $wgHooks ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function doTestPersonalUrls( $wgHooks, $user ) { |
|
66
|
|
|
|
|
67
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
68
|
|
|
|
|
69
|
|
|
$skinTemplate = $this->getMockBuilder( '\SkinTemplate' ) |
|
70
|
|
|
->disableOriginalConstructor() |
|
71
|
|
|
->getMock(); |
|
72
|
|
|
|
|
73
|
|
|
$skinTemplate->expects( $this->any() ) |
|
74
|
|
|
->method( 'getUser' ) |
|
75
|
|
|
->will( $this->returnValue( $user ) ); |
|
76
|
|
|
|
|
77
|
|
|
$personal_urls = array(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertThatHookIsExcutable( |
|
80
|
|
|
$wgHooks, |
|
81
|
|
|
'PersonalUrls', |
|
82
|
|
|
array( &$personal_urls, $title, $skinTemplate ) |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
private function doTestUserSaveOptions( $wgHooks, $user ) { |
|
87
|
|
|
|
|
88
|
|
|
$options = array(); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertThatHookIsExcutable( |
|
91
|
|
|
$wgHooks, |
|
92
|
|
|
'UserSaveOptions', |
|
93
|
|
|
array( $user, &$options ) |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
private function doTestLoadExtensionSchemaUpdates( $wgHooks ) { |
|
98
|
|
|
|
|
99
|
|
|
$databaseBase = $this->getMockBuilder( '\DatabaseBase' ) |
|
100
|
|
|
->disableOriginalConstructor() |
|
101
|
|
|
->getMockForAbstractClass(); |
|
102
|
|
|
|
|
103
|
|
|
$databaseUpdater = $this->getMockBuilder( '\DatabaseUpdater' ) |
|
104
|
|
|
->disableOriginalConstructor() |
|
105
|
|
|
->setMethods( array( 'getDB' ) ) |
|
106
|
|
|
->getMockForAbstractClass(); |
|
107
|
|
|
|
|
108
|
|
|
$databaseUpdater->expects( $this->any() ) |
|
109
|
|
|
->method( 'getDB' ) |
|
110
|
|
|
->will( $this->returnValue( $databaseBase ) ); |
|
111
|
|
|
|
|
112
|
|
|
$this->assertThatHookIsExcutable( |
|
113
|
|
|
$wgHooks, |
|
114
|
|
|
'LoadExtensionSchemaUpdates', |
|
115
|
|
|
array( $databaseUpdater ) |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
private function doTestGetPreferences( $wgHooks, $user ) { |
|
120
|
|
|
|
|
121
|
|
|
$preferences = array(); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertThatHookIsExcutable( |
|
124
|
|
|
$wgHooks, |
|
125
|
|
|
'GetPreferences', |
|
126
|
|
|
array( $user, &$preferences ) |
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function doTestStoreUpdate( $wgHooks ) { |
|
131
|
|
|
|
|
132
|
|
|
$subject = DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) ); |
|
133
|
|
|
|
|
134
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
|
135
|
|
|
->disableOriginalConstructor() |
|
136
|
|
|
->getMock(); |
|
137
|
|
|
|
|
138
|
|
|
$semanticData->expects( $this->any() ) |
|
139
|
|
|
->method( 'getSubject' ) |
|
140
|
|
|
->will( $this->returnValue( $subject ) ); |
|
141
|
|
|
|
|
142
|
|
|
$semanticData->expects( $this->any() ) |
|
143
|
|
|
->method( 'getPropertyValues' ) |
|
144
|
|
|
->will( $this->returnValue( array() ) ); |
|
145
|
|
|
|
|
146
|
|
|
$semanticData->expects( $this->any() ) |
|
147
|
|
|
->method( 'getProperties' ) |
|
148
|
|
|
->will( $this->returnValue( array() ) ); |
|
149
|
|
|
|
|
150
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
|
151
|
|
|
->disableOriginalConstructor() |
|
152
|
|
|
->getMockForAbstractClass(); |
|
153
|
|
|
|
|
154
|
|
|
$store->expects( $this->any() ) |
|
155
|
|
|
->method( 'getSemanticData' ) |
|
156
|
|
|
->will( $this->returnValue( $semanticData ) ); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertThatHookIsExcutable( |
|
159
|
|
|
$wgHooks, |
|
160
|
|
|
'SMWStore::updateDataBefore', |
|
161
|
|
|
array( $store, $semanticData ) |
|
162
|
|
|
); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
private function assertThatHookIsExcutable( $wgHooks, $hookName, $arguments ) { |
|
166
|
|
|
foreach ( $wgHooks[ $hookName ] as $hook ) { |
|
167
|
|
|
$this->assertInternalType( |
|
168
|
|
|
'boolean', |
|
169
|
|
|
call_user_func_array( $hook, $arguments ) |
|
170
|
|
|
); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|