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 }
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 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
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:305
DatabaseLogEntry\newFromId
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
Definition: LogEntry.php:223
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:37
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
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:678
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MIGRATION_OLD
const MIGRATION_OLD
Definition: Defines.php:302
DatabaseLogEntryTest\provideNewFromId
provideNewFromId()
Definition: DatabaseLogEntryTest.php:70
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:56
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:25
DatabaseLogEntryTest\tearDown
tearDown()
Definition: DatabaseLogEntryTest.php:15
DatabaseLogEntryTest\testNewFromId
testNewFromId( $id, array $selectFields, array $row=null, array $expectedFields=null, $migration)
Definition: DatabaseLogEntryTest.php:34
MediaWikiTestCase\$db
Database $db
Primary database.
Definition: MediaWikiTestCase.php:57