MediaWiki  1.32.0
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 }
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:318
DatabaseLogEntry\newFromId
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
Definition: LogEntry.php:224
DatabaseLogEntryTest\setUp
setUp()
Definition: DatabaseLogEntryTest.php:7
php
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
DatabaseLogEntryTest\testNewFromId
testNewFromId( $id, array $selectFields, array $row=null, array $expectedFields=null, $commentMigration, $actorMigration)
Definition: DatabaseLogEntryTest.php:35
DatabaseLogEntryTest
Definition: DatabaseLogEntryTest.php:6
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:706
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
array
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))
MIGRATION_OLD
const MIGRATION_OLD
Definition: Defines.php:315
SCHEMA_COMPAT_NEW
const SCHEMA_COMPAT_NEW
Definition: Defines.php:291
SCHEMA_COMPAT_OLD
const SCHEMA_COMPAT_OLD
Definition: Defines.php:290
DatabaseLogEntryTest\provideNewFromId
provideNewFromId()
Definition: DatabaseLogEntryTest.php:72
class
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
object
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
MediaWikiServices
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
DatabaseLogEntryTest\tearDown
tearDown()
Definition: DatabaseLogEntryTest.php:15
MediaWikiTestCase\$db
Database $db
Primary database.
Definition: MediaWikiTestCase.php:60