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