2013-11-02 13:36:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-26 02:12:47 +00:00
|
|
|
* Integration tests for the Thanks API module
|
2013-11-15 18:34:53 +00:00
|
|
|
*
|
2018-02-21 03:46:30 +00:00
|
|
|
* @covers ApiCoreThank
|
2013-11-02 13:36:44 +00:00
|
|
|
*
|
|
|
|
* @group Thanks
|
|
|
|
* @group Database
|
|
|
|
* @group medium
|
|
|
|
* @group API
|
|
|
|
*
|
2016-01-27 10:06:17 +00:00
|
|
|
* @author Addshore
|
2013-11-02 13:36:44 +00:00
|
|
|
*/
|
2018-02-21 03:46:30 +00:00
|
|
|
class ApiCoreThankIntegrationTest extends ApiTestCase {
|
2013-11-02 13:36:44 +00:00
|
|
|
|
2016-05-06 14:27:05 +00:00
|
|
|
/**
|
|
|
|
* @var int filled in setUp
|
|
|
|
*/
|
|
|
|
private $revId;
|
|
|
|
|
2013-11-02 13:36:44 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2016-05-06 14:27:05 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2013-11-02 13:36:44 +00:00
|
|
|
$this->doLogin( 'sysop' );
|
2016-05-06 14:27:05 +00:00
|
|
|
DeferredUpdates::clearPendingUpdates();
|
2013-11-02 13:36:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
public function testRequestWithoutToken() {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->setExpectedException( 'ApiUsageException', 'The "token" parameter must be set.' );
|
2016-04-22 20:13:56 +00:00
|
|
|
$this->doApiRequest( [
|
2013-11-02 13:36:44 +00:00
|
|
|
'action' => 'thank',
|
|
|
|
'source' => 'someSource',
|
|
|
|
'rev' => 1,
|
2016-04-22 20:13:56 +00:00
|
|
|
] );
|
2013-11-02 13:36:44 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 22:59:20 +00:00
|
|
|
public function testValidRequest() {
|
2016-04-22 20:13:56 +00:00
|
|
|
list( $result,, ) = $this->doApiRequestWithToken( [
|
2013-11-02 13:36:44 +00:00
|
|
|
'action' => 'thank',
|
2016-05-06 14:27:05 +00:00
|
|
|
'rev' => $this->revId,
|
2016-04-22 20:13:56 +00:00
|
|
|
] );
|
2013-11-02 13:36:44 +00:00
|
|
|
$this->assertSuccess( $result );
|
|
|
|
}
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
public function testValidRequestWithSource() {
|
|
|
|
list( $result,, ) = $this->doApiRequestWithToken( [
|
2013-11-02 13:36:44 +00:00
|
|
|
'action' => 'thank',
|
|
|
|
'source' => 'someSource',
|
2016-05-06 14:27:05 +00:00
|
|
|
'rev' => $this->revId,
|
2016-04-22 20:13:56 +00:00
|
|
|
] );
|
2013-11-02 13:36:44 +00:00
|
|
|
$this->assertSuccess( $result );
|
|
|
|
}
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
protected function assertSuccess( $result ) {
|
|
|
|
$this->assertEquals( [
|
|
|
|
'result' => [
|
2013-10-24 01:13:43 +00:00
|
|
|
'success' => 1,
|
2016-05-06 14:27:05 +00:00
|
|
|
'recipient' => self::$users['uploader']->getUser()->getName(),
|
2016-04-22 20:13:56 +00:00
|
|
|
],
|
|
|
|
], $result );
|
2013-11-02 13:36:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
public function testInvalidRequest() {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->setExpectedException( 'ApiUsageException' );
|
2016-04-22 20:13:56 +00:00
|
|
|
$this->doApiRequestWithToken( [ 'action' => 'thank' ] );
|
2013-11-02 13:36:44 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 08:00:55 +00:00
|
|
|
}
|