2013-11-15 18:34:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-26 02:12:47 +00:00
|
|
|
* Unit tests for the Thanks API module
|
2013-11-15 18:34:53 +00:00
|
|
|
*
|
|
|
|
* @group Thanks
|
|
|
|
* @group API
|
|
|
|
*
|
2016-01-27 10:06:17 +00:00
|
|
|
* @author Addshore
|
2013-11-15 18:34:53 +00:00
|
|
|
*/
|
2014-02-26 02:12:47 +00:00
|
|
|
class ApiRevThankUnitTest extends MediaWikiTestCase {
|
2013-11-15 18:34:53 +00:00
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
protected static $moduleName = 'thank';
|
2013-11-15 18:34:53 +00:00
|
|
|
|
|
|
|
protected function getModule() {
|
2014-02-26 02:12:47 +00:00
|
|
|
return new ApiRevThank( new ApiMain(), self::$moduleName );
|
2013-11-15 18:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideDieOnBadUser
|
|
|
|
* @covers ApiThank::dieOnBadUser
|
|
|
|
*/
|
|
|
|
public function testDieOnBadUser( $user, $expectedError ) {
|
|
|
|
$module = $this->getModule();
|
|
|
|
$method = new ReflectionMethod( $module, 'dieOnBadUser' );
|
|
|
|
$method->setAccessible( true );
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
if ( $expectedError ) {
|
2013-11-15 18:34:53 +00:00
|
|
|
$this->setExpectedException( 'UsageException', $expectedError );
|
|
|
|
}
|
|
|
|
|
|
|
|
$method->invoke( $module, $user );
|
2016-04-22 20:13:56 +00:00
|
|
|
// perhaps the method should return true.. For now we must do this
|
2013-11-15 18:34:53 +00:00
|
|
|
$this->assertTrue( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideDieOnBadUser() {
|
2016-04-22 20:13:56 +00:00
|
|
|
$testCases = [];
|
2013-11-15 18:34:53 +00:00
|
|
|
|
|
|
|
$mockUser = $this->getMock( 'User' );
|
|
|
|
$mockUser->expects( $this->once() )
|
|
|
|
->method( 'isAnon' )
|
|
|
|
->will( $this->returnValue( true ) );
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
$testCases[ 'anon' ] = [ $mockUser, 'Anonymous users cannot send thanks' ];
|
2013-11-15 18:34:53 +00:00
|
|
|
|
|
|
|
$mockUser = $this->getMock( 'User' );
|
|
|
|
$mockUser->expects( $this->once() )
|
|
|
|
->method( 'isAnon' )
|
|
|
|
->will( $this->returnValue( false ) );
|
|
|
|
$mockUser->expects( $this->once() )
|
|
|
|
->method( 'pingLimiter' )
|
|
|
|
->will( $this->returnValue( true ) );
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
$testCases[ 'ping' ] = [
|
|
|
|
$mockUser,
|
|
|
|
"You've exceeded your rate limit. Please wait some time and try again"
|
|
|
|
];
|
2013-11-15 18:34:53 +00:00
|
|
|
|
|
|
|
$mockUser = $this->getMock( 'User' );
|
|
|
|
$mockUser->expects( $this->once() )
|
|
|
|
->method( 'isAnon' )
|
|
|
|
->will( $this->returnValue( false ) );
|
|
|
|
$mockUser->expects( $this->once() )
|
|
|
|
->method( 'pingLimiter' )
|
|
|
|
->will( $this->returnValue( false ) );
|
|
|
|
$mockUser->expects( $this->once() )
|
|
|
|
->method( 'isBlocked' )
|
|
|
|
->will( $this->returnValue( true ) );
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
$testCases[ 'blocked' ] = [ $mockUser, 'You have been blocked from editing' ];
|
2013-11-15 18:34:53 +00:00
|
|
|
|
|
|
|
return $testCases;
|
|
|
|
}
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
// @todo test userAlreadySentThanksForRevision
|
|
|
|
// @todo test getRevisionFromParams
|
|
|
|
// @todo test getTitleFromRevision
|
|
|
|
// @todo test getSourceFromParams
|
|
|
|
// @todo test getUserIdFromRevision
|
|
|
|
// @todo test markResultSuccess
|
|
|
|
// @todo test sendThanks
|
2013-11-15 18:34:53 +00:00
|
|
|
|
|
|
|
}
|