3 use MediaWiki\Title\Title
;
10 class RefreshLinksPartitionTest
extends MediaWikiIntegrationTestCase
{
13 * @dataProvider provideBacklinks
14 * @covers \BacklinkJobUtils
16 public function testRefreshLinks( $ns, $dbKey, $pages ) {
17 $title = Title
::makeTitle( $ns, $dbKey );
19 $user = $this->getTestSysop()->getAuthority();
20 foreach ( $pages as [ $bns, $bdbkey ] ) {
22 Title
::makeTitle( $bns, $bdbkey ),
23 "[[{$title->getPrefixedText()}]]",
30 $backlinkCache = $this->getServiceContainer()->getBacklinkCacheFactory()
31 ->getBacklinkCache( $title );
34 $backlinkCache->getNumLinks( 'pagelinks' ),
35 'Correct number of backlinks'
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 ] );
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' );
63 $jobs2 = BacklinkJobUtils
::partitionBacklinkJob(
67 [ 'params' => $extraParams ]
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' );
86 $jobs3 = BacklinkJobUtils
::partitionBacklinkJob(
90 [ 'params' => $extraParams ]
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' );
104 public static function provideBacklinks() {
106 for ( $i = 0; $i < 20; ++
$i ) {
107 $pages[] = [ 0, "Page-$i" ];
110 [ 10, 'Bang', $pages ]