MediaWiki
REL1_22
|
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 protected function setUp() { 00085 parent::setUp(); 00086 00087 // Since we will restrict dumping by page ranges (to allow 00088 // working tests, even if the db gets prepopulated by a base 00089 // class), we have to assert, that the page id are consecutively 00090 // increasing 00091 $this->assertEquals( 00092 array( $this->pageId2, $this->pageId3, $this->pageId4 ), 00093 array( $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ), 00094 "Page ids increasing without holes" ); 00095 } 00096 00097 function testFullTextPlain() { 00098 // Preparing the dump 00099 $fname = $this->getNewTempFile(); 00100 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00101 $dumper->startId = $this->pageId1; 00102 $dumper->endId = $this->pageId4 + 1; 00103 $dumper->reporting = false; 00104 $dumper->setDb( $this->db ); 00105 00106 // Performing the dump 00107 $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT ); 00108 00109 // Checking the dumped data 00110 $this->assertDumpStart( $fname ); 00111 00112 // Page 1 00113 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00114 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00115 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87", 00116 "BackupDumperTestP1Text1" ); 00117 $this->assertPageEnd(); 00118 00119 // Page 2 00120 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00121 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1", 00122 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2", 00123 "BackupDumperTestP2Text1" ); 00124 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2", 00125 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", 00126 "BackupDumperTestP2Text2", $this->revId2_1 ); 00127 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3", 00128 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", 00129 "BackupDumperTestP2Text3", $this->revId2_2 ); 00130 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00131 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", 00132 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 ); 00133 $this->assertPageEnd(); 00134 00135 // Page 3 00136 // -> Page is marked deleted. Hence not visible 00137 00138 // Page 4 00139 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00140 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00141 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe", 00142 "Talk about BackupDumperTestP1 Text1" ); 00143 $this->assertPageEnd(); 00144 00145 $this->assertDumpEnd(); 00146 } 00147 00148 function testFullStubPlain() { 00149 // Preparing the dump 00150 $fname = $this->getNewTempFile(); 00151 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00152 $dumper->startId = $this->pageId1; 00153 $dumper->endId = $this->pageId4 + 1; 00154 $dumper->reporting = false; 00155 $dumper->setDb( $this->db ); 00156 00157 // Performing the dump 00158 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB ); 00159 00160 // Checking the dumped data 00161 $this->assertDumpStart( $fname ); 00162 00163 // Page 1 00164 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00165 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00166 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00167 $this->assertPageEnd(); 00168 00169 // Page 2 00170 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00171 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1", 00172 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" ); 00173 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2", 00174 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 ); 00175 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3", 00176 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 ); 00177 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00178 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00179 $this->assertPageEnd(); 00180 00181 // Page 3 00182 // -> Page is marked deleted. Hence not visible 00183 00184 // Page 4 00185 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00186 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00187 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00188 $this->assertPageEnd(); 00189 00190 $this->assertDumpEnd(); 00191 } 00192 00193 function testCurrentStubPlain() { 00194 // Preparing the dump 00195 $fname = $this->getNewTempFile(); 00196 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00197 $dumper->startId = $this->pageId1; 00198 $dumper->endId = $this->pageId4 + 1; 00199 $dumper->reporting = false; 00200 $dumper->setDb( $this->db ); 00201 00202 // Performing the dump 00203 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB ); 00204 00205 // Checking the dumped data 00206 $this->assertDumpStart( $fname ); 00207 00208 // Page 1 00209 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00210 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00211 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00212 $this->assertPageEnd(); 00213 00214 // Page 2 00215 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00216 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00217 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00218 $this->assertPageEnd(); 00219 00220 // Page 3 00221 // -> Page is marked deleted. Hence not visible 00222 00223 // Page 4 00224 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00225 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00226 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00227 $this->assertPageEnd(); 00228 00229 $this->assertDumpEnd(); 00230 } 00231 00232 function testCurrentStubGzip() { 00233 $this->checkHasGzip(); 00234 00235 // Preparing the dump 00236 $fname = $this->getNewTempFile(); 00237 $dumper = new BackupDumper( array( "--output=gzip:" . $fname ) ); 00238 $dumper->startId = $this->pageId1; 00239 $dumper->endId = $this->pageId4 + 1; 00240 $dumper->reporting = false; 00241 $dumper->setDb( $this->db ); 00242 00243 // Performing the dump 00244 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB ); 00245 00246 // Checking the dumped data 00247 $this->gunzip( $fname ); 00248 $this->assertDumpStart( $fname ); 00249 00250 // Page 1 00251 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00252 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00253 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00254 $this->assertPageEnd(); 00255 00256 // Page 2 00257 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00258 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00259 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00260 $this->assertPageEnd(); 00261 00262 // Page 3 00263 // -> Page is marked deleted. Hence not visible 00264 00265 // Page 4 00266 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00267 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00268 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00269 $this->assertPageEnd(); 00270 00271 $this->assertDumpEnd(); 00272 } 00273 00274 00275 function testXmlDumpsBackupUseCase() { 00276 // xmldumps-backup typically performs a single dump that that writes 00277 // out three files 00278 // * gzipped stubs of everything (meta-history) 00279 // * gzipped stubs of latest revisions of all pages (meta-current) 00280 // * gzipped stubs of latest revisions of all pages of namespage 0 00281 // (articles) 00282 // 00283 // We reproduce such a setup with our mini fixture, although we omit 00284 // chunks, and all the other gimmicks of xmldumps-backup. 00285 // 00286 $this->checkHasGzip(); 00287 00288 $fnameMetaHistory = $this->getNewTempFile(); 00289 $fnameMetaCurrent = $this->getNewTempFile(); 00290 $fnameArticles = $this->getNewTempFile(); 00291 00292 $dumper = new BackupDumper( array( "--output=gzip:" . $fnameMetaHistory, 00293 "--output=gzip:" . $fnameMetaCurrent, "--filter=latest", 00294 "--output=gzip:" . $fnameArticles, "--filter=latest", 00295 "--filter=notalk", "--filter=namespace:!NS_USER", 00296 "--reporting=1000" ) ); 00297 $dumper->startId = $this->pageId1; 00298 $dumper->endId = $this->pageId4 + 1; 00299 $dumper->setDb( $this->db ); 00300 00301 // xmldumps-backup uses reporting. We will not check the exact reported 00302 // message, as they are dependent on the processing power of the used 00303 // computer. We only check that reporting does not crash the dumping 00304 // and that something is reported 00305 $dumper->stderr = fopen( 'php://output', 'a' ); 00306 if ( $dumper->stderr === false ) { 00307 $this->fail( "Could not open stream for stderr" ); 00308 } 00309 00310 // Performing the dump 00311 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB ); 00312 00313 $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" ); 00314 00315 // Checking meta-history ------------------------------------------------- 00316 00317 $this->gunzip( $fnameMetaHistory ); 00318 $this->assertDumpStart( $fnameMetaHistory ); 00319 00320 // Page 1 00321 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00322 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00323 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00324 $this->assertPageEnd(); 00325 00326 // Page 2 00327 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00328 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1", 00329 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" ); 00330 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2", 00331 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 ); 00332 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3", 00333 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 ); 00334 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00335 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00336 $this->assertPageEnd(); 00337 00338 // Page 3 00339 // -> Page is marked deleted. Hence not visible 00340 00341 // Page 4 00342 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00343 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00344 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00345 $this->assertPageEnd(); 00346 00347 $this->assertDumpEnd(); 00348 00349 // Checking meta-current ------------------------------------------------- 00350 00351 $this->gunzip( $fnameMetaCurrent ); 00352 $this->assertDumpStart( $fnameMetaCurrent ); 00353 00354 // Page 1 00355 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00356 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00357 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00358 $this->assertPageEnd(); 00359 00360 // Page 2 00361 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00362 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00363 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00364 $this->assertPageEnd(); 00365 00366 // Page 3 00367 // -> Page is marked deleted. Hence not visible 00368 00369 // Page 4 00370 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00371 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00372 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00373 $this->assertPageEnd(); 00374 00375 $this->assertDumpEnd(); 00376 00377 // Checking articles ------------------------------------------------- 00378 00379 $this->gunzip( $fnameArticles ); 00380 $this->assertDumpStart( $fnameArticles ); 00381 00382 // Page 1 00383 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00384 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00385 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00386 $this->assertPageEnd(); 00387 00388 // Page 2 00389 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00390 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00391 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00392 $this->assertPageEnd(); 00393 00394 // Page 3 00395 // -> Page is marked deleted. Hence not visible 00396 00397 // Page 4 00398 // -> Page is not in $this->namespace. Hence not visible 00399 00400 $this->assertDumpEnd(); 00401 00402 $this->expectETAOutput(); 00403 } 00404 }