| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
use MediaWiki\Revision\RevisionRecord; |
| 5 |
use MediaWiki\Title\Title; |
| 6 |
use MediaWiki\Utils\MWTimestamp; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class CategoryMembershipChangeJobTest extends MediaWikiIntegrationTestCase { |
| 18 |
|
| 19 |
private const TITLE_STRING = 'UTCatChangeJobPage'; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
private $title; |
| 25 |
|
| 26 |
protected function setUp(): void { |
| 27 |
parent::setUp(); |
| 28 |
$this->overrideConfigValue( MainConfigNames::RCWatchCategoryMembership, true ); |
| 29 |
$this->setContentLang( 'qqx' ); |
| 30 |
} |
| 31 |
|
| 32 |
public function addDBData() { |
| 33 |
parent::addDBData(); |
| 34 |
$insertResult = $this->insertPage( self::TITLE_STRING, 'UT Content' ); |
| 35 |
$this->title = $insertResult['title']; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
private function editPageText( $text ) { |
| 44 |
$editResult = $this->editPage( |
| 45 |
$this->title, |
| 46 |
$text, |
| 47 |
__METHOD__, |
| 48 |
NS_MAIN, |
| 49 |
$this->getTestSysop()->getAuthority() |
| 50 |
); |
| 51 |
|
| 52 |
$revisionRecord = $editResult->getNewRevision(); |
| 53 |
$this->runJobs(); |
| 54 |
|
| 55 |
return $revisionRecord->getId(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
private function getCategorizeRecentChangeForRevId( $revId ) { |
| 64 |
$rc = RecentChange::newFromConds( |
| 65 |
[ |
| 66 |
'rc_type' => RC_CATEGORIZE, |
| 67 |
'rc_this_oldid' => $revId, |
| 68 |
], |
| 69 |
__METHOD__ |
| 70 |
); |
| 71 |
|
| 72 |
$this->assertNotNull( $rc, 'rev_id = ' . $revId ); |
| 73 |
return $rc; |
| 74 |
} |
| 75 |
|
| 76 |
public function testRun_normalCategoryAddedAndRemoved() { |
| 77 |
$addedRevId = $this->editPageText( '[[Category:Normal]]' ); |
| 78 |
$removedRevId = $this->editPageText( 'Blank' ); |
| 79 |
|
| 80 |
$this->assertEquals( |
| 81 |
'(recentchanges-page-added-to-category: ' . self::TITLE_STRING . ')', |
| 82 |
$this->getCategorizeRecentChangeForRevId( $addedRevId )->getAttribute( 'rc_comment' ) |
| 83 |
); |
| 84 |
$this->assertEquals( |
| 85 |
'(recentchanges-page-removed-from-category: ' . self::TITLE_STRING . ')', |
| 86 |
$this->getCategorizeRecentChangeForRevId( $removedRevId )->getAttribute( 'rc_comment' ) |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
public function testJobSpecRemovesDuplicates() { |
| 91 |
$jobSpec = CategoryMembershipChangeJob::newSpec( $this->title, MWTimestamp::now(), false ); |
| 92 |
$job = new CategoryMembershipChangeJob( |
| 93 |
$this->title, |
| 94 |
$jobSpec->getParams() |
| 95 |
); |
| 96 |
$this->assertTrue( $job->ignoreDuplicates() ); |
| 97 |
$this->assertTrue( $jobSpec->ignoreDuplicates() ); |
| 98 |
$this->assertEquals( $job->getDeduplicationInfo(), $jobSpec->getDeduplicationInfo() ); |
| 99 |
} |
| 100 |
|
| 101 |
public function testJobSpecDeduplicationIgnoresRevTimestamp() { |
| 102 |
$jobSpec1 = CategoryMembershipChangeJob::newSpec( $this->title, '20191008204617', false ); |
| 103 |
$jobSpec2 = CategoryMembershipChangeJob::newSpec( $this->title, '20201008204617', false ); |
| 104 |
$this->assertArrayEquals( $jobSpec1->getDeduplicationInfo(), $jobSpec2->getDeduplicationInfo() ); |
| 105 |
} |
| 106 |
} |