Merge "Revert "Limit searches at 500 per page""
[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 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
17 /**
18 * @dataProvider provider_backlinks
19 */
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 }