| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Context\RequestContext; |
| 4 |
use MediaWiki\MainConfigNames; |
| 5 |
use MediaWiki\Request\FauxRequest; |
| 6 |
use MediaWiki\Specials\SpecialRecentChanges; |
| 7 |
use MediaWiki\Tests\SpecialPage\AbstractChangesListSpecialPageTestCase; |
| 8 |
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait; |
| 9 |
use MediaWiki\Tests\User\TempUser\TempUserTestTrait; |
| 10 |
use MediaWiki\Title\Title; |
| 11 |
use MediaWiki\Watchlist\WatchedItemStoreInterface; |
| 12 |
use Wikimedia\TestingAccessWrapper; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
class SpecialRecentChangesTest extends AbstractChangesListSpecialPageTestCase { |
| 23 |
use MockAuthorityTrait; |
| 24 |
use TempUserTestTrait; |
| 25 |
|
| 26 |
protected function getPage(): SpecialRecentChanges { |
| 27 |
return new SpecialRecentChanges( |
| 28 |
$this->getServiceContainer()->getWatchedItemStore(), |
| 29 |
$this->getServiceContainer()->getMessageCache(), |
| 30 |
$this->getServiceContainer()->getUserOptionsLookup(), |
| 31 |
$this->getServiceContainer()->getChangeTagsStore(), |
| 32 |
$this->getServiceContainer()->getUserIdentityUtils(), |
| 33 |
$this->getServiceContainer()->getTempUserConfig() |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
protected function getPageAccessWrapper() { |
| 41 |
return TestingAccessWrapper::newFromObject( $this->getPage() ); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function provideParseParameters() { |
| 48 |
return [ |
| 49 |
[ 'limit=123', [ 'limit' => '123' ] ], |
| 50 |
|
| 51 |
[ '234', [ 'limit' => '234' ] ], |
| 52 |
|
| 53 |
[ 'days=3', [ 'days' => '3' ] ], |
| 54 |
|
| 55 |
[ 'days=0.25', [ 'days' => '0.25' ] ], |
| 56 |
|
| 57 |
[ 'namespace=5', [ 'namespace' => '5' ] ], |
| 58 |
|
| 59 |
[ 'namespace=5|3', [ 'namespace' => '5|3' ] ], |
| 60 |
|
| 61 |
[ 'tagfilter=foo', [ 'tagfilter' => 'foo' ] ], |
| 62 |
|
| 63 |
[ 'tagfilter=foo;bar', [ 'tagfilter' => 'foo;bar' ] ], |
| 64 |
]; |
| 65 |
} |
| 66 |
|
| 67 |
public function validateOptionsProvider() { |
| 68 |
return [ |
| 69 |
[ |
| 70 |
|
| 71 |
[ 'hideanons' => 1, 'hideliu' => 1 ], |
| 72 |
true, |
| 73 |
[ 'hideliu' => 1 ], |
| 74 |
false, |
| 75 |
], |
| 76 |
]; |
| 77 |
} |
| 78 |
|
| 79 |
public function testAddWatchlistJoins() { |
| 80 |
|
| 81 |
$testPage = $this->getExistingTestPage( 'Test page' ); |
| 82 |
$this->editPage( $testPage, 'Test content', '' ); |
| 83 |
|
| 84 |
|
| 85 |
$context = new RequestContext; |
| 86 |
$context->setTitle( Title::newFromText( __METHOD__ ) ); |
| 87 |
$context->setUser( $this->getTestUser()->getUser() ); |
| 88 |
$context->setRequest( new FauxRequest ); |
| 89 |
|
| 90 |
|
| 91 |
$rc1 = $this->getPage(); |
| 92 |
$rc1->setContext( $context ); |
| 93 |
$rc1->execute( null ); |
| 94 |
$this->assertStringContainsString( 'Test page', $rc1->getOutput()->getHTML() ); |
| 95 |
$this->assertStringContainsString( 'mw-changeslist-line-not-watched', $rc1->getOutput()->getHTML() ); |
| 96 |
|
| 97 |
|
| 98 |
$watchedItemStore = $this->getServiceContainer()->getWatchedItemStore(); |
| 99 |
$watchedItemStore->addWatch( $context->getUser(), $testPage ); |
| 100 |
$rc2 = $this->getPage(); |
| 101 |
$rc2->setContext( $context ); |
| 102 |
$rc2->execute( null ); |
| 103 |
$this->assertStringContainsString( 'Test page', $rc2->getOutput()->getHTML() ); |
| 104 |
$this->assertStringContainsString( 'mw-changeslist-line-watched', $rc2->getOutput()->getHTML() ); |
| 105 |
|
| 106 |
|
| 107 |
$db = $this->getDb(); |
| 108 |
$watchedItemId = $db->newSelectQueryBuilder() |
| 109 |
->select( 'wl_id' ) |
| 110 |
->from( 'watchlist' ) |
| 111 |
->where( [ 'wl_namespace' => $testPage->getNamespace(), 'wl_title' => $testPage->getDBkey() ] ) |
| 112 |
->caller( __METHOD__ )->fetchField(); |
| 113 |
$db->newUpdateQueryBuilder() |
| 114 |
->update( 'watchlist_expiry' ) |
| 115 |
->set( [ 'we_expiry' => $db->timestamp( '20200101000000' ) ] ) |
| 116 |
->where( [ 'we_item' => $watchedItemId ] ) |
| 117 |
->caller( __METHOD__ )->execute(); |
| 118 |
|
| 119 |
|
| 120 |
$rc3 = $this->getPage(); |
| 121 |
$rc3->setContext( $context ); |
| 122 |
$rc3->execute( null ); |
| 123 |
$this->assertStringContainsString( 'Test page', $rc3->getOutput()->getHTML() ); |
| 124 |
$this->assertStringContainsString( 'mw-changeslist-line-not-watched', $rc3->getOutput()->getHTML() ); |
| 125 |
} |
| 126 |
|
| 127 |
public function testExperienceLevelFilter() { |
| 128 |
$this->disableAutoCreateTempUser(); |
| 129 |
|
| 130 |
|
| 131 |
$testPage = $this->getExistingTestPage( 'Experience page' ); |
| 132 |
$this->editPage( $testPage, 'Registered content', |
| 133 |
'registered summary', NS_MAIN, $this->getTestUser()->getUser() ); |
| 134 |
$this->editPage( $testPage, 'Anon content', |
| 135 |
'anon summary', NS_MAIN, $this->mockAnonUltimateAuthority() ); |
| 136 |
|
| 137 |
|
| 138 |
$context = new RequestContext; |
| 139 |
$context->setTitle( Title::newFromText( __METHOD__ ) ); |
| 140 |
$context->setUser( $this->getTestUser()->getUser() ); |
| 141 |
$context->setRequest( new FauxRequest ); |
| 142 |
|
| 143 |
|
| 144 |
[ $html ] = ( new SpecialPageExecutor() )->executeSpecialPage( |
| 145 |
$this->getPage(), |
| 146 |
'', |
| 147 |
new FauxRequest() |
| 148 |
); |
| 149 |
$this->assertStringContainsString( 'Experience page', $html ); |
| 150 |
|
| 151 |
|
| 152 |
$req = new FauxRequest(); |
| 153 |
$req->setVal( 'userExpLevel', 'newcomer' ); |
| 154 |
[ $html ] = ( new SpecialPageExecutor() )->executeSpecialPage( |
| 155 |
$this->getPage(), |
| 156 |
'', |
| 157 |
$req |
| 158 |
); |
| 159 |
$this->assertStringContainsString( 'registered summary', $html ); |
| 160 |
|
| 161 |
|
| 162 |
$req = new FauxRequest(); |
| 163 |
$req->setVal( 'userExpLevel', 'unregistered' ); |
| 164 |
[ $html ] = ( new SpecialPageExecutor() )->executeSpecialPage( |
| 165 |
$this->getPage(), |
| 166 |
'', |
| 167 |
$req |
| 168 |
); |
| 169 |
$this->assertStringContainsString( 'anon summary', $html ); |
| 170 |
$this->assertStringNotContainsString( 'registered summary', $html ); |
| 171 |
|
| 172 |
|
| 173 |
$req = new FauxRequest(); |
| 174 |
$req->setVal( 'userExpLevel', 'registered' ); |
| 175 |
[ $html ] = ( new SpecialPageExecutor() )->executeSpecialPage( |
| 176 |
$this->getPage(), |
| 177 |
'', |
| 178 |
$req |
| 179 |
); |
| 180 |
$this->assertStringContainsString( 'registered summary', $html ); |
| 181 |
$this->assertStringNotContainsString( 'anon summary', $html ); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public function testIsDenseTagFilter() { |
| 189 |
$this->getServiceContainer()->getChangeTagsStore()->defineTag( 'rc-test-tag' ); |
| 190 |
$req = new FauxRequest(); |
| 191 |
$req->setVal( 'tagfilter', 'rc-test-tag' ); |
| 192 |
$page = $this->getPage(); |
| 193 |
|
| 194 |
|
| 195 |
$page->denseRcSizeThreshold = 0; |
| 196 |
$this->overrideConfigValue( MainConfigNames::MiserMode, true ); |
| 197 |
|
| 198 |
( new SpecialPageExecutor() )->executeSpecialPage( $page, '', $req ); |
| 199 |
$this->assertTrue( true ); |
| 200 |
} |
| 201 |
|
| 202 |
public static function provideDenseTagFilter() { |
| 203 |
return [ |
| 204 |
[ false ], |
| 205 |
[ true ] |
| 206 |
]; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
public function testDenseTagFilter( $dense ) { |
| 216 |
$this->getServiceContainer()->getChangeTagsStore()->defineTag( 'rc-test-tag' ); |
| 217 |
$req = new FauxRequest(); |
| 218 |
$req->setVal( 'tagfilter', 'rc-test-tag' ); |
| 219 |
|
| 220 |
$page = new class ( |
| 221 |
$dense, |
| 222 |
$this->getServiceContainer()->getWatchedItemStore(), |
| 223 |
$this->getServiceContainer()->getMessageCache(), |
| 224 |
$this->getServiceContainer()->getUserOptionsLookup() |
| 225 |
) extends SpecialRecentChanges { |
| 226 |
private $dense; |
| 227 |
|
| 228 |
public function __construct( |
| 229 |
$dense, |
| 230 |
?WatchedItemStoreInterface $watchedItemStore = null, |
| 231 |
?MessageCache $messageCache = null, |
| 232 |
?\MediaWiki\User\Options\UserOptionsLookup $userOptionsLookup = null |
| 233 |
) { |
| 234 |
parent::__construct( $watchedItemStore, $messageCache, $userOptionsLookup ); |
| 235 |
$this->dense = $dense; |
| 236 |
} |
| 237 |
|
| 238 |
protected function isDenseTagFilter( $tagIds, $limit ) { |
| 239 |
return $this->dense; |
| 240 |
} |
| 241 |
}; |
| 242 |
|
| 243 |
( new SpecialPageExecutor() )->executeSpecialPage( $page, '', $req ); |
| 244 |
$this->assertTrue( true ); |
| 245 |
} |
| 246 |
} |