mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-12-11 14:36:09 +00:00
9cef38e80f
It has been decided to not allow temporary users to thank other users (see task). This is because the transition between anonymous and temporary account is nearly invisible, and it might be confusing why the thanking ability appears and hides. Bug: T345679 Change-Id: I62e67327c9a80b3da9e98a2dccdd4ec2051f3026
125 lines
2.7 KiB
PHP
125 lines
2.7 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
|
use MediaWiki\Extension\Thanks\Api\ApiCoreThank;
|
|
use MediaWiki\User\UserIdentityValue;
|
|
|
|
/**
|
|
* Unit tests for the Thanks API module
|
|
*
|
|
* @group Thanks
|
|
* @group API
|
|
* @group Database
|
|
*
|
|
* @author Addshore
|
|
*/
|
|
class ApiCoreThankUnitTest extends ApiTestCase {
|
|
|
|
protected function getModule() {
|
|
$services = $this->getServiceContainer();
|
|
return new ApiCoreThank(
|
|
new ApiMain(),
|
|
'thank',
|
|
$services->getPermissionManager(),
|
|
$services->getRevisionStore(),
|
|
$services->getUserFactory(),
|
|
$services->getService( 'ThanksLogStore' )
|
|
);
|
|
}
|
|
|
|
private static function createBlock( $options ) {
|
|
$options = array_merge( [
|
|
'address' => 'Test user',
|
|
'by' => new UserIdentityValue( 1, 'TestUser' ),
|
|
'reason' => __METHOD__,
|
|
'timestamp' => wfTimestamp( TS_MW ),
|
|
'expiry' => 'infinity',
|
|
], $options );
|
|
return new DatabaseBlock( $options );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideDieOnBadUser
|
|
* @covers \MediaWiki\Extension\Thanks\Api\ApiThank::dieOnBadUser
|
|
* @covers \MediaWiki\Extension\Thanks\Api\ApiThank::dieOnUserBlockedFromThanks
|
|
*/
|
|
public function testDieOnBadUser(
|
|
$mockisNamed,
|
|
$mockPingLimited,
|
|
$mockBlock,
|
|
$dieMethod,
|
|
$expectedError
|
|
) {
|
|
$user = $this->createMock( User::class );
|
|
if ( $mockisNamed !== null ) {
|
|
$user->expects( $this->once() )
|
|
->method( 'isNamed' )
|
|
->willReturn( $mockisNamed );
|
|
}
|
|
if ( $mockPingLimited !== null ) {
|
|
$user->expects( $this->once() )
|
|
->method( 'pingLimiter' )
|
|
->willReturn( $mockPingLimited );
|
|
}
|
|
if ( $mockBlock !== null ) {
|
|
$user->expects( $this->once() )
|
|
->method( 'getBlock' )
|
|
->willReturn( $mockBlock );
|
|
}
|
|
|
|
$module = $this->getModule();
|
|
$method = new ReflectionMethod( $module, $dieMethod );
|
|
$method->setAccessible( true );
|
|
|
|
if ( $expectedError ) {
|
|
$this->expectApiErrorCode( $expectedError );
|
|
}
|
|
|
|
$method->invoke( $module, $user );
|
|
// perhaps the method should return true.. For now we must do this
|
|
$this->assertTrue( true );
|
|
}
|
|
|
|
public static function provideDieOnBadUser() {
|
|
return [
|
|
'anon' => [
|
|
false,
|
|
null,
|
|
null,
|
|
'dieOnBadUser',
|
|
'notloggedin'
|
|
],
|
|
'ping' => [
|
|
true,
|
|
true,
|
|
null,
|
|
'dieOnBadUser',
|
|
'ratelimited'
|
|
],
|
|
'sitewide blocked' => [
|
|
null,
|
|
null,
|
|
self::createBlock( [] ),
|
|
'dieOnUserBlockedFromThanks',
|
|
'blocked'
|
|
],
|
|
'partial blocked' => [
|
|
null,
|
|
null,
|
|
self::createBlock( [ 'sitewide' => false ] ),
|
|
'dieOnUserBlockedFromThanks',
|
|
false
|
|
],
|
|
];
|
|
}
|
|
|
|
// @todo test userAlreadySentThanksForRevision
|
|
// @todo test getRevisionFromParams
|
|
// @todo test getTitleFromRevision
|
|
// @todo test getSourceFromParams
|
|
// @todo test getUserIdFromRevision
|
|
// @todo test markResultSuccess
|
|
// @todo test sendThanks
|
|
|
|
}
|