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