10 class ApiLogoutTest
extends ApiTestCase
{
11 public function setUp() {
15 public function testUserLogoutBadToken() {
17 $token = 'invalid token';
18 $retLogout = $this->doUserLogout( $token );
20 catch ( ApiUsageException
$e ) {
21 $exceptionMsg = $e->getMessage();
24 $this->assertSame( "Invalid CSRF token.", $exceptionMsg );
27 public function testUserLogout() {
28 // TODO: there has to be a cleaner way to make User::doLogout happy
30 $wgUser = User
::newFromId( '127.0.0.1' );
32 $token = $this->getUserCsrfTokenFromApi();
33 $retLogout = $this->doUserLogout( $token );
34 $this->assertFalse( $wgUser->isLoggedIn() );
37 public function getUserCsrfTokenFromApi() {
38 $retToken = $this->doApiRequest( [
44 $this->assertArrayNotHasKey( 'warnings', $retToken );
46 return $retToken[0]['query']['tokens']['csrftoken'];
49 public function doUserLogout( $logoutToken ) {
50 return $this->doApiRequest( [
52 'token' => $logoutToken