mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-13 17:52:33 +00:00
Add really basic API tests
This also includes the unit test hooks Jenkings job will be added with I6ec2edf62b9 Change-Id: Id085db7096db420416e9fba72a65586d021f1c76
This commit is contained in:
parent
e7f3c65fde
commit
422f0f6062
|
@ -207,4 +207,31 @@ class ThanksHooks {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to add PHPUnit test cases.
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
|
||||
*
|
||||
* @param array &$files
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function registerUnitTests( array &$files ) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/' );
|
||||
|
||||
/**
|
||||
* @var SplFileInfo $fileInfo
|
||||
*/
|
||||
$ourFiles = array();
|
||||
foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
|
||||
if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
|
||||
$ourFiles[] = $fileInfo->getPathname();
|
||||
}
|
||||
}
|
||||
|
||||
$files = array_merge( $files, $ourFiles );
|
||||
return true;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ $wgHooks['BeforeCreateEchoEvent'][] = 'ThanksHooks::onBeforeCreateEchoEvent';
|
|||
$wgHooks['EchoGetDefaultNotifiedUsers'][] = 'ThanksHooks::onEchoGetDefaultNotifiedUsers';
|
||||
$wgHooks['AddNewAccount'][] = 'ThanksHooks::onAccountCreated';
|
||||
$wgHooks['BeforeSpecialMobileDiffDisplay'][] = 'ThanksHooks::onBeforeSpecialMobileDiffDisplay';
|
||||
$wgHooks['UnitTestsList'][] = 'ThanksHooks::registerUnitTests';
|
||||
|
||||
// Register modules
|
||||
$wgResourceModules['ext.thanks'] = array(
|
||||
|
|
|
@ -27,6 +27,7 @@ class EchoThanksFormatter extends EchoBasicFormatter {
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
parent::processParam( $event, $param, $message, $user );
|
||||
}
|
||||
|
|
64
tests/ApiThankTest.php
Normal file
64
tests/ApiThankTest.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @covers ApiThank
|
||||
*
|
||||
* @group Thanks
|
||||
* @group Database
|
||||
* @group medium
|
||||
* @group API
|
||||
*
|
||||
* @author Adam Shorland
|
||||
*/
|
||||
class ApiThankTest extends \ApiTestCase {
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->doLogin( 'sysop' );
|
||||
}
|
||||
|
||||
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(){
|
||||
/** @var Status $result */
|
||||
$result = $this->editPage( 'thanks' . rand( 0, 100 ), 'thanks' . rand( 0, 100 ), 'thanksSummary' );
|
||||
$result = $result->getValue();
|
||||
/** @var Revision $revision */
|
||||
$revision = $result['revision'];
|
||||
return $revision->getId();
|
||||
}
|
||||
|
||||
protected function assertSuccess( $result ){
|
||||
$this->assertEquals( array( 'result' => array( 'success' => 1 ) ), $result );
|
||||
}
|
||||
|
||||
public function testInvalidRequest(){
|
||||
$this->setExpectedException( 'UsageException' );
|
||||
$this->doApiRequestWithToken( array( 'action' => 'thank' ) );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue