2013-11-19 00:12:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group JobQueue
|
|
|
|
|
* @group medium
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class RefreshLinksPartitionTest extends MediaWikiIntegrationTestCase {
|
2021-03-08 03:23:08 +00:00
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2021-03-08 03:23:08 +00:00
|
|
|
parent::setUp();
|
2013-11-19 00:12:12 +00:00
|
|
|
|
|
|
|
|
$this->tablesUsed[] = 'page';
|
|
|
|
|
$this->tablesUsed[] = 'revision';
|
|
|
|
|
$this->tablesUsed[] = 'pagelinks';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_backlinks
|
2017-12-25 04:06:06 +00:00
|
|
|
* @covers BacklinkJobUtils::partitionBacklinkJob
|
2013-11-19 00:12:12 +00:00
|
|
|
*/
|
|
|
|
|
public function testRefreshLinks( $ns, $dbKey, $pages ) {
|
|
|
|
|
$title = Title::makeTitle( $ns, $dbKey );
|
|
|
|
|
|
2021-06-24 08:42:19 +00:00
|
|
|
$user = $this->getTestSysop()->getUser();
|
2020-06-18 14:57:50 +00:00
|
|
|
foreach ( $pages as [ $bns, $bdbkey ] ) {
|
2013-11-19 00:12:12 +00:00
|
|
|
$bpage = WikiPage::factory( Title::makeTitle( $bns, $bdbkey ) );
|
|
|
|
|
$content = ContentHandler::makeContent( "[[{$title->getPrefixedText()}]]", $bpage->getTitle() );
|
2021-06-24 08:42:19 +00:00
|
|
|
$bpage->doUserEditContent( $content, $user, "test" );
|
2013-11-19 00:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title->getBacklinkCache()->clear();
|
2014-04-24 16:06:46 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
20,
|
|
|
|
|
$title->getBacklinkCache()->getNumLinks( 'pagelinks' ),
|
|
|
|
|
'Correct number of backlinks'
|
|
|
|
|
);
|
2013-11-19 00:12:12 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$job = new RefreshLinksJob( $title, [ 'recursive' => true, 'table' => 'pagelinks' ]
|
2013-11-19 00:12:12 +00:00
|
|
|
+ Job::newRootJobParams( "refreshlinks:pagelinks:{$title->getPrefixedText()}" ) );
|
|
|
|
|
$extraParams = $job->getRootJobParams();
|
2016-02-17 09:09:32 +00:00
|
|
|
$jobs = BacklinkJobUtils::partitionBacklinkJob( $job, 9, 1, [ 'params' => $extraParams ] );
|
2013-11-19 00:12:12 +00:00
|
|
|
|
2020-02-28 15:45:22 +00:00
|
|
|
$this->assertCount( 10, $jobs, 'Correct number of sub-jobs' );
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->assertEquals( $pages[0], current( $jobs[0]->params['pages'] ),
|
2013-11-19 00:12:12 +00:00
|
|
|
'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' );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( isset( $jobs[9]->params['recursive'] ),
|
2013-11-19 00:12:12 +00:00
|
|
|
'Last job is recursive sub-job' );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $jobs[9]->params['recursive'],
|
2013-11-19 00:12:12 +00:00
|
|
|
'Last job is recursive sub-job' );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( is_array( $jobs[9]->params['range'] ),
|
2013-11-19 00:12:12 +00:00
|
|
|
'Last job is recursive sub-job' );
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(),
|
2013-11-19 00:12:12 +00:00
|
|
|
'Base job title retainend in leaf job' );
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(),
|
2013-11-19 00:12:12 +00:00
|
|
|
'Base job title retainend recursive sub-job' );
|
|
|
|
|
$this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params['rootJobSignature'],
|
|
|
|
|
'Leaf job has root params' );
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params['rootJobSignature'],
|
2013-11-19 00:12:12 +00:00
|
|
|
'Recursive sub-job has root params' );
|
|
|
|
|
|
2014-04-24 16:06:46 +00:00
|
|
|
$jobs2 = BacklinkJobUtils::partitionBacklinkJob(
|
|
|
|
|
$jobs[9],
|
|
|
|
|
9,
|
|
|
|
|
1,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'params' => $extraParams ]
|
2014-04-24 16:06:46 +00:00
|
|
|
);
|
2013-11-19 00:12:12 +00:00
|
|
|
|
2020-02-28 15:45:22 +00:00
|
|
|
$this->assertCount( 10, $jobs2, 'Correct number of sub-jobs' );
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->assertEquals( $pages[9], current( $jobs2[0]->params['pages'] ),
|
2013-11-19 00:12:12 +00:00
|
|
|
'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' );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( isset( $jobs2[9]->params['recursive'] ),
|
2013-11-19 00:12:12 +00:00
|
|
|
'Last job is recursive sub-job' );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $jobs2[9]->params['recursive'],
|
2013-11-19 00:12:12 +00:00
|
|
|
'Last job is recursive sub-job' );
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( is_array( $jobs2[9]->params['range'] ),
|
2013-11-19 00:12:12 +00:00
|
|
|
'Last job is recursive sub-job' );
|
|
|
|
|
$this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params['rootJobSignature'],
|
|
|
|
|
'Leaf job has root params' );
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params['rootJobSignature'],
|
2013-11-19 00:12:12 +00:00
|
|
|
'Recursive sub-job has root params' );
|
|
|
|
|
|
2014-04-24 16:06:46 +00:00
|
|
|
$jobs3 = BacklinkJobUtils::partitionBacklinkJob(
|
|
|
|
|
$jobs2[9],
|
|
|
|
|
9,
|
|
|
|
|
1,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'params' => $extraParams ]
|
2014-04-24 16:06:46 +00:00
|
|
|
);
|
2013-11-19 00:12:12 +00:00
|
|
|
|
2020-02-28 15:45:22 +00:00
|
|
|
$this->assertCount( 2, $jobs3, 'Correct number of sub-jobs' );
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->assertEquals( $pages[18], current( $jobs3[0]->params['pages'] ),
|
2013-11-19 00:12:12 +00:00
|
|
|
'First job is leaf job with proper title' );
|
|
|
|
|
$this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params['rootJobSignature'],
|
|
|
|
|
'Leaf job has root params' );
|
2013-12-01 19:58:51 +00:00
|
|
|
$this->assertEquals( $pages[19], current( $jobs3[1]->params['pages'] ),
|
2013-11-19 00:12:12 +00:00
|
|
|
'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() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$pages = [];
|
2013-12-01 19:58:51 +00:00
|
|
|
for ( $i = 0; $i < 20; ++$i ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$pages[] = [ 0, "Page-$i" ];
|
2013-11-19 00:12:12 +00:00
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 10, 'Bang', $pages ]
|
|
|
|
|
];
|
2013-11-19 00:12:12 +00:00
|
|
|
}
|
|
|
|
|
}
|