mediawiki-extensions-Thanks/tests/phpunit/ApiRevThankIntegrationTest.php
Reedy b96f1a8b70 Remove 'UnitTestList' hook
No longer needed now that extension unittests are autodiscovered.

Bug: T142120
Bug: T142121
Change-Id: Ic856aa0d3d7af53f1405ceee43aff41bface3b58
2016-08-05 17:40:28 +01:00

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' ] );
}
}