MediaWiki  REL1_24
RefreshLinksPartitionTest.php
Go to the documentation of this file.
00001 <?php
00002 
00008 class RefreshLinksPartitionTest extends MediaWikiTestCase {
00009     public function __construct( $name = null, array $data = array(), $dataName = '' ) {
00010         parent::__construct( $name, $data, $dataName );
00011 
00012         $this->tablesUsed[] = 'page';
00013         $this->tablesUsed[] = 'revision';
00014         $this->tablesUsed[] = 'pagelinks';
00015     }
00016 
00020     public function testRefreshLinks( $ns, $dbKey, $pages ) {
00021         $title = Title::makeTitle( $ns, $dbKey );
00022 
00023         foreach ( $pages as $page ) {
00024             list( $bns, $bdbkey ) = $page;
00025             $bpage = WikiPage::factory( Title::makeTitle( $bns, $bdbkey ) );
00026             $content = ContentHandler::makeContent( "[[{$title->getPrefixedText()}]]", $bpage->getTitle() );
00027             $bpage->doEditContent( $content, "test" );
00028         }
00029 
00030         $title->getBacklinkCache()->clear();
00031         $this->assertEquals(
00032             20,
00033             $title->getBacklinkCache()->getNumLinks( 'pagelinks' ),
00034             'Correct number of backlinks'
00035         );
00036 
00037         $job = new RefreshLinksJob( $title, array( 'recursive' => true, 'table' => 'pagelinks' )
00038             + Job::newRootJobParams( "refreshlinks:pagelinks:{$title->getPrefixedText()}" ) );
00039         $extraParams = $job->getRootJobParams();
00040         $jobs = BacklinkJobUtils::partitionBacklinkJob( $job, 9, 1, array( 'params' => $extraParams ) );
00041 
00042         $this->assertEquals( 10, count( $jobs ), 'Correct number of sub-jobs' );
00043         $this->assertEquals( $pages[0], current( $jobs[0]->params['pages'] ),
00044             'First job is leaf job with proper title' );
00045         $this->assertEquals( $pages[8], current( $jobs[8]->params['pages'] ),
00046             'Last leaf job is leaf job with proper title' );
00047         $this->assertEquals( true, isset( $jobs[9]->params['recursive'] ),
00048             'Last job is recursive sub-job' );
00049         $this->assertEquals( true, $jobs[9]->params['recursive'],
00050             'Last job is recursive sub-job' );
00051         $this->assertEquals( true, is_array( $jobs[9]->params['range'] ),
00052             'Last job is recursive sub-job' );
00053         $this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(),
00054             'Base job title retainend in leaf job' );
00055         $this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(),
00056             'Base job title retainend recursive sub-job' );
00057         $this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params['rootJobSignature'],
00058             'Leaf job has root params' );
00059         $this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params['rootJobSignature'],
00060             'Recursive sub-job has root params' );
00061 
00062         $jobs2 = BacklinkJobUtils::partitionBacklinkJob(
00063             $jobs[9],
00064             9,
00065             1,
00066             array( 'params' => $extraParams )
00067         );
00068 
00069         $this->assertEquals( 10, count( $jobs2 ), 'Correct number of sub-jobs' );
00070         $this->assertEquals( $pages[9], current( $jobs2[0]->params['pages'] ),
00071             'First job is leaf job with proper title' );
00072         $this->assertEquals( $pages[17], current( $jobs2[8]->params['pages'] ),
00073             'Last leaf job is leaf job with proper title' );
00074         $this->assertEquals( true, isset( $jobs2[9]->params['recursive'] ),
00075             'Last job is recursive sub-job' );
00076         $this->assertEquals( true, $jobs2[9]->params['recursive'],
00077             'Last job is recursive sub-job' );
00078         $this->assertEquals( true, is_array( $jobs2[9]->params['range'] ),
00079             'Last job is recursive sub-job' );
00080         $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params['rootJobSignature'],
00081             'Leaf job has root params' );
00082         $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params['rootJobSignature'],
00083             'Recursive sub-job has root params' );
00084 
00085         $jobs3 = BacklinkJobUtils::partitionBacklinkJob(
00086             $jobs2[9],
00087             9,
00088             1,
00089             array( 'params' => $extraParams )
00090         );
00091 
00092         $this->assertEquals( 2, count( $jobs3 ), 'Correct number of sub-jobs' );
00093         $this->assertEquals( $pages[18], current( $jobs3[0]->params['pages'] ),
00094             'First job is leaf job with proper title' );
00095         $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params['rootJobSignature'],
00096             'Leaf job has root params' );
00097         $this->assertEquals( $pages[19], current( $jobs3[1]->params['pages'] ),
00098             'Last job is leaf job with proper title' );
00099         $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[1]->params['rootJobSignature'],
00100             'Last leaf job has root params' );
00101     }
00102 
00103     public static function provider_backlinks() {
00104         $pages = array();
00105         for ( $i = 0; $i < 20; ++$i ) {
00106             $pages[] = array( 0, "Page-$i" );
00107         }
00108         return array(
00109             array( 10, 'Bang', $pages )
00110         );
00111     }
00112 }