MediaWiki  master
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  $actorMigration
39  ) {
40  $this->setMwGlobals( [
41  'wgActorTableSchemaMigrationStage' => $actorMigration,
42  ] );
43 
44  $row = $row ? (object)$row : null;
45  $db = $this->getMock( IDatabase::class );
46  $db->expects( self::once() )
47  ->method( 'selectRow' )
48  ->with( $selectFields['tables'],
49  $selectFields['fields'],
50  $selectFields['conds'],
51  'DatabaseLogEntry::newFromId',
52  $selectFields['options'],
53  $selectFields['join_conds']
54  )
55  ->will( self::returnValue( $row ) );
56 
58  $logEntry = DatabaseLogEntry::newFromId( $id, $db );
59 
60  if ( !$expectedFields ) {
61  self::assertNull( $logEntry, "Expected no log entry returned for id=$id" );
62  } else {
63  self::assertEquals( $id, $logEntry->getId() );
64  self::assertEquals( $expectedFields['type'], $logEntry->getType() );
65  self::assertEquals( $expectedFields['comment'], $logEntry->getComment() );
66  }
67  }
68 
69  public function provideNewFromId() {
70  $oldTables = [
71  'tables' => [
72  'logging', 'user',
73  'comment_log_comment' => 'comment',
74  ],
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' => 'comment_log_comment.comment_text',
88  'log_comment_data' => 'comment_log_comment.comment_data',
89  'log_comment_cid' => 'comment_log_comment.comment_id',
90  'log_user' => 'log_user',
91  'log_user_text' => 'log_user_text',
92  'log_actor' => 'NULL',
93  ],
94  'options' => [],
95  'join_conds' => [
96  'user' => [ 'LEFT JOIN', 'user_id=log_user' ],
97  'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
98  ],
99  ];
100  $newTables = [
101  'tables' => [
102  'logging',
103  'user',
104  'comment_log_comment' => 'comment',
105  'actor_log_user' => 'actor'
106  ],
107  'fields' => [
108  'log_id',
109  'log_type',
110  'log_action',
111  'log_timestamp',
112  'log_namespace',
113  'log_title',
114  'log_params',
115  'log_deleted',
116  'user_id',
117  'user_name',
118  'user_editcount',
119  'log_comment_text' => 'comment_log_comment.comment_text',
120  'log_comment_data' => 'comment_log_comment.comment_data',
121  'log_comment_cid' => 'comment_log_comment.comment_id',
122  'log_user' => 'actor_log_user.actor_user',
123  'log_user_text' => 'actor_log_user.actor_name',
124  'log_actor' => 'log_actor',
125  ],
126  'options' => [],
127  'join_conds' => [
128  'user' => [ 'LEFT JOIN', 'user_id=actor_log_user.actor_user' ],
129  'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
130  'actor_log_user' => [ 'JOIN', 'actor_log_user.actor_id = log_actor' ],
131  ],
132  ];
133  return [
134  [
135  0,
136  $oldTables + [ 'conds' => [ 'log_id' => 0 ] ],
137  null,
138  null,
140  ],
141  [
142  123,
143  $oldTables + [ 'conds' => [ 'log_id' => 123 ] ],
144  [
145  'log_id' => 123,
146  'log_type' => 'foobarize',
147  'log_comment_text' => 'test!',
148  'log_comment_data' => null,
149  ],
150  [ 'type' => 'foobarize', 'comment' => 'test!' ],
152  ],
153  [
154  567,
155  $newTables + [ 'conds' => [ 'log_id' => 567 ] ],
156  [
157  'log_id' => 567,
158  'log_type' => 'foobarize',
159  'log_comment_text' => 'test!',
160  'log_comment_data' => null,
161  ],
162  [ 'type' => 'foobarize', 'comment' => 'test!' ],
164  ],
165  ];
166  }
167 }
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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:25
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 MediaWikiServices
Definition: injection.txt:23
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
testNewFromId( $id, array $selectFields, array $row=null, array $expectedFields=null, $actorMigration)
DatabaseLogEntry::newFromId DatabaseLogEntry::getSelectQueryData.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown...
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
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
const SCHEMA_COMPAT_NEW
Definition: Defines.php:287
Database $db
Primary database.
const SCHEMA_COMPAT_OLD
Definition: Defines.php:286