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
20 public function testRefreshLinks( $ns, $dbKey, $pages ) {
21 $title = Title
::makeTitle( $ns, $dbKey );
23 foreach ( $pages as $page ) {
24 list( $bns, $bdbkey ) = $page;
25 $bpage = WikiPage
::factory( Title
::makeTitle( $bns, $bdbkey ) );
26 $content = ContentHandler
::makeContent( "[[{$title->getPrefixedText()}]]", $bpage->getTitle() );
27 $bpage->doEditContent( $content, "test" );
30 $title->getBacklinkCache()->clear();
33 $title->getBacklinkCache()->getNumLinks( 'pagelinks' ),
34 'Correct number of backlinks'
37 $job = new RefreshLinksJob( $title, [ 'recursive' => true, 'table' => 'pagelinks' ]
38 + Job
::newRootJobParams( "refreshlinks:pagelinks:{$title->getPrefixedText()}" ) );
39 $extraParams = $job->getRootJobParams();
40 $jobs = BacklinkJobUtils
::partitionBacklinkJob( $job, 9, 1, [ 'params' => $extraParams ] );
42 $this->assertEquals( 10, count( $jobs ), 'Correct number of sub-jobs' );
43 $this->assertEquals( $pages[0], current( $jobs[0]->params
['pages'] ),
44 'First job is leaf job with proper title' );
45 $this->assertEquals( $pages[8], current( $jobs[8]->params
['pages'] ),
46 'Last leaf job is leaf job with proper title' );
47 $this->assertEquals( true, isset( $jobs[9]->params
['recursive'] ),
48 'Last job is recursive sub-job' );
49 $this->assertEquals( true, $jobs[9]->params
['recursive'],
50 'Last job is recursive sub-job' );
51 $this->assertEquals( true, is_array( $jobs[9]->params
['range'] ),
52 'Last job is recursive sub-job' );
53 $this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(),
54 'Base job title retainend in leaf job' );
55 $this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(),
56 'Base job title retainend recursive sub-job' );
57 $this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params
['rootJobSignature'],
58 'Leaf job has root params' );
59 $this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params
['rootJobSignature'],
60 'Recursive sub-job has root params' );
62 $jobs2 = BacklinkJobUtils
::partitionBacklinkJob(
66 [ 'params' => $extraParams ]
69 $this->assertEquals( 10, count( $jobs2 ), 'Correct number of sub-jobs' );
70 $this->assertEquals( $pages[9], current( $jobs2[0]->params
['pages'] ),
71 'First job is leaf job with proper title' );
72 $this->assertEquals( $pages[17], current( $jobs2[8]->params
['pages'] ),
73 'Last leaf job is leaf job with proper title' );
74 $this->assertEquals( true, isset( $jobs2[9]->params
['recursive'] ),
75 'Last job is recursive sub-job' );
76 $this->assertEquals( true, $jobs2[9]->params
['recursive'],
77 'Last job is recursive sub-job' );
78 $this->assertEquals( true, is_array( $jobs2[9]->params
['range'] ),
79 'Last job is recursive sub-job' );
80 $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params
['rootJobSignature'],
81 'Leaf job has root params' );
82 $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params
['rootJobSignature'],
83 'Recursive sub-job has root params' );
85 $jobs3 = BacklinkJobUtils
::partitionBacklinkJob(
89 [ 'params' => $extraParams ]
92 $this->assertEquals( 2, count( $jobs3 ), 'Correct number of sub-jobs' );
93 $this->assertEquals( $pages[18], current( $jobs3[0]->params
['pages'] ),
94 'First job is leaf job with proper title' );
95 $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params
['rootJobSignature'],
96 'Leaf job has root params' );
97 $this->assertEquals( $pages[19], current( $jobs3[1]->params
['pages'] ),
98 'Last job is leaf job with proper title' );
99 $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[1]->params
['rootJobSignature'],
100 'Last leaf job has root params' );
103 public static function provider_backlinks() {
105 for ( $i = 0; $i < 20; ++
$i ) {
106 $pages[] = [ 0, "Page-$i" ];
109 [ 10, 'Bang', $pages ]