MediaWiki REL1_32
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
35 public function testNewFromId( $id,
36 array $selectFields,
37 array $row = null,
38 array $expectedFields = null,
39 $commentMigration,
40 $actorMigration
41 ) {
42 $this->setMwGlobals( [
43 'wgCommentTableSchemaMigrationStage' => $commentMigration,
44 'wgActorTableSchemaMigrationStage' => $actorMigration,
45 ] );
46
47 $row = $row ? (object)$row : null;
48 $db = $this->getMock( IDatabase::class );
49 $db->expects( self::once() )
50 ->method( 'selectRow' )
51 ->with( $selectFields['tables'],
52 $selectFields['fields'],
53 $selectFields['conds'],
54 'DatabaseLogEntry::newFromId',
55 $selectFields['options'],
56 $selectFields['join_conds']
57 )
58 ->will( self::returnValue( $row ) );
59
61 $logEntry = DatabaseLogEntry::newFromId( $id, $db );
62
63 if ( !$expectedFields ) {
64 self::assertNull( $logEntry, "Expected no log entry returned for id=$id" );
65 } else {
66 self::assertEquals( $id, $logEntry->getId() );
67 self::assertEquals( $expectedFields['type'], $logEntry->getType() );
68 self::assertEquals( $expectedFields['comment'], $logEntry->getComment() );
69 }
70 }
71
72 public function provideNewFromId() {
73 $oldTables = [
74 'tables' => [ 'logging', 'user' ],
75 'fields' => [
76 'log_id',
77 'log_type',
78 'log_action',
79 'log_timestamp',
80 'log_namespace',
81 'log_title',
82 'log_params',
83 'log_deleted',
84 'user_id',
85 'user_name',
86 'user_editcount',
87 'log_comment_text' => 'log_comment',
88 'log_comment_data' => 'NULL',
89 'log_comment_cid' => 'NULL',
90 'log_user' => 'log_user',
91 'log_user_text' => 'log_user_text',
92 'log_actor' => 'NULL',
93 ],
94 'options' => [],
95 'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id=log_user' ] ],
96 ];
97 $newTables = [
98 'tables' => [
99 'logging',
100 'user',
101 'comment_log_comment' => 'comment',
102 'actor_log_user' => 'actor'
103 ],
104 'fields' => [
105 'log_id',
106 'log_type',
107 'log_action',
108 'log_timestamp',
109 'log_namespace',
110 'log_title',
111 'log_params',
112 'log_deleted',
113 'user_id',
114 'user_name',
115 'user_editcount',
116 'log_comment_text' => 'comment_log_comment.comment_text',
117 'log_comment_data' => 'comment_log_comment.comment_data',
118 'log_comment_cid' => 'comment_log_comment.comment_id',
119 'log_user' => 'actor_log_user.actor_user',
120 'log_user_text' => 'actor_log_user.actor_name',
121 'log_actor' => 'log_actor',
122 ],
123 'options' => [],
124 'join_conds' => [
125 'user' => [ 'LEFT JOIN', 'user_id=actor_log_user.actor_user' ],
126 'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
127 'actor_log_user' => [ 'JOIN', 'actor_log_user.actor_id = log_actor' ],
128 ],
129 ];
130 return [
131 [
132 0,
133 $oldTables + [ 'conds' => [ 'log_id' => 0 ] ],
134 null,
135 null,
138 ],
139 [
140 123,
141 $oldTables + [ 'conds' => [ 'log_id' => 123 ] ],
142 [
143 'log_id' => 123,
144 'log_type' => 'foobarize',
145 'log_comment_text' => 'test!',
146 'log_comment_data' => null,
147 ],
148 [ 'type' => 'foobarize', 'comment' => 'test!' ],
151 ],
152 [
153 567,
154 $newTables + [ 'conds' => [ 'log_id' => 567 ] ],
155 [
156 'log_id' => 567,
157 'log_type' => 'foobarize',
158 'log_comment_text' => 'test!',
159 'log_comment_data' => null,
160 ],
161 [ 'type' => 'foobarize', 'comment' => 'test!' ],
164 ],
165 ];
166 }
167}
testNewFromId( $id, array $selectFields, array $row=null, array $expectedFields=null, $commentMigration, $actorMigration)
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
Definition LogEntry.php:224
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 $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:62
const SCHEMA_COMPAT_OLD
Definition Defines.php:290
const MIGRATION_NEW
Definition Defines.php:318
const SCHEMA_COMPAT_NEW
Definition Defines.php:291
const MIGRATION_OLD
Definition Defines.php:315
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))