2015-04-09 09:09:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-25 07:26:01 +00:00
|
|
|
* @covers NewUsersLogFormatter
|
2015-04-09 09:09:36 +00:00
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class NewUsersLogFormatterTest extends LogFormatterTestCase {
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2015-04-09 09:09:36 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
// Register LogHandler, see $wgNewUserLog in Setup.php
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->mergeMwGlobalArrayValue( 'wgLogActionsHandlers', [
|
2018-01-13 00:02:09 +00:00
|
|
|
'newusers/newusers' => NewUsersLogFormatter::class,
|
|
|
|
|
'newusers/create' => NewUsersLogFormatter::class,
|
|
|
|
|
'newusers/create2' => NewUsersLogFormatter::class,
|
|
|
|
|
'newusers/byemail' => NewUsersLogFormatter::class,
|
|
|
|
|
'newusers/autocreate' => NewUsersLogFormatter::class,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2015-04-09 09:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provide different rows from the logging table to test
|
|
|
|
|
* for backward compatibility.
|
|
|
|
|
* Do not change the existing data, just add a new database row
|
|
|
|
|
*/
|
|
|
|
|
public static function provideNewUsersLogDatabaseRows() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-04-09 09:09:36 +00:00
|
|
|
// Only old logs
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2015-04-09 09:09:36 +00:00
|
|
|
'type' => 'newusers',
|
|
|
|
|
'action' => 'newusers',
|
|
|
|
|
'comment' => 'newusers comment',
|
|
|
|
|
'user' => 0,
|
|
|
|
|
'user_text' => 'New user',
|
|
|
|
|
'namespace' => NS_USER,
|
|
|
|
|
'title' => 'New user',
|
2016-02-17 09:09:32 +00:00
|
|
|
'params' => [],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-04-09 09:09:36 +00:00
|
|
|
'legacy' => true,
|
|
|
|
|
'text' => 'User account New user was created',
|
2016-02-17 09:09:32 +00:00
|
|
|
'api' => [],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2015-04-09 09:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideNewUsersLogDatabaseRows
|
|
|
|
|
*/
|
|
|
|
|
public function testNewUsersLogDatabaseRows( $row, $extra ) {
|
|
|
|
|
$this->doTestLogFormatter( $row, $extra );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provide different rows from the logging table to test
|
|
|
|
|
* for backward compatibility.
|
|
|
|
|
* Do not change the existing data, just add a new database row
|
|
|
|
|
*/
|
|
|
|
|
public static function provideCreateLogDatabaseRows() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-04-09 09:09:36 +00:00
|
|
|
// Current format
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2015-04-09 09:09:36 +00:00
|
|
|
'type' => 'newusers',
|
|
|
|
|
'action' => 'create',
|
|
|
|
|
'comment' => 'newusers comment',
|
|
|
|
|
'user' => 0,
|
|
|
|
|
'user_text' => 'New user',
|
|
|
|
|
'namespace' => NS_USER,
|
|
|
|
|
'title' => 'New user',
|
2016-02-17 09:09:32 +00:00
|
|
|
'params' => [
|
2015-06-06 18:55:03 +00:00
|
|
|
'4::userid' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-04-09 09:09:36 +00:00
|
|
|
'text' => 'User account New user was created',
|
2016-02-17 09:09:32 +00:00
|
|
|
'api' => [
|
2015-04-09 09:09:36 +00:00
|
|
|
'userid' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2015-04-09 09:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideCreateLogDatabaseRows
|
|
|
|
|
*/
|
|
|
|
|
public function testCreateLogDatabaseRows( $row, $extra ) {
|
|
|
|
|
$this->doTestLogFormatter( $row, $extra );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provide different rows from the logging table to test
|
|
|
|
|
* for backward compatibility.
|
|
|
|
|
* Do not change the existing data, just add a new database row
|
|
|
|
|
*/
|
|
|
|
|
public static function provideCreate2LogDatabaseRows() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-04-09 09:09:36 +00:00
|
|
|
// Current format
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2015-04-09 09:09:36 +00:00
|
|
|
'type' => 'newusers',
|
|
|
|
|
'action' => 'create2',
|
|
|
|
|
'comment' => 'newusers comment',
|
|
|
|
|
'user' => 0,
|
|
|
|
|
'user_text' => 'User',
|
|
|
|
|
'namespace' => NS_USER,
|
2017-05-17 01:36:58 +00:00
|
|
|
'title' => 'UTSysop'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2017-05-17 01:36:58 +00:00
|
|
|
'text' => 'User account UTSysop was created by User'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2015-04-09 09:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideCreate2LogDatabaseRows
|
|
|
|
|
*/
|
|
|
|
|
public function testCreate2LogDatabaseRows( $row, $extra ) {
|
2017-05-17 01:36:58 +00:00
|
|
|
// Make UTSysop user and use its user_id (sequence does not reset to 1 for postgres)
|
|
|
|
|
$user = static::getTestSysop()->getUser();
|
|
|
|
|
$row['params']['4::userid'] = $user->getId();
|
|
|
|
|
$extra['api']['userid'] = $user->getId();
|
2015-04-09 09:09:36 +00:00
|
|
|
$this->doTestLogFormatter( $row, $extra );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provide different rows from the logging table to test
|
|
|
|
|
* for backward compatibility.
|
|
|
|
|
* Do not change the existing data, just add a new database row
|
|
|
|
|
*/
|
|
|
|
|
public static function provideByemailLogDatabaseRows() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-04-09 09:09:36 +00:00
|
|
|
// Current format
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2015-04-09 09:09:36 +00:00
|
|
|
'type' => 'newusers',
|
|
|
|
|
'action' => 'byemail',
|
|
|
|
|
'comment' => 'newusers comment',
|
|
|
|
|
'user' => 0,
|
|
|
|
|
'user_text' => 'Sysop',
|
|
|
|
|
'namespace' => NS_USER,
|
2017-05-17 01:36:58 +00:00
|
|
|
'title' => 'UTSysop'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2017-05-17 01:36:58 +00:00
|
|
|
'text' => 'User account UTSysop was created by Sysop and password was sent by email'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2015-04-09 09:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideByemailLogDatabaseRows
|
|
|
|
|
*/
|
|
|
|
|
public function testByemailLogDatabaseRows( $row, $extra ) {
|
2017-05-17 01:36:58 +00:00
|
|
|
// Make UTSysop user and use its user_id (sequence does not reset to 1 for postgres)
|
|
|
|
|
$user = static::getTestSysop()->getUser();
|
|
|
|
|
$row['params']['4::userid'] = $user->getId();
|
|
|
|
|
$extra['api']['userid'] = $user->getId();
|
2015-04-09 09:09:36 +00:00
|
|
|
$this->doTestLogFormatter( $row, $extra );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provide different rows from the logging table to test
|
|
|
|
|
* for backward compatibility.
|
|
|
|
|
* Do not change the existing data, just add a new database row
|
|
|
|
|
*/
|
|
|
|
|
public static function provideAutocreateLogDatabaseRows() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-04-09 09:09:36 +00:00
|
|
|
// Current format
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[
|
2015-04-09 09:09:36 +00:00
|
|
|
'type' => 'newusers',
|
|
|
|
|
'action' => 'autocreate',
|
|
|
|
|
'comment' => 'newusers comment',
|
|
|
|
|
'user' => 0,
|
|
|
|
|
'user_text' => 'New user',
|
|
|
|
|
'namespace' => NS_USER,
|
|
|
|
|
'title' => 'New user',
|
2016-02-17 09:09:32 +00:00
|
|
|
'params' => [
|
2015-06-06 18:55:03 +00:00
|
|
|
'4::userid' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-04-09 09:09:36 +00:00
|
|
|
'text' => 'User account New user was created automatically',
|
2016-02-17 09:09:32 +00:00
|
|
|
'api' => [
|
2015-04-09 09:09:36 +00:00
|
|
|
'userid' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2015-04-09 09:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideAutocreateLogDatabaseRows
|
|
|
|
|
*/
|
|
|
|
|
public function testAutocreateLogDatabaseRows( $row, $extra ) {
|
|
|
|
|
$this->doTestLogFormatter( $row, $extra );
|
|
|
|
|
}
|
|
|
|
|
}
|