jenkins-bot has submitted this change and it was merged.

Change subject: Added PHPunit tests for BounceHandler extesnsion
......................................................................


Added PHPunit tests for BounceHandler extesnsion

Test to check the IP whitelisting while a bouncehandler API request

Change-Id: Ib3f7f5cf4ba0e04f8563d09cddc425dfd06e982e
---
M BounceHandler.php
M BounceHandlerHooks.php
A tests/ApiBounceHandlerTest.php
3 files changed, 75 insertions(+), 0 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/BounceHandler.php b/BounceHandler.php
index 7a59148..7f6784f 100644
--- a/BounceHandler.php
+++ b/BounceHandler.php
@@ -37,6 +37,7 @@
 
 //Register Hooks
 $wgHooks['UserMailerChangeReturnPath'][] = 
'BounceHandlerHooks::onVERPAddressGenerate';
+$wgHooks['UnitTestsList'][] = 'BounceHandlerHooks::registerUnitTests';
 
 /*Messages Files */
 $wgMessagesDirs['BounceHandler'] = $dir. '/i18n';
diff --git a/BounceHandlerHooks.php b/BounceHandlerHooks.php
index 8d8a715..129b822 100644
--- a/BounceHandlerHooks.php
+++ b/BounceHandlerHooks.php
@@ -49,6 +49,34 @@
                return $returnPath;
        }
 
+
+       /**
+        * 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
+       }
+
        /**
         *
         * Add tables to Database
diff --git a/tests/ApiBounceHandlerTest.php b/tests/ApiBounceHandlerTest.php
new file mode 100644
index 0000000..42b8d54
--- /dev/null
+++ b/tests/ApiBounceHandlerTest.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Tests for API module
+ * @group API
+ * @group medium
+ */
+class ApiBounceHandlerTest extends ApiTestCase {
+
+       /**
+        * @var string
+        */
+       static $bounceEmail = "This is a test email";
+
+       function setUp() {
+               parent::setUp();
+               $this->doLogin( 'sysop' );
+       }
+
+       /**
+        * Tests API request from an allowed IP
+        */
+       function testBounceHandlerWithGoodIPPasses() {
+               $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'127.0.0.1' ) );
+               list( $apiResult ) = $this->doApiRequest( array(
+                       'action' => 'bouncehandler',
+                       'email' => self::$bounceEmail
+               ) );
+
+               $this->assertEquals( 'job', 
$apiResult['bouncehandler']['submitted'] );
+       }
+
+       /**
+        * Tests API request from an unknown IP
+        *
+        * @expectedException UsageException
+        * @expectedExceptionMessage This API module is for internal use only.
+        */
+       function testBounceHandlerWithBadIPPasses() {
+               $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'111.111.111.111' ) );
+               $this->doApiRequest( array(
+                       'action' => 'bouncehandler',
+                       'email' => self::$bounceEmail
+               ) );
+       }
+
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/151867
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib3f7f5cf4ba0e04f8563d09cddc425dfd06e982e
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: 01tonythomas <[email protected]>
Gerrit-Reviewer: 01tonythomas <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jgreen <[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

Reply via email to