Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/93161


Change subject: Add really basic API tests
......................................................................

Add really basic API tests

Change-Id: Id085db7096db420416e9fba72a65586d021f1c76
---
A tests/ApiTest.php
1 file changed, 65 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks 
refs/changes/61/93161/1

diff --git a/tests/ApiTest.php b/tests/ApiTest.php
new file mode 100644
index 0000000..b6f902a
--- /dev/null
+++ b/tests/ApiTest.php
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * @covers ApiThank
+ *
+ * @group Thanks
+ * @group Database
+ * @group medium
+ * @group API
+ *
+ * @licence GNU GPL v2+
+ * @author Adam Shorland
+ */
+class ApiTest 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: newchange
Gerrit-Change-Id: Id085db7096db420416e9fba72a65586d021f1c76
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to