Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / jobqueue / jobs / CategoryMembershipChangeJobTest.php
blobe244f275707d5601c94dc0a3b9403ab42a42187b
1 <?php
3 use MediaWiki\MainConfigNames;
4 use MediaWiki\Revision\RevisionRecord;
5 use MediaWiki\Title\Title;
6 use MediaWiki\Utils\MWTimestamp;
8 /**
9 * @covers \CategoryMembershipChangeJob
11 * @group JobQueue
12 * @group Database
14 * @license GPL-2.0-or-later
15 * @author Addshore
17 class CategoryMembershipChangeJobTest extends MediaWikiIntegrationTestCase {
19 private const TITLE_STRING = 'UTCatChangeJobPage';
21 /**
22 * @var Title
24 private $title;
26 protected function setUp(): void {
27 parent::setUp();
28 $this->overrideConfigValue( MainConfigNames::RCWatchCategoryMembership, true );
29 $this->setContentLang( 'qqx' );
32 public function addDBData() {
33 parent::addDBData();
34 $insertResult = $this->insertPage( self::TITLE_STRING, 'UT Content' );
35 $this->title = $insertResult['title'];
38 /**
39 * @param string $text new page text
41 * @return int|null
43 private function editPageText( $text ) {
44 $editResult = $this->editPage(
45 $this->title,
46 $text,
47 __METHOD__,
48 NS_MAIN,
49 $this->getTestSysop()->getAuthority()
51 /** @var RevisionRecord $revisionRecord */
52 $revisionRecord = $editResult->getNewRevision();
53 $this->runJobs();
55 return $revisionRecord->getId();
58 /**
59 * @param int $revId
61 * @return RecentChange|null
63 private function getCategorizeRecentChangeForRevId( $revId ) {
64 $rc = RecentChange::newFromConds(
66 'rc_type' => RC_CATEGORIZE,
67 'rc_this_oldid' => $revId,
69 __METHOD__
72 $this->assertNotNull( $rc, 'rev_id = ' . $revId );
73 return $rc;
76 public function testRun_normalCategoryAddedAndRemoved() {
77 $addedRevId = $this->editPageText( '[[Category:Normal]]' );
78 $removedRevId = $this->editPageText( 'Blank' );
80 $this->assertEquals(
81 '(recentchanges-page-added-to-category: ' . self::TITLE_STRING . ')',
82 $this->getCategorizeRecentChangeForRevId( $addedRevId )->getAttribute( 'rc_comment' )
84 $this->assertEquals(
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(
93 $this->title,
94 $jobSpec->getParams()
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() );