| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Context\RequestContext; |
| 4 |
use MediaWiki\Request\FauxRequest; |
| 5 |
use MediaWiki\SpecialPage\SpecialPage; |
| 6 |
use MediaWiki\Specials\SpecialUserLogout; |
| 7 |
use MediaWiki\Tests\User\TempUser\TempUserTestTrait; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class SpecialUserLogoutTest extends SpecialPageTestBase { |
| 14 |
|
| 15 |
use TempUserTestTrait; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
protected function newSpecialPage() { |
| 23 |
return new SpecialUserLogout( $this->getServiceContainer()->getTempUserConfig() ); |
| 24 |
} |
| 25 |
|
| 26 |
public function testUserLogoutComplete() { |
| 27 |
$oldName = __METHOD__; |
| 28 |
$user = new TestUser( $oldName ); |
| 29 |
|
| 30 |
$session = RequestContext::getMain()->getRequest()->getSession(); |
| 31 |
$fauxRequest = new FauxRequest( |
| 32 |
[ 'wpEditToken' => $session->getToken( 'logoutToken' ) ], |
| 33 |
true, |
| 34 |
$session |
| 35 |
); |
| 36 |
|
| 37 |
$oldNameInHook = null; |
| 38 |
$this->setTemporaryHook( |
| 39 |
'UserLogoutComplete', |
| 40 |
static function ( $user, $injected_html, $oldName ) use ( &$oldNameInHook ) { |
| 41 |
$oldNameInHook = $oldName; |
| 42 |
} |
| 43 |
); |
| 44 |
|
| 45 |
[ $html ] = $this->executeSpecialPage( '', $fauxRequest, 'qqx', $user->getUser(), true ); |
| 46 |
|
| 47 |
$this->assertStringContainsString( '(logouttext:', $html ); |
| 48 |
$this->assertStringContainsString( '(userlogout)', $html ); |
| 49 |
|
| 50 |
$this->assertEquals( |
| 51 |
$oldName, |
| 52 |
$oldNameInHook, |
| 53 |
'old name in UserLogoutComplete hook was incorrect' |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
public function testExecuteForTemporaryAccount() { |
| 58 |
$this->enableAutoCreateTempUser(); |
| 59 |
$user = $this->getServiceContainer()->getTempUserCreator()->create( null, new FauxRequest() )->getUser(); |
| 60 |
|
| 61 |
$session = RequestContext::getMain()->getRequest()->getSession(); |
| 62 |
$session->setUser( $user ); |
| 63 |
$fauxRequest = new FauxRequest( [ 'wpEditToken' => $session->getToken( 'logoutToken' ) ], true, $session ); |
| 64 |
|
| 65 |
[ $html ] = $this->executeSpecialPage( '', $fauxRequest, 'qqx', $user, true ); |
| 66 |
|
| 67 |
$this->assertStringContainsString( '(logouttext-for-temporary-account:', $html ); |
| 68 |
$this->assertStringContainsString( '(templogout)', $html ); |
| 69 |
} |
| 70 |
|
| 71 |
public function testViewForTemporaryAccountAfterApiLogout() { |
| 72 |
$user = $this->getServiceContainer()->getUserFactory()->newAnonymous( '1.2.3.4' ); |
| 73 |
|
| 74 |
$fauxRequest = new FauxRequest( [ 'wasTempUser' => 1 ] ); |
| 75 |
|
| 76 |
[ $html ] = $this->executeSpecialPage( '', $fauxRequest, 'qqx', $user, true ); |
| 77 |
|
| 78 |
$this->assertStringContainsString( '(logouttext-for-temporary-account:', $html ); |
| 79 |
$this->assertStringContainsString( '(templogout)', $html ); |
| 80 |
} |
| 81 |
|
| 82 |
public function testViewForTemporaryAccount() { |
| 83 |
$this->enableAutoCreateTempUser(); |
| 84 |
$user = $this->getServiceContainer()->getTempUserCreator()->create( null, new FauxRequest() )->getUser(); |
| 85 |
|
| 86 |
[ $html ] = $this->executeSpecialPage( '', null, 'qqx', $user, true ); |
| 87 |
|
| 88 |
$this->assertStringContainsString( '(templogout)', $html ); |
| 89 |
$this->assertStringContainsString( '(htmlform-submit)', $html ); |
| 90 |
} |
| 91 |
} |