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
;
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(
49 $this->assertStringNotContainsString( 'mw-pager-body', $html );
52 public function testExecuteInvalidTarget() {
53 [ $html ] = $this->executeSpecialPage(
59 $this->assertStringNotContainsString( 'mw-pager-body', $html );
62 /** @dataProvider provideExecuteNoResultsForIPTarget */
63 public function testExecuteNoResultsForIPTarget( $temporaryAccountsEnabled, $expectedPageTitleMessageKey ) {
64 if ( $temporaryAccountsEnabled ) {
65 $this->enableAutoCreateTempUser();
67 $this->disableAutoCreateTempUser();
69 [ $html ] = $this->executeSpecialPage(
76 $specialPageDocument = DOMUtils
::parseHTML( $html );
77 $contentHtml = DOMCompat
::querySelector( $specialPageDocument, '#content' )->nodeValue
;
78 $this->assertStringNotContainsString( 'mw-pager-body', $contentHtml );
79 $this->assertStringContainsString( "($expectedPageTitleMessageKey: 127.0.0.1", $contentHtml );
82 public static function provideExecuteNoResultsForIPTarget() {
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(
99 $this->assertStringContainsString( 'mw-pager-body', $html );
102 public function testExecuteNamespaceFilter() {
103 [ $html ] = $this->executeSpecialPage(
104 self
::$sysop->getName(),
106 'namespace' => NS_TALK
,
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' );
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 );