| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Title\Title; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class RefreshLinksPartitionTest extends MediaWikiIntegrationTestCase { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public function testRefreshLinks( $ns, $dbKey, $pages ) { |
| 17 |
$title = Title::makeTitle( $ns, $dbKey ); |
| 18 |
|
| 19 |
$user = $this->getTestSysop()->getAuthority(); |
| 20 |
foreach ( $pages as [ $bns, $bdbkey ] ) { |
| 21 |
$this->editPage( |
| 22 |
Title::makeTitle( $bns, $bdbkey ), |
| 23 |
"[[{$title->getPrefixedText()}]]", |
| 24 |
'test', |
| 25 |
NS_MAIN, |
| 26 |
$user |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
$backlinkCache = $this->getServiceContainer()->getBacklinkCacheFactory() |
| 31 |
->getBacklinkCache( $title ); |
| 32 |
$this->assertEquals( |
| 33 |
20, |
| 34 |
$backlinkCache->getNumLinks( 'pagelinks' ), |
| 35 |
'Correct number of backlinks' |
| 36 |
); |
| 37 |
|
| 38 |
$job = new RefreshLinksJob( $title, [ 'recursive' => true, 'table' => 'pagelinks' ] |
| 39 |
+ Job::newRootJobParams( 'refreshlinks:pagelinks:' . $title->getPrefixedText() ) ); |
| 40 |
$extraParams = $job->getRootJobParams(); |
| 41 |
$jobs = BacklinkJobUtils::partitionBacklinkJob( $job, 9, 1, [ 'params' => $extraParams ] ); |
| 42 |
|
| 43 |
$this->assertCount( 10, $jobs, 'Correct number of sub-jobs' ); |
| 44 |
$this->assertEquals( $pages[0], current( $jobs[0]->params['pages'] ), |
| 45 |
'First job is leaf job with proper title' ); |
| 46 |
$this->assertEquals( $pages[8], current( $jobs[8]->params['pages'] ), |
| 47 |
'Last leaf job is leaf job with proper title' ); |
| 48 |
$this->assertTrue( isset( $jobs[9]->params['recursive'] ), |
| 49 |
'Last job is recursive sub-job' ); |
| 50 |
$this->assertTrue( $jobs[9]->params['recursive'], |
| 51 |
'Last job is recursive sub-job' ); |
| 52 |
$this->assertIsArray( $jobs[9]->params['range'], |
| 53 |
'Last job is recursive sub-job' ); |
| 54 |
$this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(), |
| 55 |
'Base job title retainend in leaf job' ); |
| 56 |
$this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(), |
| 57 |
'Base job title retainend recursive sub-job' ); |
| 58 |
$this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params['rootJobSignature'], |
| 59 |
'Leaf job has root params' ); |
| 60 |
$this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params['rootJobSignature'], |
| 61 |
'Recursive sub-job has root params' ); |
| 62 |
|
| 63 |
$jobs2 = BacklinkJobUtils::partitionBacklinkJob( |
| 64 |
$jobs[9], |
| 65 |
9, |
| 66 |
1, |
| 67 |
[ 'params' => $extraParams ] |
| 68 |
); |
| 69 |
|
| 70 |
$this->assertCount( 10, $jobs2, 'Correct number of sub-jobs' ); |
| 71 |
$this->assertEquals( $pages[9], current( $jobs2[0]->params['pages'] ), |
| 72 |
'First job is leaf job with proper title' ); |
| 73 |
$this->assertEquals( $pages[17], current( $jobs2[8]->params['pages'] ), |
| 74 |
'Last leaf job is leaf job with proper title' ); |
| 75 |
$this->assertTrue( isset( $jobs2[9]->params['recursive'] ), |
| 76 |
'Last job is recursive sub-job' ); |
| 77 |
$this->assertTrue( $jobs2[9]->params['recursive'], |
| 78 |
'Last job is recursive sub-job' ); |
| 79 |
$this->assertIsArray( $jobs2[9]->params['range'], |
| 80 |
'Last job is recursive sub-job' ); |
| 81 |
$this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params['rootJobSignature'], |
| 82 |
'Leaf job has root params' ); |
| 83 |
$this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params['rootJobSignature'], |
| 84 |
'Recursive sub-job has root params' ); |
| 85 |
|
| 86 |
$jobs3 = BacklinkJobUtils::partitionBacklinkJob( |
| 87 |
$jobs2[9], |
| 88 |
9, |
| 89 |
1, |
| 90 |
[ 'params' => $extraParams ] |
| 91 |
); |
| 92 |
|
| 93 |
$this->assertCount( 2, $jobs3, 'Correct number of sub-jobs' ); |
| 94 |
$this->assertEquals( $pages[18], current( $jobs3[0]->params['pages'] ), |
| 95 |
'First job is leaf job with proper title' ); |
| 96 |
$this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params['rootJobSignature'], |
| 97 |
'Leaf job has root params' ); |
| 98 |
$this->assertEquals( $pages[19], current( $jobs3[1]->params['pages'] ), |
| 99 |
'Last job is leaf job with proper title' ); |
| 100 |
$this->assertEquals( $extraParams['rootJobSignature'], $jobs3[1]->params['rootJobSignature'], |
| 101 |
'Last leaf job has root params' ); |
| 102 |
} |
| 103 |
|
| 104 |
public static function provideBacklinks() { |
| 105 |
$pages = []; |
| 106 |
for ( $i = 0; $i < 20; ++$i ) { |
| 107 |
$pages[] = [ 0, "Page-$i" ]; |
| 108 |
} |
| 109 |
return [ |
| 110 |
[ 10, 'Bang', $pages ] |
| 111 |
]; |
| 112 |
} |
| 113 |
} |