Merge "Changed FOR UPDATE handling in Postgresql"
[lhc/web/wiklou.git] / tests / phpunit / includes / jobqueue / RefreshLinksPartitionTest.php
1 <?php
2
3 /**
4 * @group JobQueue
5 * @group medium
6 * @group Database
7 */
8 class RefreshLinksPartitionTest extends MediaWikiTestCase {
9 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
17 /**
18 * @dataProvider provider_backlinks
19 */
20 public function testRefreshLinks( $ns, $dbKey, $pages ) {
21 $title = Title::makeTitle( $ns, $dbKey );
22
23 $dbw = wfGetDB( DB_MASTER );
24
25 $rows = array();
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" );
31 }
32
33 $title->getBacklinkCache()->clear();
34 $this->assertEquals( 20, $title->getBacklinkCache()->getNumLinks( 'pagelinks' ), 'Correct number of backlinks' );
35
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 ) );
40
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' );
60
61 $jobs2 = BacklinkJobUtils::partitionBacklinkJob( $jobs[9], 9, 1, array( 'params' => $extraParams ) );
62
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' );
78
79 $jobs3 = BacklinkJobUtils::partitionBacklinkJob( $jobs2[9], 9, 1, array( 'params' => $extraParams ) );
80
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' );
90 }
91
92 public static function provider_backlinks() {
93 $pages = array();
94 for ( $i = 0; $i < 20; ++$i ) {
95 $pages[] = array( 0, "Page-$i" );
96 }
97 return array(
98 array( 10, 'Bang', $pages )
99 );
100 }
101 }