3 use MediaWiki\MainConfigNames
;
4 use MediaWiki\Revision\RevisionRecord
;
5 use MediaWiki\Title\Title
;
6 use MediaWiki\Utils\MWTimestamp
;
9 * @covers \CategoryMembershipChangeJob
14 * @license GPL-2.0-or-later
17 class CategoryMembershipChangeJobTest
extends MediaWikiIntegrationTestCase
{
19 private const TITLE_STRING
= 'UTCatChangeJobPage';
26 protected function setUp(): void
{
28 $this->overrideConfigValue( MainConfigNames
::RCWatchCategoryMembership
, true );
29 $this->setContentLang( 'qqx' );
32 public function addDBData() {
34 $insertResult = $this->insertPage( self
::TITLE_STRING
, 'UT Content' );
35 $this->title
= $insertResult['title'];
39 * @param string $text new page text
43 private function editPageText( $text ) {
44 $editResult = $this->editPage(
49 $this->getTestSysop()->getAuthority()
51 /** @var RevisionRecord $revisionRecord */
52 $revisionRecord = $editResult->getNewRevision();
55 return $revisionRecord->getId();
61 * @return RecentChange|null
63 private function getCategorizeRecentChangeForRevId( $revId ) {
64 $rc = RecentChange
::newFromConds(
66 'rc_type' => RC_CATEGORIZE
,
67 'rc_this_oldid' => $revId,
72 $this->assertNotNull( $rc, 'rev_id = ' . $revId );
76 public function testRun_normalCategoryAddedAndRemoved() {
77 $addedRevId = $this->editPageText( '[[Category:Normal]]' );
78 $removedRevId = $this->editPageText( 'Blank' );
81 '(recentchanges-page-added-to-category: ' . self
::TITLE_STRING
. ')',
82 $this->getCategorizeRecentChangeForRevId( $addedRevId )->getAttribute( 'rc_comment' )
85 '(recentchanges-page-removed-from-category: ' . self
::TITLE_STRING
. ')',
86 $this->getCategorizeRecentChangeForRevId( $removedRevId )->getAttribute( 'rc_comment' )
90 public function testJobSpecRemovesDuplicates() {
91 $jobSpec = CategoryMembershipChangeJob
::newSpec( $this->title
, MWTimestamp
::now(), false );
92 $job = new CategoryMembershipChangeJob(
96 $this->assertTrue( $job->ignoreDuplicates() );
97 $this->assertTrue( $jobSpec->ignoreDuplicates() );
98 $this->assertEquals( $job->getDeduplicationInfo(), $jobSpec->getDeduplicationInfo() );
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() );