jenkins-bot has submitted this change and it was merged.
Change subject: Add really basic API tests
......................................................................
Add really basic API tests
This also includes the unit test hooks
Jenkings job will be added with I6ec2edf62b9
Change-Id: Id085db7096db420416e9fba72a65586d021f1c76
---
M Thanks.hooks.php
M Thanks.php
M ThanksFormatter.php
A tests/ApiThankTest.php
4 files changed, 93 insertions(+), 0 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Thanks.hooks.php b/Thanks.hooks.php
index c6f2f87..eb0796d 100644
--- a/Thanks.hooks.php
+++ b/Thanks.hooks.php
@@ -207,4 +207,31 @@
}
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
+ }
}
diff --git a/Thanks.php b/Thanks.php
index f79a2aa..e4c2d00 100644
--- a/Thanks.php
+++ b/Thanks.php
@@ -59,6 +59,7 @@
$wgHooks['EchoGetDefaultNotifiedUsers'][] =
'ThanksHooks::onEchoGetDefaultNotifiedUsers';
$wgHooks['AddNewAccount'][] = 'ThanksHooks::onAccountCreated';
$wgHooks['BeforeSpecialMobileDiffDisplay'][] =
'ThanksHooks::onBeforeSpecialMobileDiffDisplay';
+$wgHooks['UnitTestsList'][] = 'ThanksHooks::registerUnitTests';
// Register modules
$wgResourceModules['ext.thanks'] = array(
diff --git a/ThanksFormatter.php b/ThanksFormatter.php
index a26ebc0..a7a2aa3 100644
--- a/ThanksFormatter.php
+++ b/ThanksFormatter.php
@@ -27,6 +27,7 @@
)
)
);
+
} else {
parent::processParam( $event, $param, $message, $user );
}
diff --git a/tests/ApiThankTest.php b/tests/ApiThankTest.php
new file mode 100644
index 0000000..e92efc6
--- /dev/null
+++ b/tests/ApiThankTest.php
@@ -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' ) );
+ }
+
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/93161
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id085db7096db420416e9fba72a65586d021f1c76
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits