MediaWiki  1.30.2
NewUsersLogFormatterTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  protected function setUp() {
9  parent::setUp();
10 
11  // Register LogHandler, see $wgNewUserLog in Setup.php
12  $this->mergeMwGlobalArrayValue( 'wgLogActionsHandlers', [
13  'newusers/newusers' => 'NewUsersLogFormatter',
14  'newusers/create' => 'NewUsersLogFormatter',
15  'newusers/create2' => 'NewUsersLogFormatter',
16  'newusers/byemail' => 'NewUsersLogFormatter',
17  'newusers/autocreate' => 'NewUsersLogFormatter',
18  ] );
19  }
20 
26  public static function provideNewUsersLogDatabaseRows() {
27  return [
28  // Only old logs
29  [
30  [
31  'type' => 'newusers',
32  'action' => 'newusers',
33  'comment' => 'newusers comment',
34  'user' => 0,
35  'user_text' => 'New user',
36  'namespace' => NS_USER,
37  'title' => 'New user',
38  'params' => [],
39  ],
40  [
41  'legacy' => true,
42  'text' => 'User account New user was created',
43  'api' => [],
44  ],
45  ],
46  ];
47  }
48 
52  public function testNewUsersLogDatabaseRows( $row, $extra ) {
53  $this->doTestLogFormatter( $row, $extra );
54  }
55 
61  public static function provideCreateLogDatabaseRows() {
62  return [
63  // Current format
64  [
65  [
66  'type' => 'newusers',
67  'action' => 'create',
68  'comment' => 'newusers comment',
69  'user' => 0,
70  'user_text' => 'New user',
71  'namespace' => NS_USER,
72  'title' => 'New user',
73  'params' => [
74  '4::userid' => 1,
75  ],
76  ],
77  [
78  'text' => 'User account New user was created',
79  'api' => [
80  'userid' => 1,
81  ],
82  ],
83  ],
84  ];
85  }
86 
90  public function testCreateLogDatabaseRows( $row, $extra ) {
91  $this->doTestLogFormatter( $row, $extra );
92  }
93 
99  public static function provideCreate2LogDatabaseRows() {
100  return [
101  // Current format
102  [
103  [
104  'type' => 'newusers',
105  'action' => 'create2',
106  'comment' => 'newusers comment',
107  'user' => 0,
108  'user_text' => 'User',
109  'namespace' => NS_USER,
110  'title' => 'UTSysop'
111  ],
112  [
113  'text' => 'User account UTSysop was created by User'
114  ],
115  ],
116  ];
117  }
118 
122  public function testCreate2LogDatabaseRows( $row, $extra ) {
123  // Make UTSysop user and use its user_id (sequence does not reset to 1 for postgres)
124  $user = static::getTestSysop()->getUser();
125  $row['params']['4::userid'] = $user->getId();
126  $extra['api']['userid'] = $user->getId();
127  $this->doTestLogFormatter( $row, $extra );
128  }
129 
135  public static function provideByemailLogDatabaseRows() {
136  return [
137  // Current format
138  [
139  [
140  'type' => 'newusers',
141  'action' => 'byemail',
142  'comment' => 'newusers comment',
143  'user' => 0,
144  'user_text' => 'Sysop',
145  'namespace' => NS_USER,
146  'title' => 'UTSysop'
147  ],
148  [
149  'text' => 'User account UTSysop was created by Sysop and password was sent by email'
150  ],
151  ],
152  ];
153  }
154 
158  public function testByemailLogDatabaseRows( $row, $extra ) {
159  // Make UTSysop user and use its user_id (sequence does not reset to 1 for postgres)
160  $user = static::getTestSysop()->getUser();
161  $row['params']['4::userid'] = $user->getId();
162  $extra['api']['userid'] = $user->getId();
163  $this->doTestLogFormatter( $row, $extra );
164  }
165 
171  public static function provideAutocreateLogDatabaseRows() {
172  return [
173  // Current format
174  [
175  [
176  'type' => 'newusers',
177  'action' => 'autocreate',
178  'comment' => 'newusers comment',
179  'user' => 0,
180  'user_text' => 'New user',
181  'namespace' => NS_USER,
182  'title' => 'New user',
183  'params' => [
184  '4::userid' => 1,
185  ],
186  ],
187  [
188  'text' => 'User account New user was created automatically',
189  'api' => [
190  'userid' => 1,
191  ],
192  ],
193  ],
194  ];
195  }
196 
200  public function testAutocreateLogDatabaseRows( $row, $extra ) {
201  $this->doTestLogFormatter( $row, $extra );
202  }
203 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
NewUsersLogFormatterTest
Database.
Definition: NewUsersLogFormatterTest.php:6
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:807
NewUsersLogFormatterTest\provideNewUsersLogDatabaseRows
static provideNewUsersLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility.
Definition: NewUsersLogFormatterTest.php:26
NewUsersLogFormatterTest\testByemailLogDatabaseRows
testByemailLogDatabaseRows( $row, $extra)
provideByemailLogDatabaseRows
Definition: NewUsersLogFormatterTest.php:158
NewUsersLogFormatterTest\provideAutocreateLogDatabaseRows
static provideAutocreateLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility.
Definition: NewUsersLogFormatterTest.php:171
NewUsersLogFormatterTest\setUp
setUp()
Definition: NewUsersLogFormatterTest.php:8
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
LogFormatterTestCase
Definition: LogFormatterTestCase.php:6
NewUsersLogFormatterTest\testAutocreateLogDatabaseRows
testAutocreateLogDatabaseRows( $row, $extra)
provideAutocreateLogDatabaseRows
Definition: NewUsersLogFormatterTest.php:200
NewUsersLogFormatterTest\provideByemailLogDatabaseRows
static provideByemailLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility.
Definition: NewUsersLogFormatterTest.php:135
NewUsersLogFormatterTest\provideCreate2LogDatabaseRows
static provideCreate2LogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility.
Definition: NewUsersLogFormatterTest.php:99
NewUsersLogFormatterTest\testCreate2LogDatabaseRows
testCreate2LogDatabaseRows( $row, $extra)
provideCreate2LogDatabaseRows
Definition: NewUsersLogFormatterTest.php:122
LogFormatterTestCase\doTestLogFormatter
doTestLogFormatter( $row, $extra)
Definition: LogFormatterTestCase.php:8
NS_USER
const NS_USER
Definition: Defines.php:67
NewUsersLogFormatterTest\testCreateLogDatabaseRows
testCreateLogDatabaseRows( $row, $extra)
provideCreateLogDatabaseRows
Definition: NewUsersLogFormatterTest.php:90
NewUsersLogFormatterTest\provideCreateLogDatabaseRows
static provideCreateLogDatabaseRows()
Provide different rows from the logging table to test for backward compatibility.
Definition: NewUsersLogFormatterTest.php:61
NewUsersLogFormatterTest\testNewUsersLogDatabaseRows
testNewUsersLogDatabaseRows( $row, $extra)
provideNewUsersLogDatabaseRows
Definition: NewUsersLogFormatterTest.php:52