Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/365630 )

Change subject: Common setup for donation API tests, add one for PayPal EC
......................................................................

Common setup for donation API tests, add one for PayPal EC

Bug: T167923
Change-Id: I2664e4c3747be462b396b715b795c0506f3d3d47
---
M DonationInterface.class.php
M tests/phpunit/Adapter/Amazon/AmazonApiTest.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php
A tests/phpunit/Adapter/PayPal/PayPalApiTest.php
A tests/phpunit/DonationInterfaceApiTestCase.php
M tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
6 files changed, 109 insertions(+), 27 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/30/365630/1

diff --git a/DonationInterface.class.php b/DonationInterface.class.php
index 2f2f7db..2a0f3e4 100644
--- a/DonationInterface.class.php
+++ b/DonationInterface.class.php
@@ -68,6 +68,7 @@
                $files[] = $testDir . 'AllTests.php';
 
                $wgAutoloadClasses['DonationInterfaceTestCase'] = $testDir . 
'DonationInterfaceTestCase.php';
+               $wgAutoloadClasses['DonationInterfaceApiTestCase'] = $testDir . 
'DonationInterfaceApiTestCase.php';
                $wgAutoloadClasses['MockAmazonClient'] = $testDir . 
'includes/MockAmazonClient.php';
                $wgAutoloadClasses['MockAmazonResponse'] = $testDir . 
'includes/MockAmazonResponse.php';
                $wgAutoloadClasses['TestingQueue'] = $testDir . 
'includes/TestingQueue.php';
diff --git a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php 
b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
index 8ee1c83..4f5c0ab 100644
--- a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
+++ b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
@@ -4,20 +4,15 @@
 
 /**
  * @group Amazon
+ * @group DonationInterface
+ * @group DonationInterfaceApi
+ * @group Fundraising
  * @group medium
  */
