Eileen has uploaded a new change for review. https://gerrit.wikimedia.org/r/297712
Change subject: Merge branch 'master' of https://gerrit.wikimedia.org/r/wikimedia/fundraising/crm into deployment ...................................................................... Merge branch 'master' of https://gerrit.wikimedia.org/r/wikimedia/fundraising/crm into deployment This includes the CiviCRM upgrade to 4.7.9 + drupal to 7.44 4e715d4 Drupal submodule update 5d42516 CiviCRM submodule update 69a432a Fix for regression in tests. 12c42a5 CiviCRM submodule update 787ff0c Add mysql to drop triggers to git and update trigger code for create. 747fdec Add prospecting custom fields 8b902db Remove unused merge function. afd9d80 Temporarily remove line in test. 6eeddd1 Remove code to include our custom tables. 7d317c4 Update tests to ignore field revenue_recognition_date 314189b Per merge connection id 0b34d38 Fix merge hook to remove calculated fields from merge_conflicts a322f7a Fix merge hook to remove calculated fields from merge_conflicts 81fbad6 Express Checkout is recorded as PayPal 769c905 Create civicrm_strip_non_numeric during test. ca98b28 Import errors are logged and recoverable d88af01 Send failmail and set no_thank_you on TY errors 346c9d3 Remove old email edit hook 758e75a Save sql to generate triggers against latest CiviCRM (4.7.8) 48bcdb8 Save sql to generate triggers against current CiviCRM (4.6.9) a9c0142 Move test code to test support 38a961c We don't care to get failmail when banner history import fails Change-Id: I674d45fbe344d2937872d240f98fc5411cfd4c65 --- D sites/all/modules/queue2civicrm/tests/includes/Message.php D sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php D sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php D sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php D sites/all/modules/wmf_civicrm/tests/phpunit/PhoneImportTest.php D sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php 6 files changed, 0 insertions(+), 1,203 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/12/297712/1 diff --git a/sites/all/modules/queue2civicrm/tests/includes/Message.php b/sites/all/modules/queue2civicrm/tests/includes/Message.php deleted file mode 100644 index dfe028a..0000000 --- a/sites/all/modules/queue2civicrm/tests/includes/Message.php +++ /dev/null @@ -1,154 +0,0 @@ -<<<<<<< HEAD (bb9bf1 Revert "Express Checkout is recorded as PayPal") -======= -<?php - -class Message { - protected $defaults = array(); - - public $body; - public $headers; - - protected $data; - - function __construct( $values = array() ) { - $this->data = $this->defaults; - $this->headers = array(); - $this->set( $values ); - } - - function set( $values ) { - if ( is_array( $values ) ) { - $this->data = $values + $this->data; - } - - $this->body = json_encode( $this->data ); - } - - function setHeaders( $values ) { - if ( is_array( $values ) ) { - $this->headers = array_merge( $this->headers, $values ); - } - } - - function getBody() { - return $this->data; - } - - function getHeaders() { - return $this->headers; - } - - function loadDefaults( $name ) { - if ( !$this->defaults ) { - $path = __DIR__ . "/../data/{$name}.json"; - $this->defaults = json_decode( file_get_contents( $path ), true ); - } - } - - /** - * Generates random data for queue and donation insertion testing - */ - public static function generateRandom() { - //language codes - $lang = array( 'en', 'de', 'fr' ); - - $currency_codes = array( 'USD', 'GBP', 'EUR', 'ILS' ); - shuffle( $currency_codes ); - $currency = ( mt_rand( 0, 1 ) ) ? 'USD' : $currency_codes[0]; - - $message = array( - 'contribution_tracking_id' => '', - 'optout' => mt_rand( 0, 1 ), - 'anonymous' => mt_rand( 0, 1 ), - 'comment' => mt_rand(), - 'utm_source' => mt_rand(), - 'utm_medium' => mt_rand(), - 'utm_campaign' => mt_rand(), - 'language' => $lang[array_rand( $lang )], - 'referrer' => 'http://example.com/' . mt_rand(), - 'email' => mt_rand() . '@example.com', - 'first_name' => mt_rand(), - 'middle_name' => mt_rand(), - 'last_name' => mt_rand(), - 'street_address' => mt_rand(), - 'supplemental_address_1' => '', - 'city' => 'San Francisco', - 'state_province' => 'CA', - 'country' => 'USA', - 'countryID' => 'US', - 'postal_code' => mt_rand( 2801, 99999 ), - 'gateway' => 'insert_test', - 'gateway_txn_id' => mt_rand(), - 'response' => mt_rand(), - 'currency' => $currency, - 'original_currency' => $currency_codes[0], - 'original_gross' => mt_rand( 0, 10000 ) / 100, - 'fee' => '0', - 'gross' => mt_rand( 0, 10000 ) / 100, - 'net' => mt_rand( 0, 10000 ) / 100, - 'date' => date( 'r' ), //time(), - ); - return $message; - } -} - -class TransactionMessage extends Message { - protected $txn_id_key = 'gateway_txn_id'; - - function __construct( $values = array() ) { - $this->loadDefaults( "donation" ); - - parent::__construct( array( - $this->txn_id_key => mt_rand(), - 'order_id' => mt_rand(), - ) + $values ); - - $this->setHeaders( array( - "persistent" => 'true', - // FIXME: this might indicate a key error in our application code. - "correlation-id" => "{$this->data['gateway']}-{$this->data[$this->txn_id_key]}", - "JMSCorrelationID" => "{$this->data['gateway']}-{$this->data[$this->txn_id_key]}", - ) ); - } - - function getGateway() { - return $this->data['gateway']; - } - - function getGatewayTxnId() { - return $this->data[$this->txn_id_key]; - } - - function get( $key ) { - return $this->data[$key]; - } -} - -class RefundMessage extends TransactionMessage { - function __construct( $values = array() ) { - $this->loadDefaults( "refund" ); - - $this->txn_id_key = 'gateway_refund_id'; - - parent::__construct( $values ); - } -} - -class RecurringPaymentMessage extends TransactionMessage { - function __construct( $values = array() ) { - $this->loadDefaults( "recurring_payment" ); - - $this->txn_id_key = 'txn_id'; - - parent::__construct( $values ); - } -} - -class RecurringSignupMessage extends TransactionMessage { - function __construct( $values = array() ) { - $this->loadDefaults( "recurring_signup" ); - - parent::__construct( $values ); - } -} ->>>>>>> BRANCH (4e715d Drupal submodule update) diff --git a/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php b/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php deleted file mode 100644 index e5c133a..0000000 --- a/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php +++ /dev/null @@ -1,274 +0,0 @@ -<<<<<<< HEAD (bb9bf1 Revert "Express Checkout is recorded as PayPal") -======= -<?php - -class QueueConsumer { - protected $queue_name = 'civiCRM_test'; - protected $url = 'tcp://localhost:61613'; - - function __construct() { - $this->recip_email = variable_get('wmf_test_settings_email', ''); - - variable_set( 'queue2civicrm_subscription', "/queue/{$this->queue_name}" ); - variable_set( 'queue2civicrm_url', $this->url ); - variable_set( 'queue2civicrm_failmail', $this->recip_email ); - } - - function tearDown(){ - parent::tearDown(); - } - - //determine that we are in fact able to read and write to activeMQ - function testStompPushPop() { - $this->emptyQueue(); - //queue2civicrm_insertmq_form_submit($form, &$form_state) $form_state['values'] appears to be where all the $key=>$value form pairs live. - ////Just fake it out. :p queue2civicrm_generate_message() will do nicely. - $message = Message::generateRandom(); - //I think we want gateway_txn_id and contribution_tracking_id to match much the same way we did before. - $message['gateway_txn_id'] = "civiTest"; - $message['contribution_tracking_id'] = $message['gateway_txn_id']; - $message['queue'] = variable_get('queue2civicrm_subscription', '/queue/oopsie'); - $message = array('values' => $message); - - $ret = queue2civicrm_insertmq_form_submit(array(), $message); - $message_return = $this->getItemFromQueue(); - $this->assertTrue(is_object($message_return), "No message was returned"); - $body = json_decode($message_return->body, true); - foreach($message['values'] as $key=>$value){ - $this->assertTrue($body[$key] == $value, $body[$key] . " != $value"); - } - } - - function testConnect(){ - $this->assertDrushLogEmpty(true); - variable_set('queue2civicrm_url', 'tcp://bananas:123'); - $con = wmf_common_stomp_connection(true); - $this->assertTrue($con === false, "Connection did not fail appropriately."); - //check for the drush errors... - $this->assertDrushLogEmpty(false); - $this->assertCheckDrushLog('STOMP_BAD_CONNECTION', true, "Appropriate Drush error was not thrown."); - - //put everything back to normaltestCurrencyConversion - $this->assertDeleteDrushLog(); - variable_set('queue2civicrm_url', 'tcp://localhost:61613'); //@fixme: This should be grabbing from an ini or something. - $con = wmf_common_stomp_connection(true); - - $this->assertTrue($con !== false, "Connection failed, and should have worked the second time 'round."); - } - - function testRequiredFields(){ - $this->assertDeleteDrushLog(); - - //Should be required: - //first, last, email, amount, currency, payment type, gateway transaction ID - $required = array( - 'email' => $this->recip_email, - 'gross' => '7.77', - 'original_currency' => 'USD', - 'gateway' => 'something', - 'gateway_txn_id' => '11235' . time() - ); - queue2civicrm_import( $required ); - $this->assertDrushLogEmpty(true); - - foreach ($required as $key=>$value){ - $msg = $required; - unset($msg[$key]); - queue2civicrm_import( $msg ); - $this->assertDrushLogEmpty(false); - $this->assertCheckDrushLog('CIVI_REQ_FIELD', true, "Missing required $key does not trigger an error."); - $this->assertDeleteDrushLog(); - } - - $test_name = array( - 'first_name' => 'Testy', - 'middle_name' => 'T.', - 'last_name' => 'Testaberger', - 'gross' => '8.88', - 'gateway_txn_id' => '12358' . time() - ); - - $msg = array_merge($required, $test_name); - queue2civicrm_import( $msg ); - $this->assertDrushLogEmpty(true); - - } - - function testCurrencyConversion(){ - $test_currency_conversion = array( - 'email' => $this->recip_email, - 'gross' => '7.77', - 'original_currency' => 'EUR', - 'gateway' => 'something', - 'gateway_txn_id' => '11235', - 'contribution_tracking_id' => '' //don't actually need these in the DB, as we're just testing the currency conversions. - ); - $msg = wmf_civicrm_verify_message_and_stage($test_currency_conversion); - $this->assertTrue($test_currency_conversion['gross'] == $msg['original_gross'], "Original Gross in converted message does not match actual original gross."); - // commenting out below assertion - not a foolproof assertion ~awjrichards - //$this->assertTrue($test_currency_conversion['gross'] != $msg['gross'], "Gross is identical: No conversion was done (unless " . $test_currency_conversion['original_currency'] . " = USD for a minute"); - - $test_currency_conversion['original_currency'] = 'USD'; - $msg = wmf_civicrm_verify_message_and_stage($test_currency_conversion); - $this->assertTrue($test_currency_conversion['gross'] == $msg['original_gross'], "Original Gross in converted message does not match actual original gross."); - $this->assertTrue($test_currency_conversion['gross'] == $msg['gross'], "USD to USD Gross is not identical!"); - } - - function testGetTopError(){ - $this->assertDeleteDrushLog(); - $error = _queue2civicrm_get_top_new_drush_error(); - //should return false - $this->assertFalse($error, "There are no drush errors to return, but we got '$error'"); - - //now throw three errors, and make sure the most severe is returned. - drush_set_error("IMPORT_TAG", "Test Error Message #1"); - drush_set_error("CIVI_CONFIG", "Test Error Message #2"); - drush_set_error("IMPORT_CONTACT", "Test Error Message #3"); - $error = _queue2civicrm_get_top_new_drush_error(); - - //looking for the CIVI_CONFIG error - $this->assertTrue($error['err_code'] === 'CIVI_CONFIG', "New top error should be CIVI_CONFIG; returned " . $error['err_code']); - $this->assertTrue($error['err_text'] === "Messages:\n Test Error Message #2", "Expected message not returned: " . $error['err_text']); - - //now stack some slightly less important errors and see if we get exactly the new ones. - drush_set_error("IMPORT_CONTACT", "Test Error Message #4"); - drush_set_error("IMPORT_CONTACT", "Test Error Message #5"); - drush_set_error("IMPORT_CONTACT", "Test Error Message #6"); - $error = _queue2civicrm_get_top_new_drush_error(); - - $this->assertTrue($error['err_code'] === 'IMPORT_CONTACT', "New top error should be IMPORT_CONTACT; returned " . $error['err_code']); - $this->assertTrue($error['err_text'] === "Messages:\n Test Error Message #4\n Test Error Message #5\n Test Error Message #6", "Expected message not returned: " . $error['err_text']); - - queue2civicrm_failmail($error, "This is a test message!", true); - queue2civicrm_failmail($error, "This is another test message!", false); - } - - function testBatchProcess(){ - //clear and add test messages to the testing queue. - $this->emptyQueue(); - - $messages_in = array(); - for ($i=0; $i<10; ++$i){ - $message = Message::generateRandom(); - unset($message['contribution_tracking_id']); - $message['gateway'] = 'CiviTest' . $i; - $message['gateway_txn_id'] = time(); - $message['queue'] = variable_get('queue2civicrm_subscription', '/queue/oopsie'); - //create some havoc - if($i == 3){ - unset($message['email']); //this should throw a nice error and email and things. - } - $messages_in[] = $message; - $message = array('values' => $message); - $ret = queue2civicrm_insertmq_form_submit(array(), $message); - } - - $this->assertDeleteDrushLog(); - - queue2civicrm_batch_process(); - - //check the final drush log for all the relevant entries - $this->assertDrushLogEmpty(false); - $this->assertCheckDrushLog('CIVI_REQ_FIELD', true, "There should be an error regarding the missing email address."); - - } - - function getItemFromQueue(){ - $con = wmf_common_stomp_connection(); - $this->assertTrue(is_object($con), "Could not establish stomp connection"); - $subscription_queue = variable_get('queue2civicrm_subscription', '/queue/test'); - if ($con) { - $con->subscribe($subscription_queue, array('ack' => 'client')); - - $msg = $con->readFrame(); - - // Skip processing if no message to process. - if ($msg !== FALSE) { - watchdog('queue2civicrm', 'Read frame:<pre>' . check_plain(print_r($msg, TRUE)) . '</pre>'); - set_time_limit(60); - try { - $con->ack($msg); - return $msg; - } - catch (Exception $e) { - watchdog('queue2civicrm', 'Could not process frame from queue.', array(), WATCHDOG_ERROR); - } - } - else { - watchdog('queue2civicrm', 'Nothing to process.'); - } - $con->unsubscribe( $subscription_queue ); - } - return FALSE; - } - - function emptyQueue(){ - while (is_object($this->getItemFromQueue())){ - //uh. Yeah. That. Weirdest while loop EVAR. - } - } - - function assertDeleteDrushLog(){ - $error_log =& drush_get_context('DRUSH_ERROR_LOG', array()); - $error_log = array(); //gwa ha ha ha - $error = drush_get_error_log(); - $this->assertTrue(empty($error), "Drush error log should now be empty" . print_r($error, true)); - } - - function assertCheckDrushLog($drush_error_type, $exists, $assertFailMessage){ - $error = drush_get_error_log(); - $this->assertTrue(array_key_exists($drush_error_type, $error) === $exists, $assertFailMessage . "\nLooking for $drush_error_type\n" . print_r($error, true)); - } - - function assertDrushLogEmpty($state){ - $error = drush_get_error_log(); - $message = "Drush log should " . (($state)?"":"not ") . "be empty\n" . print_r($error, true); - $this->assertTrue(empty($error) === $state, $message); - } - - function assertEmailIsSet(){ - if ($this->recip_email == ''){ - $this->fail("Recipient email for testing is not configured. Please configure this value in the wmf_test_settings module."); - return false; - } else { - return true; - } - } - - /** - * Test methods in Queue2civicrmTrxnCounter and associated wrapper functions - */ - function testQueue2CivicrmTrxnCounter() { - $trxn_counter = Queue2civicrmTrxnCounter::instance(); - $trxn_counter->foo = 'bar'; - $this->assertIdentical( $trxn_counter, Queue2civicrmTrxnCounter::instance(), - 'Queue2civicrmTrxnCounter::instance() not returning identical objects.'); - - // make sure adding and fetching counts work - Queue2civicrmTrxnCounter::instance()->increment( 'lions' ); - $lions_count = $trxn_counter->get_count_total( 'lions' ); - $this->assertEqual( $lions_count, 1, 'Gateway count test failed, expected 1, got ' . $lions_count ); - Queue2civicrmTrxnCounter::instance()->increment( 'lions', 3 ); - $lions_count = $trxn_counter->get_count_total( 'lions' ); - $this->assertEqual( $lions_count, 4, 'Gateway count test failed, expected 4, got ' . $lions_count ); - $overall_count = $trxn_counter->get_count_total(); - $this->assertEqual( $overall_count, 4, 'Overall gateway count test failed. Expected 4, got ' . $overall_count ); - - // make sure that our overall counts are right and that we didn't get a count for 'foo' gateway - Queue2civicrmTrxnCounter::instance()->increment( 'bears' ); - Queue2civicrmTrxnCounter::instance()->increment( 'foo' ); - $this->assertFalse( in_array( 'foo', array_keys( $trxn_counter->get_trxn_counts())), 'Was able to set an invalid gateway.' ); - $overall_count = $trxn_counter->get_count_total(); - $this->assertEqual( $overall_count, 5, 'Overall gateway count test failed. Expected 5, got ' . $overall_count ); - - // make sure gateways are properly being set. - $allGateways = 'lions, bears, foo'; - $gateways = implode( ", ", array_keys( $trxn_counter->get_trxn_counts())); - $this->assertEqual( $allGateways, $gateways, - 'Gateways are not properly being set in Queue2civicrmTrxnCounter. Expected "' . $allGateways . '", got "' . $gateways . '".' ); - } - -} - -?> ->>>>>>> BRANCH (4e715d Drupal submodule update) 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 2e37ea3..0000000 --- a/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php +++ /dev/null @@ -1,470 +0,0 @@ -<<<<<<< HEAD (bb9bf1 Revert "Express Checkout is recorded as PayPal") -======= -<?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() { - 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 ) { - civicrm_api_classapi()->Contribution->Delete( array( - 'id' => $this->contribution_id, - 'version' => '3', - ) ); - } - 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'] ) ) { - $api = civicrm_api_classapi(); - $api->Contact->Get( array( - 'id' => $contribution['contact_id'], - 'version' => 3, - ) ); - $contact = (array) $api->values[0]; - $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['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( - array( - 'currency' => 'USD', - 'date' => '2012-05-01 00:00:00', - 'email' => '[email protected]', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - 'gross' => '1.23', - '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' => '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' => '', - ), - ), - ), - - // Minimal contribution with comma thousand separator. - array( - array( - 'currency' => 'USD', - 'date' => '2012-05-01 00:00:00', - 'email' => '[email protected]', - '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' => '', - ), - ), - ), - - // 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' => '[email protected]', - 'first_name' => 'First', - 'fee' => '0.03', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => $gateway_txn_id, - '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.', - ), - '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, - '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', - ), - ), - ), - - // 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' => '[email protected]', - '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' => '', - ), - ), - ), - ); - } - - 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 ); - - $api = civicrm_api_classapi(); - $api->GroupContact->Get( array( - 'contact_id' => $contribution['contact_id'], - - 'version' => 3, - ) ); - $this->assertEquals( 1, count( $api->values ) ); - $this->assertEquals( $fixtures->contact_group_id, $api->values[0]->group_id ); - } - - /** - * 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); - - } - - /** - * 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 (4e715d Drupal submodule update) diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php b/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php deleted file mode 100644 index a67e318..0000000 --- a/sites/all/modules/wmf_civicrm/tests/phpunit/MergeTest.php +++ /dev/null @@ -1,112 +0,0 @@ -<?php - -/** - * @group Pipeline - * @group WmfCivicrm - */ -class MergeTest extends BaseWmfDrupalPhpUnitTestCase { - - /** - * Id of the contact created in the setup function. - * - * @var int - */ - protected $contactID; - - /** - * Id of the contact created in the setup function. - * - * @var int - */ - protected $contactID2; - - public function setUp() { - parent::setUp(); - civicrm_initialize(); - $this->imitateAdminUser(); - $contact = $this->callAPISuccess('Contact', 'create', array( - 'contact_type' => 'Individual', - 'first_name' => 'Donald', - 'last_name' => 'Duck', - 'email' => '[email protected]', - wmf_civicrm_get_custom_field_name('do_not_solicit') => 0, - )); - $this->contactID = $contact['id']; - - $contact = $this->callAPISuccess('Contact', 'create', array( - 'contact_type' => 'Individual', - 'first_name' => 'Donald', - 'last_name' => 'Duck', - 'email' => '[email protected]', - wmf_civicrm_get_custom_field_name('do_not_solicit') => 1, - )); - $this->contactID2 = $contact['id']; - } - - public function tearDown() { - $this->callAPISuccess('Contribution', 'get', array( - 'contact_id' => array('IN' => array($this->contactID, $this->contactID2)), - 'api.Contribution.delete' => 1, - )); - $this->callAPISuccess('Contact', 'delete', array('id' => $this->contactID)); - $this->callAPISuccess('Contact', 'delete', array('id' => $this->contactID2)); - parent::tearDown(); - } - - /** - * Test that the merge hook causes our custom fields to not be treated as conflicts. - * - * We also need to check the custom data fields afterwards. - */ - public function testMergeHook() { - $this->callAPISuccess('Contribution', 'create', array( - 'contact_id' => $this->contactID, - 'financial_type_id' => 'Cash', - 'total_amount' => 10, - 'currencty' => 'USD', - )); - $this->callAPISuccess('Contribution', 'create', array( - 'contact_id' => $this->contactID2, - 'financial_type_id' => 'Cash', - 'total_amount' => 5, - 'currencty' => 'USD', - )); - $contact = $this->callAPISuccess('Contact', 'get', array( - 'id' => $this->contactID, - 'sequential' => 1, - 'return' => array(wmf_civicrm_get_custom_field_name('lifetime_usd_total'), wmf_civicrm_get_custom_field_name('do_not_solicit')), - )); - $this->assertEquals(10, $contact['values'][0][wmf_civicrm_get_custom_field_name('lifetime_usd_total')]); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array( - 'criteria' => array('contact' => array('id' => array('IN' => array($this->contactID, $this->contactID2)))), - )); - $this->assertEquals(1, count($result['values']['merged'])); - $contact = $this->callAPISuccess('Contact', 'get', array( - 'id' => $this->contactID, - 'sequential' => 1, - 'return' => array(wmf_civicrm_get_custom_field_name('lifetime_usd_total'), wmf_civicrm_get_custom_field_name('do_not_solicit')), - )); - $this->assertEquals(15, $contact['values'][0][wmf_civicrm_get_custom_field_name('lifetime_usd_total')]); - $this->assertEquals(1, $contact['values'][0][wmf_civicrm_get_custom_field_name('do_not_solicit')]); - - // Now lets check the one to be deleted has a do_not_solicit = 0. - $this->callAPISuccess('Contact', 'create', array( - 'contact_type' => 'Individual', - 'first_name' => 'Donald', - 'last_name' => 'Duck', - 'email' => '[email protected]', - wmf_civicrm_get_custom_field_name('do_not_solicit') => 0, - )); - $result = $this->callAPISuccess('Job', 'process_batch_merge', array( - 'criteria' => array('contact' => array('id' => $this->contactID)), - )); - $this->assertEquals(1, count($result['values']['merged'])); - $contact = $this->callAPISuccess('Contact', 'get', array( - 'id' => $this->contactID, - 'sequential' => 1, - 'return' => array(wmf_civicrm_get_custom_field_name('lifetime_usd_total'), wmf_civicrm_get_custom_field_name('do_not_solicit')), - )); - $this->assertEquals(1, $contact['values'][0][wmf_civicrm_get_custom_field_name('do_not_solicit')]); - } - -} diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/PhoneImportTest.php b/sites/all/modules/wmf_civicrm/tests/phpunit/PhoneImportTest.php deleted file mode 100644 index a10365a..0000000 --- a/sites/all/modules/wmf_civicrm/tests/phpunit/PhoneImportTest.php +++ /dev/null @@ -1,53 +0,0 @@ -<<<<<<< HEAD (bb9bf1 Revert "Express Checkout is recorded as PayPal") -======= -<?php - -/** - * @group Pipeline - * @group WmfCivicrm - */ -class PhoneImportTest extends BaseWmfDrupalPhpUnitTestCase { - - public function testPhoneImport() { - $this->refreshStripFunction(); - - $phone = '555-555-5555'; - - $msg = array( - 'currency' => 'USD', - 'date' => time(), - 'email' => '[email protected]', - 'gateway' => 'test_gateway', - 'gateway_txn_id' => mt_rand(), - 'gross' => '1.23', - 'payment_method' => 'cc', - - 'phone' => $phone, - ); - - $contribution = wmf_civicrm_contribution_message_import( $msg ); - - $api = civicrm_api_classapi(); - $api->Phone->Get( array( - 'contact_id' => $contribution['contact_id'], - ) ); - - $this->assertEquals( $phone, $api->values[0]->phone ); - $this->assertEquals( 1, $api->values[0]->is_primary ); - $this->assertEquals( wmf_civicrm_get_default_location_type_id(), $api->values[0]->location_type_id ); - $this->assertEquals( CRM_Core_OptionGroup::getValue('phone_type', 'phone'), $api->values[0]->phone_type_id ); - } - - /** - * This SQL function is not created during the test at the right time & it seems the triggers ARE - * created despite it not being present. This is not an issue on live (where the function seems to already exist). - */ - public function refreshStripFunction() { - civicrm_initialize(); - CRM_Core_DAO::executeQuery(CRM_Contact_BAO_Contact::DROP_STRIP_FUNCTION_43); - CRM_Core_DAO::executeQuery(CRM_Contact_BAO_Contact::CREATE_STRIP_FUNCTION_43); - CRM_Core_DAO::executeQuery("UPDATE civicrm_phone SET phone_numeric = civicrm_strip_non_numeric(phone)"); - } - -} ->>>>>>> BRANCH (4e715d Drupal submodule update) diff --git a/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php b/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php deleted file mode 100644 index 62dc55c..0000000 --- a/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php +++ /dev/null @@ -1,140 +0,0 @@ -<<<<<<< HEAD (bb9bf1 Revert "Express Checkout is recorded as PayPal") -======= -<?php - -class BaseWmfDrupalPhpUnitTestCase extends PHPUnit_Framework_TestCase { - public function setUp() { - parent::setUp(); - - if ( !defined( 'DRUPAL_ROOT' ) ) { - throw new Exception( "Define DRUPAL_ROOT somewhere before running unit tests." ); - } - - global $user, $_exchange_rate_cache; - $_exchange_rate_cache = array(); - - $user = new stdClass(); - $user->name = "foo_who"; - $user->uid = "321"; - $user->roles = array( DRUPAL_AUTHENTICATED_RID => 'authenticated user' ); - } - - /** - * Temporarily set foreign exchange rates to known values - * - * TODO: Should reset after each test. - */ - protected function setExchangeRates( $timestamp, $rates ) { - foreach ( $rates as $currency => $rate ) { - exchange_rate_cache_set( $currency, $timestamp, $rate ); - } - } - - /** - * Create a temporary directory and return the name - * @return string|boolean directory path if creation was successful, or false - */ - protected function getTempDir() { - $tempFile = tempnam( sys_get_temp_dir(), 'wmfDrupalTest_' ); - if ( file_exists( $tempFile ) ) { - unlink( $tempFile ); - } - mkdir( $tempFile ); - if ( is_dir( $tempFile ) ) { - return $tempFile . '/'; - } - return false; - } - - /** - * API wrapper function from core (more or less). - * - * so we can ensure they succeed & throw exceptions without littering the test with checks. - * - * This is not the full function but it we think it'w worth keeping a copy it should maybe - * go in the parent. - * - * @param string $entity - * @param string $action - * @param array $params - * @param mixed $checkAgainst - * Optional value to check result against, implemented for getvalue,. - * getcount, getsingle. Note that for getvalue the type is checked rather than the value - * for getsingle the array is compared against an array passed in - the id is not compared (for - * better or worse ) - * - * @return array|int - */ - public function callAPISuccess($entity, $action, $params, $checkAgainst = NULL) { - $params = array_merge(array( - 'version' => 3, - 'debug' => 1, - ), - $params - ); - try { - $result = civicrm_api3($entity, $action, $params); - } - catch (CiviCRM_API3_Exception $e) { - $this->assertEquals(0, $e->getMessage() . print_r($e->getExtraParams(), TRUE)); - } - $this->assertAPISuccess($result, "Failure in api call for $entity $action"); - return $result; - } - - /** - * Check that api returned 'is_error' => 0. - * - * @param array $apiResult - * Api result. - * @param string $prefix - * Extra test to add to message. - */ - public function assertAPISuccess($apiResult, $prefix = '') { - if (!empty($prefix)) { - $prefix .= ': '; - } - $errorMessage = empty($apiResult['error_message']) ? '' : " " . $apiResult['error_message']; - - if (!empty($apiResult['debug_information'])) { - $errorMessage .= "\n " . print_r($apiResult['debug_information'], TRUE); - } - if (!empty($apiResult['trace'])) { - $errorMessage .= "\n" . print_r($apiResult['trace'], TRUE); - } - $this->assertEquals(0, $apiResult['is_error'], $prefix . $errorMessage); - } - - - /** - * Emulate a logged in user since certain functions use that. - * value to store a record in the DB (like activity) - * CRM-8180 - * - * @return int - * Contact ID of the created user. - */ - public function imitateAdminUser() { - $result = $this->callAPISuccess('UFMatch', 'get', array( - 'uf_id' => 1, - 'sequential' => 1, - )); - if (empty($result['id'])) { - $contact = $this->callAPISuccess('Contact', 'create', array( - 'first_name' => 'Super', - 'last_name' => 'Duper', - 'contact_type' => 'Individual', - 'api.UFMatch.create' => array('uf_id' => 1, 'uf_name' => 'Wizard'), - )); - $contactID = $contact['id']; - } - else { - $contactID = $result['values'][0]['contact_id']; - } - $session = CRM_Core_Session::singleton(); - $session->set('userID', $contactID); - return $contactID; - } - -} ->>>>>>> BRANCH (4e715d Drupal submodule update) -- To view, visit https://gerrit.wikimedia.org/r/297712 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I674d45fbe344d2937872d240f98fc5411cfd4c65 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: deployment Gerrit-Owner: Eileen <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
