wiki.techinc.nl/tests/phpunit/includes/jobqueue/RefreshLinksPartitionTest.php
Thiemo Kreuz 67c56155c7 Replace trivial usages of code in strings with concatenation
This is really hard to read. What is code, what is string? These
places are so simple, they really don't need the "{$var}" syntax.

Change-Id: I589dedb8c0193eec4eef500bbb896b5b790b727b
2022-08-26 12:26:44 +00:00

116 lines
4.3 KiB
PHP

<?php
/**
* @group JobQueue
* @group medium
* @group Database
*/
class RefreshLinksPartitionTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->tablesUsed[] = 'page';
$this->tablesUsed[] = 'revision';
$this->tablesUsed[] = 'pagelinks';
}
/**
* @dataProvider provider_backlinks
* @covers BacklinkJobUtils::partitionBacklinkJob
*/
public function testRefreshLinks( $ns, $dbKey, $pages ) {
$title = Title::makeTitle( $ns, $dbKey );
$user = $this->getTestSysop()->getUser();
foreach ( $pages as [ $bns, $bdbkey ] ) {
$bpage = WikiPage::factory( Title::makeTitle( $bns, $bdbkey ) );
$content = ContentHandler::makeContent( "[[{$title->getPrefixedText()}]]", $bpage->getTitle() );
$bpage->doUserEditContent( $content, $user, "test" );
}
$backlinkCache = $this->getServiceContainer()->getBacklinkCacheFactory()
->getBacklinkCache( $title );
$backlinkCache->clear();
$this->assertEquals(
20,
$backlinkCache->getNumLinks( 'pagelinks' ),
'Correct number of backlinks'
);
$job = new RefreshLinksJob( $title, [ 'recursive' => true, 'table' => 'pagelinks' ]
+ Job::newRootJobParams( 'refreshlinks:pagelinks:' . $title->getPrefixedText() ) );
$extraParams = $job->getRootJobParams();
$jobs = BacklinkJobUtils::partitionBacklinkJob( $job, 9, 1, [ 'params' => $extraParams ] );
$this->assertCount( 10, $jobs, 'Correct number of sub-jobs' );
$this->assertEquals( $pages[0], current( $jobs[0]->params['pages'] ),
'First job is leaf job with proper title' );
$this->assertEquals( $pages[8], current( $jobs[8]->params['pages'] ),
'Last leaf job is leaf job with proper title' );
$this->assertTrue( isset( $jobs[9]->params['recursive'] ),
'Last job is recursive sub-job' );
$this->assertTrue( $jobs[9]->params['recursive'],
'Last job is recursive sub-job' );
$this->assertTrue( is_array( $jobs[9]->params['range'] ),
'Last job is recursive sub-job' );
$this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(),
'Base job title retainend in leaf job' );
$this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(),
'Base job title retainend recursive sub-job' );
$this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params['rootJobSignature'],
'Leaf job has root params' );
$this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params['rootJobSignature'],
'Recursive sub-job has root params' );
$jobs2 = BacklinkJobUtils::partitionBacklinkJob(
$jobs[9],
9,
1,
[ 'params' => $extraParams ]
);
$this->assertCount( 10, $jobs2, 'Correct number of sub-jobs' );
$this->assertEquals( $pages[9], current( $jobs2[0]->params['pages'] ),
'First job is leaf job with proper title' );
$this->assertEquals( $pages[17], current( $jobs2[8]->params['pages'] ),
'Last leaf job is leaf job with proper title' );
$this->assertTrue( isset( $jobs2[9]->params['recursive'] ),
'Last job is recursive sub-job' );
$this->assertTrue( $jobs2[9]->params['recursive'],
'Last job is recursive sub-job' );
$this->assertTrue( is_array( $jobs2[9]->params['range'] ),
'Last job is recursive sub-job' );
$this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params['rootJobSignature'],
'Leaf job has root params' );
$this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params['rootJobSignature'],
'Recursive sub-job has root params' );
$jobs3 = BacklinkJobUtils::partitionBacklinkJob(
$jobs2[9],
9,
1,
[ 'params' => $extraParams ]
);
$this->assertCount( 2, $jobs3, 'Correct number of sub-jobs' );
$this->assertEquals( $pages[18], current( $jobs3[0]->params['pages'] ),
'First job is leaf job with proper title' );
$this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params['rootJobSignature'],
'Leaf job has root params' );
$this->assertEquals( $pages[19], current( $jobs3[1]->params['pages'] ),
'Last job is leaf job with proper title' );
$this->assertEquals( $extraParams['rootJobSignature'], $jobs3[1]->params['rootJobSignature'],
'Last leaf job has root params' );
}
public static function provider_backlinks() {
$pages = [];
for ( $i = 0; $i < 20; ++$i ) {
$pages[] = [ 0, "Page-$i" ];
}
return [
[ 10, 'Bang', $pages ]
];
}
}