Merge "Drop cache interwiki"
[mediawiki.git] / tests / phpunit / includes / specials / SpecialDeletedContributionsTest.php
blobef85ec5441443dc56f33f83946cf5655bd6e9ce5
1 <?php
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;
11 /**
12 * @group Database
13 * @covers \MediaWiki\Specials\SpecialDeletedContributions
15 class SpecialDeletedContributionsTest extends SpecialPageTestBase {
17 use TempUserTestTrait;
19 private static User $sysop;
20 private static User $userNameWithSpaces;
22 protected function newSpecialPage(): SpecialDeletedContributions {
23 $services = $this->getServiceContainer();
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()
42 public function testExecuteNoTarget() {
43 [ $html ] = $this->executeSpecialPage(
44 '',
45 null,
46 null,
47 self::$sysop,
49 $this->assertStringNotContainsString( 'mw-pager-body', $html );
52 public function testExecuteInvalidTarget() {
53 [ $html ] = $this->executeSpecialPage(
54 '#InvalidUserName',
55 null,
56 null,
57 self::$sysop,
59 $this->assertStringNotContainsString( 'mw-pager-body', $html );
62 /** @dataProvider provideExecuteNoResultsForIPTarget */
63 public function testExecuteNoResultsForIPTarget( $temporaryAccountsEnabled, $expectedPageTitleMessageKey ) {
64 if ( $temporaryAccountsEnabled ) {
65 $this->enableAutoCreateTempUser();
66 } else {
67 $this->disableAutoCreateTempUser();
69 [ $html ] = $this->executeSpecialPage(
70 '127.0.0.1',
71 null,
72 null,
73 self::$sysop,
74 true
76 $specialPageDocument = DOMUtils::parseHTML( $html );
77 $contentHtml = DOMCompat::querySelector( $specialPageDocument, '.mw-content-container' )->nodeValue;
78 $this->assertStringNotContainsString( 'mw-pager-body', $contentHtml );
79 $this->assertStringContainsString( "($expectedPageTitleMessageKey: 127.0.0.1", $contentHtml );
82 public static function provideExecuteNoResultsForIPTarget() {
83 return [
84 'Temporary accounts not enabled' => [ false, 'deletedcontributions-title' ],
85 'Temporary accounts enabled' => [
86 true, 'deletedcontributions-title-for-ip-when-temporary-accounts-enabled',
91 public function testExecuteUserNameWithEscapedSpaces() {
92 $par = strtr( self::$userNameWithSpaces->getName(), ' ', '_' );
93 [ $html ] = $this->executeSpecialPage(
94 $par,
95 null,
96 null,
97 self::$sysop,
99 $this->assertStringContainsString( 'mw-pager-body', $html );
102 public function testExecuteNamespaceFilter() {
103 [ $html ] = $this->executeSpecialPage(
104 self::$sysop->getName(),
105 new FauxRequest( [
106 'namespace' => NS_TALK,
107 ] ),
108 null,
109 self::$sysop,
111 $this->assertStringContainsString( 'mw-pager-body', $html );
114 public function addDBDataOnce() {
115 self::$sysop = $this->getTestSysop()->getUser();
116 self::$userNameWithSpaces = $this->getMutableTestUser( [], 'Test User' )->getUser();
118 $title = Title::makeTitle( NS_TALK, 'DeletedContribsPagerTest' );
120 // Make some edits
121 $this->editPage( $title, '', '', NS_MAIN, self::$sysop );
122 $this->editPage( $title, 'test', '', NS_MAIN, self::$userNameWithSpaces );
123 $status = $this->editPage( $title, 'Test content.', '', NS_MAIN, self::$sysop );
125 // Delete the page where the edits were made
126 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
127 $this->deletePage( $page );