-class AmazonApiTest extends ApiTestCase {
+class AmazonApiTest extends DonationInterfaceApiTestCase {
        public function setUp() {
                parent::setUp();
-               $config = TestingGlobalConfiguration::create();
-               TestingContext::init( $config );
                TestingAmazonAdapter::$mockClient = new MockAmazonClient();
-               $this->setMwGlobals( array(
-                       'wgDonationInterfaceEnableQueue' => true,
-                       'wgDonationInterfaceDefaultQueueServer' => array(
-                               'type' => 'TestingQueue',
-                       ),
-               ) );
        }
 
        public function tearDown() {
diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php 
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php
index f3738eb..285495d 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectApiTest.php
@@ -1,23 +1,15 @@
 <?php
-
-use SmashPig\Tests\TestingContext;
-use SmashPig\Tests\TestingGlobalConfiguration;
+use SmashPig\CrmLink\Messages\SourceFields;
 
 /**
  * @group Fundraising
  * @group DonationInterface
  * @group GlobalCollect
  * @group GlobalCollectApi
+ * @group DonationInterfaceApi
  * @group medium
  */
-
-class GlobalCollectApiTest extends ApiTestCase {
-
-       public function setUp() {
-               parent::setUp();
-               $config = TestingGlobalConfiguration::create();
-               TestingContext::init( $config );
-       }
+class GlobalCollectApiTest extends DonationInterfaceApiTestCase {
 
        public function testGoodSubmit() {
                $init = DonationInterfaceTestCase::getDonorTestData();
@@ -35,5 +27,33 @@
                $this->assertTrue( $result['status'], 'GC API result status 
should be true' );
                preg_match( 
"/Special:GlobalCollectGatewayResult\?order_id={$orderId}\$/", 
$result['returnurl'], $match );
                $this->assertNotEmpty( $match, 'GC API not setting proper 
return url' );
+               $message = DonationQueue::instance()->pop( 'pending' );
+               $this->assertNotNull( $message, 'Not sending a message to the 
pending queue' );
+               SourceFields::removeFromMessage( $message );
+               $expected = array(
+                       'gateway_txn_id' => '626113410',
+                       'response' => 'Response Status: 20',
+                       'gateway_account' => 'test',
+                       'fee' => 0,
+                       'utm_source' => '..cc',
+                       'language' => 'en',
+                       'email' => 'g...@innocent.com',
+                       'first_name' => 'Firstname',
+                       'last_name' => 'Surname',
+                       'country' => 'US',
+                       'gateway' => 'globalcollect',
+                       'order_id' => '626113410',
+                       'recurring' => '',
+                       'payment_method' => 'cc',
+                       'payment_submethod' => '',
+                       'currency' => 'USD',
+                       'gross' => '1.55',
+                       'user_ip' => '127.0.0.1',
+                       'street_address' => '123 Fake Street',
+                       'city' => 'San Francisco',
+                       'state_province' => 'CA',
+                       'postal_code' => '94105'
+               );
+               $this->assertArraySubset( $expected, $message );
        }
 }
diff --git a/tests/phpunit/Adapter/PayPal/PayPalApiTest.php 
b/tests/phpunit/Adapter/PayPal/PayPalApiTest.php
new file mode 100644
index 0000000..86d76ed
--- /dev/null
+++ b/tests/phpunit/Adapter/PayPal/PayPalApiTest.php
@@ -0,0 +1,47 @@
+<?php
+use SmashPig\PaymentProviders\PayPal\Tests\PayPalTestConfiguration;
+use SmashPig\Tests\TestingContext;
+
+/**
+ * @group Fundraising
+ * @group DonationInterface
+ * @group PayPal
+ * @group DonationInterfaceApi
+ * @group medium
+ */
+class PayPalApiTest extends DonationInterfaceApiTestCase {
+
+       public function setUp() {
+               parent::setUp();
+               $ctx = TestingContext::get();
+               $ctx->providerConfigurationOverride = 
PayPalTestConfiguration::get(
+                       $ctx->getGlobalConfiguration()
+               );
+               $this->setMwGlobals( array(
+                       'wgDonationInterfaceCancelPage' => 
'https://example.com/tryAgain.php',
+                       'wgPaypalExpressGatewayEnabled' => true,
+                       'wgDonationInterfaceThankYouPage' => 
'https://example.org/wiki/Thank_You',
+               ) );
+       }
+
+       public function testGoodSubmit() {
+               $init = array(
+                       'amount' => 1.55,
+                       'currency' => 'USD',
+                       'payment_method' => 'paypal',
+                       'utm_source' => 'CD1234_FR',
+                       'utm_medium' => 'sitenotice',
+                       'country' => 'US',
+                       'contribution_tracking_id' => strval( mt_rand() ),
+                       'language' => 'fr',
+               );
+               $init['gateway'] = 'paypal_ec';
+               $init['action'] = 'donate';
+
+               $apiResult = $this->doApiRequest( $init );
+               $result = $apiResult[0]['result'];
+               $expectedUrl = 
'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-8US12345X1234567U';
+               $this->assertEquals( $expectedUrl, $result['formaction'], 
'PayPal Express API not setting formaction' );
+               $this->assertTrue( $result['status'], 'PayPal Express result 
status should be true' );
+       }
+}
diff --git a/tests/phpunit/DonationInterfaceApiTestCase.php 
b/tests/phpunit/DonationInterfaceApiTestCase.php
new file mode 100644
index 0000000..d50ec00
--- /dev/null
+++ b/tests/phpunit/DonationInterfaceApiTestCase.php
@@ -0,0 +1,26 @@
+<?php
+
+use SmashPig\Core\Context;
+use SmashPig\Tests\TestingContext;
+use SmashPig\Tests\TestingGlobalConfiguration;
+
+class DonationInterfaceApiTestCase extends ApiTestCase {
+
+       public function setUp() {
+               parent::setUp();
+               $config = TestingGlobalConfiguration::create();
+               TestingContext::init( $config );
+               $this->setMwGlobals( array(
+                       'wgDonationInterfaceEnableQueue' => true,
+                       'wgDonationInterfaceDefaultQueueServer' => array(
+                               'type' => 'TestingQueue',
+                       ),
+               ) );
+       }
+
+       public function tearDown() {
+               parent::tearDown();
+               Context::set( null );
+               TestingQueue::clearAll();
+       }
+}
diff --git 
a/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php 
b/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
index 728c435..a936b6c 100644
--- a/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
+++ b/tests/phpunit/includes/test_gateway/TestingGlobalCollectAdapter.php
@@ -9,8 +9,6 @@
 
        public $curled = array ( );
 
-       public $pending_messages = array();
-
        public $dummyGatewayResponseCode;
 
        /**
@@ -45,11 +43,6 @@
                        return;
                }
                parent::defineOrderIDMeta();
-       }
-
-       // TODO: Store and test the actual messages.
-       public function sendPendingMessage() {
-               $this->pending_messages[] = false;
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2664e4c3747be462b396b715b795c0506f3d3d47
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to