jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/381355 )
Change subject: Merge branch 'master' into deployment ...................................................................... Merge branch 'master' into deployment 33bb710ce CiviFixtures cleans up after itself better 45a8dad0f Duplicate invoice special handling in message requeue bb236a869 WmfDatabase: Rollback all if Civi txn marked for rollback d57689655 When updating an email return early on email match, set on_hold to 0 if email is not on hold in DB already. b27179c18 Add test for Exception Rollback 0248b45c7 Update CiviCRM submodule for dedupe limit Change-Id: Id90953097606d74a8da34440c41c42bd90547941 --- D sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php D sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php D sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php 3 files changed, 0 insertions(+), 1,005 deletions(-) Approvals: jenkins-bot: Verified Ejegg: Looks good to me, approved diff --git a/sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php b/sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php deleted file mode 100644 index e17aeae..0000000 --- a/sites/all/modules/wmf_civicrm/tests/includes/CiviFixtures.php +++ /dev/null @@ -1,113 +0,0 @@ -<<<<<<< HEAD (3f48cb Merge branch 'master' into deployment) -======= -<?php - -/** - * Manage some simple CRM fixtures - * - * Instantiate a new one of these for each test suite, and preferrably for each test. - */ -class CiviFixtures { - // TODO: Clean up interface by grouping each fixture under an object. - public $contact_group_name; - public $contact_group_id; - public $contact_id; - public $contribution_recur_id; - public $epoch_time; - public $org_contact_id; - public $org_contact_name; - public $recur_amount; - public $subscription_id; - public $contribution_amount; - public $contribution_invoice_id; - public $contribution_id; - - /** - * @return CiviFixtures - */ - static function create() { - civicrm_initialize(); - $out = new CiviFixtures(); - - $individual = civicrm_api3('Contact', 'Create', array( - 'contact_type' => 'Individual', - 'first_name' => 'Test', - 'last_name' => 'Es' - )); - $out->contact_id = $individual['id']; - - $out->org_contact_name = 'Test DAF ' . mt_rand(); - - $organization = civicrm_api3('Contact', 'Create', array( - 'contact_type' => 'Organization', - 'organization_name' => $out->org_contact_name, - )); - $out->org_contact_id = $organization['id']; - - $out->recur_amount = '2.34'; - $out->subscription_id = 'SUB-' . mt_rand(); - $out->epoch_time = time(); - $out->sql_time = wmf_common_date_unix_to_sql( $out->epoch_time ); - - $subscription_params = array( - 'contact_id' => $out->contact_id, - 'amount' => $out->recur_amount, - 'currency' => 'USD', - 'frequency_unit' => 'month', - 'frequency_interval' => '1', - 'installments' => '0', - 'start_date' => wmf_common_date_unix_to_civicrm( $out->epoch_time ), - 'create_date' => wmf_common_date_unix_to_civicrm( $out->epoch_time ), - 'cancel_date' => null, - 'processor_id' => 1, - 'cycle_day' => '1', - 'next_sched_contribution' => null, - 'trxn_id' => "RECURRING TEST_GATEWAY {$out->subscription_id}-1 {$out->epoch_time}", - - 'version' => 3, - ); - $contributionRecur = civicrm_api3('ContributionRecur', 'Create', $subscription_params); - $out->contribution_recur_id = $contributionRecur['id']; - - $out->contact_group_name = 'test_thrilled_demographic'; - $group = civicrm_api3('Group', 'get', array('title' => $out->contact_group_name)); - - if ($group['count'] === 1 ) { - $out->contact_group_id = $group['id']; - } else { - $group = civicrm_api3('Group', 'create', array( - 'title' => $out->contact_group_name, - 'name' => $out->contact_group_name, - )); - $out->contact_group_id = $group['id']; - } - - $out->contribution_amount = '1.00'; - - $contribution_params = array( - 'contact_id' => $out->contact_id, - 'amount' => $out->contribution_amount, - 'total_amount' => $out->contribution_amount, - 'create_date' => wmf_common_date_unix_to_civicrm( $out->epoch_time ), - 'financial_type_id' => 1, - 'invoice_id' => mt_rand(), - ); - $contribution = civicrm_api3('Contribution', 'Create', $contribution_params); - $out->contribution_id = $contribution['id']; - $contribution_values = $contribution['values'][$out->contribution_id]; - $out->contribution_invoice_id = $contribution_values['invoice_id']; - - (new CRM_Core_Transaction())->commit(); - return $out; - } - - /** - * Tear down function. - */ - public function __destruct() { - civicrm_api3('ContributionRecur', 'delete', array('id' => $this->contribution_recur_id)); - civicrm_api3('Contribution', 'delete', array('id' => $this->contribution_id)); - civicrm_api3('Contact', 'delete', array('id' => $this->contact_id)); - } -} ->>>>>>> BRANCH (0248b4 Update CiviCRM submodule for dedupe limit) diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php b/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php deleted file mode 100644 index cdc96c8..0000000 --- a/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php +++ /dev/null @@ -1,668 +0,0 @@ -<<<<<<< HEAD (3f48cb Merge branch 'master' into deployment) -======= -<?php - -define( 'ImportMessageTest_campaign', 'test mail code here + ' . mt_rand() ); - -/** - * @group Import - * @group Pipeline - * @group WmfCivicrm - */ -class ImportMessageTest extends BaseWmfDrupalPhpUnitTestCase { - protected $contact_custom_mangle; - protected $contribution_id; - protected $contribution_custom_mangle; - static protected $fixtures; - - /** - * These are contribution fields that we do not check for in our comparison. - * - * Since we never set these always checking for them adds boilerplate code - * and potential test breakiness. - * - * @var array - */ - protected $fieldsToIgnore = array( - 'address_id', - 'contact_id', - 'cancel_date', - 'cancel_reason', - 'thankyou_date', - 'amount_level', - 'contribution_recur_id', - 'contribution_page_id', - 'creditnote_id', - 'is_test', - 'id', - 'invoice_id', - 'is_pay_later', - 'campaign_id', - 'tax_amount', - 'revenue_recognition_date', - ); - - protected $moneyFields = array( - 'total_amount', - 'source', - 'net_amount', - 'fee_amount', - ); - - public function setUp() { - parent::setUp(); - civicrm_api3( 'OptionValue', 'create', array( - 'option_group_id' => WMF_CAMPAIGNS_OPTION_GROUP_NAME, - 'label' => ImportMessageTest_campaign, - 'value' => ImportMessageTest_campaign, - ) ); - } - - public function tearDown() { - if ( $this->contribution_id ) { - $this->callAPISuccess('Contribution', 'delete', array('id' => $this->contribution_id)); - } - parent::tearDown(); - } - - /** - * @dataProvider messageProvider - */ - public function testMessageInsert( $msg, $expected ) { - $contribution = wmf_civicrm_contribution_message_import( $msg ); - $this->contribution_id = $contribution['id']; - - // Ignore contact_id if we have no expectation. - if ( empty( $expected['contribution']['contact_id'] ) ) { - $this->fieldsToIgnore[] = 'contact_id'; - } - - $this->assertComparable( $expected['contribution'], $contribution ); - - if ( !empty( $expected['contribution_custom_values'] ) ) { - $actual_contribution_custom_values = wmf_civicrm_get_custom_values( - $contribution['id'], - array_keys( $expected['contribution_custom_values'] ) - ); - $this->assertEquals( $expected['contribution_custom_values'], $actual_contribution_custom_values ); - } - - if ( !empty( $expected['contact'] ) ) { - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $contribution['contact_id'])); - $renamedFields = array('prefix' => 1, 'suffix' => 1); - $this->assertEquals( array_diff_key($expected['contact'], $renamedFields), array_intersect_key( $expected['contact'], $contact ) ); - foreach (array_keys($renamedFields) as $renamedField) { - $this->assertEquals(civicrm_api3('OptionValue', 'getvalue', array( - 'value' => $contact[$renamedField . '_id'], - 'option_group_id' => 'individual_' . $renamedField, - 'return' => 'name', - )), $expected['contact'][$renamedField]); - } - } - - if ( !empty( $expected['address'] ) ) { - $addresses = civicrm_api3( 'Address', 'get', array( - 'contact_id' => $contribution['contact_id'], - 'return' => 'city,postal_code,street_address,geo_code_1,geo_code_2,timezone', - ) ); - $address = $addresses['values'][$addresses['id']]; - $this->assertComparable( $expected['address'], $address ); - } - - if ( !empty( $expected['contact_custom_values'] ) ) { - $actual_contact_custom_values = wmf_civicrm_get_custom_values( - $contribution['contact_id'], - array_keys( $expected['contact_custom_values'] ) - ); - $this->assertEquals( $expected['contact_custom_values'], $actual_contact_custom_values ); - } - } - - public function messageProvider() { - // Make static so it isn't destroyed until class cleanup. - self::$fixtures = CiviFixtures::create(); - - $contribution_type_cash = wmf_civicrm_get_civi_id( 'contribution_type_id', 'Cash' ); - $payment_instrument_cc = wmf_civicrm_get_civi_id( 'payment_instrument_id', 'Credit Card' ); - $payment_instrument_check = wmf_civicrm_get_civi_id( 'payment_instrument_id', 'Check' ); - - $gateway_txn_id = mt_rand(); - $check_number = (string) mt_rand(); - - $new_prefix = 'M' . mt_rand(); - - return array( - // Minimal contribution - array( - $this->getMinimalImportData($gateway_txn_id), - array( - 'contribution' => $this->getBaseContribution($gateway_txn_id), - ), - ), - - // Minimal contribution with comma thousand separator. - array( - array( - 'currency' => 'USD', - 'date' => '2012-05-01 00:00:00', - 'email' => 'nob...@wikimedia.org', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gross' => '1,000.23', - 'payment_method' => 'cc', - ), - array( - 'contribution' => array( - 'contribution_status_id' => '1', - 'contribution_type_id' => $contribution_type_cash, - 'currency' => 'USD', - 'fee_amount' => '0', - 'total_amount' => '1,000.23', - 'net_amount' => '1,000.23', - 'non_deductible_amount' => '', - 'payment_instrument_id' => $payment_instrument_cc, - 'receipt_date' => '', - 'receive_date' => '20120501000000', - 'source' => 'USD 1,000.23', - 'trxn_id' => "TEST_GATEWAY {$gateway_txn_id}", - 'financial_type_id' => $contribution_type_cash, - 'check_number' => '', - ), - ), - ), - - // over-long city. - array( - array_merge( - $this->getMinimalImportData($gateway_txn_id), - array('city' => 'This is just stupidly long and I do not know why I would enter something this crazily long into a field') - ), - array( - 'contribution' => $this->getBaseContribution($gateway_txn_id), - ), - ), - - // Maximal contribution - array( - array( - 'check_number' => $check_number, - 'currency' => 'USD', - 'date' => '2012-03-01 00:00:00', - 'direct_mail_appeal' => ImportMessageTest_campaign, - 'do_not_email' => 'Y', - 'do_not_mail' => 'Y', - 'do_not_phone' => 'Y', - 'do_not_sms' => 'Y', - 'do_not_solicit' => 'Y', - 'email' => 'nob...@wikimedia.org', - 'first_name' => 'First', - 'fee' => '0.03', - 'preferred_language' => 'en_US', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gateway_status' => 'P', - 'gift_source' => 'Legacy Gift', - 'gross' => '1.23', - 'import_batch_number' => '4321', - 'is_opt_out' => 'Y', - 'last_name' => 'Last', - 'middle_name' => 'Middle', - 'no_thank_you' => 'no forwarding address', - 'name_prefix' => $new_prefix, - 'name_suffix' => 'Sr.', - 'payment_method' => 'check', - 'stock_description' => 'Long-winded prolegemenon', - 'thankyou_date' => '2012-04-01', - ), - array( - 'contact' => array( - 'do_not_email' => '1', - 'do_not_mail' => '1', - 'do_not_phone' => '1', - 'do_not_sms' => '1', - 'first_name' => 'First', - 'is_opt_out' => '1', - 'last_name' => 'Last', - 'middle_name' => 'Middle', - 'prefix' => $new_prefix, - 'suffix' => 'Sr.', - 'preferred_language' => 'en_US', - ), - 'contribution' => array( - 'address_id' => '', - 'amount_level' => '', - 'campaign_id' => '', - 'cancel_date' => '', - 'cancel_reason' => '', - 'check_number' => $check_number, - 'contribution_page_id' => '', - 'contribution_recur_id' => '', - 'contribution_status_id' => '1', - 'contribution_type_id' => $contribution_type_cash, - 'currency' => 'USD', - 'fee_amount' => '0.03', - 'invoice_id' => '', - 'is_pay_later' => '', - 'is_test' => '', - 'net_amount' => '1.2', # :( - 'non_deductible_amount' => '', - 'payment_instrument_id' => $payment_instrument_check, - 'receipt_date' => '', - 'receive_date' => '20120301000000', - 'source' => 'USD 1.23', - 'thankyou_date' => '20120401000000', - 'total_amount' => '1.23', - 'trxn_id' => "TEST_GATEWAY {$gateway_txn_id}", - 'financial_type_id' => $contribution_type_cash, - 'creditnote_id' => '', - 'tax_amount' => '', - ), - 'contribution_custom_values' => array( - 'Appeal' => ImportMessageTest_campaign, - 'import_batch_number' => '4321', - 'Campaign' => 'Legacy Gift', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => (string) $gateway_txn_id, - 'gateway_status_raw' => 'P', - 'no_thank_you' => 'no forwarding address', - 'Description_of_Stock' => 'Long-winded prolegemenon', - ), - 'contact_custom_values' => array( - 'do_not_solicit' => '1', - 'is_2010_donor' => '0', - 'is_2011_donor' => '1', # Fiscal year - 'is_2012_donor' => '0', - 'last_donation_date' => '2012-03-01 00:00:00', - 'last_donation_usd' => '1.23', - 'lifetime_usd_total' => '1.23', - ), - ), - ), - // Invalid language suffix for valid short lang. - 'invalid language suffix' => array( - array( - 'currency' => 'USD', - 'date' => '2012-05-01 00:00:00', - 'email' => 'nob...@wikimedia.org', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gross' => '1.23', - 'payment_method' => 'cc', - 'preferred_language' => 'en_ZZ', - 'name_prefix' => $new_prefix, - 'name_suffix' => 'Sr.', - ), - array( - 'contact' => array( - 'preferred_language' => 'en', - 'prefix' => $new_prefix, - 'suffix' => 'Sr.', - ), - 'contribution' => $this->getBaseContribution($gateway_txn_id), - ), - ), - - // Invalid language suffix for invalid short lang. - 'invalid short language' => array( - array( - 'currency' => 'USD', - 'date' => '2012-05-01 00:00:00', - 'email' => 'nob...@wikimedia.org', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gross' => '1.23', - 'payment_method' => 'cc', - 'preferred_language' => 'zz_ZZ', - 'name_prefix' => $new_prefix, - 'name_suffix' => 'Sr.', - 'prefix' => $new_prefix, - 'suffix' => 'Sr.', - ), - array( - 'contact' => array( - 'preferred_language' => 'zz_ZZ', - 'prefix' => $new_prefix, - 'suffix' => 'Sr.', - ), - 'contribution' => $this->getBaseContribution($gateway_txn_id), - ), - ), - - // Organization contribution - array( - array( - 'contact_type' => 'Organization', - 'currency' => 'USD', - 'date' => '2012-03-01 00:00:00', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gross' => '1.23', - 'organization_name' => 'Hedgeco', - 'org_contact_name' => 'Testname', - 'org_contact_title' => 'Testtitle', - 'payment_method' => 'cc', - ), - array( - 'contribution' => array( - 'address_id' => '', - 'amount_level' => '', - 'campaign_id' => '', - 'cancel_date' => '', - 'cancel_reason' => '', - 'check_number' => '', - 'contribution_page_id' => '', - 'contribution_recur_id' => '', - 'contribution_status_id' => '1', - 'contribution_type_id' => $contribution_type_cash, - 'currency' => 'USD', - 'fee_amount' => '0', - 'invoice_id' => '', - 'is_pay_later' => '', - 'is_test' => '', - 'net_amount' => '1.23', - 'non_deductible_amount' => '', - 'payment_instrument_id' => $payment_instrument_cc, - 'receipt_date' => '', - 'receive_date' => '20120301000000', - 'source' => 'USD 1.23', - 'thankyou_date' => '', - 'total_amount' => '1.23', - 'trxn_id' => "TEST_GATEWAY {$gateway_txn_id}", - 'financial_type_id' => $contribution_type_cash, - 'creditnote_id' => '', - 'tax_amount' => '', - ), - 'contact_custom_values' => array( - 'Name' => 'Testname', - 'Title' => 'Testtitle', - ), - ), - ), - - // Subscription payment - array( - array( - 'contact_id' => self::$fixtures->contact_id, - 'contribution_recur_id' => self::$fixtures->contribution_recur_id, - 'currency' => 'USD', - 'date' => '2014-01-01 00:00:00', - 'effort_id' => 2, - 'email' => 'nob...@wikimedia.org', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gross' => self::$fixtures->recur_amount, - 'payment_method' => 'cc', - ), - array( - 'contribution' => array( - 'address_id' => '', - 'amount_level' => '', - 'campaign_id' => '', - 'cancel_date' => '', - 'cancel_reason' => '', - 'check_number' => '', - 'contact_id' => strval( self::$fixtures->contact_id ), - 'contribution_page_id' => '', - 'contribution_recur_id' => strval( self::$fixtures->contribution_recur_id ), - 'contribution_status_id' => '1', - 'contribution_type_id' => $contribution_type_cash, - 'currency' => 'USD', - 'fee_amount' => '0', - 'invoice_id' => '', - 'is_pay_later' => '', - 'is_test' => '', - 'net_amount' => self::$fixtures->recur_amount, - 'non_deductible_amount' => '', - 'payment_instrument_id' => $payment_instrument_cc, - 'receipt_date' => '', - 'receive_date' => '20140101000000', - 'source' => 'USD ' . self::$fixtures->recur_amount, - 'thankyou_date' => '', - 'total_amount' => self::$fixtures->recur_amount, - 'trxn_id' => "TEST_GATEWAY {$gateway_txn_id}", - 'financial_type_id' => $contribution_type_cash, - 'creditnote_id' => '', - 'tax_amount' => '', - ), - ), - ), - // US address import is geocoded - array( - array( - 'city' => 'Somerville', - 'country' => 'US', - 'currency' => 'USD', - 'date' => '2012-05-01 00:00:00', - 'email' => 'nob...@wikimedia.org', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gross' => '1.23', - 'payment_method' => 'cc', - 'postal_code' => '02144', - 'state_province' => 'MA', - 'street_address' => '1 Davis Square', - ), - array( - 'contribution' => $this->getBaseContribution( $gateway_txn_id ), - 'address' => array( - 'city' => 'Somerville', - 'postal_code' => '02144', - 'street_address' => '1 Davis Square', - 'geo_code_1' => '42.399546', - 'geo_code_2' => '-71.12165', - 'timezone' => 'UTC-5', - ) - ), - ), - ); - } - - public function testImportContactGroups() { - $fixtures = CiviFixtures::create(); - - $msg = array( - 'currency' => 'USD', - 'date' => '2012-03-01 00:00:00', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => mt_rand(), - 'gross' => '1.23', - 'payment_method' => 'cc', - 'contact_groups' => $fixtures->contact_group_name, - ); - $contribution = wmf_civicrm_contribution_message_import( $msg ); - - $group = $this->callAPISuccessGetSingle('GroupContact', array('contact_id' => $contribution['contact_id'])); - $this->assertEquals($fixtures->contact_group_id, $group['group_id']); - } - - /** - * Test that existing on hold setting is retained. - */ - public function testKeepOnHold() { - self::$fixtures = CiviFixtures::create(); - $this->callAPISuccess('Email', 'create', array( - 'email' => 'aga...@wikimedia.org', - 'on_hold' => 1, - 'location_type_id' => 1, - 'contact_id' => self::$fixtures->contact_id, - )); - - $msg = array( - 'contact_id' => self::$fixtures->contact_id, - 'contribution_recur_id' => self::$fixtures->contribution_recur_id, - 'currency' => 'USD', - 'date' => '2014-01-01 00:00:00', - 'effort_id' => 2, - 'email' => 'aga...@wikimedia.org', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => mt_rand(), - 'gross' => self::$fixtures->recur_amount, - 'payment_method' => 'cc', - ); - $contribution = wmf_civicrm_contribution_message_import($msg); - $emails = $this->callAPISuccess('Email', 'get', array('contact_id' => self::$fixtures->contact_id, 'sequential' => 1)); - $this->assertEquals(1, $emails['count']); - - $this->assertEquals(1, $emails['values'][0]['on_hold']); - $this->assertEquals('aga...@wikimedia.org', $emails['values'][0]['email']); - - $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id'])); - - } - - /** - * Test that existing on hold setting is removed if the email changes. - */ - public function testRemoveOnHoldWhenUpdating() { - self::$fixtures = CiviFixtures::create(); - $this->callAPISuccess('Email', 'create', array( - 'email' => 'aga...@wikimedia.org', - 'on_hold' => 1, - 'location_type_id' => 1, - 'contact_id' => self::$fixtures->contact_id, - )); - - $msg = array( - 'contact_id' => self::$fixtures->contact_id, - 'contribution_recur_id' => self::$fixtures->contribution_recur_id, - 'currency' => 'USD', - 'date' => '2014-01-01 00:00:00', - 'effort_id' => 2, - 'email' => 'pan...@wikimedia.org', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => mt_rand(), - 'gross' => self::$fixtures->recur_amount, - 'payment_method' => 'cc', - ); - $contribution = wmf_civicrm_contribution_message_import($msg); - $emails = $this->callAPISuccess('Email', 'get', array('contact_id' => self::$fixtures->contact_id, 'sequential' => 1)); - $this->assertEquals(1, $emails['count']); - - $this->assertEquals(0, $emails['values'][0]['on_hold']); - $this->assertEquals('pan...@wikimedia.org', $emails['values'][0]['email']); - - $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id'])); - } - - - public function testDuplicateHandling() { - $fixtures = CiviFixtures::create(); - $error = null; - $msg = array( - 'currency' => 'USD', - 'date' => '2012-03-01 00:00:00', - 'gateway' => 'test_gateway', - 'order_id' => $fixtures->contribution_invoice_id, - 'gross' => '1.23', - 'payment_method' => 'cc', - 'gateway_txn_id' => 'CON_TEST_GATEWAY' . mt_rand(), - ); - $exceptioned = false; - try { - wmf_civicrm_contribution_message_import( $msg ); - } catch ( WmfException $ex ) { - $exceptioned = true; - $this->assertTrue( $ex->isRequeue() ); - $this->assertEquals( 'DUPLICATE_INVOICE', $ex->getErrorName() ); - $this->assertEquals( WmfException::DUPLICATE_INVOICE, $ex->getCode() ); - } - $this->assertTrue( $exceptioned ); - } - - /** - * Assert that 2 arrays are the same in all the ways that matter :-). - * - * This has been written for a specific test & will probably take extra work - * to use more broadly. - * - * @param array $array1 - * @param array $array2 - */ - public function assertComparable($array1, $array2) { - $this->reformatMoneyFields($array1); - $this->reformatMoneyFields($array2); - $array1 = $this->filterIgnoredFieldsFromArray($array1); - $array2 = $this->filterIgnoredFieldsFromArray($array2); - $this->assertEquals($array1, $array2); - - } - - protected function getMinimalImportData($gateway_txn_id) { - return array( - 'currency' => 'USD', - 'date' => '2012-05-01 00:00:00', - 'email' => 'nob...@wikimedia.org', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gross' => '1.23', - 'payment_method' => 'cc', - ); - } - - /** - * Get the basic array of contribution data. - * - * @param string $gateway_txn_id - * - * @return array - */ - protected function getBaseContribution($gateway_txn_id) { - $contribution_type_cash = wmf_civicrm_get_civi_id( 'contribution_type_id', 'Cash' ); - $payment_instrument_cc = wmf_civicrm_get_civi_id( 'payment_instrument_id', 'Credit Card' ); - return array( - 'address_id' => '', - 'amount_level' => '', - 'campaign_id' => '', - 'cancel_date' => '', - 'cancel_reason' => '', - 'check_number' => '', - 'contribution_page_id' => '', - 'contribution_recur_id' => '', - 'contribution_status_id' => '1', - 'contribution_type_id' => $contribution_type_cash, - 'currency' => 'USD', - 'fee_amount' => '0', - 'invoice_id' => '', - 'is_pay_later' => '', - 'is_test' => '', - 'net_amount' => '1.23', - 'non_deductible_amount' => '', - 'payment_instrument_id' => $payment_instrument_cc, - 'receipt_date' => '', - 'receive_date' => '20120501000000', - 'source' => 'USD 1.23', - 'thankyou_date' => '', - 'total_amount' => '1.23', - 'trxn_id' => "TEST_GATEWAY {$gateway_txn_id}", - 'financial_type_id' => $contribution_type_cash, - 'creditnote_id' => '', - 'tax_amount' => '', - ); - } - - /** - * Remove commas from money fields. - * - * @param array $array - */ - public function reformatMoneyFields(&$array) { - foreach ($array as $field => $value) { - if (in_array($field, $this->moneyFields)) { - $array[$field] = str_replace(',', '', $value); - } - } - } - - /** - * Remove fields we don't care about from the array. - * - * @param array $array - * - * @return array - */ - public function filterIgnoredFieldsFromArray($array) { - return array_diff_key($array, array_flip($this->fieldsToIgnore)); - } - -} ->>>>>>> BRANCH (0248b4 Update CiviCRM submodule for dedupe limit) diff --git a/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php b/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php deleted file mode 100644 index 91f0c7d..0000000 --- a/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php +++ /dev/null @@ -1,224 +0,0 @@ -<<<<<<< HEAD (3f48cb Merge branch 'master' into deployment) -======= -<?php - -/** - * @group WmfCommon - */ -class WmfTransactionTestCase extends BaseWmfDrupalPhpUnitTestCase { - public function testParseUniqueId() { - $transaction = WmfTransaction::from_unique_id( "RFD RECURRING GLOBALCOLLECT 1234 432" ); - $this->assertEquals( - $transaction->gateway_txn_id, "1234", - "5-argument form gateway_txn_id is parsed correctly." ); - $this->assertEquals( - true, $transaction->is_refund, - "refund flag parsed" ); - $this->assertEquals( - true, $transaction->is_recurring, - "recurring flag parsed" ); - $this->assertEquals( - "globalcollect", strtolower( $transaction->gateway ), - "gateway is correctly parsed" ); - $this->assertEquals( - "432", $transaction->timestamp, - "timestamp is correctly parsed" ); - $this->assertEquals( - $transaction->get_unique_id(), "RFD RECURRING GLOBALCOLLECT 1234", - "5-argument form is renormalized to 4-form" ); - - $transaction = WmfTransaction::from_unique_id( "RFD GLOBALCOLLECT 1234 432" ); - $this->assertEquals( - $transaction->gateway_txn_id, "1234", - "4-argument form gateway_txn_id is parsed correctly." ); - $this->assertEquals( - true, $transaction->is_refund, - "refund flag parsed" ); - $this->assertEquals( - "432", $transaction->timestamp, - "timestamp is correctly parsed" ); - $this->assertEquals( - $transaction->get_unique_id(), "RFD GLOBALCOLLECT 1234", - "4-argument form is renormalized correctly" ); - - $transaction = WmfTransaction::from_unique_id( "GLOBALCOLLECT 1234x 432" ); - $this->assertEquals( - $transaction->gateway_txn_id, "1234x", - "3-argument form gateway_txn_id is parsed correctly." ); - $this->assertEquals( - $transaction->get_unique_id(), strtoupper( "GLOBALCOLLECT 1234x" ), - "3-argument form is renormalized correctly" ); - - $transaction = WmfTransaction::from_unique_id( "GLOBALCOLLECT 1234" ); - $this->assertEquals( - $transaction->gateway_txn_id, "1234", - "2-argument form gateway_txn_id is parsed correctly." ); - $this->assertNull( $transaction->timestamp, - "timestamp is not unnecessarily invented" ); - } - - public function testParseMessage() { - $msg = array( - 'gateway' => "globalcollect", - 'gateway_txn_id' => "1234", - 'recurring' => null, - ); - $transaction = WmfTransaction::from_message( $msg ); - $this->assertEquals( - "1234", $transaction->gateway_txn_id, - "parsed message gateway_txn_id is correct" ); - $this->assertEquals( 1, - preg_match( "/GLOBALCOLLECT 1234/", $transaction->get_unique_id() ), - "parsed message has correct trxn_id" ); - } - - /** - * @expectedException WmfException - * @expectedExceptionCode WmfException::INVALID_MESSAGE - */ - function testInvalidEmptyId() { - $transaction = WmfTransaction::from_unique_id( "" ); - } - - /** - * @expectedException WmfException - * @expectedExceptionCode WmfException::INVALID_MESSAGE - */ - function testInvalidAlmostEmptyId() { - $transaction = WmfTransaction::from_unique_id( 'RFD RECURRING' ); - } - - /** - * @expectedException WmfException - * @expectedExceptionCode WmfException::INVALID_MESSAGE - */ - function testInvalidWhitespaceId() { - $transaction = WmfTransaction::from_unique_id( 'RFD RECURRING ' ); - } - - /** - * @expectedException WmfException - * @expectedExceptionCode WmfException::INVALID_MESSAGE - */ - function testInvalidExtraPartsId() { - $transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY 123 1234 EXTRA_PART' ); - } - - /** - * @expectedException WmfException - * @expectedExceptionCode WmfException::INVALID_MESSAGE - */ - function testInvalidTimestampId() { - $transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY 123 BAD_TIMESTAMP' ); - } - - function testExistsNone() { - civicrm_initialize(); - $transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY ' . mt_rand() ); - $this->assertEquals( false, $transaction->exists() ); - } - - function testExistsOne() { - $gateway_txn_id = mt_rand(); - $msg = array( - 'gross' => 1, - 'currency' => 'USD', - 'gateway' => 'TEST_GATEWAY', - 'gateway_txn_id' => $gateway_txn_id, - 'payment_method' => 'cc', - 'email' => 'nob...@wikimedia.org', - ); - wmf_civicrm_contribution_message_import( $msg ); - $transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY ' . $gateway_txn_id ); - $this->assertEquals( true, $transaction->exists() ); - } - - /** - * @expectedException NonUniqueTransaction - */ - function testGetContributionMany() { - $gateway_txn_id = mt_rand(); - $contact = $this->callAPISuccess('Contact', 'create', array( - 'contact_type' => 'Individual', - 'display_name' => 'test', - )); - $params = array( - 'contact_id' => $contact['id'], - 'contribution_type' => 'Cash', - 'total_amount' => 1, - 'version' => 3, - ); - $contribution = $this->callAPISuccess('Contribution', 'create', $params); - wmf_civicrm_set_custom_field_values($contribution['id'], array( - 'gateway' => 'TEST_GATEWAY', - 'gateway_txn_id' => $gateway_txn_id, - ) ); - $contribution = $this->callAPISuccess('Contribution', 'create', $params); - wmf_civicrm_set_custom_field_values($contribution['id'], array( - 'gateway' => 'TEST_GATEWAY', - 'gateway_txn_id' => $gateway_txn_id, - ) ); - - $transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY ' . $gateway_txn_id ); - $transaction->getContribution(); - } - - /** - * Test that when an exception is thrown without our wrapper no further rollback happens. - * - * (this is really just the 'control' for the following test. - */ - public function testNoRollBack() { - civicrm_initialize(); - CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET description = 'WMF'"); - - $this->callbackFunction(1); - - $this->assertEquals('Cool planet', CRM_Core_DAO::singleValueQuery('SELECT description FROM civicrm_domain LIMIT 1')); - $contact = $this->callAPISuccess('Contact', 'get', array('external_identifier' => 'oh so strange')); - $this->assertEquals(1, $contact['count']); - - // Cleanup - $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id'])); - CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET description = 'WMF'"); - } - - /** - * Test that when an exception is thrown with our wrapper the whole lot rolls back. - */ - public function testFullRollBack() { - civicrm_initialize(); - CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET description = 'WMF'"); - - try { - WmfDatabase::transactionalCall(array($this, 'callbackFunction'), array()); - } - catch (RuntimeException $e) { - // We were expecting this :-) - } - - $this->assertEquals('WMF', CRM_Core_DAO::singleValueQuery('SELECT description FROM civicrm_domain LIMIT 1')); - $contact = $this->callAPISuccess('Contact', 'getcount', array('external_identifier' => 'oh so strange')); - $this->assertEquals(0, $contact['count']); - } - - public function callbackFunction() { - CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET description = 'Cool planet'"); - $contact = array( - 'contact_type' => 'Individual', - 'first_name' => 'Dr', - 'last_name' => 'Strange', - 'external_identifier' => 'oh so strange', - ); - $this->callAPISuccess('Contact', 'create', $contact); - try { - civicrm_api3('Contact', 'create', $contact); - } - catch (Exception $e) { - // We have done nothing to roll back. - return; - } - } - -} ->>>>>>> BRANCH (0248b4 Update CiviCRM submodule for dedupe limit) -- To view, visit https://gerrit.wikimedia.org/r/381355 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id90953097606d74a8da34440c41c42bd90547941 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: deployment Gerrit-Owner: Ejegg <ej...@ejegg.com> Gerrit-Reviewer: Ejegg <ej...@ejegg.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits