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
|
|
|
*
|
2014-02-26 02:12:47 +00:00
|
|
|
* @covers ApiRevThank
|
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
|
|
|
*/
|
2014-02-26 02:12:47 +00:00
|
|
|
class ApiRevThankTest extends ApiTestCase {
|
2013-11-02 13:36:44 +00:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->doLogin( 'sysop' );
|
2014-10-29 18:58:27 +00:00
|
|
|
\DeferredUpdates::clearPendingUpdates();
|
2016-03-29 22:11:52 +00:00
|
|
|
// Make one edit
|
|
|
|
$this->newRevId();
|
2013-11-02 13:36:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
public function testRequestWithoutToken() {
|
2013-11-02 13:36:44 +00:00
|
|
|
$this->setExpectedException( 'UsageException', '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
|
|
|
}
|
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
public function testValidRequest() {
|
|
|
|
list( $result,, ) = $this->doApiRequestWithToken( [
|
2013-11-02 13:36:44 +00:00
|
|
|
'action' => 'thank',
|
|
|
|
'rev' => $this->newRevId(),
|
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',
|
|
|
|
'rev' => $this->newRevId(),
|
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 newRevId() {
|
2013-11-24 06:45:12 +00:00
|
|
|
// You can't thank yourself, kind of hacky
|
2015-08-07 16:06:47 +00:00
|
|
|
$this->setMwGlobals( 'wgUser', self::$users['uploader']->getUser() );
|
2013-11-24 06:45:12 +00:00
|
|
|
|
2013-11-02 13:36:44 +00:00
|
|
|
/** @var Status $result */
|
2016-04-22 20:13:56 +00:00
|
|
|
$result = $this->editPage(
|
|
|
|
'thanks' . rand( 0, 100 ),
|
|
|
|
'thanks' . rand( 0, 100 ),
|
|
|
|
'thanksSummary'
|
|
|
|
);
|
2013-11-02 13:36:44 +00:00
|
|
|
$result = $result->getValue();
|
|
|
|
/** @var Revision $revision */
|
|
|
|
$revision = $result['revision'];
|
2013-11-24 06:45:12 +00:00
|
|
|
|
2015-08-07 16:06:47 +00:00
|
|
|
$this->setMwGlobals( 'wgUser', self::$users['sysop']->getUser() );
|
2013-11-24 06:45:12 +00:00
|
|
|
|
2013-11-02 13:36:44 +00:00
|
|
|
return $revision->getId();
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
'recipient' => self::$users['uploader']->username,
|
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() {
|
2013-11-02 13:36:44 +00:00
|
|
|
$this->setExpectedException( 'UsageException' );
|
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
|
|
|
}
|