| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Request\FauxRequest; |
| 4 |
use MediaWiki\Specials\SpecialDeletedContributions; |
| 5 |
use MediaWiki\Tests\User\TempUser\TempUserTestTrait; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
use MediaWiki\User\User; |
| 8 |
use Wikimedia\Parsoid\Utils\DOMCompat; |
| 9 |
use Wikimedia\Parsoid\Utils\DOMUtils; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class SpecialDeletedContributionsTest extends SpecialPageTestBase { |
| 16 |
|
| 17 |
use TempUserTestTrait; |
| 18 |
|
| 19 |
private static User $sysop; |
| 20 |
private static User $userNameWithSpaces; |
| 21 |
|
| 22 |
protected function newSpecialPage(): SpecialDeletedContributions { |
| 23 |
$services = $this->getServiceContainer(); |
| 24 |
|
| 25 |
return new SpecialDeletedContributions( |
| 26 |
$services->getPermissionManager(), |
| 27 |
$services->getConnectionProvider(), |
| 28 |
$services->getRevisionStore(), |
| 29 |
$services->getNamespaceInfo(), |
| 30 |
$services->getUserNameUtils(), |
| 31 |
$services->getUserNamePrefixSearch(), |
| 32 |
$services->getUserOptionsLookup(), |
| 33 |
$services->getCommentFormatter(), |
| 34 |
$services->getLinkBatchFactory(), |
| 35 |
$services->getUserFactory(), |
| 36 |
$services->getUserIdentityLookup(), |
| 37 |
$services->getDatabaseBlockStore(), |
| 38 |
$services->getTempUserConfig() |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
public function testExecuteNoTarget() { |
| 43 |
[ $html ] = $this->executeSpecialPage( |
| 44 |
'', |
| 45 |
null, |
| 46 |
null, |
| 47 |
self::$sysop, |
| 48 |
); |
| 49 |
$this->assertStringNotContainsString( 'mw-pager-body', $html ); |
| 50 |
} |
| 51 |
|
| 52 |
public function testExecuteInvalidTarget() { |
| 53 |
[ $html ] = $this->executeSpecialPage( |
| 54 |
'#InvalidUserName', |
| 55 |
null, |
| 56 |
null, |
| 57 |
self::$sysop, |
| 58 |
); |
| 59 |
$this->assertStringNotContainsString( 'mw-pager-body', $html ); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
public function testExecuteNoResultsForIPTarget( $temporaryAccountsEnabled, $expectedPageTitleMessageKey ) { |
| 64 |
if ( $temporaryAccountsEnabled ) { |
| 65 |
$this->enableAutoCreateTempUser(); |
| 66 |
} else { |
| 67 |
$this->disableAutoCreateTempUser(); |
| 68 |
} |
| 69 |
[ $html ] = $this->executeSpecialPage( |
| 70 |
'127.0.0.1', |
| 71 |
null, |
| 72 |
null, |
| 73 |
self::$sysop, |
| 74 |
true |
| 75 |
); |
| 76 |
$specialPageDocument = DOMUtils::parseHTML( $html ); |
| 77 |
$contentHtml = DOMCompat::getInnerHTML( |
| 78 |
DOMCompat::querySelector( $specialPageDocument, '#content' ) |
| 79 |
); |
| 80 |
$pagerContents = trim( DOMCompat::querySelector( |
| 81 |
$specialPageDocument, '#content .mw-pager-body' |
| 82 |
)->textContent ); |
| 83 |
$this->assertEquals( '(nocontribs)', $pagerContents ); |
| 84 |
$this->assertStringContainsString( "($expectedPageTitleMessageKey: <bdi>127.0.0.1</bdi>", $contentHtml ); |
| 85 |
} |
| 86 |
|
| 87 |
public static function provideExecuteNoResultsForIPTarget() { |
| 88 |
return [ |
| 89 |
'Temporary accounts not enabled' => [ false, 'deletedcontributions-title' ], |
| 90 |
'Temporary accounts enabled' => [ |
| 91 |
true, 'deletedcontributions-title-for-ip-when-temporary-accounts-enabled', |
| 92 |
], |
| 93 |
]; |
| 94 |
} |
| 95 |
|
| 96 |
public function testExecuteUserNameWithEscapedSpaces() { |
| 97 |
$par = strtr( self::$userNameWithSpaces->getName(), ' ', '_' ); |
| 98 |
[ $html ] = $this->executeSpecialPage( |
| 99 |
$par, |
| 100 |
null, |
| 101 |
null, |
| 102 |
self::$sysop, |
| 103 |
); |
| 104 |
$this->assertStringContainsString( 'mw-pager-body', $html ); |
| 105 |
} |
| 106 |
|
| 107 |
public function testExecuteNamespaceFilter() { |
| 108 |
[ $html ] = $this->executeSpecialPage( |
| 109 |
self::$sysop->getName(), |
| 110 |
new FauxRequest( [ |
| 111 |
'namespace' => NS_TALK, |
| 112 |
] ), |
| 113 |
null, |
| 114 |
self::$sysop, |
| 115 |
); |
| 116 |
$this->assertStringContainsString( 'mw-pager-body', $html ); |
| 117 |
} |
| 118 |
|
| 119 |
public function addDBDataOnce() { |
| 120 |
self::$sysop = $this->getTestSysop()->getUser(); |
| 121 |
self::$userNameWithSpaces = $this->getMutableTestUser( [], 'Test User' )->getUser(); |
| 122 |
|
| 123 |
$title = Title::makeTitle( NS_TALK, 'DeletedContribsPagerTest' ); |
| 124 |
|
| 125 |
|
| 126 |
$this->editPage( $title, '', '', NS_MAIN, self::$sysop ); |
| 127 |
$this->editPage( $title, 'test', '', NS_MAIN, self::$userNameWithSpaces ); |
| 128 |
$status = $this->editPage( $title, 'Test content.', '', NS_MAIN, self::$sysop ); |
| 129 |
|
| 130 |
|
| 131 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 132 |
$this->deletePage( $page ); |
| 133 |
} |
| 134 |
} |