Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/283003
Change subject: Merge master into deployment
......................................................................
Merge master into deployment
d6f9a8b142d3fa478bb5b47dbe78f1a681e3142f New column headers for JP Morgan
eaa2d2e74f88351a15cd7a9b12d4c008348e8dd8 Split out contribution save hook
de93632e477fe24a0ffad78a639bcf9aa13855e7 Fix source field on partial refunds
c33e3505fce9511e544fdf29c9f8b5e187d6232c Whitespace + readability
Change-Id: Idf27e6c6731fd60d5b5aba52441f992f1ab267b3
---
D sites/all/modules/offline2civicrm/tests/JpMorganFileTest.php
D sites/all/modules/offline2civicrm/tests/data/jpmorgan.csv
D sites/all/modules/wmf_civicrm/tests/phpunit/InstallFunctionsTest.php
D sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
4 files changed, 0 insertions(+), 414 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/03/283003/1
diff --git a/sites/all/modules/offline2civicrm/tests/JpMorganFileTest.php
b/sites/all/modules/offline2civicrm/tests/JpMorganFileTest.php
deleted file mode 100644
index 415049d..0000000
--- a/sites/all/modules/offline2civicrm/tests/JpMorganFileTest.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<<<<<<< HEAD (a20ac4 Merge master into deployment)
-=======
-<?php
-
-/**
- * @group Import
- * @group Offline2Civicrm
- */
-class JpMorganFileTest extends BaseChecksFileTest {
- protected $epochtime;
- protected $strtime;
-
- function setUp() {
- parent::setUp();
-
- require_once __DIR__ . "/includes/JpMorganFileProbe.php";
-
- $this->strtime = '04/02/2000';
- $this->epochtime = wmf_common_date_parse_string('2000-04-02');
- $this->setExchangeRates( $this->epochtime, array( 'USD' => 1, 'EUR' =>
3 ) );
- }
-
- function testParseRow() {
- $data = array(
- 'Account Name' => 'Testes EUR_Public',
- 'Currency' => 'EUR',
- 'Customer Reference' => 'UNAVAILABLE',
- 'Bank Reference' => '1234TEST',
- 'Transaction Date' => '04/01/2000',
- 'Description' => 'FOO CREDIT RECEIVED',
- 'Value Date' => $this->strtime,
- 'Credit Amount' => '5.50',
- );
- $expected_normal = array(
- 'contact_source' => 'check',
- 'contact_type' => 'Individual',
- 'country' => 'US',
- 'currency' => 'EUR',
- 'date' => 954547200,
- 'direct_mail_appeal' => 'White Mail',
- 'email' => '[email protected]',
- 'gateway_account' => 'Testes EUR_Public',
- 'gateway' => 'jpmorgan',
- 'gateway_txn_id' => '1234TEST',
- 'gift_source' => 'Community Gift',
- 'gross' => '5.50',
- 'no_thank_you' => 'No Contact Details',
- 'payment_instrument' => 'JP Morgan EUR',
- 'restrictions' => 'Unrestricted - General',
- 'settlement_date' => $this->epochtime,
- );
-
- $importer = new JpMorganFileProbe( "no URI" );
- $output = $importer->_parseRow( $data );
-
- $this->stripSourceData( $output );
- $this->assertEquals( $expected_normal, $output );
- }
-
- function testImport() {
- //FIXME
- $_GET['q'] = '';
- //FIXME
- civicrm_initialize();
-
- // Clean slate.
- $contributions = wmf_civicrm_get_contributions_from_gateway_id(
'jpmorgan', '1234TEST' );
- if ( $contributions ) {
- foreach ( $contributions as $existing ) {
- $success = civicrm_api_classapi()->Contribution->Delete( array(
- 'id' => $existing['id'],
- 'version' => 3,
- ) );
- $this->assertTrue( $success );
- }
- }
-
- $this->setExchangeRates( wmf_common_date_parse_string( '2000-04-01' ),
array( 'USD' => 1, 'EUR' => 3 ) );
-
- $importer = new JpMorganFileProbe( __DIR__ . "/data/jpmorgan.csv" );
- $importer->import();
-
- $contribution = wmf_civicrm_get_contributions_from_gateway_id(
'jpmorgan', '1234TEST' );
- $this->assertEquals( 1, count( $contribution ) );
- $this->assertEquals( $contribution[0]['trxn_id'], 'JPMORGAN 1234TEST'
);
- }
-
- /**
- * @expectedException WmfException
- * @expectedExceptionCode WmfException::INVALID_FILE_FORMAT
- * @expectedExceptionMessage Duplicate column headers: CURRENCY, reference
- */
- function testImportDuplicateHeaders() {
- //FIXME
- $_GET['q'] = '';
- //FIXME
- civicrm_initialize();
-
- $importer = new JpMorganFileProbe( __DIR__ .
"/data/duplicate_header.csv" );
- $importer->import();
- }
-}
->>>>>>> BRANCH (c33e35 Whitespace + readability)
diff --git a/sites/all/modules/offline2civicrm/tests/data/jpmorgan.csv
b/sites/all/modules/offline2civicrm/tests/data/jpmorgan.csv
deleted file mode 100644
index c11e60a..0000000
--- a/sites/all/modules/offline2civicrm/tests/data/jpmorgan.csv
+++ /dev/null
@@ -1,5 +0,0 @@
-<<<<<<< HEAD (a20ac4 Merge master into deployment)
-=======
-Account Name,Currency,Customer Reference,Bank Reference,Transaction
Date,Description,Value Date,Credit Amount
-Testes EUR_Public,EUR,UNAVAILABLE,1234TEST,04/01/2000,FOO CREDIT
RECEIVED,04/02/2000,5.50
->>>>>>> BRANCH (c33e35 Whitespace + readability)
diff --git
a/sites/all/modules/wmf_civicrm/tests/phpunit/InstallFunctionsTest.php
b/sites/all/modules/wmf_civicrm/tests/phpunit/InstallFunctionsTest.php
deleted file mode 100644
index c7765ef..0000000
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/InstallFunctionsTest.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
-require_once( __DIR__ . "/../../bootstrap.inc" );
-
-/**
- * @group WmfCivicrm
- */
-class InstallFunctionsTest extends BaseWmfDrupalPhpUnitTestCase {
-
- /**
- * Test that the install function for creating option values works.
- *
- * Test with multiple values and an appostrophe for good measure.
- *
- * @throws \CiviCRM_API3_Exception
- */
- public function testCreateOptionValues() {
- wmf_civicrm_create_option_values( 'payment_instrument',
array('Monopoly Money', "IOU's", 'Drakmar'));
- $options = civicrm_api3('Contribution', 'getoptions', array('field' =>
'payment_instrument_id'));
- $this->assertTrue(in_array('Monopoly Money', $options['values']));
- $this->assertTrue(in_array("IOU's", $options['values']));
- $this->assertTrue(in_array('Drakmar', $options['values']));
- }
-
- /**
- * Test that an option value can be created and used for 'tag_used_for'.
- *
- * Wmf sets tags against contributions & needs to add a used_for for that.
- *
- * Here we test against participants since that should NOT be in the DB.
- *
- * (am unsure whether it would be better if the install just used the
- * equivalent functions in the .module file or there was a reason not to).
- */
- public function testUsedForTag() {
- wmf_civicrm_create_option_values_detailed('tag_used_for', array(
- 'Participants' => array('value' => 'civicrm_participant'),
- ));
- $options = civicrm_api3('Tag', 'getoptions', array('field' =>
'used_for'));
- $this->assertArrayHasKey('civicrm_contact', $options['values']);
- $this->assertArrayHasKey('civicrm_participant', $options['values']);
- }
-
-}
diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
b/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
deleted file mode 100644
index 1be0779..0000000
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
+++ /dev/null
@@ -1,262 +0,0 @@
-<<<<<<< HEAD (a20ac4 Merge master into deployment)
-=======
-<?php
-
-/**
- * @group Pipeline
- * @group WmfCivicrm
- */
-class RefundTest extends BaseWmfDrupalPhpUnitTestCase {
-
- /**
- * Id of the contribution created in the setup function.
- *
- * @var int
- */
- protected $original_contribution_id;
-
- public function setUp() {
- parent::setUp();
- civicrm_initialize();
-
- $results = $this->callAPISuccess( 'contact', 'create', array(
- 'contact_type' => 'Individual',
- 'first_name' => 'Test',
- 'last_name' => 'Es',
- 'debug' => 1,
- ) );
- $this->contact_id = $results['id'];
-
- $this->original_currency = 'EUR';
- $this->original_amount = '1.23';
- $this->gateway_txn_id = mt_rand();
- $time = time();
- $this->trxn_id = "TEST_GATEWAY {$this->gateway_txn_id} {$time}";
-
- $this->setExchangeRates( $time, array( 'USD' => 1, 'EUR' => 0.5 ) );
-
- $results = civicrm_api3( 'contribution', 'create', array(
- 'contact_id' => $this->contact_id,
- 'financial_type_id' => 'Cash',
- 'total_amount' => $this->original_amount,
- 'contribution_source' => $this->original_currency . ' ' .
$this->original_amount,
- 'receive_date' => wmf_common_date_unix_to_civicrm( $time ),
- 'trxn_id' => $this->trxn_id,
- ) );
- $this->original_contribution_id = $results['id'];
-
- $this->refund_contribution_id = null;
- }
-
- public function tearDown() {
- civicrm_api3('contribution', 'delete', array(
- 'id' => $this->original_contribution_id,
- ));
-
- if ($this->refund_contribution_id && $this->refund_contribution_id !=
$this->original_contribution_id) {
- civicrm_api3('contribution', 'delete', array(
- 'id' => $this->refund_contribution_id,
- ));
- }
-
- civicrm_api3( 'contact', 'delete', array(
- 'id' => $this->contact_id,
- ) );
-
- parent::tearDown();
- }
-
- /**
- * Check chargeback status exists.
- */
- public function testStatuses() {
- $options = $this->callAPISuccess('Contribution', 'getoptions',
array('field' => 'contribution_status_id'));
- $this->assertTrue(in_array('Chargeback', $options['values']));
- }
-
- /**
- * Covers wmf_civicrm_mark_refund.
- */
- public function testMarkRefund() {
- wmf_civicrm_mark_refund( $this->original_contribution_id, 'refund',
false, '2015-09-09', 'my_special_ref');
-
- $contribution = civicrm_api3( 'contribution', 'getsingle', array(
- 'id' => $this->original_contribution_id,
- ) );
-
- $this->assertEquals( 'Refunded', $contribution['contribution_status'],
- 'Refunded contribution has correct status' );
-
- $financialTransactions = civicrm_api3('EntityFinancialTrxn', 'get',
array(
- 'entity_id' => $this->original_contribution_id,
- 'entity_table' => 'civicrm_contribution',
- 'api.financial_trxn.get' => 1,
- 'sequential' => TRUE,
- ));
- $this->assertEquals(2, $financialTransactions['count']);
- $transaction1 =
$financialTransactions['values']['0']['api.financial_trxn.get']['values'][0];
- $transaction2 =
$financialTransactions['values']['1']['api.financial_trxn.get']['values'][0];
-
- $this->assertEquals($transaction1['trxn_id'], $this->trxn_id);
- $this->assertEquals(strtotime($transaction2['trxn_date']),
strtotime('2015-09-09'));
- $this->assertEquals($transaction2['trxn_id'], 'my_special_ref');
- }
-
- /**
- * Check that marking a contribution as refunded updates custom data
appropriately.
- */
- public function testMarkRefundCheckCustomData() {
- civicrm_api3('contribution', 'create', array(
- 'contact_id' => $this->contact_id,
- 'financial_type_id' => 'Cash',
- 'total_amount' => 50,
- 'contribution_source' => 'USD 50',
- 'receive_date' => '2014-11-01',
- ));
- // Create an additional negative contribution. This is how they were prior
to Feb 2016.
- // We want to check it is ignored for the purpose of determining the most
recent donation
- // although it should contribute to the lifetime total.
- civicrm_api3('contribution', 'create', array(
- 'contact_id' => $this->contact_id,
- 'financial_type_id' => 'Cash',
- 'total_amount' => -10,
- 'contribution_source' => 'USD -10',
- 'receive_date' => '2015-12-01',
- ));
- wmf_civicrm_mark_refund( $this->original_contribution_id, 'refund', false,
'2015-09-09', 'my_special_ref');
- $contact = civicrm_api3('Contact', 'getsingle', array(
- 'id' => $this->contact_id,
- 'return' => array(
- wmf_civicrm_get_custom_field_name('lifetime_usd_total'),
- wmf_civicrm_get_custom_field_name('last_donation_date'),
- wmf_civicrm_get_custom_field_name('last_donation_amount'),
- wmf_civicrm_get_custom_field_name('last_donation_usd'),
- wmf_civicrm_get_custom_field_name('is_2014_donor'),
- wmf_civicrm_get_custom_field_name('is_' . date('Y') . '_donor'),
- wmf_civicrm_get_custom_field_name('is_2015_donor'),
- ),
- ));
- $this->assertEquals(40.00,
$contact[wmf_civicrm_get_custom_field_name('lifetime_usd_total')]);
- $this->assertEquals(50.00,
$contact[wmf_civicrm_get_custom_field_name('last_donation_usd')]);
- $this->assertEquals(50,
$contact[wmf_civicrm_get_custom_field_name('last_donation_amount')]);
- $this->assertEquals('2014-11-01 00:00:00',
$contact[wmf_civicrm_get_custom_field_name('last_donation_date')]);
- $this->assertEquals(TRUE,
$contact[wmf_civicrm_get_custom_field_name('is_2014_donor')]);
- $this->assertEquals(0, $contact[wmf_civicrm_get_custom_field_name('is_' .
date('Y') . '_donor')]);
- $this->assertEquals(0,
$contact[wmf_civicrm_get_custom_field_name('is_2015_donor')]);
- }
-
-
- /**
- * Make a refund with type set to "chargeback"
- */
- public function testMarkRefundWithType() {
- $this->refund_contribution_id = wmf_civicrm_mark_refund(
$this->original_contribution_id, 'chargeback' );
-
- $contribution = civicrm_api3('contribution', 'getsingle', array(
- 'id' => $this->original_contribution_id,
- ));
-
- $this->assertEquals( 'Chargeback',
$contribution['contribution_status'],
- 'Refund contribution has correct type' );
- }
-
- /**
- * Make a refund for less than the original amount
- */
- public function testMakeLesserRefund() {
- $lesser_amount = round( $this->original_amount - 0.25, 2 );
- wmf_civicrm_mark_refund(
- $this->original_contribution_id,
- 'chargeback',
- true, null, null,
- $this->original_currency, $lesser_amount
- );
-
-
- $this->refund_contribution_id = CRM_Core_DAO::singleValueQuery("
- SELECT entity_id FROM wmf_contribution_extra
- WHERE
- parent_contribution_id = %1",
- array(1 => array($this->original_contribution_id, 'Integer'))
- );
-
- $refund_contribution = civicrm_api3('Contribution', 'getsingle', array(
- 'id' => $this->refund_contribution_id,
- ));
-
- $this->assertEquals(
- "{$this->original_currency} 0.25",
- $refund_contribution['contribution_source'],
- 'Refund contribution has correct lesser amount'
- );
- }
-
- /**
- * Make a refund in the wrong currency
- *
- * @expectedException WmfException
- */
- public function testMakeWrongCurrencyRefund() {
- $wrong_currency = 'GBP';
- $this->assertNotEquals( $this->original_currency, $wrong_currency );
- wmf_civicrm_mark_refund(
- $this->original_contribution_id, 'refund',
- true, null, null,
- $wrong_currency, $this->original_amount
- );
- }
-
- /**
- * Make a refund for too much
- *
- * @expectedException WmfException
- */
- public function testMakeScammerRefund() {
- wmf_civicrm_mark_refund(
- $this->original_contribution_id, 'refund',
- true, null, null,
- $this->original_currency, $this->original_amount + 100.00
- );
- }
-
- /**
- * Make a lesser refund in the wrong currency
- */
- public function testLesserWrongCurrencyRefund() {
- $strtime = '04/03/2000';
- $dbtime = '2000-04-03';
- $epochtime = wmf_common_date_parse_string( $dbtime );
- $this->setExchangeRates( $epochtime, array('COP' => .01 ) );
-
- $result = $this->callAPISuccess('contribution', 'create', array(
- 'contact_id' => $this->contact_id,
- 'financial_type_id' => 'Cash',
- 'total_amount' => 200,
- 'contribution_source' => 'COP 20000',
- 'trxn_id' => "TEST_GATEWAY {$this->gateway_txn_id} " . (time() + 20),
- ));
-
- wmf_civicrm_mark_refund(
- $result['id'],
- 'refund',
- TRUE,
- $dbtime,
- NULL,
- 'COP',
- 5000
- );
-
- $contributions = $this->callAPISuccess('Contribution', 'get', array(
- 'contact_id' => $this->contact_id,
- 'sequential' => TRUE
- ));
- $this->assertEquals(3, $contributions['count'], print_r($contributions,
TRUE));
- $this->assertEquals(200, $contributions['values'][1]['total_amount']);
- $this->assertEquals('USD', $contributions['values'][2]['currency']);
- // Exchange rates might move a bit but hopefully it stays less than the
original amount.
- $this->assertEquals($contributions['values'][2]['total_amount'], 150);
- $this->assertEquals('COP 15000',
$contributions['values'][2]['contribution_source']);
- }
-
-}
->>>>>>> BRANCH (c33e35 Whitespace + readability)
--
To view, visit https://gerrit.wikimedia.org/r/283003
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idf27e6c6731fd60d5b5aba52441f992f1ab267b3
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits