MediaWiki
REL1_21
|
00001 <?php 00008 class BackupDumperPageTest extends DumpTestCase { 00009 00010 // We'll add several pages, revision and texts. The following variables hold the 00011 // corresponding ids. 00012 private $pageId1, $pageId2, $pageId3, $pageId4, $pageId5; 00013 private $pageTitle1, $pageTitle2, $pageTitle3, $pageTitle4, $pageTitle5; 00014 private $revId1_1, $textId1_1; 00015 private $revId2_1, $textId2_1, $revId2_2, $textId2_2; 00016 private $revId2_3, $textId2_3, $revId2_4, $textId2_4; 00017 private $revId3_1, $textId3_1, $revId3_2, $textId3_2; 00018 private $revId4_1, $textId4_1; 00019 private $namespace, $talk_namespace; 00020 00021 function addDBData() { 00022 // be sure, titles created here using english namespace names 00023 $this->setMwGlobals( array( 00024 'wgLanguageCode' => 'en', 00025 'wgContLang' => Language::factory( 'en' ), 00026 ) ); 00027 00028 $this->tablesUsed[] = 'page'; 00029 $this->tablesUsed[] = 'revision'; 00030 $this->tablesUsed[] = 'text'; 00031 00032 try { 00033 $this->namespace = $this->getDefaultWikitextNS(); 00034 $this->talk_namespace = NS_TALK; 00035 00036 if ( $this->namespace === $this->talk_namespace ) { 00037 //@todo: work around this. 00038 throw new MWException( "The default wikitext namespace is the talk namespace. " 00039 . " We can't currently deal with that." ); 00040 } 00041 00042 $this->pageTitle1 = Title::newFromText( 'BackupDumperTestP1', $this->namespace ); 00043 $page = WikiPage::factory( $this->pageTitle1 ); 00044 list( $this->revId1_1, $this->textId1_1 ) = $this->addRevision( $page, 00045 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" ); 00046 $this->pageId1 = $page->getId(); 00047 00048 $this->pageTitle2 = Title::newFromText( 'BackupDumperTestP2', $this->namespace ); 00049 $page = WikiPage::factory( $this->pageTitle2 ); 00050 list( $this->revId2_1, $this->textId2_1 ) = $this->addRevision( $page, 00051 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" ); 00052 list( $this->revId2_2, $this->textId2_2 ) = $this->addRevision( $page, 00053 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" ); 00054 list( $this->revId2_3, $this->textId2_3 ) = $this->addRevision( $page, 00055 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" ); 00056 list( $this->revId2_4, $this->textId2_4 ) = $this->addRevision( $page, 00057 "BackupDumperTestP2Text4 some additional Text ", 00058 "BackupDumperTestP2Summary4 extra " ); 00059 $this->pageId2 = $page->getId(); 00060 00061 $this->pageTitle3 = Title::newFromText( 'BackupDumperTestP3', $this->namespace ); 00062 $page = WikiPage::factory( $this->pageTitle3 ); 00063 list( $this->revId3_1, $this->textId3_1 ) = $this->addRevision( $page, 00064 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" ); 00065 list( $this->revId3_2, $this->textId3_2 ) = $this->addRevision( $page, 00066 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" ); 00067 $this->pageId3 = $page->getId(); 00068 $page->doDeleteArticle( "Testing ;)" ); 00069 00070 $this->pageTitle4 = Title::newFromText( 'BackupDumperTestP1', $this->talk_namespace ); 00071 $page = WikiPage::factory( $this->pageTitle4 ); 00072 list( $this->revId4_1, $this->textId4_1 ) = $this->addRevision( $page, 00073 "Talk about BackupDumperTestP1 Text1", 00074 "Talk BackupDumperTestP1 Summary1" ); 00075 $this->pageId4 = $page->getId(); 00076 } catch ( Exception $e ) { 00077 // We'd love to pass $e directly. However, ... see 00078 // documentation of exceptionFromAddDBData in 00079 // DumpTestCase 00080 $this->exceptionFromAddDBData = $e; 00081 } 00082 00083 } 00084 00085 protected function setUp() { 00086 parent::setUp(); 00087 00088 // Since we will restrict dumping by page ranges (to allow 00089 // working tests, even if the db gets prepopulated by a base 00090 // class), we have to assert, that the page id are consecutively 00091 // increasing 00092 $this->assertEquals( 00093 array( $this->pageId2, $this->pageId3, $this->pageId4 ), 00094 array( $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ), 00095 "Page ids increasing without holes" ); 00096 00097 } 00098 00099 function testFullTextPlain() { 00100 // Preparing the dump 00101 $fname = $this->getNewTempFile(); 00102 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00103 $dumper->startId = $this->pageId1; 00104 $dumper->endId = $this->pageId4 + 1; 00105 $dumper->reporting = false; 00106 $dumper->setDb( $this->db ); 00107 00108 // Performing the dump 00109 $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT ); 00110 00111 // Checking the dumped data 00112 $this->assertDumpStart( $fname ); 00113 00114 // Page 1 00115 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00116 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00117 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87", 00118 "BackupDumperTestP1Text1" ); 00119 $this->assertPageEnd(); 00120 00121 // Page 2 00122 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00123 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1", 00124 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2", 00125 "BackupDumperTestP2Text1" ); 00126 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2", 00127 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", 00128 "BackupDumperTestP2Text2", $this->revId2_1 ); 00129 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3", 00130 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", 00131 "BackupDumperTestP2Text3", $this->revId2_2 ); 00132 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00133 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", 00134 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 ); 00135 $this->assertPageEnd(); 00136 00137 // Page 3 00138 // -> Page is marked deleted. Hence not visible 00139 00140 // Page 4 00141 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00142 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00143 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe", 00144 "Talk about BackupDumperTestP1 Text1" ); 00145 $this->assertPageEnd(); 00146 00147 $this->assertDumpEnd(); 00148 } 00149 00150 function testFullStubPlain() { 00151 // Preparing the dump 00152 $fname = $this->getNewTempFile(); 00153 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00154 $dumper->startId = $this->pageId1; 00155 $dumper->endId = $this->pageId4 + 1; 00156 $dumper->reporting = false; 00157 $dumper->setDb( $this->db ); 00158 00159 // Performing the dump 00160 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB ); 00161 00162 // Checking the dumped data 00163 $this->assertDumpStart( $fname ); 00164 00165 // Page 1 00166 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00167 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00168 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00169 $this->assertPageEnd(); 00170 00171 // Page 2 00172 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00173 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1", 00174 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" ); 00175 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2", 00176 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 ); 00177 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3", 00178 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 ); 00179 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00180 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00181 $this->assertPageEnd(); 00182 00183 // Page 3 00184 // -> Page is marked deleted. Hence not visible 00185 00186 // Page 4 00187 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00188 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00189 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00190 $this->assertPageEnd(); 00191 00192 $this->assertDumpEnd(); 00193 } 00194 00195 function testCurrentStubPlain() { 00196 // Preparing the dump 00197 $fname = $this->getNewTempFile(); 00198 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00199 $dumper->startId = $this->pageId1; 00200 $dumper->endId = $this->pageId4 + 1; 00201 $dumper->reporting = false; 00202 $dumper->setDb( $this->db ); 00203 00204 // Performing the dump 00205 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB ); 00206 00207 // Checking the dumped data 00208 $this->assertDumpStart( $fname ); 00209 00210 // Page 1 00211 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00212 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00213 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00214 $this->assertPageEnd(); 00215 00216 // Page 2 00217 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00218 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00219 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00220 $this->assertPageEnd(); 00221 00222 // Page 3 00223 // -> Page is marked deleted. Hence not visible 00224 00225 // Page 4 00226 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00227 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00228 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00229 $this->assertPageEnd(); 00230 00231 $this->assertDumpEnd(); 00232 } 00233 00234 function testCurrentStubGzip() { 00235 $this->checkHasGzip(); 00236 00237 // Preparing the dump 00238 $fname = $this->getNewTempFile(); 00239 $dumper = new BackupDumper( array( "--output=gzip:" . $fname ) ); 00240 $dumper->startId = $this->pageId1; 00241 $dumper->endId = $this->pageId4 + 1; 00242 $dumper->reporting = false; 00243 $dumper->setDb( $this->db ); 00244 00245 // Performing the dump 00246 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB ); 00247 00248 // Checking the dumped data 00249 $this->gunzip( $fname ); 00250 $this->assertDumpStart( $fname ); 00251 00252 // Page 1 00253 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00254 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00255 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00256 $this->assertPageEnd(); 00257 00258 // Page 2 00259 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00260 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00261 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00262 $this->assertPageEnd(); 00263 00264 // Page 3 00265 // -> Page is marked deleted. Hence not visible 00266 00267 // Page 4 00268 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00269 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00270 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00271 $this->assertPageEnd(); 00272 00273 $this->assertDumpEnd(); 00274 } 00275 00276 00277 function testXmlDumpsBackupUseCase() { 00278 // xmldumps-backup typically performs a single dump that that writes 00279 // out three files 00280 // * gzipped stubs of everything (meta-history) 00281 // * gzipped stubs of latest revisions of all pages (meta-current) 00282 // * gzipped stubs of latest revisions of all pages of namespage 0 00283 // (articles) 00284 // 00285 // We reproduce such a setup with our mini fixture, although we omit 00286 // chunks, and all the other gimmicks of xmldumps-backup. 00287 // 00288 $this->checkHasGzip(); 00289 00290 $fnameMetaHistory = $this->getNewTempFile(); 00291 $fnameMetaCurrent = $this->getNewTempFile(); 00292 $fnameArticles = $this->getNewTempFile(); 00293 00294 $dumper = new BackupDumper( array( "--output=gzip:" . $fnameMetaHistory, 00295 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest", 00296 "--output=gzip:" . $fnameArticles, "--filter=latest", 00297 "--filter=notalk", "--filter=namespace:!NS_USER", 00298 "--reporting=1000" ) ); 00299 $dumper->startId = $this->pageId1; 00300 $dumper->endId = $this->pageId4 + 1; 00301 $dumper->setDb( $this->db ); 00302 00303 // xmldumps-backup uses reporting. We will not check the exact reported 00304 // message, as they are dependent on the processing power of the used 00305 // computer. We only check that reporting does not crash the dumping 00306 // and that something is reported 00307 $dumper->stderr = fopen( 'php://output', 'a' ); 00308 if ( $dumper->stderr === false ) { 00309 $this->fail( "Could not open stream for stderr" ); 00310 } 00311 00312 // Performing the dump 00313 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB ); 00314 00315 $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" ); 00316 00317 // Checking meta-history ------------------------------------------------- 00318 00319 $this->gunzip( $fnameMetaHistory ); 00320 $this->assertDumpStart( $fnameMetaHistory ); 00321 00322 // Page 1 00323 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00324 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00325 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00326 $this->assertPageEnd(); 00327 00328 // Page 2 00329 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00330 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1", 00331 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" ); 00332 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2", 00333 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 ); 00334 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3", 00335 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 ); 00336 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00337 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00338 $this->assertPageEnd(); 00339 00340 // Page 3 00341 // -> Page is marked deleted. Hence not visible 00342 00343 // Page 4 00344 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00345 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00346 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00347 $this->assertPageEnd(); 00348 00349 $this->assertDumpEnd(); 00350 00351 // Checking meta-current ------------------------------------------------- 00352 00353 $this->gunzip( $fnameMetaCurrent ); 00354 $this->assertDumpStart( $fnameMetaCurrent ); 00355 00356 // Page 1 00357 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00358 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00359 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00360 $this->assertPageEnd(); 00361 00362 // Page 2 00363 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00364 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00365 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00366 $this->assertPageEnd(); 00367 00368 // Page 3 00369 // -> Page is marked deleted. Hence not visible 00370 00371 // Page 4 00372 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00373 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00374 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00375 $this->assertPageEnd(); 00376 00377 $this->assertDumpEnd(); 00378 00379 // Checking articles ------------------------------------------------- 00380 00381 $this->gunzip( $fnameArticles ); 00382 $this->assertDumpStart( $fnameArticles ); 00383 00384 // Page 1 00385 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00386 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00387 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00388 $this->assertPageEnd(); 00389 00390 // Page 2 00391 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00392 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00393 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00394 $this->assertPageEnd(); 00395 00396 // Page 3 00397 // -> Page is marked deleted. Hence not visible 00398 00399 // Page 4 00400 // -> Page is not in $this->namespace. Hence not visible 00401 00402 $this->assertDumpEnd(); 00403 00404 $this->expectETAOutput(); 00405 } 00406 00407 00408 }