MediaWiki
REL1_23
|
00001 <?php 00009 class BackupDumperPageTest extends DumpTestCase { 00010 00011 // We'll add several pages, revision and texts. The following variables hold the 00012 // corresponding ids. 00013 private $pageId1, $pageId2, $pageId3, $pageId4, $pageId5; 00014 private $pageTitle1, $pageTitle2, $pageTitle3, $pageTitle4, $pageTitle5; 00015 private $revId1_1, $textId1_1; 00016 private $revId2_1, $textId2_1, $revId2_2, $textId2_2; 00017 private $revId2_3, $textId2_3, $revId2_4, $textId2_4; 00018 private $revId3_1, $textId3_1, $revId3_2, $textId3_2; 00019 private $revId4_1, $textId4_1; 00020 private $namespace, $talk_namespace; 00021 00022 function addDBData() { 00023 // be sure, titles created here using english namespace names 00024 $this->setMwGlobals( array( 00025 'wgLanguageCode' => 'en', 00026 'wgContLang' => Language::factory( 'en' ), 00027 ) ); 00028 00029 $this->tablesUsed[] = 'page'; 00030 $this->tablesUsed[] = 'revision'; 00031 $this->tablesUsed[] = 'text'; 00032 00033 try { 00034 $this->namespace = $this->getDefaultWikitextNS(); 00035 $this->talk_namespace = NS_TALK; 00036 00037 if ( $this->namespace === $this->talk_namespace ) { 00038 // @todo work around this. 00039 throw new MWException( "The default wikitext namespace is the talk namespace. " 00040 . " We can't currently deal with that." ); 00041 } 00042 00043 $this->pageTitle1 = Title::newFromText( 'BackupDumperTestP1', $this->namespace ); 00044 $page = WikiPage::factory( $this->pageTitle1 ); 00045 list( $this->revId1_1, $this->textId1_1 ) = $this->addRevision( $page, 00046 "BackupDumperTestP1Text1", "BackupDumperTestP1Summary1" ); 00047 $this->pageId1 = $page->getId(); 00048 00049 $this->pageTitle2 = Title::newFromText( 'BackupDumperTestP2', $this->namespace ); 00050 $page = WikiPage::factory( $this->pageTitle2 ); 00051 list( $this->revId2_1, $this->textId2_1 ) = $this->addRevision( $page, 00052 "BackupDumperTestP2Text1", "BackupDumperTestP2Summary1" ); 00053 list( $this->revId2_2, $this->textId2_2 ) = $this->addRevision( $page, 00054 "BackupDumperTestP2Text2", "BackupDumperTestP2Summary2" ); 00055 list( $this->revId2_3, $this->textId2_3 ) = $this->addRevision( $page, 00056 "BackupDumperTestP2Text3", "BackupDumperTestP2Summary3" ); 00057 list( $this->revId2_4, $this->textId2_4 ) = $this->addRevision( $page, 00058 "BackupDumperTestP2Text4 some additional Text ", 00059 "BackupDumperTestP2Summary4 extra " ); 00060 $this->pageId2 = $page->getId(); 00061 00062 $this->pageTitle3 = Title::newFromText( 'BackupDumperTestP3', $this->namespace ); 00063 $page = WikiPage::factory( $this->pageTitle3 ); 00064 list( $this->revId3_1, $this->textId3_1 ) = $this->addRevision( $page, 00065 "BackupDumperTestP3Text1", "BackupDumperTestP2Summary1" ); 00066 list( $this->revId3_2, $this->textId3_2 ) = $this->addRevision( $page, 00067 "BackupDumperTestP3Text2", "BackupDumperTestP2Summary2" ); 00068 $this->pageId3 = $page->getId(); 00069 $page->doDeleteArticle( "Testing ;)" ); 00070 00071 $this->pageTitle4 = Title::newFromText( 'BackupDumperTestP1', $this->talk_namespace ); 00072 $page = WikiPage::factory( $this->pageTitle4 ); 00073 list( $this->revId4_1, $this->textId4_1 ) = $this->addRevision( $page, 00074 "Talk about BackupDumperTestP1 Text1", 00075 "Talk BackupDumperTestP1 Summary1" ); 00076 $this->pageId4 = $page->getId(); 00077 } catch ( Exception $e ) { 00078 // We'd love to pass $e directly. However, ... see 00079 // documentation of exceptionFromAddDBData in 00080 // DumpTestCase 00081 $this->exceptionFromAddDBData = $e; 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 function testFullTextPlain() { 00099 // Preparing the dump 00100 $fname = $this->getNewTempFile(); 00101 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00102 $dumper->startId = $this->pageId1; 00103 $dumper->endId = $this->pageId4 + 1; 00104 $dumper->reporting = false; 00105 $dumper->setDb( $this->db ); 00106 00107 // Performing the dump 00108 $dumper->dump( WikiExporter::FULL, WikiExporter::TEXT ); 00109 00110 // Checking the dumped data 00111 $this->assertDumpStart( $fname ); 00112 00113 // Page 1 00114 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00115 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00116 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87", 00117 "BackupDumperTestP1Text1" ); 00118 $this->assertPageEnd(); 00119 00120 // Page 2 00121 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00122 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1", 00123 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2", 00124 "BackupDumperTestP2Text1" ); 00125 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2", 00126 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", 00127 "BackupDumperTestP2Text2", $this->revId2_1 ); 00128 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3", 00129 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", 00130 "BackupDumperTestP2Text3", $this->revId2_2 ); 00131 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00132 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", 00133 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 ); 00134 $this->assertPageEnd(); 00135 00136 // Page 3 00137 // -> Page is marked deleted. Hence not visible 00138 00139 // Page 4 00140 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00141 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00142 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe", 00143 "Talk about BackupDumperTestP1 Text1" ); 00144 $this->assertPageEnd(); 00145 00146 $this->assertDumpEnd(); 00147 } 00148 00149 function testFullStubPlain() { 00150 // Preparing the dump 00151 $fname = $this->getNewTempFile(); 00152 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00153 $dumper->startId = $this->pageId1; 00154 $dumper->endId = $this->pageId4 + 1; 00155 $dumper->reporting = false; 00156 $dumper->setDb( $this->db ); 00157 00158 // Performing the dump 00159 $dumper->dump( WikiExporter::FULL, WikiExporter::STUB ); 00160 00161 // Checking the dumped data 00162 $this->assertDumpStart( $fname ); 00163 00164 // Page 1 00165 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00166 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00167 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00168 $this->assertPageEnd(); 00169 00170 // Page 2 00171 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00172 $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1", 00173 $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" ); 00174 $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2", 00175 $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 ); 00176 $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3", 00177 $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 ); 00178 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00179 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00180 $this->assertPageEnd(); 00181 00182 // Page 3 00183 // -> Page is marked deleted. Hence not visible 00184 00185 // Page 4 00186 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00187 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00188 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00189 $this->assertPageEnd(); 00190 00191 $this->assertDumpEnd(); 00192 } 00193 00194 function testCurrentStubPlain() { 00195 // Preparing the dump 00196 $fname = $this->getNewTempFile(); 00197 $dumper = new BackupDumper( array( "--output=file:" . $fname ) ); 00198 $dumper->startId = $this->pageId1; 00199 $dumper->endId = $this->pageId4 + 1; 00200 $dumper->reporting = false; 00201 $dumper->setDb( $this->db ); 00202 00203 // Performing the dump 00204 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB ); 00205 00206 // Checking the dumped data 00207 $this->assertDumpStart( $fname ); 00208 00209 // Page 1 00210 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00211 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00212 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00213 $this->assertPageEnd(); 00214 00215 // Page 2 00216 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00217 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00218 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00219 $this->assertPageEnd(); 00220 00221 // Page 3 00222 // -> Page is marked deleted. Hence not visible 00223 00224 // Page 4 00225 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00226 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00227 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00228 $this->assertPageEnd(); 00229 00230 $this->assertDumpEnd(); 00231 } 00232 00233 function testCurrentStubGzip() { 00234 $this->checkHasGzip(); 00235 00236 // Preparing the dump 00237 $fname = $this->getNewTempFile(); 00238 $dumper = new BackupDumper( array( "--output=gzip:" . $fname ) ); 00239 $dumper->startId = $this->pageId1; 00240 $dumper->endId = $this->pageId4 + 1; 00241 $dumper->reporting = false; 00242 $dumper->setDb( $this->db ); 00243 00244 // Performing the dump 00245 $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB ); 00246 00247 // Checking the dumped data 00248 $this->gunzip( $fname ); 00249 $this->assertDumpStart( $fname ); 00250 00251 // Page 1 00252 $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() ); 00253 $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1", 00254 $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" ); 00255 $this->assertPageEnd(); 00256 00257 // Page 2 00258 $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() ); 00259 $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra", 00260 $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 ); 00261 $this->assertPageEnd(); 00262 00263 // Page 3 00264 // -> Page is marked deleted. Hence not visible 00265 00266 // Page 4 00267 $this->assertPageStart( $this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText() ); 00268 $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1", 00269 $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" ); 00270 $this->assertPageEnd(); 00271 00272 $this->assertDumpEnd(); 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 }