MediaWiki  REL1_24
backup_PageTest.php
Go to the documentation of this file.
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(
00141             $this->pageId4,
00142             $this->talk_namespace,
00143             $this->pageTitle4->getPrefixedText()
00144         );
00145         $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
00146             $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe",
00147             "Talk about BackupDumperTestP1 Text1" );
00148         $this->assertPageEnd();
00149 
00150         $this->assertDumpEnd();
00151     }
00152 
00153     function testFullStubPlain() {
00154         // Preparing the dump
00155         $fname = $this->getNewTempFile();
00156         $dumper = new BackupDumper( array( "--output=file:" . $fname ) );
00157         $dumper->startId = $this->pageId1;
00158         $dumper->endId = $this->pageId4 + 1;
00159         $dumper->reporting = false;
00160         $dumper->setDb( $this->db );
00161 
00162         // Performing the dump
00163         $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
00164 
00165         // Checking the dumped data
00166         $this->assertDumpStart( $fname );
00167 
00168         // Page 1
00169         $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
00170         $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
00171             $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
00172         $this->assertPageEnd();
00173 
00174         // Page 2
00175         $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
00176         $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
00177             $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
00178         $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
00179             $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 );
00180         $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
00181             $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 );
00182         $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
00183             $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
00184         $this->assertPageEnd();
00185 
00186         // Page 3
00187         // -> Page is marked deleted. Hence not visible
00188 
00189         // Page 4
00190         $this->assertPageStart(
00191             $this->pageId4,
00192             $this->talk_namespace,
00193             $this->pageTitle4->getPrefixedText()
00194         );
00195         $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
00196             $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
00197         $this->assertPageEnd();
00198 
00199         $this->assertDumpEnd();
00200     }
00201 
00202     function testCurrentStubPlain() {
00203         // Preparing the dump
00204         $fname = $this->getNewTempFile();
00205         $dumper = new BackupDumper( array( "--output=file:" . $fname ) );
00206         $dumper->startId = $this->pageId1;
00207         $dumper->endId = $this->pageId4 + 1;
00208         $dumper->reporting = false;
00209         $dumper->setDb( $this->db );
00210 
00211         // Performing the dump
00212         $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
00213 
00214         // Checking the dumped data
00215         $this->assertDumpStart( $fname );
00216 
00217         // Page 1
00218         $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
00219         $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
00220             $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
00221         $this->assertPageEnd();
00222 
00223         // Page 2
00224         $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
00225         $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
00226             $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
00227         $this->assertPageEnd();
00228 
00229         // Page 3
00230         // -> Page is marked deleted. Hence not visible
00231 
00232         // Page 4
00233         $this->assertPageStart(
00234             $this->pageId4,
00235             $this->talk_namespace,
00236             $this->pageTitle4->getPrefixedText()
00237         );
00238         $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
00239             $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
00240         $this->assertPageEnd();
00241 
00242         $this->assertDumpEnd();
00243     }
00244 
00245     function testCurrentStubGzip() {
00246         $this->checkHasGzip();
00247 
00248         // Preparing the dump
00249         $fname = $this->getNewTempFile();
00250         $dumper = new BackupDumper( array( "--output=gzip:" . $fname ) );
00251         $dumper->startId = $this->pageId1;
00252         $dumper->endId = $this->pageId4 + 1;
00253         $dumper->reporting = false;
00254         $dumper->setDb( $this->db );
00255 
00256         // Performing the dump
00257         $dumper->dump( WikiExporter::CURRENT, WikiExporter::STUB );
00258 
00259         // Checking the dumped data
00260         $this->gunzip( $fname );
00261         $this->assertDumpStart( $fname );
00262 
00263         // Page 1
00264         $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
00265         $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
00266             $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
00267         $this->assertPageEnd();
00268 
00269         // Page 2
00270         $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
00271         $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
00272             $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
00273         $this->assertPageEnd();
00274 
00275         // Page 3
00276         // -> Page is marked deleted. Hence not visible
00277 
00278         // Page 4
00279         $this->assertPageStart(
00280             $this->pageId4,
00281             $this->talk_namespace,
00282             $this->pageTitle4->getPrefixedText()
00283         );
00284         $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
00285             $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
00286         $this->assertPageEnd();
00287 
00288         $this->assertDumpEnd();
00289     }
00290 
00291     function testXmlDumpsBackupUseCase() {
00292         // xmldumps-backup typically performs a single dump that that writes
00293         // out three files
00294         // * gzipped stubs of everything (meta-history)
00295         // * gzipped stubs of latest revisions of all pages (meta-current)
00296         // * gzipped stubs of latest revisions of all pages of namespage 0
00297         //   (articles)
00298         //
00299         // We reproduce such a setup with our mini fixture, although we omit
00300         // chunks, and all the other gimmicks of xmldumps-backup.
00301         //
00302         $this->checkHasGzip();
00303 
00304         $fnameMetaHistory = $this->getNewTempFile();
00305         $fnameMetaCurrent = $this->getNewTempFile();
00306         $fnameArticles = $this->getNewTempFile();
00307 
00308         $dumper = new BackupDumper( array( "--output=gzip:" . $fnameMetaHistory,
00309             "--output=gzip:" . $fnameMetaCurrent, "--filter=latest",
00310             "--output=gzip:" . $fnameArticles, "--filter=latest",
00311             "--filter=notalk", "--filter=namespace:!NS_USER",
00312             "--reporting=1000" ) );
00313         $dumper->startId = $this->pageId1;
00314         $dumper->endId = $this->pageId4 + 1;
00315         $dumper->setDb( $this->db );
00316 
00317         // xmldumps-backup uses reporting. We will not check the exact reported
00318         // message, as they are dependent on the processing power of the used
00319         // computer. We only check that reporting does not crash the dumping
00320         // and that something is reported
00321         $dumper->stderr = fopen( 'php://output', 'a' );
00322         if ( $dumper->stderr === false ) {
00323             $this->fail( "Could not open stream for stderr" );
00324         }
00325 
00326         // Performing the dump
00327         $dumper->dump( WikiExporter::FULL, WikiExporter::STUB );
00328 
00329         $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" );
00330 
00331         // Checking meta-history -------------------------------------------------
00332 
00333         $this->gunzip( $fnameMetaHistory );
00334         $this->assertDumpStart( $fnameMetaHistory );
00335 
00336         // Page 1
00337         $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
00338         $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
00339             $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
00340         $this->assertPageEnd();
00341 
00342         // Page 2
00343         $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
00344         $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
00345             $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2" );
00346         $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
00347             $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1 );
00348         $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
00349             $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2 );
00350         $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
00351             $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
00352         $this->assertPageEnd();
00353 
00354         // Page 3
00355         // -> Page is marked deleted. Hence not visible
00356 
00357         // Page 4
00358         $this->assertPageStart(
00359             $this->pageId4,
00360             $this->talk_namespace,
00361             $this->pageTitle4->getPrefixedText()
00362         );
00363         $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
00364             $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
00365         $this->assertPageEnd();
00366 
00367         $this->assertDumpEnd();
00368 
00369         // Checking meta-current -------------------------------------------------
00370 
00371         $this->gunzip( $fnameMetaCurrent );
00372         $this->assertDumpStart( $fnameMetaCurrent );
00373 
00374         // Page 1
00375         $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
00376         $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
00377             $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
00378         $this->assertPageEnd();
00379 
00380         // Page 2
00381         $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
00382         $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
00383             $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
00384         $this->assertPageEnd();
00385 
00386         // Page 3
00387         // -> Page is marked deleted. Hence not visible
00388 
00389         // Page 4
00390         $this->assertPageStart(
00391             $this->pageId4,
00392             $this->talk_namespace,
00393             $this->pageTitle4->getPrefixedText()
00394         );
00395         $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
00396             $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe" );
00397         $this->assertPageEnd();
00398 
00399         $this->assertDumpEnd();
00400 
00401         // Checking articles -------------------------------------------------
00402 
00403         $this->gunzip( $fnameArticles );
00404         $this->assertDumpStart( $fnameArticles );
00405 
00406         // Page 1
00407         $this->assertPageStart( $this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText() );
00408         $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
00409             $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87" );
00410         $this->assertPageEnd();
00411 
00412         // Page 2
00413         $this->assertPageStart( $this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText() );
00414         $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
00415             $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3 );
00416         $this->assertPageEnd();
00417 
00418         // Page 3
00419         // -> Page is marked deleted. Hence not visible
00420 
00421         // Page 4
00422         // -> Page is not in $this->namespace. Hence not visible
00423 
00424         $this->assertDumpEnd();
00425 
00426         $this->expectETAOutput();
00427     }
00428 }