8 class RefreshLinksPartitionTest
extends MediaWikiTestCase
{
9 function __construct( $name = null, array $data = array(), $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 $dbw = wfGetDB( DB_MASTER
);
26 foreach ( $pages as $page ) {
27 list( $bns, $bdbkey ) = $page;
28 $bpage = WikiPage
::factory( Title
::makeTitle( $bns, $bdbkey ) );
29 $content = ContentHandler
::makeContent( "[[{$title->getPrefixedText()}]]", $bpage->getTitle() );
30 $bpage->doEditContent( $content, "test" );
33 $title->getBacklinkCache()->clear();
34 $this->assertEquals( 20, $title->getBacklinkCache()->getNumLinks( 'pagelinks' ), 'Correct number of backlinks' );
36 $job = new RefreshLinksJob( $title, array( 'recursive' => true, 'table' => 'pagelinks' )
37 + Job
::newRootJobParams( "refreshlinks:pagelinks:{$title->getPrefixedText()}" ) );
38 $extraParams = $job->getRootJobParams();
39 $jobs = BacklinkJobUtils
::partitionBacklinkJob( $job, 9, 1, array( 'params' => $extraParams ) );
41 $this->assertEquals( 10, count( $jobs ), 'Correct number of sub-jobs' );
42 $this->assertEquals( $pages[0], current( $jobs[0]->params
['pages'] ),
43 'First job is leaf job with proper title' );
44 $this->assertEquals( $pages[8], current( $jobs[8]->params
['pages'] ),
45 'Last leaf job is leaf job with proper title' );
46 $this->assertEquals( true, isset( $jobs[9]->params
['recursive'] ),
47 'Last job is recursive sub-job' );
48 $this->assertEquals( true, $jobs[9]->params
['recursive'],
49 'Last job is recursive sub-job' );
50 $this->assertEquals( true, is_array( $jobs[9]->params
['range'] ),
51 'Last job is recursive sub-job' );
52 $this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(),
53 'Base job title retainend in leaf job' );
54 $this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(),
55 'Base job title retainend recursive sub-job' );
56 $this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params
['rootJobSignature'],
57 'Leaf job has root params' );
58 $this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params
['rootJobSignature'],
59 'Recursive sub-job has root params' );
61 $jobs2 = BacklinkJobUtils
::partitionBacklinkJob( $jobs[9], 9, 1, array( 'params' => $extraParams ) );
63 $this->assertEquals( 10, count( $jobs2 ), 'Correct number of sub-jobs' );
64 $this->assertEquals( $pages[9], current( $jobs2[0]->params
['pages'] ),
65 'First job is leaf job with proper title' );
66 $this->assertEquals( $pages[17], current( $jobs2[8]->params
['pages'] ),
67 'Last leaf job is leaf job with proper title' );
68 $this->assertEquals( true, isset( $jobs2[9]->params
['recursive'] ),
69 'Last job is recursive sub-job' );
70 $this->assertEquals( true, $jobs2[9]->params
['recursive'],
71 'Last job is recursive sub-job' );
72 $this->assertEquals( true, is_array( $jobs2[9]->params
['range'] ),
73 'Last job is recursive sub-job' );
74 $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params
['rootJobSignature'],
75 'Leaf job has root params' );
76 $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params
['rootJobSignature'],
77 'Recursive sub-job has root params' );
79 $jobs3 = BacklinkJobUtils
::partitionBacklinkJob( $jobs2[9], 9, 1, array( 'params' => $extraParams ) );
81 $this->assertEquals( 2, count( $jobs3 ), 'Correct number of sub-jobs' );
82 $this->assertEquals( $pages[18], current( $jobs3[0]->params
['pages'] ),
83 'First job is leaf job with proper title' );
84 $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params
['rootJobSignature'],
85 'Leaf job has root params' );
86 $this->assertEquals( $pages[19], current( $jobs3[1]->params
['pages'] ),
87 'Last job is leaf job with proper title' );
88 $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[1]->params
['rootJobSignature'],
89 'Last leaf job has root params' );
92 public static function provider_backlinks() {
94 for ( $i = 0; $i < 20; ++
$i ) {
95 $pages[] = array( 0, "Page-$i" );
98 array( 10, 'Bang', $pages )