Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7409903
CheckUserPrivateEventsHandlerTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
CheckUserPrivateEventsHandlerTest.php
View Options
<?php
namespace
MediaWiki\CheckUser\Tests\Unit\HookHandler
;
use
MailAddress
;
use
MediaWiki\Auth\AuthenticationResponse
;
use
MediaWiki\CheckUser\HookHandler\CheckUserPrivateEventsHandler
;
use
MediaWiki\CheckUser\Services\CheckUserInsert
;
use
MediaWiki\Config\Config
;
use
MediaWiki\Config\HashConfig
;
use
MediaWiki\Deferred\DeferredUpdates
;
use
MediaWiki\MainConfigNames
;
use
MediaWiki\User\User
;
use
MediaWiki\User\UserFactory
;
use
MediaWiki\User\UserIdentityLookup
;
use
MediaWikiUnitTestCase
;
use
Wikimedia\Rdbms\ReadOnlyMode
;
/**
* @covers \MediaWiki\CheckUser\HookHandler\CheckUserPrivateEventsHandler
* @group CheckUser
*/
class
CheckUserPrivateEventsHandlerTest
extends
MediaWikiUnitTestCase
{
public
function
getObjectUnderTestForNoCheckUserInsertCalls
(
$overrides
=
[]
):
CheckUserPrivateEventsHandler
{
$noOpMockCheckUserInsert
=
$this
->
createNoOpMock
(
CheckUserInsert
::
class
);
return
new
CheckUserPrivateEventsHandler
(
$noOpMockCheckUserInsert
,
$overrides
[
'config'
]
??
$this
->
createMock
(
Config
::
class
),
$overrides
[
'userIdentityLookup'
]
??
$this
->
createMock
(
UserIdentityLookup
::
class
),
$overrides
[
'userFactory'
]
??
$this
->
createMock
(
UserFactory
::
class
),
$overrides
[
'readOnlyMode'
]
??
$this
->
createMock
(
ReadOnlyMode
::
class
)
);
}
public
function
testUserLogoutCompleteWhenLogLoginsConfigSetToFalse
()
{
$handler
=
$this
->
getObjectUnderTestForNoCheckUserInsertCalls
(
[
'config'
=>
new
HashConfig
(
[
'CheckUserLogLogins'
=>
false
]
),
]
);
$html
=
''
;
$handler
->
onUserLogoutComplete
(
$this
->
createMock
(
User
::
class
),
$html
,
'OldName'
);
}
public
function
testOnAuthManagerLoginAuthenticateAuditWhenLogLoginsConfigSetToFalse
()
{
$handler
=
$this
->
getObjectUnderTestForNoCheckUserInsertCalls
(
[
'config'
=>
new
HashConfig
(
[
'CheckUserLogLogins'
=>
false
]
),
]
);
$handler
->
onAuthManagerLoginAuthenticateAudit
(
AuthenticationResponse
::
newPass
(
'test'
),
$this
->
createMock
(
User
::
class
),
'test'
,
[]
);
}
public
function
testOnEmailUserNoSaveForSelfEmail
()
{
// Call the method under test, with $to and $from having the same email and name.
$to
=
new
MailAddress
(
'test@test.com'
,
'Test'
);
$from
=
new
MailAddress
(
'test@test.com'
,
'Test'
);
$subject
=
'Test'
;
$text
=
'Test'
;
$error
=
false
;
$this
->
getObjectUnderTestForNoCheckUserInsertCalls
()
->
onEmailUser
(
$to
,
$from
,
$subject
,
$text
,
$error
);
// Run DeferredUpdates as the private event is created in a DeferredUpdate.
DeferredUpdates
::
doUpdates
();
}
public
function
testOnEmailUserForNoSecretKey
()
{
// Mock that wgSecretKey is set to null.
$handler
=
$this
->
getObjectUnderTestForNoCheckUserInsertCalls
(
[
'config'
=>
new
HashConfig
(
[
'SecretKey'
=>
null
]
),
]
);
// Call the method under test
$to
=
new
MailAddress
(
'test@test.com'
,
'Test'
);
$from
=
new
MailAddress
(
'testing@test.com'
,
'Testing'
);
$subject
=
'Test'
;
$text
=
'Test'
;
$error
=
false
;
$handler
->
onEmailUser
(
$to
,
$from
,
$subject
,
$text
,
$error
);
// Run DeferredUpdates as the private event is created in a DeferredUpdate.
DeferredUpdates
::
doUpdates
();
}
public
function
testOnEmailUserReadOnlyMode
()
{
// Mock that the wgSecretKey is defined but the site is in read only mode.
$mockReadOnlyMode
=
$this
->
createMock
(
ReadOnlyMode
::
class
);
$mockReadOnlyMode
->
method
(
'isReadOnly'
)->
willReturn
(
true
);
$handler
=
$this
->
getObjectUnderTestForNoCheckUserInsertCalls
(
[
'readOnlyMode'
=>
$mockReadOnlyMode
,
'config'
=>
new
HashConfig
(
[
'SecretKey'
=>
'test'
]
),
]
);
// Call the method under test
$to
=
new
MailAddress
(
'test@test.com'
,
'Test'
);
$from
=
new
MailAddress
(
'testing@test.com'
,
'Testing'
);
$subject
=
'Test'
;
$text
=
'Test'
;
$error
=
false
;
$handler
->
onEmailUser
(
$to
,
$from
,
$subject
,
$text
,
$error
);
// Run DeferredUpdates as the private event is created in a DeferredUpdate.
DeferredUpdates
::
doUpdates
();
}
/** @dataProvider provideOnLocalUserCreatedWhenNotSavedToPreventDuplicateEvent */
public
function
testOnLocalUserCreatedWhenNotSavedToPreventDuplicateEvent
(
$logRestrictionsConfig
)
{
$handler
=
$this
->
getObjectUnderTestForNoCheckUserInsertCalls
(
[
'config'
=>
new
HashConfig
(
[
MainConfigNames
::
NewUserLog
=>
true
,
MainConfigNames
::
LogRestrictions
=>
$logRestrictionsConfig
,
]
),
]
);
$handler
->
onLocalUserCreated
(
$this
->
createMock
(
User
::
class
),
false
);
}
public
static
function
provideOnLocalUserCreatedWhenNotSavedToPreventDuplicateEvent
()
{
return
[
'wgLogRestrictions is empty'
=>
[
[]
],
'wgLogRestrictions contains a "newusers" key with value of "*"'
=>
[
[
'newusers'
=>
'*'
]
],
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 22:42 (1 d, 21 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
9b/ae/cb797227976d3cdf550b9a7ae396
Default Alt Text
CheckUserPrivateEventsHandlerTest.php (4 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment