8 class RefreshLinksPartitionTest
extends MediaWikiTestCase
{
9 public function __construct( $name = null, array $data = [], $dataName = '' ) {
10 parent
::__construct( $name, $data, $dataName );
12 $this->tablesUsed
[] = 'page';
13 $this->tablesUsed
[] = 'revision';
14 $this->tablesUsed
[] = 'pagelinks';
18 * @dataProvider provider_backlinks
19 * @covers BacklinkJobUtils::partitionBacklinkJob
21 public function testRefreshLinks( $ns, $dbKey, $pages ) {
22 $title = Title
::makeTitle( $ns, $dbKey );
24 foreach ( $pages as $page ) {
25 list( $bns, $bdbkey ) = $page;
26 $bpage = WikiPage
::factory( Title
::makeTitle( $bns, $bdbkey ) );
27 $content = ContentHandler
::makeContent( "[[{$title->getPrefixedText()}]]", $bpage->getTitle() );
28 $bpage->doEditContent( $content, "test" );
31 $title->getBacklinkCache()->clear();
34 $title->getBacklinkCache()->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->assertEquals( 10, count( $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->assertEquals( true, isset( $jobs[9]->params
['recursive'] ),
49 'Last job is recursive sub-job' );
50 $this->assertEquals( true, $jobs[9]->params
['recursive'],
51 'Last job is recursive sub-job' );
52 $this->assertEquals( true, is_array( $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->assertEquals( 10, count( $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->assertEquals( true, isset( $jobs2[9]->params
['recursive'] ),
76 'Last job is recursive sub-job' );
77 $this->assertEquals( true, $jobs2[9]->params
['recursive'],
78 'Last job is recursive sub-job' );
79 $this->assertEquals( true, is_array( $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->assertEquals( 2, count( $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 provider_backlinks() {
106 for ( $i = 0; $i < 20; ++
$i ) {
107 $pages[] = [ 0, "Page-$i" ];
110 [ 10, 'Bang', $pages ]