mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-12-17 00:40:33 +00:00
5c0b21593f
Bug: T134582 Change-Id: I5317616f99f1344557fd818d0b00073a82197d05
79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Integration tests for the Thanks API module
|
|
*
|
|
* @covers ApiRevThank
|
|
*
|
|
* @group Thanks
|
|
* @group Database
|
|
* @group medium
|
|
* @group API
|
|
*
|
|
* @author Addshore
|
|
*/
|
|
class ApiRevThankIntegrationTest extends ApiTestCase {
|
|
|
|
/**
|
|
* @var int filled in setUp
|
|
*/
|
|
private $revId;
|
|
|
|
public function setUp() {
|
|
parent::setUp();
|
|
|
|
// You can't thank yourself, kind of hacky but just use this other user
|
|
$this->doLogin( 'uploader' );
|
|
$result = $this->editPage( __CLASS__ . rand( 0, 100 ), __CLASS__ . rand( 0, 100 ) );
|
|
/** @var Status $result */
|
|
$result = $result->getValue();
|
|
/** @var Revision $revision */
|
|
$revision = $result['revision'];
|
|
$this->revId = $revision->getId();
|
|
|
|
$this->doLogin( 'sysop' );
|
|
DeferredUpdates::clearPendingUpdates();
|
|
}
|
|
|
|
public function testRequestWithoutToken() {
|
|
$this->setExpectedException( 'UsageException', 'The token parameter must be set' );
|
|
$this->doApiRequest( [
|
|
'action' => 'thank',
|
|
'source' => 'someSource',
|
|
'rev' => 1,
|
|
] );
|
|
}
|
|
|
|
public function testValidRequest() {
|
|
list( $result,, ) = $this->doApiRequestWithToken( [
|
|
'action' => 'thank',
|
|
'rev' => $this->revId,
|
|
] );
|
|
$this->assertSuccess( $result );
|
|
}
|
|
|
|
public function testValidRequestWithSource() {
|
|
list( $result,, ) = $this->doApiRequestWithToken( [
|
|
'action' => 'thank',
|
|
'source' => 'someSource',
|
|
'rev' => $this->revId,
|
|
] );
|
|
$this->assertSuccess( $result );
|
|
}
|
|
|
|
protected function assertSuccess( $result ) {
|
|
$this->assertEquals( [
|
|
'result' => [
|
|
'success' => 1,
|
|
'recipient' => self::$users['uploader']->getUser()->getName(),
|
|
],
|
|
], $result );
|
|
}
|
|
|
|
public function testInvalidRequest() {
|
|
$this->setExpectedException( 'UsageException' );
|
|
$this->doApiRequestWithToken( [ 'action' => 'thank' ] );
|
|
}
|
|
|
|
}
|