@@ -246,21 +246,59 @@ public function testBadLoginSequence() {
246246
247247 public function testLogout () {
248248 $ client = $ this ->getMockClient ();
249- $ client ->expects ( $ this ->at ( 0 ) )
250- ->method ( 'request ' )
251- ->with ( 'POST ' , null , $ this ->getExpectedRequestOpts ( [ 'action ' => 'logout ' ], 'form_params ' ) )
252- ->will ( $ this ->returnValue ( $ this ->getMockResponse ( [] ) ) );
249+ $ client ->method ( 'request ' )
250+ ->withConsecutive (
251+ [ 'POST ' , null , $ this ->getExpectedRequestOpts ( [
252+ 'action ' => 'query ' ,
253+ 'meta ' => 'tokens ' ,
254+ 'type ' => 'csrf ' ,
255+ 'continue ' => ''
256+ ], 'form_params ' ) ],
257+ [ 'POST ' , null , $ this ->getExpectedRequestOpts ( [
258+ 'action ' => 'logout ' ,
259+ 'token ' => 'TKN-csrf '
260+ ], 'form_params ' ) ]
261+ )
262+ ->willReturnOnConsecutiveCalls (
263+ $ this ->returnValue ( $ this ->getMockResponse ( [
264+ 'query ' => [
265+ 'tokens ' => [
266+ 'csrf ' => 'TKN-csrf ' ,
267+ ]
268+ ]
269+ ] ) ),
270+ $ this ->returnValue ( $ this ->getMockResponse ( [] ) )
271+ );
253272 $ api = new MediawikiApi ( '' , $ client );
254273
255274 $ this ->assertTrue ( $ api ->logout () );
256275 }
257276
258277 public function testLogoutOnFailure () {
259278 $ client = $ this ->getMockClient ();
260- $ client ->expects ( $ this ->at ( 0 ) )
261- ->method ( 'request ' )
262- ->with ( 'POST ' , null , $ this ->getExpectedRequestOpts ( [ 'action ' => 'logout ' ], 'form_params ' ) )
263- ->will ( $ this ->returnValue ( $ this ->getMockResponse ( null ) ) );
279+ $ client ->method ( 'request ' )
280+ ->withConsecutive (
281+ [ 'POST ' , null , $ this ->getExpectedRequestOpts ( [
282+ 'action ' => 'query ' ,
283+ 'meta ' => 'tokens ' ,
284+ 'type ' => 'csrf ' ,
285+ 'continue ' => ''
286+ ], 'form_params ' ) ],
287+ [ 'POST ' , null , $ this ->getExpectedRequestOpts ( [
288+ 'action ' => 'logout ' ,
289+ 'token ' => 'TKN-csrf '
290+ ], 'form_params ' ) ]
291+ )
292+ ->willReturnOnConsecutiveCalls (
293+ $ this ->returnValue ( $ this ->getMockResponse ( [
294+ 'query ' => [
295+ 'tokens ' => [
296+ 'csrf ' => 'TKN-csrf ' ,
297+ ]
298+ ]
299+ ] ) ),
300+ $ this ->returnValue ( $ this ->getMockResponse ( null ) )
301+ );
264302 $ api = new MediawikiApi ( '' , $ client );
265303
266304 $ this ->assertFalse ( $ api ->logout () );
0 commit comments