mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-24 23:05:26 +00:00
ed087b044c
Originally introduced in b84eedc74e
, it was reverted for security concerns.
New changes:
* Instead of bundling the log summary with notification, load it on display
* If the log event has been suppressed after the thanks for it has been sent,
silently delete the event to prevent the confusion of linking to something
zapped.
* Keep the 'already sent' cache key compatible with old format
* Validate the log id in the API
* Change ApiCoreThank::getRevisionFromParams() to ApiCoreThank::getRevisionFromId()
Bug: T186855
Bug: T188791
Depends-On: Ic5e9db0def857d9dcecbd06bf081c8c83712c1ea
Change-Id: I03aea7d9f4dfa0fe49639c53968deabf89999d2d
138 lines
3.5 KiB
PHP
138 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Integration tests for the Thanks API module
|
|
*
|
|
* @covers ApiCoreThank
|
|
*
|
|
* @group Thanks
|
|
* @group Database
|
|
* @group medium
|
|
* @group API
|
|
*
|
|
* @author Addshore
|
|
*/
|
|
class ApiCoreThankIntegrationTest extends ApiTestCase {
|
|
|
|
/**
|
|
* @var int filled in setUp
|
|
*/
|
|
private $revId;
|
|
|
|
/**
|
|
* @var int The ID of a deletion log entry.
|
|
*/
|
|
protected $logId;
|
|
|
|
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();
|
|
|
|
// 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();
|
|
|
|
$this->doLogin( 'sysop' );
|
|
DeferredUpdates::clearPendingUpdates();
|
|
}
|
|
|
|
public function testRequestWithoutToken() {
|
|
$this->setExpectedException( 'ApiUsageException', 'The "token" parameter must be set.' );
|
|
$this->doApiRequest( [
|
|
'action' => 'thank',
|
|
'source' => 'someSource',
|
|
'rev' => 1,
|
|
] );
|
|
}
|
|
|
|
public function testValidRevRequest() {
|
|
list( $result,, ) = $this->doApiRequestWithToken( [
|
|
'action' => 'thank',
|
|
'rev' => $this->revId,
|
|
] );
|
|
$this->assertSuccess( $result );
|
|
}
|
|
|
|
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,
|
|
] );
|
|
}
|
|
|
|
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( 'ApiUsageException' );
|
|
$this->doApiRequestWithToken( [ 'action' => 'thank' ] );
|
|
}
|
|
|
|
}
|