MediaWiki  1.23.2
backup_LogTest.php
Go to the documentation of this file.
1 <?php
10 
11  // We'll add several log entries and users for this test. The following
12  // variables hold the corresponding ids.
13  private $userId1, $userId2;
14  private $logId1, $logId2, $logId3;
15 
30  private function addLogEntry( $type, $subtype, User $user, $ns, $title,
31  $comment = null, $parameters = null
32  ) {
33  $logEntry = new ManualLogEntry( $type, $subtype );
34  $logEntry->setPerformer( $user );
35  $logEntry->setTarget( Title::newFromText( $title, $ns ) );
36  if ( $comment !== null ) {
37  $logEntry->setComment( $comment );
38  }
39  if ( $parameters !== null ) {
40  $logEntry->setParameters( $parameters );
41  }
42 
43  return $logEntry->insert();
44  }
45 
46  function addDBData() {
47  $this->tablesUsed[] = 'logging';
48  $this->tablesUsed[] = 'user';
49 
50  try {
51  $user1 = User::newFromName( 'BackupDumperLogUserA' );
52  $this->userId1 = $user1->getId();
53  if ( $this->userId1 === 0 ) {
54  $user1->addToDatabase();
55  $this->userId1 = $user1->getId();
56  }
57  $this->assertGreaterThan( 0, $this->userId1 );
58 
59  $user2 = User::newFromName( 'BackupDumperLogUserB' );
60  $this->userId2 = $user2->getId();
61  if ( $this->userId2 === 0 ) {
62  $user2->addToDatabase();
63  $this->userId2 = $user2->getId();
64  }
65  $this->assertGreaterThan( 0, $this->userId2 );
66 
67  $this->logId1 = $this->addLogEntry( 'type', 'subtype',
68  $user1, NS_MAIN, "PageA" );
69  $this->assertGreaterThan( 0, $this->logId1 );
70 
71  $this->logId2 = $this->addLogEntry( 'supress', 'delete',
72  $user2, NS_TALK, "PageB", "SomeComment" );
73  $this->assertGreaterThan( 0, $this->logId2 );
74 
75  $this->logId3 = $this->addLogEntry( 'move', 'delete',
76  $user2, NS_MAIN, "PageA", "SomeOtherComment",
77  array( 'key1' => 1, 3 => 'value3' ) );
78  $this->assertGreaterThan( 0, $this->logId3 );
79  } catch ( Exception $e ) {
80  // We'd love to pass $e directly. However, ... see
81  // documentation of exceptionFromAddDBData in
82  // DumpTestCase
83  $this->exceptionFromAddDBData = $e;
84  }
85  }
86 
101  private function assertLogItem( $id, $user_name, $user_id, $comment, $type,
102  $subtype, $title, $parameters = array()
103  ) {
104 
105  $this->assertNodeStart( "logitem" );
106  $this->skipWhitespace();
107 
108  $this->assertTextNode( "id", $id );
109  $this->assertTextNode( "timestamp", false );
110 
111  $this->assertNodeStart( "contributor" );
112  $this->skipWhitespace();
113  $this->assertTextNode( "username", $user_name );
114  $this->assertTextNode( "id", $user_id );
115  $this->assertNodeEnd( "contributor" );
116  $this->skipWhitespace();
117 
118  if ( $comment !== null ) {
119  $this->assertTextNode( "comment", $comment );
120  }
121  $this->assertTextNode( "type", $type );
122  $this->assertTextNode( "action", $subtype );
123  $this->assertTextNode( "logtitle", $title );
124 
125  $this->assertNodeStart( "params" );
126  $parameters_xml = unserialize( $this->xml->value );
127  $this->assertEquals( $parameters, $parameters_xml );
128  $this->assertTrue( $this->xml->read(), "Skipping past processed text of params" );
129  $this->assertNodeEnd( "params" );
130  $this->skipWhitespace();
131 
132  $this->assertNodeEnd( "logitem" );
133  $this->skipWhitespace();
134  }
135 
136  function testPlain() {
138 
139  // Preparing the dump
140  $fname = $this->getNewTempFile();
141  $dumper = new BackupDumper( array( "--output=file:" . $fname ) );
142  $dumper->startId = $this->logId1;
143  $dumper->endId = $this->logId3 + 1;
144  $dumper->reporting = false;
145  $dumper->setDb( $this->db );
146 
147  // Performing the dump
149 
150  // Analyzing the dumped data
151  $this->assertDumpStart( $fname );
152 
153  $this->assertLogItem( $this->logId1, "BackupDumperLogUserA",
154  $this->userId1, null, "type", "subtype", "PageA" );
155 
156  $this->assertNotNull( $wgContLang, "Content language object validation" );
157  $namespace = $wgContLang->getNsText( NS_TALK );
158  $this->assertInternalType( 'string', $namespace );
159  $this->assertGreaterThan( 0, strlen( $namespace ) );
160  $this->assertLogItem( $this->logId2, "BackupDumperLogUserB",
161  $this->userId2, "SomeComment", "supress", "delete",
162  $namespace . ":PageB" );
163 
164  $this->assertLogItem( $this->logId3, "BackupDumperLogUserB",
165  $this->userId2, "SomeOtherComment", "move", "delete",
166  "PageA", array( 'key1' => 1, 3 => 'value3' ) );
167 
168  $this->assertDumpEnd();
169  }
170 
173 
174  $this->checkHasGzip();
175 
176  // Preparing the dump
177  $fname = $this->getNewTempFile();
178  $dumper = new BackupDumper( array( "--output=gzip:" . $fname,
179  "--reporting=2" ) );
180  $dumper->startId = $this->logId1;
181  $dumper->endId = $this->logId3 + 1;
182  $dumper->setDb( $this->db );
183 
184  // xmldumps-backup demands reporting, although this is currently not
185  // implemented in BackupDumper, when dumping logging data. We
186  // nevertheless capture the output of the dump process already now,
187  // to be able to alert (once dumping produces reports) that this test
188  // needs updates.
189  $dumper->stderr = fopen( 'php://output', 'a' );
190  if ( $dumper->stderr === false ) {
191  $this->fail( "Could not open stream for stderr" );
192  }
193 
194  // Performing the dump
196 
197  $this->assertTrue( fclose( $dumper->stderr ), "Closing stderr handle" );
198 
199  // Analyzing the dumped data
200  $this->gunzip( $fname );
201 
202  $this->assertDumpStart( $fname );
203 
204  $this->assertLogItem( $this->logId1, "BackupDumperLogUserA",
205  $this->userId1, null, "type", "subtype", "PageA" );
206 
207  $this->assertNotNull( $wgContLang, "Content language object validation" );
208  $namespace = $wgContLang->getNsText( NS_TALK );
209  $this->assertInternalType( 'string', $namespace );
210  $this->assertGreaterThan( 0, strlen( $namespace ) );
211  $this->assertLogItem( $this->logId2, "BackupDumperLogUserB",
212  $this->userId2, "SomeComment", "supress", "delete",
213  $namespace . ":PageB" );
214 
215  $this->assertLogItem( $this->logId3, "BackupDumperLogUserB",
216  $this->userId2, "SomeOtherComment", "move", "delete",
217  "PageA", array( 'key1' => 1, 3 => 'value3' ) );
218 
219  $this->assertDumpEnd();
220 
221  // Currently, no reporting is implemented. Alert via failure, once
222  // this changes.
223  // If reporting for log dumps has been implemented, please update
224  // the following statement to catch good output
225  $this->expectOutputString( '' );
226  }
227 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
BackupDumperLoggerTest\addLogEntry
addLogEntry( $type, $subtype, User $user, $ns, $title, $comment=null, $parameters=null)
adds a log entry to the database.
Definition: backup_LogTest.php:30
BackupDumperLoggerTest\$userId1
$userId1
Definition: backup_LogTest.php:13
BackupDumperLoggerTest
Tests for log dumps of BackupDumper.
Definition: backup_LogTest.php:9
DumpTestCase
Base TestCase for dumps.
Definition: DumpTestCase.php:6
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
$dumper
$dumper
Definition: dumpBackup.php:35
$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
DumpTestCase\assertTextNode
assertTextNode( $name, $text, $skip_ws=true)
Asserts that the xml reader is at an element of given tag that contains a given text,...
Definition: DumpTestCase.php:240
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
fail
as a message key or array as accepted by ApiBase::dieUsageMsg after processing request parameters Return false to let the request fail
Definition: hooks.txt:375
BackupDumperLoggerTest\addDBData
addDBData()
Stub.
Definition: backup_LogTest.php:46
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
DumpTestCase\assertDumpEnd
assertDumpEnd( $name="mediawiki")
Asserts that the xml reader is at the final closing tag of an xml file and closes the reader.
Definition: DumpTestCase.php:176
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
DumpTestCase\assertNodeEnd
assertNodeEnd( $name, $skip=true)
Asserts that the xml reader is at an closing element of given name, and optionally skips past it.
Definition: DumpTestCase.php:221
WikiExporter\TEXT
const TEXT
Definition: Export.php:49
BackupDumperLoggerTest\testPlain
testPlain()
Definition: backup_LogTest.php:136
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:156
DumpTestCase\assertNodeStart
assertNodeStart( $name, $skip=true)
Asserts that the xml reader is at an element of given name, and optionally skips past it.
Definition: DumpTestCase.php:205
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$comment
$comment
Definition: importImages.php:107
BackupDumperLoggerTest\assertLogItem
assertLogItem( $id, $user_name, $user_id, $comment, $type, $subtype, $title, $parameters=array())
asserts that the xml reader is at the beginning of a log entry and skips over it while analyzing it.
Definition: backup_LogTest.php:101
BackupDumperLoggerTest\testXmlDumpsBackupUseCaseLogging
testXmlDumpsBackupUseCaseLogging()
Definition: backup_LogTest.php:171
MediaWikiTestCase\checkHasGzip
checkHasGzip()
Check whether we have the 'gzip' commandline utility, will skip the test whenever "gzip -V" fails.
Definition: MediaWikiTestCase.php:983
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
DumpTestCase\assertDumpStart
assertDumpStart( $fname, $skip_siteinfo=true)
Opens an XML file to analyze and optionally skips past siteinfo.
Definition: DumpTestCase.php:159
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
BackupDumper
Definition: backup.inc:39
WikiExporter\LOGS
const LOGS
Definition: Export.php:43
BackupDumperLoggerTest\$userId2
$userId2
Definition: backup_LogTest.php:13
BackupDumperLoggerTest\$logId3
$logId3
Definition: backup_LogTest.php:14
DumpTestCase\gunzip
gunzip( $fname)
gunzips the given file and stores the result in the original file name
Definition: DumpTestCase.php:55
ManualLogEntry
Class for creating log entries manually, for example to inject them into the database.
Definition: LogEntry.php:339
NS_TALK
const NS_TALK
Definition: Defines.php:80
BackupDumperLoggerTest\$logId1
$logId1
Definition: backup_LogTest.php:14
$e
if( $useReadline) $e
Definition: eval.php:66
DumpTestCase\skipWhitespace
skipWhitespace()
Steps the xml reader over white space.
Definition: DumpTestCase.php:189
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
BackupDumperLoggerTest\$logId2
$logId2
Definition: backup_LogTest.php:14
$type
$type
Definition: testCompression.php:46