MediaWiki  1.32.5
backupPrefetchTest.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
15 
21  private $dump = null;
22 
23  protected function tearDown() {
24  if ( $this->dump !== null ) {
25  $this->dump->close();
26  }
27 
28  // T39458, parent teardown need to be done after closing the
29  // dump or it might cause some permissions errors.
30  parent::tearDown();
31  }
32 
40  private function assertPrefetchEquals( $expected, $page, $revision ) {
41  $this->assertEquals( $expected, $this->dump->prefetch( $page, $revision ),
42  "Prefetch of page $page revision $revision" );
43  }
44 
45  function testSequential() {
46  $fname = $this->setUpPrefetch();
47  $this->dump = new BaseDump( $fname );
48 
49  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
50  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
51  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
52  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
53  }
54 
56  $fname = $this->setUpPrefetch();
57  $this->dump = new BaseDump( $fname );
58 
59  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
60  $this->assertPrefetchEquals( null, 2, 3 );
61  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
62  }
63 
65  $fname = $this->setUpPrefetch();
66  $this->dump = new BaseDump( $fname );
67 
68  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
69  $this->assertPrefetchEquals( null, 2, 40 );
70  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
71  }
72 
74  $fname = $this->setUpPrefetch();
75  $this->dump = new BaseDump( $fname );
76 
77  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
78  $this->assertPrefetchEquals( null, 3, 40 );
79  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
80  }
81 
82  function testPageMissAtEnd() {
83  $fname = $this->setUpPrefetch();
84  $this->dump = new BaseDump( $fname );
85 
86  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
87  $this->assertPrefetchEquals( null, 6, 40 );
88  }
89 
90  function testRevisionMissAtEnd() {
91  $fname = $this->setUpPrefetch();
92  $this->dump = new BaseDump( $fname );
93 
94  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
95  $this->assertPrefetchEquals( null, 4, 40 );
96  }
97 
99  $fname = $this->setUpPrefetch();
100  $this->dump = new BaseDump( $fname );
101 
102  $this->assertPrefetchEquals( null, 0, 2 );
103  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
104  }
105 
107  $fname = $this->setUpPrefetch();
108  $this->dump = new BaseDump( $fname );
109 
110  $this->assertPrefetchEquals( null, 1, -2 );
111  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
112  }
113 
115  $fname1 = $this->setUpPrefetch( [ 1 ] );
116  $fname2 = $this->setUpPrefetch( [ 2, 4 ] );
117  $this->dump = new BaseDump( $fname1 . ";" . $fname2 );
118 
119  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
120  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
121  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
122  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
123  }
124 
126  $fname1 = $this->setUpPrefetch( [ 1 ] );
127  $fname2 = $this->setUpPrefetch( [ 2 ] );
128  $fname3 = $this->setUpPrefetch( [ 4 ] );
129  $this->dump = new BaseDump( $fname1 . ";" . $fname2 . ";" . $fname3 );
130 
131  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
132  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
133  }
134 
136  $fname1 = $this->setUpPrefetch( [ 1 ] );
137  $fname2 = $this->setUpPrefetch( [ 2 ] );
138  $this->dump = new BaseDump( $fname1 . ";" . $fname2 );
139 
140  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
141  }
142 
152  private function setUpPrefetch( $requested_pages = [ 1, 2, 4 ] ) {
153  // The file name, where we store the prepared prefetch file
154  $fname = $this->getNewTempFile();
155 
156  // The header of every prefetch file
157  // phpcs:ignore Generic.Files.LineLength
158  $header = '<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.7/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.7/ http://www.mediawiki.org/xml/export-0.7.xsd" version="0.7" xml:lang="en">
159  <siteinfo>
160  <sitename>wikisvn</sitename>
161  <base>http://localhost/wiki-svn/index.php/Main_Page</base>
162  <generator>MediaWiki 1.21alpha</generator>
163  <case>first-letter</case>
164  <namespaces>
165  <namespace key="-2" case="first-letter">Media</namespace>
166  <namespace key="-1" case="first-letter">Special</namespace>
167  <namespace key="0" case="first-letter" />
168  <namespace key="1" case="first-letter">Talk</namespace>
169  <namespace key="2" case="first-letter">User</namespace>
170  <namespace key="3" case="first-letter">User talk</namespace>
171  <namespace key="4" case="first-letter">Wikisvn</namespace>
172  <namespace key="5" case="first-letter">Wikisvn talk</namespace>
173  <namespace key="6" case="first-letter">File</namespace>
174  <namespace key="7" case="first-letter">File talk</namespace>
175  <namespace key="8" case="first-letter">MediaWiki</namespace>
176  <namespace key="9" case="first-letter">MediaWiki talk</namespace>
177  <namespace key="10" case="first-letter">Template</namespace>
178  <namespace key="11" case="first-letter">Template talk</namespace>
179  <namespace key="12" case="first-letter">Help</namespace>
180  <namespace key="13" case="first-letter">Help talk</namespace>
181  <namespace key="14" case="first-letter">Category</namespace>
182  <namespace key="15" case="first-letter">Category talk</namespace>
183  </namespaces>
184  </siteinfo>
185 ';
186 
187  // An array holding the pages that are available for prefetch
188  $available_pages = [];
189 
190  // Simple plain page
191  $available_pages[1] = ' <page>
192  <title>BackupDumperTestP1</title>
193  <ns>0</ns>
194  <id>1</id>
195  <revision>
196  <id>1</id>
197  <timestamp>2012-04-01T16:46:05Z</timestamp>
198  <contributor>
199  <ip>127.0.0.1</ip>
200  </contributor>
201  <comment>BackupDumperTestP1Summary1</comment>
202  <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
203  <text xml:space="preserve">BackupDumperTestP1Text1</text>
204  <model name="wikitext">1</model>
205  <format mime="text/x-wiki">1</format>
206  </revision>
207  </page>
208 ';
209  // Page with more than one revisions. Hole in rev ids.
210  $available_pages[2] = ' <page>
211  <title>BackupDumperTestP2</title>
212  <ns>0</ns>
213  <id>2</id>
214  <revision>
215  <id>2</id>
216  <timestamp>2012-04-01T16:46:05Z</timestamp>
217  <contributor>
218  <ip>127.0.0.1</ip>
219  </contributor>
220  <comment>BackupDumperTestP2Summary1</comment>
221  <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
222  <text xml:space="preserve">BackupDumperTestP2Text1</text>
223  <model name="wikitext">1</model>
224  <format mime="text/x-wiki">1</format>
225  </revision>
226  <revision>
227  <id>5</id>
228  <parentid>2</parentid>
229  <timestamp>2012-04-01T16:46:05Z</timestamp>
230  <contributor>
231  <ip>127.0.0.1</ip>
232  </contributor>
233  <comment>BackupDumperTestP2Summary4 extra</comment>
234  <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
235  <text xml:space="preserve">BackupDumperTestP2Text4 some additional Text</text>
236  <model name="wikitext">1</model>
237  <format mime="text/x-wiki">1</format>
238  </revision>
239  </page>
240 ';
241  // Page with id higher than previous id + 1
242  $available_pages[4] = ' <page>
243  <title>Talk:BackupDumperTestP1</title>
244  <ns>1</ns>
245  <id>4</id>
246  <revision>
247  <id>8</id>
248  <timestamp>2012-04-01T16:46:05Z</timestamp>
249  <contributor>
250  <ip>127.0.0.1</ip>
251  </contributor>
252  <comment>Talk BackupDumperTestP1 Summary1</comment>
253  <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
254  <model name="wikitext">1</model>
255  <format mime="text/x-wiki">1</format>
256  <text xml:space="preserve">Talk about BackupDumperTestP1 Text1</text>
257  </revision>
258  </page>
259 ';
260 
261  // The common ending for all files
262  $tail = '</mediawiki>
263 ';
264 
265  // Putting together the content of the prefetch files
266  $content = $header;
267  foreach ( $requested_pages as $i ) {
268  $this->assertTrue( array_key_exists( $i, $available_pages ),
269  "Check for availability of requested page " . $i );
270  $content .= $available_pages[$i];
271  }
272  $content .= $tail;
273 
274  $this->assertEquals( strlen( $content ), file_put_contents(
275  $fname, $content ), "Length of prepared prefetch" );
276 
277  return $fname;
278  }
279 }
BaseDump
Readahead helper for making large MediaWiki data dumps; reads in a previous XML dump to sequentially ...
Definition: BaseDump.php:42
MediaWiki\Tests\Maintenance\BaseDumpTest\testPageMissAtEnd
testPageMissAtEnd()
Definition: backupPrefetchTest.php:82
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizePageMiss
testSynchronizePageMiss()
Definition: backupPrefetchTest.php:73
MediaWiki\Tests\Maintenance\BaseDumpTest\assertPrefetchEquals
assertPrefetchEquals( $expected, $page, $revision)
asserts that a prefetch yields an expected string
Definition: backupPrefetchTest.php:40
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Tests\Maintenance\BaseDumpTest\$dump
BaseDump $dump
The BaseDump instance used within a test.
Definition: backupPrefetchTest.php:21
MediaWiki\Tests\Maintenance
Definition: backup_LogTest.php:3
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:471
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeSkipAcrossFile
testSynchronizeSkipAcrossFile()
Definition: backupPrefetchTest.php:125
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:121
MediaWiki\Tests\Maintenance\BaseDumpTest\testRevisionMissAtEnd
testRevisionMissAtEnd()
Definition: backupPrefetchTest.php:90
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizePageMissAtStart
testSynchronizePageMissAtStart()
Definition: backupPrefetchTest.php:98
$header
$header
Definition: updateCredits.php:35
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeMissInWholeFirstFile
testSynchronizeMissInWholeFirstFile()
Definition: backupPrefetchTest.php:135
MediaWiki\Tests\Maintenance\BaseDumpTest
Tests for BaseDump.
Definition: backupPrefetchTest.php:14
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$content
$content
Definition: pageupdater.txt:72
MediaWiki\Tests\Maintenance\BaseDumpTest\testSequentialAcrossFiles
testSequentialAcrossFiles()
Definition: backupPrefetchTest.php:114
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeRevisionMissToRevision
testSynchronizeRevisionMissToRevision()
Definition: backupPrefetchTest.php:55
MediaWiki\Tests\Maintenance\BaseDumpTest\testSequential
testSequential()
Definition: backupPrefetchTest.php:45
MediaWiki\Tests\Maintenance\BaseDumpTest\setUpPrefetch
setUpPrefetch( $requested_pages=[1, 2, 4])
Constructs a temporary file that can be used for prefetching.
Definition: backupPrefetchTest.php:152
MediaWiki\Tests\Maintenance\BaseDumpTest\tearDown
tearDown()
Definition: backupPrefetchTest.php:23
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeRevisionMissToPage
testSynchronizeRevisionMissToPage()
Definition: backupPrefetchTest.php:64
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeRevisionMissAtStart
testSynchronizeRevisionMissAtStart()
Definition: backupPrefetchTest.php:106