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;
|
|
|
|
|
2018-03-03 04:00:40 +00:00
|
|
|
/**
|
|
|
|
* @var int The ID of a deletion log entry.
|
|
|
|
*/
|
|
|
|
protected $logId;
|
|
|
|
|
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' );
|
2018-03-20 00:54:51 +00:00
|
|
|
|
|
|
|
$pageName = __CLASS__;
|
|
|
|
$content = __CLASS__;
|
|
|
|
$pageTitle = Title::newFromText( $pageName );
|
|
|
|
// If the page already exists, delete it, otherwise our edit will not result in a new revision
|
|
|
|
if ( $pageTitle->exists() ) {
|
|
|
|
$wikiPage = WikiPage::factory( $pageTitle );
|
|
|
|
$wikiPage->doDeleteArticleReal( '' );
|
|
|
|
}
|
|
|
|
$result = $this->editPage( $pageName, $content );
|
2016-05-06 14:27:05 +00:00
|
|
|
/** @var Status $result */
|
|
|
|
$result = $result->getValue();
|
|
|
|
/** @var Revision $revision */
|
|
|
|
$revision = $result['revision'];
|
|
|
|
$this->revId = $revision->getId();
|
|
|
|
|
2018-03-03 04:00:40 +00:00
|
|
|
// Create a 2nd page and delete it, so we can thank for the log entry.
|
|
|
|
$pageToDeleteTitle = Title::newFromText( 'Page to delete' );
|
|
|
|
$pageToDelete = WikiPage::factory( $pageToDeleteTitle );
|
|
|
|
$pageToDelete->doEditContent( ContentHandler::makeContent( '', $pageToDeleteTitle ), '' );
|
|
|
|
$deleteStatus = $pageToDelete->doDeleteArticleReal( '' );
|
|
|
|
$this->logId = $deleteStatus->getValue();
|
|
|
|
|
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-03 04:00:40 +00:00
|
|
|
public function testValidRevRequest() {
|
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 );
|
|
|
|
}
|
|
|
|
|
2018-03-03 04:00:40 +00:00
|
|
|
public function testValidLogRequest() {
|
|
|
|
list( $result,, ) = $this->doApiRequestWithToken( [
|
|
|
|
'action' => 'thank',
|
|
|
|
'log' => $this->logId,
|
|
|
|
] );
|
|
|
|
$this->assertSuccess( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLogRequestWithDisallowedLogType() {
|
|
|
|
// Empty the log-type whitelist.
|
|
|
|
$this->setMwGlobals( [ 'wgThanksLogTypeWhitelist' => [] ] );
|
|
|
|
$this->setExpectedException(
|
|
|
|
ApiUsageException::class,
|
|
|
|
"Log type 'delete' is not in the whitelist of permitted log types."
|
|
|
|
);
|
|
|
|
$this->doApiRequestWithToken( [
|
|
|
|
'action' => 'thank',
|
|
|
|
'log' => $this->logId,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLogThanksForADeletedLogEntry() {
|
|
|
|
global $wgUser;
|
|
|
|
|
|
|
|
// Mark our test log entry as deleted.
|
|
|
|
// To do this we briefly switch back to our 'uploader' test user.
|
|
|
|
$this->doLogin( 'uploader' );
|
|
|
|
$wgUser->mRights[] = 'deletelogentry';
|
|
|
|
$this->doApiRequestWithToken( [
|
|
|
|
'action' => 'revisiondelete',
|
|
|
|
'type' => 'logging',
|
|
|
|
'ids' => $this->logId,
|
|
|
|
'hide' => 'content',
|
|
|
|
] );
|
|
|
|
$this->doLogin( 'sysop' );
|
|
|
|
|
|
|
|
// Then try to thank for it, and we should get an exception.
|
|
|
|
$this->setExpectedException(
|
|
|
|
ApiUsageException::class,
|
|
|
|
"The requested log entry has been deleted and thanks cannot be given for it."
|
|
|
|
);
|
|
|
|
$this->doApiRequestWithToken( [
|
|
|
|
'action' => 'thank',
|
|
|
|
'log' => $this->logId,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|