1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests; |
4
|
|
|
|
5
|
|
|
use SMW\DeferredRequestDispatchManager; |
6
|
|
|
use SMW\DIWikiPage; |
7
|
|
|
use SMW\Tests\TestEnvironment; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \SMW\DeferredRequestDispatchManager |
11
|
|
|
* @group semantic-mediawiki |
12
|
|
|
* |
13
|
|
|
* @license GNU GPL v2+ |
14
|
|
|
* @since 2.3 |
15
|
|
|
* |
16
|
|
|
* @author mwjames |
17
|
|
|
*/ |
18
|
|
|
class DeferredRequestDispatchManagerTest extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
private $spyLogger; |
21
|
|
|
|
22
|
|
|
protected function setUp() { |
23
|
|
|
parent::setUp(); |
24
|
|
|
|
25
|
|
|
$testEnvironment = new TestEnvironment(); |
26
|
|
|
$this->spyLogger = $testEnvironment->getUtilityFactory()->newSpyLogger(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testCanConstruct() { |
30
|
|
|
|
31
|
|
|
$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\SocketRequest' ) |
32
|
|
|
->disableOriginalConstructor() |
33
|
|
|
->getMock(); |
34
|
|
|
|
35
|
|
|
$this->assertInstanceOf( |
36
|
|
|
'\SMW\DeferredRequestDispatchManager', |
37
|
|
|
new DeferredRequestDispatchManager( $httpRequest ) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @dataProvider dispatchableJobProvider |
43
|
|
|
*/ |
44
|
|
|
public function testDispatchJobFor( $type, $deferredJobRequestState, $parameters = array() ) { |
45
|
|
|
|
46
|
|
|
$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\SocketRequest' ) |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->getMock(); |
49
|
|
|
|
50
|
|
|
$httpRequest->expects( $this->any() ) |
51
|
|
|
->method( 'ping' ) |
52
|
|
|
->will( $this->returnValue( true ) ); |
53
|
|
|
|
54
|
|
|
$instance = new DeferredRequestDispatchManager( $httpRequest ); |
55
|
|
|
$instance->reset(); |
56
|
|
|
|
57
|
|
|
$instance->isEnabledHttpDeferredRequest( $deferredJobRequestState ); |
58
|
|
|
$instance->isEnabledJobQueue( false ); |
59
|
|
|
$instance->setLogger( $this->spyLogger ); |
60
|
|
|
|
61
|
|
|
$this->assertTrue( |
62
|
|
|
$instance->dispatchJobRequestWith( $type, DIWikiPage::newFromText( __METHOD__ )->getTitle(), $parameters ) |
|
|
|
|
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testDispatchParserCachePurgeJob() { |
67
|
|
|
|
68
|
|
|
$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\SocketRequest' ) |
69
|
|
|
->disableOriginalConstructor() |
70
|
|
|
->getMock(); |
71
|
|
|
|
72
|
|
|
$httpRequest->expects( $this->once() ) |
73
|
|
|
->method( 'ping' ) |
74
|
|
|
->will( $this->returnValue( true ) ); |
75
|
|
|
|
76
|
|
|
$instance = new DeferredRequestDispatchManager( $httpRequest ); |
77
|
|
|
$instance->reset(); |
78
|
|
|
|
79
|
|
|
$instance->isEnabledHttpDeferredRequest( true ); |
80
|
|
|
$instance->isEnabledJobQueue( false ); |
81
|
|
|
|
82
|
|
|
$parameters = array( 'idlist' => '1|2' ); |
83
|
|
|
$title = DIWikiPage::newFromText( __METHOD__ )->getTitle(); |
84
|
|
|
|
85
|
|
|
$this->assertTrue( |
86
|
|
|
$instance->dispatchParserCachePurgeJobWith( $title, $parameters ) |
|
|
|
|
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testDispatchFulltextSearchTableUpdateJob() { |
91
|
|
|
|
92
|
|
|
$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\SocketRequest' ) |
93
|
|
|
->disableOriginalConstructor() |
94
|
|
|
->getMock(); |
95
|
|
|
|
96
|
|
|
$httpRequest->expects( $this->once() ) |
97
|
|
|
->method( 'ping' ) |
98
|
|
|
->will( $this->returnValue( true ) ); |
99
|
|
|
|
100
|
|
|
$instance = new DeferredRequestDispatchManager( $httpRequest ); |
101
|
|
|
$instance->reset(); |
102
|
|
|
|
103
|
|
|
$instance->isEnabledHttpDeferredRequest( true ); |
104
|
|
|
$instance->isEnabledJobQueue( false ); |
105
|
|
|
|
106
|
|
|
$parameters = array(); |
107
|
|
|
$title = DIWikiPage::newFromText( __METHOD__ )->getTitle(); |
108
|
|
|
|
109
|
|
|
$this->assertTrue( |
110
|
|
|
$instance->dispatchFulltextSearchTableUpdateJobWith( $title, $parameters ) |
|
|
|
|
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @dataProvider preliminaryCheckProvider |
116
|
|
|
*/ |
117
|
|
|
public function testPreliminaryCheckForType( $type, $parameters = array() ) { |
118
|
|
|
|
119
|
|
|
$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\SocketRequest' ) |
120
|
|
|
->disableOriginalConstructor() |
121
|
|
|
->getMock(); |
122
|
|
|
|
123
|
|
|
$httpRequest->expects( $this->any() ) |
124
|
|
|
->method( 'ping' ) |
125
|
|
|
->will( $this->returnValue( true ) ); |
126
|
|
|
|
127
|
|
|
$instance = new DeferredRequestDispatchManager( $httpRequest ); |
128
|
|
|
$instance->reset(); |
129
|
|
|
|
130
|
|
|
$instance->isEnabledJobQueue( false ); |
131
|
|
|
|
132
|
|
|
$this->assertNull( |
133
|
|
|
$instance->dispatchJobRequestWith( $type, DIWikiPage::newFromText( __METHOD__ )->getTitle(), $parameters ) |
|
|
|
|
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function dispatchableJobProvider() { |
138
|
|
|
|
139
|
|
|
$provider[] = array( |
|
|
|
|
140
|
|
|
'SMW\UpdateJob', |
141
|
|
|
false |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
$provider[] = array( |
145
|
|
|
'SMW\UpdateJob', |
146
|
|
|
true |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
$provider[] = array( |
150
|
|
|
'SMW\TempChangeOpPurgeJob', |
151
|
|
|
true |
152
|
|
|
); |
153
|
|
|
|
154
|
|
|
$provider[] = array( |
155
|
|
|
'SMW\ParserCachePurgeJob', |
156
|
|
|
false, |
157
|
|
|
array( 'idlist' => '1|2' ) |
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
$provider[] = array( |
161
|
|
|
'SMW\ParserCachePurgeJob', |
162
|
|
|
true, |
163
|
|
|
array( 'idlist' => '1|2' ) |
164
|
|
|
); |
165
|
|
|
|
166
|
|
|
return $provider; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function preliminaryCheckProvider() { |
170
|
|
|
|
171
|
|
|
$provider[] = array( |
|
|
|
|
172
|
|
|
'UnknownJob' |
173
|
|
|
); |
174
|
|
|
|
175
|
|
|
return $provider; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
} |
179
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: