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
|
|
|
|
*
|
|
|
|
* @author Adam Shorland
|
|
|
|
*/
|
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();
|
2013-11-02 13:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRequestWithoutToken(){
|
|
|
|
$this->setExpectedException( 'UsageException', 'The token parameter must be set' );
|
|
|
|
$this->doApiRequest( array(
|
|
|
|
'action' => 'thank',
|
|
|
|
'source' => 'someSource',
|
|
|
|
'rev' => 1,
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidRequest(){
|
|
|
|
list( $result,, ) = $this->doApiRequestWithToken( array(
|
|
|
|
'action' => 'thank',
|
|
|
|
'rev' => $this->newRevId(),
|
|
|
|
) );
|
|
|
|
$this->assertSuccess( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidRequestWithSource(){
|
|
|
|
list( $result,, ) = $this->doApiRequestWithToken( array(
|
|
|
|
'action' => 'thank',
|
|
|
|
'source' => 'someSource',
|
|
|
|
'rev' => $this->newRevId(),
|
|
|
|
) );
|
|
|
|
$this->assertSuccess( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function newRevId(){
|
2013-11-24 06:45:12 +00:00
|
|
|
// You can't thank yourself, kind of hacky
|
|
|
|
$this->setMwGlobals( 'wgUser' , self::$users['uploader']->user );
|
|
|
|
|
2013-11-02 13:36:44 +00:00
|
|
|
/** @var Status $result */
|
|
|
|
$result = $this->editPage( 'thanks' . rand( 0, 100 ), 'thanks' . rand( 0, 100 ), 'thanksSummary' );
|
|
|
|
$result = $result->getValue();
|
|
|
|
/** @var Revision $revision */
|
|
|
|
$revision = $result['revision'];
|
2013-11-24 06:45:12 +00:00
|
|
|
|
|
|
|
$this->setMwGlobals( 'wgUser' , self::$users['sysop']->user );
|
|
|
|
|
2013-11-02 13:36:44 +00:00
|
|
|
return $revision->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function assertSuccess( $result ){
|
2013-10-24 01:13:43 +00:00
|
|
|
$this->assertEquals( array(
|
|
|
|
'result' => array(
|
|
|
|
'success' => 1,
|
|
|
|
'recipient' => self::$users['uploader']->username,
|
|
|
|
),
|
|
|
|
), $result );
|
2013-11-02 13:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidRequest(){
|
|
|
|
$this->setExpectedException( 'UsageException' );
|
|
|
|
$this->doApiRequestWithToken( array( 'action' => 'thank' ) );
|
|
|
|
}
|
|
|
|
|
2013-12-06 08:00:55 +00:00
|
|
|
}
|