MediaWiki  1.33.0
backupPrefetchTest.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
13 
19  private $dump = null;
20 
21  protected function tearDown() {
22  if ( $this->dump !== null ) {
23  $this->dump->close();
24  }
25 
26  // T39458, parent teardown need to be done after closing the
27  // dump or it might cause some permissions errors.
28  parent::tearDown();
29  }
30 
38  private function assertPrefetchEquals( $expected, $page, $revision ) {
39  $this->assertEquals( $expected, $this->dump->prefetch( $page, $revision ),
40  "Prefetch of page $page revision $revision" );
41  }
42 
43  function testSequential() {
44  $fname = $this->setUpPrefetch();
45  $this->dump = new BaseDump( $fname );
46 
47  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
48  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
49  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
50  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
51  }
52 
54  $fname = $this->setUpPrefetch();
55  $this->dump = new BaseDump( $fname );
56 
57  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
58  $this->assertPrefetchEquals( null, 2, 3 );
59  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
60  }
61 
63  $fname = $this->setUpPrefetch();
64  $this->dump = new BaseDump( $fname );
65 
66  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
67  $this->assertPrefetchEquals( null, 2, 40 );
68  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
69  }
70 
72  $fname = $this->setUpPrefetch();
73  $this->dump = new BaseDump( $fname );
74 
75  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
76  $this->assertPrefetchEquals( null, 3, 40 );
77  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
78  }
79 
80  function testPageMissAtEnd() {
81  $fname = $this->setUpPrefetch();
82  $this->dump = new BaseDump( $fname );
83 
84  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
85  $this->assertPrefetchEquals( null, 6, 40 );
86  }
87 
88  function testRevisionMissAtEnd() {
89  $fname = $this->setUpPrefetch();
90  $this->dump = new BaseDump( $fname );
91 
92  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
93  $this->assertPrefetchEquals( null, 4, 40 );
94  }
95 
97  $fname = $this->setUpPrefetch();
98  $this->dump = new BaseDump( $fname );
99 
100  $this->assertPrefetchEquals( null, 0, 2 );
101  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
102  }
103 
105  $fname = $this->setUpPrefetch();
106  $this->dump = new BaseDump( $fname );
107 
108  $this->assertPrefetchEquals( null, 1, -2 );
109  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
110  }
111 
113  $fname1 = $this->setUpPrefetch( [ 1 ] );
114  $fname2 = $this->setUpPrefetch( [ 2, 4 ] );
115  $this->dump = new BaseDump( $fname1 . ";" . $fname2 );
116 
117  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
118  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
119  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
120  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
121  }
122 
124  $fname1 = $this->setUpPrefetch( [ 1 ] );
125  $fname2 = $this->setUpPrefetch( [ 2 ] );
126  $fname3 = $this->setUpPrefetch( [ 4 ] );
127  $this->dump = new BaseDump( $fname1 . ";" . $fname2 . ";" . $fname3 );
128 
129  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
130  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
131  }
132 
134  $fname1 = $this->setUpPrefetch( [ 1 ] );
135  $fname2 = $this->setUpPrefetch( [ 2 ] );
136  $this->dump = new BaseDump( $fname1 . ";" . $fname2 );
137 
138  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
139  }
140 
150  private function setUpPrefetch( $requested_pages = [ 1, 2, 4 ] ) {
151  // The file name, where we store the prepared prefetch file
152  $fname = $this->getNewTempFile();
153 
154  // The header of every prefetch file
155  // phpcs:ignore Generic.Files.LineLength
156  $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">
157  <siteinfo>
158  <sitename>wikisvn</sitename>
159  <base>http://localhost/wiki-svn/index.php/Main_Page</base>
160  <generator>MediaWiki 1.21alpha</generator>
161  <case>first-letter</case>
162  <namespaces>
163  <namespace key="-2" case="first-letter">Media</namespace>
164  <namespace key="-1" case="first-letter">Special</namespace>
165  <namespace key="0" case="first-letter" />
166  <namespace key="1" case="first-letter">Talk</namespace>
167  <namespace key="2" case="first-letter">User</namespace>
168  <namespace key="3" case="first-letter">User talk</namespace>
169  <namespace key="4" case="first-letter">Wikisvn</namespace>
170  <namespace key="5" case="first-letter">Wikisvn talk</namespace>
171  <namespace key="6" case="first-letter">File</namespace>
172  <namespace key="7" case="first-letter">File talk</namespace>
173  <namespace key="8" case="first-letter">MediaWiki</namespace>
174  <namespace key="9" case="first-letter">MediaWiki talk</namespace>
175  <namespace key="10" case="first-letter">Template</namespace>
176  <namespace key="11" case="first-letter">Template talk</namespace>
177  <namespace key="12" case="first-letter">Help</namespace>
178  <namespace key="13" case="first-letter">Help talk</namespace>
179  <namespace key="14" case="first-letter">Category</namespace>
180  <namespace key="15" case="first-letter">Category talk</namespace>
181  </namespaces>
182  </siteinfo>
183 ';
184 
185  // An array holding the pages that are available for prefetch
186  $available_pages = [];
187 
188  // Simple plain page
189  $available_pages[1] = ' <page>
190  <title>BackupDumperTestP1</title>
191  <ns>0</ns>
192  <id>1</id>
193  <revision>
194  <id>1</id>
195  <timestamp>2012-04-01T16:46:05Z</timestamp>
196  <contributor>
197  <ip>127.0.0.1</ip>
198  </contributor>
199  <comment>BackupDumperTestP1Summary1</comment>
200  <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
201  <text xml:space="preserve">BackupDumperTestP1Text1</text>
202  <model name="wikitext">1</model>
203  <format mime="text/x-wiki">1</format>
204  </revision>
205  </page>
206 ';
207  // Page with more than one revisions. Hole in rev ids.
208  $available_pages[2] = ' <page>
209  <title>BackupDumperTestP2</title>
210  <ns>0</ns>
211  <id>2</id>
212  <revision>
213  <id>2</id>
214  <timestamp>2012-04-01T16:46:05Z</timestamp>
215  <contributor>
216  <ip>127.0.0.1</ip>
217  </contributor>
218  <comment>BackupDumperTestP2Summary1</comment>
219  <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
220  <text xml:space="preserve">BackupDumperTestP2Text1</text>
221  <model name="wikitext">1</model>
222  <format mime="text/x-wiki">1</format>
223  </revision>
224  <revision>
225  <id>5</id>
226  <parentid>2</parentid>
227  <timestamp>2012-04-01T16:46:05Z</timestamp>
228  <contributor>
229  <ip>127.0.0.1</ip>
230  </contributor>
231  <comment>BackupDumperTestP2Summary4 extra</comment>
232  <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
233  <text xml:space="preserve">BackupDumperTestP2Text4 some additional Text</text>
234  <model name="wikitext">1</model>
235  <format mime="text/x-wiki">1</format>
236  </revision>
237  </page>
238 ';
239  // Page with id higher than previous id + 1
240  $available_pages[4] = ' <page>
241  <title>Talk:BackupDumperTestP1</title>
242  <ns>1</ns>
243  <id>4</id>
244  <revision>
245  <id>8</id>
246  <timestamp>2012-04-01T16:46:05Z</timestamp>
247  <contributor>
248  <ip>127.0.0.1</ip>
249  </contributor>
250  <comment>Talk BackupDumperTestP1 Summary1</comment>
251  <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
252  <model name="wikitext">1</model>
253  <format mime="text/x-wiki">1</format>
254  <text xml:space="preserve">Talk about BackupDumperTestP1 Text1</text>
255  </revision>
256  </page>
257 ';
258 
259  // The common ending for all files
260  $tail = '</mediawiki>
261 ';
262 
263  // Putting together the content of the prefetch files
264  $content = $header;
265  foreach ( $requested_pages as $i ) {
266  $this->assertTrue( array_key_exists( $i, $available_pages ),
267  "Check for availability of requested page " . $i );
268  $content .= $available_pages[$i];
269  }
270  $content .= $tail;
271 
272  $this->assertEquals( strlen( $content ), file_put_contents(
273  $fname, $content ), "Length of prepared prefetch" );
274 
275  return $fname;
276  }
277 }
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:80
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizePageMiss
testSynchronizePageMiss()
Definition: backupPrefetchTest.php:71
MediaWiki\Tests\Maintenance\BaseDumpTest\assertPrefetchEquals
assertPrefetchEquals( $expected, $page, $revision)
asserts that a prefetch yields an expected string
Definition: backupPrefetchTest.php:38
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:19
MediaWiki\Tests\Maintenance
Definition: backup_LogTest.php:3
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:474
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
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:123
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:123
MediaWiki\Tests\Maintenance\BaseDumpTest\testRevisionMissAtEnd
testRevisionMissAtEnd()
Definition: backupPrefetchTest.php:88
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizePageMissAtStart
testSynchronizePageMissAtStart()
Definition: backupPrefetchTest.php:96
$header
$header
Definition: updateCredits.php:41
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeMissInWholeFirstFile
testSynchronizeMissInWholeFirstFile()
Definition: backupPrefetchTest.php:133
MediaWiki\Tests\Maintenance\BaseDumpTest
Dump BaseDump.
Definition: backupPrefetchTest.php:12
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:112
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeRevisionMissToRevision
testSynchronizeRevisionMissToRevision()
Definition: backupPrefetchTest.php:53
MediaWiki\Tests\Maintenance\BaseDumpTest\testSequential
testSequential()
Definition: backupPrefetchTest.php:43
MediaWiki\Tests\Maintenance\BaseDumpTest\setUpPrefetch
setUpPrefetch( $requested_pages=[1, 2, 4])
Constructs a temporary file that can be used for prefetching.
Definition: backupPrefetchTest.php:150
MediaWiki\Tests\Maintenance\BaseDumpTest\tearDown
tearDown()
Definition: backupPrefetchTest.php:21
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeRevisionMissToPage
testSynchronizeRevisionMissToPage()
Definition: backupPrefetchTest.php:62
MediaWiki\Tests\Maintenance\BaseDumpTest\testSynchronizeRevisionMissAtStart
testSynchronizeRevisionMissAtStart()
Definition: backupPrefetchTest.php:104