MediaWiki
REL1_23
|
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( 20, $title->getBacklinkCache()->getNumLinks( 'pagelinks' ), 'Correct number of backlinks' ); 00032 00033 $job = new RefreshLinksJob( $title, array( 'recursive' => true, 'table' => 'pagelinks' ) 00034 + Job::newRootJobParams( "refreshlinks:pagelinks:{$title->getPrefixedText()}" ) ); 00035 $extraParams = $job->getRootJobParams(); 00036 $jobs = BacklinkJobUtils::partitionBacklinkJob( $job, 9, 1, array( 'params' => $extraParams ) ); 00037 00038 $this->assertEquals( 10, count( $jobs ), 'Correct number of sub-jobs' ); 00039 $this->assertEquals( $pages[0], current( $jobs[0]->params['pages'] ), 00040 'First job is leaf job with proper title' ); 00041 $this->assertEquals( $pages[8], current( $jobs[8]->params['pages'] ), 00042 'Last leaf job is leaf job with proper title' ); 00043 $this->assertEquals( true, isset( $jobs[9]->params['recursive'] ), 00044 'Last job is recursive sub-job' ); 00045 $this->assertEquals( true, $jobs[9]->params['recursive'], 00046 'Last job is recursive sub-job' ); 00047 $this->assertEquals( true, is_array( $jobs[9]->params['range'] ), 00048 'Last job is recursive sub-job' ); 00049 $this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(), 00050 'Base job title retainend in leaf job' ); 00051 $this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(), 00052 'Base job title retainend recursive sub-job' ); 00053 $this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params['rootJobSignature'], 00054 'Leaf job has root params' ); 00055 $this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params['rootJobSignature'], 00056 'Recursive sub-job has root params' ); 00057 00058 $jobs2 = BacklinkJobUtils::partitionBacklinkJob( $jobs[9], 9, 1, array( 'params' => $extraParams ) ); 00059 00060 $this->assertEquals( 10, count( $jobs2 ), 'Correct number of sub-jobs' ); 00061 $this->assertEquals( $pages[9], current( $jobs2[0]->params['pages'] ), 00062 'First job is leaf job with proper title' ); 00063 $this->assertEquals( $pages[17], current( $jobs2[8]->params['pages'] ), 00064 'Last leaf job is leaf job with proper title' ); 00065 $this->assertEquals( true, isset( $jobs2[9]->params['recursive'] ), 00066 'Last job is recursive sub-job' ); 00067 $this->assertEquals( true, $jobs2[9]->params['recursive'], 00068 'Last job is recursive sub-job' ); 00069 $this->assertEquals( true, is_array( $jobs2[9]->params['range'] ), 00070 'Last job is recursive sub-job' ); 00071 $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params['rootJobSignature'], 00072 'Leaf job has root params' ); 00073 $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params['rootJobSignature'], 00074 'Recursive sub-job has root params' ); 00075 00076 $jobs3 = BacklinkJobUtils::partitionBacklinkJob( $jobs2[9], 9, 1, array( 'params' => $extraParams ) ); 00077 00078 $this->assertEquals( 2, count( $jobs3 ), 'Correct number of sub-jobs' ); 00079 $this->assertEquals( $pages[18], current( $jobs3[0]->params['pages'] ), 00080 'First job is leaf job with proper title' ); 00081 $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params['rootJobSignature'], 00082 'Leaf job has root params' ); 00083 $this->assertEquals( $pages[19], current( $jobs3[1]->params['pages'] ), 00084 'Last job is leaf job with proper title' ); 00085 $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[1]->params['rootJobSignature'], 00086 'Last leaf job has root params' ); 00087 } 00088 00089 public static function provider_backlinks() { 00090 $pages = array(); 00091 for ( $i = 0; $i < 20; ++$i ) { 00092 $pages[] = array( 0, "Page-$i" ); 00093 } 00094 return array( 00095 array( 10, 'Bang', $pages ) 00096 ); 00097 } 00098 }