dump !== null ) { $this->dump->close(); } // T39458, parent teardown need to be done after closing the // dump or it might cause some permissions errors. parent::tearDown(); } /** * asserts that a prefetch yields an expected string * * @param string|null $expected The exepcted result of the prefetch * @param int $page The page number to prefetch the text for * @param int $revision The revision number to prefetch the text for * @param string $slot The role name of the slot to fetch */ private function assertPrefetchEquals( $expected, $page, $revision, $slot = SlotRecord::MAIN ) { $this->assertEquals( $expected, $this->dump->prefetch( $page, $revision, $slot ), "Prefetch of page $page revision $revision" ); } public function testSequential() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 ); $this->assertPrefetchEquals( "BackupDumperTestP1Text1aux", 1, 1, 'aux' ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 ); $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 ); } public function testSynchronizeSlotMissToRevision() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( "BackupDumperTestP1Text1aux", 1, 1, 'aux' ); $this->assertPrefetchEquals( null, 1, 1, 'xyzzy' ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); $this->assertPrefetchEquals( null, 2, 2, 'aux' ); $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 ); } public function testSynchronizeRevisionMissToRevision() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); $this->assertPrefetchEquals( null, 2, 3 ); $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 ); } public function testSynchronizeRevisionMissToPage() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); $this->assertPrefetchEquals( null, 2, 40 ); $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 ); } public function testSynchronizePageMiss() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); $this->assertPrefetchEquals( null, 3, 40 ); $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 ); } public function testPageMissAtEnd() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); $this->assertPrefetchEquals( null, 6, 40 ); } public function testRevisionMissAtEnd() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); $this->assertPrefetchEquals( null, 4, 40 ); } public function testSynchronizePageMissAtStart() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( null, 0, 2 ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); } public function testSynchronizeRevisionMissAtStart() { $fname = $this->setUpPrefetch(); $this->dump = new BaseDump( $fname ); $this->assertPrefetchEquals( null, 1, -2 ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); } public function testSequentialAcrossFiles() { $fname1 = $this->setUpPrefetch( [ 1 ] ); $fname2 = $this->setUpPrefetch( [ 2, 4 ] ); $this->dump = new BaseDump( $fname1 . ";" . $fname2 ); $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 ); $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 ); } public function testSynchronizeSkipAcrossFile() { $fname1 = $this->setUpPrefetch( [ 1 ] ); $fname2 = $this->setUpPrefetch( [ 2 ] ); $fname3 = $this->setUpPrefetch( [ 4 ] ); $this->dump = new BaseDump( $fname1 . ";" . $fname2 . ";" . $fname3 ); $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 ); $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 ); } public function testSynchronizeMissInWholeFirstFile() { $fname1 = $this->setUpPrefetch( [ 1 ] ); $fname2 = $this->setUpPrefetch( [ 2 ] ); $this->dump = new BaseDump( $fname1 . ";" . $fname2 ); $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 ); } /** * Constructs a temporary file that can be used for prefetching * * The temporary file is removed by DumpBackup upon tearDown. * * @param array $requested_pages The indices of the page parts that should * go into the prefetch file. 1,2,4 are available. * @return string The file name of the created temporary file */ private function setUpPrefetch( $requested_pages = [ 1, 2, 4 ] ) { // The file name, where we store the prepared prefetch file $fname = $this->getNewTempFile(); // The header of every prefetch file // phpcs:ignore Generic.Files.LineLength $header = ' wikisvn http://localhost/wiki-svn/index.php/Main_Page MediaWiki 1.21alpha first-letter Media Special Talk User User talk Wikisvn Wikisvn talk File File talk MediaWiki MediaWiki talk Template Template talk Help Help talk Category Category talk '; // An array holding the pages that are available for prefetch $available_pages = []; // Simple plain page $available_pages[1] = ' BackupDumperTestP1 0 1 1 2012-04-01T16:46:05Z 127.0.0.1 BackupDumperTestP1Summary1 BackupDumperTestP1Text1 1 1 aux 2 wikitext text/x-wiki BackupDumperTestP1Text1aux 0bolhl6ol7i6x0e7yq91gxgaan39j87 '; // Page with more than one revisions. Hole in rev ids. $available_pages[2] = ' BackupDumperTestP2 0 2 2 2012-04-01T16:46:05Z 127.0.0.1 BackupDumperTestP2Summary1 jprywrymfhysqllua29tj3sc7z39dl2 BackupDumperTestP2Text1 1 1 5 2 2012-04-01T16:46:05Z 127.0.0.1 BackupDumperTestP2Summary4 extra 6o1ciaxa6pybnqprmungwofc4lv00wv BackupDumperTestP2Text4 some additional Text 1 1 '; // Page with id higher than previous id + 1 $available_pages[4] = ' Talk:BackupDumperTestP1 1 4 8 2012-04-01T16:46:05Z 127.0.0.1 Talk BackupDumperTestP1 Summary1 nktofwzd0tl192k3zfepmlzxoax1lpe 1 1 Talk about BackupDumperTestP1 Text1 '; // The common ending for all files $tail = ' '; // Putting together the content of the prefetch files $content = $header; foreach ( $requested_pages as $i ) { $this->assertTrue( array_key_exists( $i, $available_pages ), "Check for availability of requested page " . $i ); $content .= $available_pages[$i]; } $content .= $tail; $this->assertEquals( strlen( $content ), file_put_contents( $fname, $content ), "Length of prepared prefetch" ); return $fname; } }