MediaWiki REL1_31
DatabaseLogEntryTest.php
Go to the documentation of this file.
1<?php
2
5
7 public function setUp() {
8 parent::setUp();
9
10 // These services cache their joins
11 MediaWikiServices::getInstance()->resetServiceForTesting( 'CommentStore' );
12 MediaWikiServices::getInstance()->resetServiceForTesting( 'ActorMigration' );
13 }
14
15 public function tearDown() {
16 parent::tearDown();
17
18 MediaWikiServices::getInstance()->resetServiceForTesting( 'CommentStore' );
19 MediaWikiServices::getInstance()->resetServiceForTesting( 'ActorMigration' );
20 }
21
34 public function testNewFromId( $id,
35 array $selectFields,
36 array $row = null,
37 array $expectedFields = null,
38 $migration
39 ) {
40 $this->setMwGlobals( [
41 'wgCommentTableSchemaMigrationStage' => $migration,
42 'wgActorTableSchemaMigrationStage' => $migration,
43 ] );
44
45 $row = $row ? (object)$row : null;
46 $db = $this->getMock( IDatabase::class );
47 $db->expects( self::once() )
48 ->method( 'selectRow' )
49 ->with( $selectFields['tables'],
50 $selectFields['fields'],
51 $selectFields['conds'],
52 'DatabaseLogEntry::newFromId',
53 $selectFields['options'],
54 $selectFields['join_conds']
55 )
56 ->will( self::returnValue( $row ) );
57
59 $logEntry = DatabaseLogEntry::newFromId( $id, $db );
60
61 if ( !$expectedFields ) {
62 self::assertNull( $logEntry, "Expected no log entry returned for id=$id" );
63 } else {
64 self::assertEquals( $id, $logEntry->getId() );
65 self::assertEquals( $expectedFields['type'], $logEntry->getType() );
66 self::assertEquals( $expectedFields['comment'], $logEntry->getComment() );
67 }
68 }
69
70 public function provideNewFromId() {
71 $oldTables = [
72 'tables' => [ 'logging', 'user' ],
73 'fields' => [
74 'log_id',
75 'log_type',
76 'log_action',
77 'log_timestamp',
78 'log_namespace',
79 'log_title',
80 'log_params',
81 'log_deleted',
82 'user_id',
83 'user_name',
84 'user_editcount',
85 'log_comment_text' => 'log_comment',
86 'log_comment_data' => 'NULL',
87 'log_comment_cid' => 'NULL',
88 'log_user' => 'log_user',
89 'log_user_text' => 'log_user_text',
90 'log_actor' => 'NULL',
91 ],
92 'options' => [],
93 'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id=log_user' ] ],
94 ];
95 $newTables = [
96 'tables' => [
97 'logging',
98 'user',
99 'comment_log_comment' => 'comment',
100 'actor_log_user' => 'actor'
101 ],
102 'fields' => [
103 'log_id',
104 'log_type',
105 'log_action',
106 'log_timestamp',
107 'log_namespace',
108 'log_title',
109 'log_params',
110 'log_deleted',
111 'user_id',
112 'user_name',
113 'user_editcount',
114 'log_comment_text' => 'comment_log_comment.comment_text',
115 'log_comment_data' => 'comment_log_comment.comment_data',
116 'log_comment_cid' => 'comment_log_comment.comment_id',
117 'log_user' => 'actor_log_user.actor_user',
118 'log_user_text' => 'actor_log_user.actor_name',
119 'log_actor' => 'log_actor',
120 ],
121 'options' => [],
122 'join_conds' => [
123 'user' => [ 'LEFT JOIN', 'user_id=actor_log_user.actor_user' ],
124 'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
125 'actor_log_user' => [ 'JOIN', 'actor_log_user.actor_id = log_actor' ],
126 ],
127 ];
128 return [
129 [
130 0,
131 $oldTables + [ 'conds' => [ 'log_id' => 0 ] ],
132 null,
133 null,
135 ],
136 [
137 123,
138 $oldTables + [ 'conds' => [ 'log_id' => 123 ] ],
139 [
140 'log_id' => 123,
141 'log_type' => 'foobarize',
142 'log_comment_text' => 'test!',
143 'log_comment_data' => null,
144 ],
145 [ 'type' => 'foobarize', 'comment' => 'test!' ],
147 ],
148 [
149 567,
150 $newTables + [ 'conds' => [ 'log_id' => 567 ] ],
151 [
152 'log_id' => 567,
153 'log_type' => 'foobarize',
154 'log_comment_text' => 'test!',
155 'log_comment_data' => null,
156 ],
157 [ 'type' => 'foobarize', 'comment' => 'test!' ],
159 ],
160 ];
161 }
162}
testNewFromId( $id, array $selectFields, array $row=null, array $expectedFields=null, $migration)
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
Definition LogEntry.php:223
Database $db
Primary database.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
MediaWikiServices is the service locator for the application scope of MediaWiki.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition globals.txt:64
const MIGRATION_NEW
Definition Defines.php:305
const MIGRATION_OLD
Definition Defines.php:302
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38