Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/160230
Change subject: Won't be needing Simpletest cruft ...................................................................... Won't be needing Simpletest cruft Change-Id: I30d6fb7b85cecf3b1971905126ccf465e9fc8c3a --- D sites/all/modules/queue2civicrm/tests/simpletest/BaseTestCase.php D sites/all/modules/queue2civicrm/tests/simpletest/GlobalcollectRecurring.test D sites/all/modules/queue2civicrm/tests/simpletest/PaypalRecurring.test D sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm.test D sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm_tests.info D sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm_tests.module D sites/all/modules/queue2civicrm/tests/simpletest/refund.test D sites/all/modules/queue2civicrm/tests/simpletest/txnid.test 8 files changed, 0 insertions(+), 766 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/30/160230/1 diff --git a/sites/all/modules/queue2civicrm/tests/simpletest/BaseTestCase.php b/sites/all/modules/queue2civicrm/tests/simpletest/BaseTestCase.php deleted file mode 100644 index 8eb0409..0000000 --- a/sites/all/modules/queue2civicrm/tests/simpletest/BaseTestCase.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php -/** - * Set up schemas and constants. - */ -class BaseTestCase extends DrupalWebTestCase { - protected $profile = 'minimal'; - - public function setUp() { - // FIXME: pass module names from subclass setUp - parent::setUp( - 'dblog', 'exchange_rates', 'queue2civicrm', 'wmf_common', 'wmf_civicrm', 'contribution_tracking', 'wmf_refund_qc', 'recurring', 'recurring_globalcollect', 'offline2civicrm', - // civi schema is not installed here, - 'civicrm' - ); - - // This is a terrible hack: we are using the "development" - // civicrm database configured in civicrm.settings.php, and avoid the - // overhead of creating a new test db by protecting with a transaction. - // It probably subtly breaks all kinds of simpletest things. - $this->civicrm_transaction = new CRM_Core_Transaction(); - - // FIXME: reference data is hardcoded - $this->currency = "BAA"; - // FIXME: this will always be a losing race, until value_in_usd table update method is exposed. - module_invoke( 'exchange_rate', 'cache_set', $this->currency, time(), 2); - // settlement currency is hardcoded - module_invoke( 'exchange_rate', 'cache_set', "USD", time(), 1); - } - - public function tearDown() { - $mails = $this->drupalGetMails(); - - $this->civicrm_transaction->rollback(); - - parent::tearDown(); - } - - /** - * Check that all elements of $inner match in $super, recursively. - */ - protected function assertSuperset( $super, $inner, $path = array() ) { - $expected_value = static::array_dereference( $inner, $path ); - if ( is_array( $expected_value ) ) { - foreach ( array_keys( $expected_value ) as $key ) { - $inner_path = $path; - $inner_path[] = $key; - $this->assertSuperset( $super, $inner, $inner_path ); - } - } else { - try { - $this->assertIdentical( - static::array_dereference( $super, $path ), - $expected_value, - "Match at " . implode( ".", $path ) ); - } catch ( Exception $ex ) { - $this->assert( false, $ex->getMessage() ); - } - } - } - - static function array_dereference( $root, $path ) { - $cur_path = array(); - while ( count( $path ) ) { - $key = array_shift( $path ); - $cur_path[] = $key; - if ( !is_array( $root ) or !array_key_exists( $key, $root ) ) { - throw new Exception( "Missing value for key " . implode( ".", $cur_path ) ); - } - $root = $root[$key]; - } - return $root; - } -} diff --git a/sites/all/modules/queue2civicrm/tests/simpletest/GlobalcollectRecurring.test b/sites/all/modules/queue2civicrm/tests/simpletest/GlobalcollectRecurring.test deleted file mode 100644 index 261592c..0000000 --- a/sites/all/modules/queue2civicrm/tests/simpletest/GlobalcollectRecurring.test +++ /dev/null @@ -1,101 +0,0 @@ -<?php - -require_once __DIR__ . '/BaseTestCase.php'; -require_once __DIR__ . '/../includes/Message.php'; - -class GlobalcollectRecurringTest extends BaseTestCase { - public static function getInfo() { - return array( - 'name' => 'Globalcollect recurring', - 'group' => 'Donations Pipeline', - 'description' => 'Process recurring messages', - ); - } - - public function setUp() { - parent::setUp(); - - $this->subscr_id = mt_rand(); - $this->amount = '2.01'; - - $this->subscription_message = new TransactionMessage( array( - 'txn_type' => 'subscr_signup', - 'subscr_id' => $this->subscr_id, - 'original_gross' => $this->amount, - 'gross' => $this->amount, - 'amount' => $this->amount, - 'frequency_unit' => 'month', - 'frequency_interval' => '1', - 'installments' => '10', - 'create_date' => strtotime( '2000-01-01 00:01:02' ), - 'start_date' => strtotime( '2000-01-01 01:02:03' ), - ) ); - - $this->payment_message = new TransactionMessage( array( - 'txn_type' => 'subscr_payment', - 'subscr_id' => $this->subscr_id, - 'original_gross' => $this->amount, - 'gross' => $this->amount, - 'payment_date' => strtotime( "2000-02-01 01:02:03" ), - ) ); - - recurring_import( $this->subscription_message ); - recurring_import( $this->payment_message ); - } - - public function testUpdateSuccess() { - $recur_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - - _recurring_globalcollect_update_record_success( $recur_record->id ); - - $updated_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - $this->verbose(json_encode($updated_record)); - $this->assertSuperset( get_object_vars( $updated_record ), array( - 'failure_count' => '0', - 'failure_retry_date' => null, - 'contribution_status_id' => (string)civicrm_api_contribution_status('Completed'), - ) ); - } - - public function testUpdateInProgress() { - $recur_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - - _recurring_globalcollect_update_record_in_progress( $recur_record->id ); - - $updated_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - $this->verbose(json_encode($updated_record)); - $this->assertSuperset( get_object_vars( $updated_record ), array( - 'contribution_status_id' => (string)civicrm_api_contribution_status('In Progress'), - ) ); - } - - public function testUpdateFailure() { - $recur_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - - variable_set( 'recurring_globalcollect_failures_before_cancellation', 2 ); - - _recurring_globalcollect_update_record_failure( $recur_record->id ); - - $updated_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - $this->verbose(json_encode($updated_record)); - $this->assertSuperset( get_object_vars( $updated_record ), array( - 'failure_count' => '1', - 'contribution_status_id' => (string)civicrm_api_contribution_status('Failed'), - ) ); - $retry_date = new DateTime( $updated_record->failure_retry_date ); - $now = new DateTime( "now - 1 hour" ); - // Yes, this diff function is backwards - $diff = date_diff( $now, $retry_date ); - $this->assertTrue( $diff->days >= 1 && $diff->invert == 0, - "Retry date was set to a day in the future" ); - - _recurring_globalcollect_update_record_failure( $recur_record->id ); - $cancelled_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - $this->verbose(json_encode($cancelled_record)); - $this->assertSuperset( get_object_vars( $cancelled_record ), array( - 'failure_count' => '2', - 'contribution_status_id' => (string)civicrm_api_contribution_status('Cancelled'), - 'next_sched_contribution' => null, - ) ); - } -} diff --git a/sites/all/modules/queue2civicrm/tests/simpletest/PaypalRecurring.test b/sites/all/modules/queue2civicrm/tests/simpletest/PaypalRecurring.test deleted file mode 100644 index 65319be..0000000 --- a/sites/all/modules/queue2civicrm/tests/simpletest/PaypalRecurring.test +++ /dev/null @@ -1,192 +0,0 @@ -<?php - -require_once __DIR__ . '/BaseTestCase.php'; -require_once __DIR__ . '/../includes/Message.php'; - -class PaypalRecurringTest extends BaseTestCase { - public static function getInfo() { - return array( - 'name' => 'PayPal recurring', - 'group' => 'Donations Pipeline', - 'description' => 'Process recurring messages', - ); - } - - public function setUp() { - parent::setUp(); - - $this->subscr_id = mt_rand(); - $this->amount = '2.01'; - - $this->subscription_message = new TransactionMessage( array( - 'txn_type' => 'subscr_signup', - 'subscr_id' => $this->subscr_id, - 'original_gross' => $this->amount, - 'gross' => $this->amount, - 'amount' => $this->amount, - 'frequency_unit' => 'month', - 'frequency_interval' => '1', - 'installments' => '10', - 'create_date' => strtotime( '2000-01-01 00:01:02' ), - 'start_date' => strtotime( '2000-01-01 01:02:03' ), - ) ); - - $this->payment_message = new TransactionMessage( array( - 'txn_type' => 'subscr_payment', - 'subscr_id' => $this->subscr_id, - 'original_gross' => $this->amount, - 'gross' => $this->amount, - 'payment_date' => strtotime( "2000-02-01 01:02:03" ), - ) ); - - $this->expire_message = new TransactionMessage( array( - 'txn_type' => 'subscr_eot', - 'subscr_id' => $this->subscr_id, - ) ); - - $this->cancel_message = new TransactionMessage( array( - 'txn_type' => 'subscr_cancel', - 'subscr_id' => $this->subscr_id, - 'cancel_date' => strtotime( '2000-04-01 00:01:02' ), - ) ); - - $this->failed_message = new TransactionMessage( array( - 'txn_type' => 'subscr_failed', - 'subscr_id' => $this->subscr_id, - 'failure_count' => '3', - 'failure_retry_date' => strtotime( '2000-05-01 00:01:02' ), - ) ); - - //TODO: modification messages are not processed currently - - $this->existing_subscr_id = mt_rand(); - - $this->existing_contrib_message_body = array( - 'subscr_id' => $this->existing_subscr_id, - 'payment_date' => wmf_common_date_unix_to_civicrm( time() ), - 'txn_type' => 'subscr_payment', - ); - - $api = civicrm_api_classapi(); - - $api->Contact->Create( array( - 'contact_type' => 'Individual', - 'email' => 'f...@example.com', - 'version' => 3, - ) ); - $this->contact_id = $api->id; - - $api->ContributionRecur->Create( array( - 'contact_id' => $this->contact_id, - 'frequency_interval' => 1, - 'trxn_id' => $this->existing_subscr_id, - 'version' => 3, - ) ); - $this->existing_recur_id = $api->id; - - $api->Contribution->Create( array( - 'contact_id' => $this->contact_id, - 'contribution_type' => 'Cash', - 'contribution_recur_id' => $this->existing_recur_id, - 'total_amount' => '20.01', - 'version' => 3, - ) ); - $this->existing_contribution_id = $api->id; - - $this->ctid = wmf_civicrm_insert_contribution_tracking( 'foo', 'web', time(), $this->existing_contribution_id, true, true ); - } - - public function tearDown() { - $api = civicrm_api_classapi(); - - $api->ContributionRecur->Delete( array( - 'id' => $this->existing_recur_id, - 'version' => 3, - ) ); - - $api->Contribution->Delete( array( - 'id' => $this->existing_contribution_id, - 'version' => 3, - ) ); - - parent::tearDown(); - } - - public function testNormalPayment() { - recurring_import( $this->subscription_message ); - recurring_import( $this->payment_message ); - - $payment_data = $this->payment_message->getBody(); - - $contributions = wmf_civicrm_get_contributions_from_gateway_id( $payment_data['gateway'], $payment_data['gateway_txn_id'] ); - $recur_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - //FIXME: convert to array - - $this->verbose( json_encode( $contributions ) ); - $this->assertSuperset( $contributions, array( - array( - 'original_amount' => $this->amount, - 'contribution_recur_id' => $recur_record->id, - ), - ) ); - - $this->verbose( json_encode( $recur_record ) ); - $this->assertSuperset( get_object_vars( $recur_record ), array( - 'amount' => $this->amount, - 'next_sched_contribution' => '2000-03-01 01:02:03', - 'frequency_interval' => '1', - 'frequency_unit' => 'month', - 'cycle_day' => '1', - 'create_date' => '2000-01-01 00:01:02', - 'start_date' => '2000-01-01 01:02:03', - 'end_date' => null, - 'installments' => '10', - 'trxn_id' => (string)$this->subscr_id, - ) ); - } - - public function testNoSubscription() { - try { - recurring_import( $this->payment_message ); - $this->fail( "should have gotten a RequeueError." ); - } catch ( RequeueError $ex ) { - // good. - } - } - - public function testExpire() { - recurring_import( $this->subscription_message ); - recurring_import( $this->expire_message ); - - $recur_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - $this->assertNotNull( $recur_record->end_date ); - } - - public function testCancel() { - recurring_import( $this->subscription_message ); - recurring_import( $this->cancel_message ); - - $recur_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - $this->assertSuperset( get_object_vars( $recur_record ), array( - 'end_date' => '2000-04-01 00:01:02', - 'cancel_date' => '2000-04-01 00:01:02', - ) ); - } - - public function testFailed() { - recurring_import( $this->subscription_message ); - recurring_import( $this->failed_message ); - - $recur_record = wmf_civicrm_get_recur_record( $this->subscr_id ); - $this->assertSuperset( get_object_vars( $recur_record ), array( - 'failure_count' => '3', - 'failure_retry_date' => '2000-05-01 00:01:02', - ) ); - } - - public function testRecurring_get_contribution_tracking_idFromPrevious() { - $ctid = recurring_get_contribution_tracking_id( $this->existing_contrib_message_body ); - $this->assertEqual( $this->ctid, $ctid, - "Contribution tracking can be looked up from msg.subscr_id" ); - } -} diff --git a/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm.test b/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm.test deleted file mode 100644 index d36712d..0000000 --- a/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm.test +++ /dev/null @@ -1,292 +0,0 @@ -<?php - -class Queue2CiviCRMTest extends DrupalUnitTestCase { - public $faux_gateways = "lions, tigers, bears"; - - public static function getInfo() { - return array( - 'name' => 'Queue 2 CiviCRM tests', - 'description' => 'Tests for the queue2civicrm module.', - 'group' => 'Donations Pipeline', - ); - } - - function run(){ - $this->recip_email = variable_get('wmf_test_settings_email', ''); - if (!$this->assertEmailIsSet()){ - return; - } - return parent::run(); - } - - function setUp(){ - parent::setUp(); - error_reporting('E_NONE'); - variable_set('queue2civicrm_subscription', '/queue/civiCRM_test'); - variable_set('queue2civicrm_url', 'tcp://localhost:61613'); - variable_set('queue2civicrm_failmail', $this->recip_email); - variable_set( 'queue2civicrm_gateways_to_monitor', $this->faux_gateways ); - } - - 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 = queue2civicrm_generate_message(); - //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); - $url = 'tcp://bananas:123'; - $con = new Queue($url); - try { - $this->assertTrue($con->getConnection()); - $this->assertFalse($con->isConnected(), "Connection did not fail appropriately."); - } catch (WmfException $ex) { - $this->assertEqual( 'STOMP_BAD_CONNECTION', $ex->getErrorName(), - "Appropriate Drush error was not thrown."); - } - //check for the drush errors... - $this->assertDrushLogEmpty(false); - $this->assertCheckDrushLog('STOMP_BAD_CONNECTION', true, "Appropriate Drush error was not logged."); - - //put everything back to normaltestCurrencyConversion // FIXME should not matter - $this->assertDeleteDrushLog(); - //@fixme: This should be grabbing from an ini or something. - $con = new Queue(queue2civicrm_stomp_url()); - $con->getConnection(); - $this->assertTrue($con->isConnected(), "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 = queue2civicrm_generate_message(); - 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(){ - #FIXME this is testing Stomp.php and not Queue or queue2civicrm - $con = queue2civicrm_stomp()->getConnection(); - $this->assertTrue($con->isConnected(), "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 = _queue2civicrm_trxn_counter_get(); - $trxn_counter->foo = 'bar'; - // make sure that _queue2civicrm_trxn_counter_get() is returning the same trxnc counter - $this->assertEqual( $trxn_counter, _queue2civicrm_trxn_counter_get(), "_queue2civicrm_trxn_counter_get() not returning identical objects."); - - // make sure gateways are properly being set. - $gateways = implode( ", ", array_keys( $trxn_counter->get_trxn_counts())); - $this->assertEqual( $this->faux_gateways, $gateways, 'Gateways are not properly being set in Queue2civicrmTrxnCounter. Expected "' . $this->faux_gateways . '", got "' . $gateways . '".' ); - - // make sure adding and fetching counts work - _queue2civicrm_trxn_counter_add( 'lions' ); - $lions_count = $trxn_counter->get_count_total( 'lions' ); - $this->assertEqual( $lions_count, 1, 'Gateway count test failed, expected 1, got ' . $lions_count ); - _queue2civicrm_trxn_counter_add( '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 - _queue2civicrm_trxn_counter_add( 'bears' ); - _queue2civicrm_trxn_counter_add( '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 ); - } - -} - -?> diff --git a/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm_tests.info b/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm_tests.info deleted file mode 100644 index e597003..0000000 --- a/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm_tests.info +++ /dev/null @@ -1,13 +0,0 @@ -name = Queue to CiviCRM Tests -description = Tests -core = 7.x -dependencies[] = queue2civicrm -dependencies[] = recurring -dependencies[] = wmf_civicrm -dependencies[] = wmf_refund_qc -dependencies[] = recurring_globalcollect -package = queue2civicrm.simpletest -files[] = PaypalRecurring.test -files[] = GlobalcollectRecurring.test -files[] = refund.test -files[] = txnid.test diff --git a/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm_tests.module b/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm_tests.module deleted file mode 100644 index b3d9bbc..0000000 --- a/sites/all/modules/queue2civicrm/tests/simpletest/queue2civicrm_tests.module +++ /dev/null @@ -1 +0,0 @@ -<?php diff --git a/sites/all/modules/queue2civicrm/tests/simpletest/refund.test b/sites/all/modules/queue2civicrm/tests/simpletest/refund.test deleted file mode 100644 index d6c8001..0000000 --- a/sites/all/modules/queue2civicrm/tests/simpletest/refund.test +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -require_once __DIR__ . '/BaseTestCase.php'; -require_once __DIR__ . '/../includes/Message.php'; - -class RefundTest extends BaseTestCase { - public function setUp() { - parent::setUp(); - - $this->payment_message = new TransactionMessage(); - $this->parent_txn_id = WmfTransaction::from_message( $this->payment_message->getBody() )->gateway_txn_id; - - $payment_data = $this->payment_message->getBody(); - $this->refund_message = new RefundMessage( array( - 'gateway_parent_id' => $this->parent_txn_id, - 'gross' => $payment_data['gross'], - 'gross_currency' => $payment_data['currency'], - ) ); - } - - public static function getInfo() { - return array( - 'name' => 'Refund message', - 'group' => 'Donations Pipeline', - 'description' => 'Process a refund message', - ); - } - - public function testImportRefund() { - $refund_data = $this->refund_message->getBody(); - -// FIXME 2: and yeah, decouple this as well - queue2civicrm_import( $this->payment_message ); -// FIXME 1: decouple refund_qc test from mark_refund test - refund_import( $this->refund_message ); - - $parent_contributions = wmf_civicrm_get_contributions_from_gateway_id( $refund_data['gateway'], $this->parent_txn_id ); - $this->assertTrue( $parent_contributions, - "Found parent contribution." ); - $this->assertSuperset( $parent_contributions, array( - array( - 'gateway' => $refund_data['gateway'], - 'gateway_txn_id' => (string) $refund_data['gateway_parent_id'], - 'finance_only' => "1", - ), - ) ); - - $contributions = wmf_civicrm_get_contributions_from_gateway_id( $refund_data['gateway'], $refund_data['gateway_refund_id'] ); - $this->assertTrue( $contributions, - "Found refund contribution." ); - $this->assertSuperset( $contributions, array( - array( - 'gateway' => $refund_data['gateway'], - 'gateway_txn_id' => (string) $refund_data['gateway_refund_id'], - 'finance_only' => "1", - 'total_amount' => (string)(0 - $parent_contributions[0]['total_amount']), - 'no_thank_you' => "refund", - ), - ) ); - } -} diff --git a/sites/all/modules/queue2civicrm/tests/simpletest/txnid.test b/sites/all/modules/queue2civicrm/tests/simpletest/txnid.test deleted file mode 100644 index 5a1586c..0000000 --- a/sites/all/modules/queue2civicrm/tests/simpletest/txnid.test +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -require_once __DIR__ . '/../includes/Message.php'; - -class TxnIdTest extends DrupalTestCase { - public function setUp() { - $txn_id = rand(); - - $this->message = new TransactionMessage( array( - 'gateway_txn_id' => $txn_id, - ) ); - - $this->similar_message = new TransactionMessage( array( - 'gateway_txn_id' => $txn_id . '2', - ) ); - } - - public function tearDown() { - } - - public static function getInfo() { - return array( - 'name' => 'Transaction ID tests', - 'group' => 'Donations Pipeline', - 'description' => 'Enqueue similar transaction numbers', - ); - } - - public function testSimilar() { - module_invoke( 'queue2civicrm', 'import', $this->similar_message ); - module_invoke( 'queue2civicrm', 'import', $this->message ); - } -} -- To view, visit https://gerrit.wikimedia.org/r/160230 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I30d6fb7b85cecf3b1971905126ccf465e9fc8c3a Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits