MediaWiki REL1_30
RefreshLinksPartitionTest.php
Go to the documentation of this file.
1<?php
2
9 public function __construct( $name = null, array $data = [], $dataName = '' ) {
10 parent::__construct( $name, $data, $dataName );
11
12 $this->tablesUsed[] = 'page';
13 $this->tablesUsed[] = 'revision';
14 $this->tablesUsed[] = 'pagelinks';
15 }
16
20 public function testRefreshLinks( $ns, $dbKey, $pages ) {
21 $title = Title::makeTitle( $ns, $dbKey );
22
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" );
28 }
29
30 $title->getBacklinkCache()->clear();
31 $this->assertEquals(
32 20,
33 $title->getBacklinkCache()->getNumLinks( 'pagelinks' ),
34 'Correct number of backlinks'
35 );
36
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 ] );
41
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' );
61
63 $jobs[9],
64 9,
65 1,
66 [ 'params' => $extraParams ]
67 );
68
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' );
84
86 $jobs2[9],
87 9,
88 1,
89 [ 'params' => $extraParams ]
90 );
91
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' );
101 }
102
103 public static function provider_backlinks() {
104 $pages = [];
105 for ( $i = 0; $i < 20; ++$i ) {
106 $pages[] = [ 0, "Page-$i" ];
107 }
108 return [
109 [ 10, 'Bang', $pages ]
110 ];
111 }
112}
static partitionBacklinkJob(Job $job, $bSize, $cSize, $opts=[])
Break down $job into approximately ($bSize/$cSize) leaf jobs and a single partition job that covers t...
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
static newRootJobParams( $key)
Get "root job" parameters for a task.
Definition Job.php:271
Job to update link tables for pages.
__construct( $name=null, array $data=[], $dataName='')
testRefreshLinks( $ns, $dbKey, $pages)
provider_backlinks
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:121
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
if(count( $args)< 1) $job