MediaWiki  1.23.8
backupPrefetchTest.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . "/../../../maintenance/backupPrefetch.inc";
4 
12 
18  private $dump = null;
19 
20  protected function tearDown() {
21  if ( $this->dump !== null ) {
22  $this->dump->close();
23  }
24 
25  // Bug 37458, parent teardown need to be done after closing the
26  // dump or it might cause some permissions errors.
27  parent::tearDown();
28  }
29 
37  private function assertPrefetchEquals( $expected, $page, $revision ) {
38  $this->assertEquals( $expected, $this->dump->prefetch( $page, $revision ),
39  "Prefetch of page $page revision $revision" );
40  }
41 
42  function testSequential() {
43  $fname = $this->setUpPrefetch();
44  $this->dump = new BaseDump( $fname );
45 
46  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
47  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
48  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
49  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
50  }
51 
53  $fname = $this->setUpPrefetch();
54  $this->dump = new BaseDump( $fname );
55 
56  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
57  $this->assertPrefetchEquals( null, 2, 3 );
58  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
59  }
60 
62  $fname = $this->setUpPrefetch();
63  $this->dump = new BaseDump( $fname );
64 
65  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
66  $this->assertPrefetchEquals( null, 2, 40 );
67  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
68  }
69 
70  function testSynchronizePageMiss() {
71  $fname = $this->setUpPrefetch();
72  $this->dump = new BaseDump( $fname );
73 
74  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
75  $this->assertPrefetchEquals( null, 3, 40 );
76  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
77  }
78 
79  function testPageMissAtEnd() {
80  $fname = $this->setUpPrefetch();
81  $this->dump = new BaseDump( $fname );
82 
83  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
84  $this->assertPrefetchEquals( null, 6, 40 );
85  }
86 
87  function testRevisionMissAtEnd() {
88  $fname = $this->setUpPrefetch();
89  $this->dump = new BaseDump( $fname );
90 
91  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
92  $this->assertPrefetchEquals( null, 4, 40 );
93  }
94 
96  $fname = $this->setUpPrefetch();
97  $this->dump = new BaseDump( $fname );
98 
99  $this->assertPrefetchEquals( null, 0, 2 );
100  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
101  }
102 
104  $fname = $this->setUpPrefetch();
105  $this->dump = new BaseDump( $fname );
106 
107  $this->assertPrefetchEquals( null, 1, -2 );
108  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
109  }
110 
111  function testSequentialAcrossFiles() {
112  $fname1 = $this->setUpPrefetch( array( 1 ) );
113  $fname2 = $this->setUpPrefetch( array( 2, 4 ) );
114  $this->dump = new BaseDump( $fname1 . ";" . $fname2 );
115 
116  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
117  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
118  $this->assertPrefetchEquals( "BackupDumperTestP2Text4 some additional Text", 2, 5 );
119  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
120  }
121 
122  function testSynchronizeSkipAcrossFile() {
123  $fname1 = $this->setUpPrefetch( array( 1 ) );
124  $fname2 = $this->setUpPrefetch( array( 2 ) );
125  $fname3 = $this->setUpPrefetch( array( 4 ) );
126  $this->dump = new BaseDump( $fname1 . ";" . $fname2 . ";" . $fname3 );
127 
128  $this->assertPrefetchEquals( "BackupDumperTestP1Text1", 1, 1 );
129  $this->assertPrefetchEquals( "Talk about BackupDumperTestP1 Text1", 4, 8 );
130  }
131 
133  $fname1 = $this->setUpPrefetch( array( 1 ) );
134  $fname2 = $this->setUpPrefetch( array( 2 ) );
135  $this->dump = new BaseDump( $fname1 . ";" . $fname2 );
136 
137  $this->assertPrefetchEquals( "BackupDumperTestP2Text1", 2, 2 );
138  }
139 
149  private function setUpPrefetch( $requested_pages = array( 1, 2, 4 ) ) {
150  // The file name, where we store the prepared prefetch file
151  $fname = $this->getNewTempFile();
152 
153  // The header of every prefetch file
154  $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">
155  <siteinfo>
156  <sitename>wikisvn</sitename>
157  <base>http://localhost/wiki-svn/index.php/Main_Page</base>
158  <generator>MediaWiki 1.21alpha</generator>
159  <case>first-letter</case>
160  <namespaces>
161  <namespace key="-2" case="first-letter">Media</namespace>
162  <namespace key="-1" case="first-letter">Special</namespace>
163  <namespace key="0" case="first-letter" />
164  <namespace key="1" case="first-letter">Talk</namespace>
165  <namespace key="2" case="first-letter">User</namespace>
166  <namespace key="3" case="first-letter">User talk</namespace>
167  <namespace key="4" case="first-letter">Wikisvn</namespace>
168  <namespace key="5" case="first-letter">Wikisvn talk</namespace>
169  <namespace key="6" case="first-letter">File</namespace>
170  <namespace key="7" case="first-letter">File talk</namespace>
171  <namespace key="8" case="first-letter">MediaWiki</namespace>
172  <namespace key="9" case="first-letter">MediaWiki talk</namespace>
173  <namespace key="10" case="first-letter">Template</namespace>
174  <namespace key="11" case="first-letter">Template talk</namespace>
175  <namespace key="12" case="first-letter">Help</namespace>
176  <namespace key="13" case="first-letter">Help talk</namespace>
177  <namespace key="14" case="first-letter">Category</namespace>
178  <namespace key="15" case="first-letter">Category talk</namespace>
179  </namespaces>
180  </siteinfo>
181 ';
182 
183  // An array holding the pages that are available for prefetch
184  $available_pages = array();
185 
186  // Simple plain page
187  $available_pages[1] = ' <page>
188  <title>BackupDumperTestP1</title>
189  <ns>0</ns>
190  <id>1</id>
191  <revision>
192  <id>1</id>
193  <timestamp>2012-04-01T16:46:05Z</timestamp>
194  <contributor>
195  <ip>127.0.0.1</ip>
196  </contributor>
197  <comment>BackupDumperTestP1Summary1</comment>
198  <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
199  <text xml:space="preserve">BackupDumperTestP1Text1</text>
200  <model name="wikitext">1</model>
201  <format mime="text/x-wiki">1</format>
202  </revision>
203  </page>
204 ';
205  // Page with more than one revisions. Hole in rev ids.
206  $available_pages[2] = ' <page>
207  <title>BackupDumperTestP2</title>
208  <ns>0</ns>
209  <id>2</id>
210  <revision>
211  <id>2</id>
212  <timestamp>2012-04-01T16:46:05Z</timestamp>
213  <contributor>
214  <ip>127.0.0.1</ip>
215  </contributor>
216  <comment>BackupDumperTestP2Summary1</comment>
217  <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
218  <text xml:space="preserve">BackupDumperTestP2Text1</text>
219  <model name="wikitext">1</model>
220  <format mime="text/x-wiki">1</format>
221  </revision>
222  <revision>
223  <id>5</id>
224  <parentid>2</parentid>
225  <timestamp>2012-04-01T16:46:05Z</timestamp>
226  <contributor>
227  <ip>127.0.0.1</ip>
228  </contributor>
229  <comment>BackupDumperTestP2Summary4 extra</comment>
230  <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
231  <text xml:space="preserve">BackupDumperTestP2Text4 some additional Text</text>
232  <model name="wikitext">1</model>
233  <format mime="text/x-wiki">1</format>
234  </revision>
235  </page>
236 ';
237  // Page with id higher than previous id + 1
238  $available_pages[4] = ' <page>
239  <title>Talk:BackupDumperTestP1</title>
240  <ns>1</ns>
241  <id>4</id>
242  <revision>
243  <id>8</id>
244  <timestamp>2012-04-01T16:46:05Z</timestamp>
245  <contributor>
246  <ip>127.0.0.1</ip>
247  </contributor>
248  <comment>Talk BackupDumperTestP1 Summary1</comment>
249  <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
250  <model name="wikitext">1</model>
251  <format mime="text/x-wiki">1</format>
252  <text xml:space="preserve">Talk about BackupDumperTestP1 Text1</text>
253  </revision>
254  </page>
255 ';
256 
257  // The common ending for all files
258  $tail = '</mediawiki>
259 ';
260 
261  // Putting together the content of the prefetch files
262  $content = $header;
263  foreach ( $requested_pages as $i ) {
264  $this->assertTrue( array_key_exists( $i, $available_pages ),
265  "Check for availability of requested page " . $i );
266  $content .= $available_pages[$i];
267  }
268  $content .= $tail;
269 
270  $this->assertEquals( strlen( $content ), file_put_contents(
271  $fname, $content ), "Length of prepared prefetch" );
272 
273  return $fname;
274  }
275 }
BaseDumpTest\testSynchronizePageMiss
testSynchronizePageMiss()
Definition: backupPrefetchTest.php:69
BaseDumpTest\testRevisionMissAtEnd
testRevisionMissAtEnd()
Definition: backupPrefetchTest.php:86
BaseDumpTest\setUpPrefetch
setUpPrefetch( $requested_pages=array(1, 2, 4))
Constructs a temporary file that can be used for prefetching.
Definition: backupPrefetchTest.php:148
BaseDump
Readahead helper for making large MediaWiki data dumps; reads in a previous XML dump to sequentially ...
Definition: backupPrefetch.inc:42
BaseDumpTest\testSynchronizePageMissAtStart
testSynchronizePageMissAtStart()
Definition: backupPrefetchTest.php:94
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
BaseDumpTest\testSequentialAcrossFiles
testSequentialAcrossFiles()
Definition: backupPrefetchTest.php:110
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:35
BaseDumpTest\testSynchronizeSkipAcrossFile
testSynchronizeSkipAcrossFile()
Definition: backupPrefetchTest.php:121
BaseDumpTest\$dump
BaseDump $dump
the BaseDump instance used within a test.
Definition: backupPrefetchTest.php:17
BaseDumpTest\tearDown
tearDown()
Definition: backupPrefetchTest.php:19
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:156
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
BaseDumpTest\testSynchronizeMissInWholeFirstFile
testSynchronizeMissInWholeFirstFile()
Definition: backupPrefetchTest.php:131
BaseDumpTest\testSynchronizeRevisionMissToRevision
testSynchronizeRevisionMissToRevision()
Definition: backupPrefetchTest.php:51
BaseDumpTest
Tests for BaseDump.
Definition: backupPrefetchTest.php:11
BaseDumpTest\testSynchronizeRevisionMissToPage
testSynchronizeRevisionMissToPage()
Definition: backupPrefetchTest.php:60
BaseDumpTest\assertPrefetchEquals
assertPrefetchEquals( $expected, $page, $revision)
asserts that a prefetch yields an expected string
Definition: backupPrefetchTest.php:36
BaseDumpTest\testSequential
testSequential()
Definition: backupPrefetchTest.php:41
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
BaseDumpTest\testSynchronizeRevisionMissAtStart
testSynchronizeRevisionMissAtStart()
Definition: backupPrefetchTest.php:102
BaseDumpTest\testPageMissAtEnd
testPageMissAtEnd()
Definition: backupPrefetchTest.php:78