MediaWiki  1.23.6
RefreshLinksPartitionTest.php
Go to the documentation of this file.
1 <?php
2 
9  public function __construct( $name = null, array $data = array(), $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( 20, $title->getBacklinkCache()->getNumLinks( 'pagelinks' ), 'Correct number of backlinks' );
32 
33  $job = new RefreshLinksJob( $title, array( 'recursive' => true, 'table' => 'pagelinks' )
34  + Job::newRootJobParams( "refreshlinks:pagelinks:{$title->getPrefixedText()}" ) );
35  $extraParams = $job->getRootJobParams();
36  $jobs = BacklinkJobUtils::partitionBacklinkJob( $job, 9, 1, array( 'params' => $extraParams ) );
37 
38  $this->assertEquals( 10, count( $jobs ), 'Correct number of sub-jobs' );
39  $this->assertEquals( $pages[0], current( $jobs[0]->params['pages'] ),
40  'First job is leaf job with proper title' );
41  $this->assertEquals( $pages[8], current( $jobs[8]->params['pages'] ),
42  'Last leaf job is leaf job with proper title' );
43  $this->assertEquals( true, isset( $jobs[9]->params['recursive'] ),
44  'Last job is recursive sub-job' );
45  $this->assertEquals( true, $jobs[9]->params['recursive'],
46  'Last job is recursive sub-job' );
47  $this->assertEquals( true, is_array( $jobs[9]->params['range'] ),
48  'Last job is recursive sub-job' );
49  $this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(),
50  'Base job title retainend in leaf job' );
51  $this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(),
52  'Base job title retainend recursive sub-job' );
53  $this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params['rootJobSignature'],
54  'Leaf job has root params' );
55  $this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params['rootJobSignature'],
56  'Recursive sub-job has root params' );
57 
58  $jobs2 = BacklinkJobUtils::partitionBacklinkJob( $jobs[9], 9, 1, array( 'params' => $extraParams ) );
59 
60  $this->assertEquals( 10, count( $jobs2 ), 'Correct number of sub-jobs' );
61  $this->assertEquals( $pages[9], current( $jobs2[0]->params['pages'] ),
62  'First job is leaf job with proper title' );
63  $this->assertEquals( $pages[17], current( $jobs2[8]->params['pages'] ),
64  'Last leaf job is leaf job with proper title' );
65  $this->assertEquals( true, isset( $jobs2[9]->params['recursive'] ),
66  'Last job is recursive sub-job' );
67  $this->assertEquals( true, $jobs2[9]->params['recursive'],
68  'Last job is recursive sub-job' );
69  $this->assertEquals( true, is_array( $jobs2[9]->params['range'] ),
70  'Last job is recursive sub-job' );
71  $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params['rootJobSignature'],
72  'Leaf job has root params' );
73  $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params['rootJobSignature'],
74  'Recursive sub-job has root params' );
75 
76  $jobs3 = BacklinkJobUtils::partitionBacklinkJob( $jobs2[9], 9, 1, array( 'params' => $extraParams ) );
77 
78  $this->assertEquals( 2, count( $jobs3 ), 'Correct number of sub-jobs' );
79  $this->assertEquals( $pages[18], current( $jobs3[0]->params['pages'] ),
80  'First job is leaf job with proper title' );
81  $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params['rootJobSignature'],
82  'Leaf job has root params' );
83  $this->assertEquals( $pages[19], current( $jobs3[1]->params['pages'] ),
84  'Last job is leaf job with proper title' );
85  $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[1]->params['rootJobSignature'],
86  'Last leaf job has root params' );
87  }
88 
89  public static function provider_backlinks() {
90  $pages = array();
91  for ( $i = 0; $i < 20; ++$i ) {
92  $pages[] = array( 0, "Page-$i" );
93  }
94  return array(
95  array( 10, 'Bang', $pages )
96  );
97  }
98 }
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
RefreshLinksPartitionTest
@group JobQueue @group medium @group Database
Definition: RefreshLinksPartitionTest.php:8
RefreshLinksPartitionTest\provider_backlinks
static provider_backlinks()
Definition: RefreshLinksPartitionTest.php:89
BacklinkJobUtils\partitionBacklinkJob
static partitionBacklinkJob(Job $job, $bSize, $cSize, $opts=array())
Break down $job into approximately ($bSize/$cSize) leaf jobs and a single partition job that covers t...
Definition: BacklinkJobUtils.php:67
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:103
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
RefreshLinksPartitionTest\__construct
__construct( $name=null, array $data=array(), $dataName='')
Definition: RefreshLinksPartitionTest.php:9
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Job\newRootJobParams
static newRootJobParams( $key)
Definition: Job.php:239
list
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
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:144
RefreshLinksJob
Job to update link tables for pages.
Definition: RefreshLinksJob.php:37
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:42
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
RefreshLinksPartitionTest\testRefreshLinks
testRefreshLinks( $ns, $dbKey, $pages)
@dataProvider provider_backlinks
Definition: RefreshLinksPartitionTest.php:20