Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/249559
Change subject: Merge civi-4.6.9 into deployment
......................................................................
Merge civi-4.6.9 into deployment
Conflicts:
.gitreview
sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
sites/all/modules/wmf_campaigns/tests/WmfCampaignTest.php
sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php
sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
Change-Id: I73776589f7e9a39dcb81475c3e2352c425d8672e
---
M .gitreview
D sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
D sites/all/modules/wmf_campaigns/tests/WmfCampaignTest.php
D sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
D sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php
D sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
D sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
7 files changed, 1 insertion(+), 1,064 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/59/249559/1
diff --git a/.gitreview b/.gitreview
index b7c5646..ecf72bd 100644
--- a/.gitreview
+++ b/.gitreview
@@ -2,9 +2,5 @@
host=gerrit.wikimedia.org
port=29418
project=wikimedia/fundraising/crm.git
-<<<<<<< HEAD (f2fa7b Merge branch 'master' into deployment)
-defaultbranch=deployment
-=======
-defaultbranch=civi-4.6.9
->>>>>>> BRANCH (d6775e Merge master into civi-4.6.9)
+defaultbranch=civi-4.6.9-deployment
defaultrebase=0
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 3da2aa9..0000000
--- a/sites/all/modules/queue2civicrm/tests/includes/QueueConsumer.php
+++ /dev/null
@@ -1,274 +0,0 @@
-<<<<<<< HEAD (f2fa7b Merge branch 'master' into deployment)
-=======
-<?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 = 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);
- 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 = 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(){
- $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 (d6775e Merge master into civi-4.6.9)
diff --git a/sites/all/modules/wmf_campaigns/tests/WmfCampaignTest.php
b/sites/all/modules/wmf_campaigns/tests/WmfCampaignTest.php
deleted file mode 100644
index 932e138..0000000
--- a/sites/all/modules/wmf_campaigns/tests/WmfCampaignTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<<<<<<< HEAD (f2fa7b Merge branch 'master' into deployment)
-=======
-<?php
-
-use wmf_communication\TestMailer;
-
-/**
- * @group WmfCampaigns
- */
-class WmfCampaignTest extends BaseWmfDrupalPhpUnitTestCase {
- public $campaign_custom_field_name;
- public $campaign_key;
- public $notification_email;
- public $contact_id;
-
- function setUp() {
- parent::setUp();
- civicrm_initialize();
-
- TestMailer::setup();
-
- $this->campaign_custom_field_name = wmf_civicrm_get_custom_field_name(
'Appeal' );
-
- $this->campaign_key = 'fooCamp' . mt_rand();
- $this->notification_email = '[email protected]';
-
- $result = civicrm_api3( 'Contact', 'create', array(
- 'contact_type' => 'Individual',
- 'first_name' => 'Testes',
- ) );
- $this->contact_id = $result['id'];
-
- db_merge( 'wmf_campaigns_campaign' )
- ->key( array( 'campaign_key' => $this->campaign_key ) )
- ->fields( array(
- 'campaign_key' => $this->campaign_key,
- 'notification_email' => $this->notification_email,
- ) )
- ->execute();
-
- civicrm_api3( 'OptionValue', 'create', array(
- 'option_group_id' => WMF_CAMPAIGNS_OPTION_GROUP_NAME,
- 'label' => $this->campaign_key,
- 'value' => $this->campaign_key,
- ) );
- }
-
- function testMatchingDonation() {
- $result = civicrm_api3( 'Contribution', 'create', array(
- 'contact_id' => $this->contact_id,
- 'contribution_type' => 'Cash',
- 'currency' => 'USD',
- 'payment_instrument' => 'Credit Card',
- 'total_amount' => '1.23',
- 'trxn_id' => 'TEST_GATEWAY ' . mt_rand(),
- $this->campaign_custom_field_name => $this->campaign_key,
- ) );
-
- $this->assertEquals( 1, TestMailer::countMailings(),
- 'Exactly one email was sent.' );
-
- $mailing = TestMailer::getMailing( 0 );
- $this->assertNotEquals( false, strpos( $mailing['html'],
$this->campaign_key ),
- 'Campaign name found in notification email.' );
- }
-
- /**
- * @expectedException CiviCRM_API3_Exception
- * @expectedExceptionMessageRegExp /fooCamp.*NOT/
- */
- function testNonMatchingDonation() {
- $result = civicrm_api3( 'Contribution', 'create', array(
- 'contact_id' => $this->contact_id,
- 'contribution_type' => 'Cash',
- 'currency' => 'USD',
- 'payment_instrument' => 'Credit Card',
- 'total_amount' => '1.23',
- 'trxn_id' => 'TEST_GATEWAY ' . mt_rand(),
- $this->campaign_custom_field_name => $this->campaign_key . "NOT",
- ) );
-
- $this->fail( 'Should have exceptioned out already.' );
- }
-
- function testNoCampaignDonation() {
- $result = civicrm_api3( 'Contribution', 'create', array(
- 'contact_id' => $this->contact_id,
- 'contribution_type' => 'Cash',
- 'currency' => 'USD',
- 'payment_instrument' => 'Credit Card',
- 'total_amount' => '1.23',
- 'trxn_id' => 'TEST_GATEWAY ' . mt_rand(),
- ) );
-
- $this->assertEquals( 0, TestMailer::countMailings() );
- }
-}
->>>>>>> BRANCH (d6775e Merge master into civi-4.6.9)
diff --git
a/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
b/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
deleted file mode 100644
index cca3ad1..0000000
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-
-/**
- * @group WmfCivicrm
- */
-class HelperFunctionsTest extends BaseWmfDrupalPhpUnitTestCase {
-
- /**
- * Test wmf_civicrm_tag_contact_for_review.
- *
- * Maintenance note: the civicrm entity_tag get api returns an odd syntax.
- *
- * If that ever gets fixed it may break this test - but only the test would
- * need to be altered to adapt.
- *
- * @throws \CiviCRM_API3_Exception
- */
- public function testTagContactForReview() {
- civicrm_initialize();
- $contact = civicrm_api3('Contact', 'create', array(
- 'contact_type' => 'Organization',
- 'organization_name' => 'The Evil Empire',
- ));
- wmf_civicrm_tag_contact_for_review($contact);
- $entityTags = civicrm_api3('EntityTag', 'get', array('entity_id' =>
$contact['id']));
- $this->assertArrayHasKey(civicrm_api3('Tag', 'getvalue', array('name'
=> 'Review', 'return' => 'id')), $entityTags['values']);
- }
-
- /**
- * Test wmf_ensure_language_exists
- *
- * Maintenance note: the civicrm entity_tag get api returns an odd syntax.
- *
- * If that ever gets fixed it may break this test - but only the test would
- * need to be altered to adapt.
- *
- * @throws \CiviCRM_API3_Exception
- */
- public function testEnsureLanguageExists() {
- civicrm_initialize();
- wmf_civicrm_ensure_language_exists('en_IL');
- $languages = civicrm_api3('OptionValue', 'get', array(
- 'option_group_name' => 'languages',
- 'name' => 'en_IL',
- ));
- $this->assertEquals(1, $languages['count']);
- }
-
-}
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 5f2ab35..0000000
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/ImportMessageTest.php
+++ /dev/null
@@ -1,364 +0,0 @@
-<<<<<<< HEAD (f2fa7b 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;
-
- 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'];
-
- $anonymized_contribution = $contribution;
- // Strip contact_id if we have no expectation.
- if ( empty( $expected['contribution']['contact_id'] ) ) {
- unset( $anonymized_contribution['contact_id'] );
- }
- unset( $anonymized_contribution['id'] );
-
- $this->assertEquals( $expected['contribution'],
$anonymized_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' => '',
- ),
- ),
- ),
-
- // 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 );
- }
-}
->>>>>>> BRANCH (d6775e Merge master into civi-4.6.9)
diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
b/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
deleted file mode 100644
index 9ab2773..0000000
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/RefundTest.php
+++ /dev/null
@@ -1,166 +0,0 @@
-<<<<<<< HEAD (f2fa7b Merge branch 'master' into deployment)
-=======
-<?php
-
-/**
- * @group Pipeline
- * @group WmfCivicrm
- */
-class RefundTest extends BaseWmfDrupalPhpUnitTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Refund',
- 'group' => 'Pipeline',
- 'description' => 'Test refund handling.',
- );
- }
-
- public function setUp() {
- parent::setUp();
- civicrm_initialize();
-
- $results = civicrm_api3( 'contact', 'create', array(
- 'contact_type' => 'Individual',
- 'first_name' => 'Test',
- 'last_name' => 'Es',
- ) );
- $this->contact_id = $results['id'];
-
- $this->original_currency = 'EUR';
- $this->original_amount = '1.23';
- $this->gateway_txn_id = mt_rand();
- $time = time();
- $this->trxn_id = "TEST_GATEWAY {$this->gateway_txn_id} {$time}";
-
- $results = civicrm_api3( 'contribution', 'create', array(
- 'contact_id' => $this->contact_id,
- 'contribution_type' => 'Cash',
- 'total_amount' => $this->original_amount,
- 'contribution_source' => $this->original_currency . ' ' .
$this->original_amount,
- 'receive_date' => wmf_common_date_unix_to_civicrm( $time ),
- 'trxn_id' => $this->trxn_id,
- ) );
- $this->original_contribution_id = $results['id'];
-
- $this->refund_contribution_id = null;
- }
-
- public function tearDown() {
- civicrm_api3( 'contribution', 'delete', array(
- 'id' => $this->original_contribution_id,
- ) );
-
- if ( $this->refund_contribution_id ) {
- civicrm_api3( 'contribution', 'delete', array(
- 'id' => $this->refund_contribution_id,
- ) );
- }
-
- civicrm_api3( 'contact', 'delete', array(
- 'id' => $this->contact_id,
- ) );
-
- parent::tearDown();
- }
-
- /**
- * Covers wmf_civicrm_mark_refund
- */
- public function testMarkRefund() {
- $this->refund_contribution_id = wmf_civicrm_mark_refund(
$this->original_contribution_id );
-
- $this->assertNotNull( $this->refund_contribution_id,
- "Refund created" );
-
- $results = civicrm_api3( 'contribution', 'get', array(
- 'id' => $this->original_contribution_id,
- ) );
- $contribution = array_pop( $results['values'] );
-
- $this->assertEquals( 'Refunded', $contribution['contribution_status'],
- 'Refunded contribution has correct status' );
-
- $results = civicrm_api3( 'contribution', 'get', array(
- 'id' => $this->refund_contribution_id,
- ) );
- $refund_contribution = array_pop( $results['values'] );
-
- $this->assertEquals( 'Refund', $refund_contribution['financial_type']
);
- $this->assertEquals( 'Pending',
$refund_contribution['contribution_status'] );
- $this->assertEquals(
- "{$this->original_currency} -{$this->original_amount}",
- $refund_contribution['contribution_source'] );
- }
-
- /**
- * Make a refund with type set to "chargeback"
- */
- public function testMarkRefundWithType() {
- $this->refund_contribution_id = wmf_civicrm_mark_refund(
$this->original_contribution_id, 'chargeback' );
-
- $api = civicrm_api_classapi();
- $results = civicrm_api3( 'contribution', 'get', array(
- 'id' => $this->refund_contribution_id,
-
- 'version' => 3,
- ) );
- $contribution = array_pop( $results['values'] );
-
- $this->assertEquals( 'Chargeback', $contribution['financial_type'],
- 'Refund contribution has correct type' );
- }
-
- /**
- * Make a refund for less than the original amount
- */
- public function testMakeLesserRefund() {
- $lesser_amount = round( $this->original_amount - 0.25, 2 );
- $this->refund_contribution_id = wmf_civicrm_mark_refund(
- $this->original_contribution_id,
- 'chargeback',
- true, null, null,
- $this->original_currency, $lesser_amount
- );
-
- $results = civicrm_api3( 'contribution', 'get', array(
- 'id' => $this->refund_contribution_id,
-
- 'version' => 3,
- ) );
- $refund_contribution = array_pop( $results['values'] );
-
- $this->assertEquals(
- "{$this->original_currency} -{$lesser_amount}",
- $refund_contribution['contribution_source'],
- 'Refund contribution has correct lesser amount' );
- }
-
- /**
- * Make a refund in the wrong currency
- *
- * @expectedException WmfException
- */
- public function testMakeWrongCurrencyRefund() {
- $wrong_currency = 'GBP';
- $this->assertNotEquals( $this->original_currency, $wrong_currency );
- wmf_civicrm_mark_refund(
- $this->original_contribution_id, 'refund',
- true, null, null,
- $wrong_currency, $this->original_amount
- );
- }
-
- /**
- * Make a refund for too much
- *
- * @expectedException WmfException
- */
- public function testMakeScammerRefund() {
- wmf_civicrm_mark_refund(
- $this->original_contribution_id, 'refund',
- true, null, null,
- $this->original_currency, $this->original_amount + 100.00
- );
- }
-}
->>>>>>> BRANCH (d6775e Merge master into civi-4.6.9)
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 306d2de..0000000
---
a/sites/all/modules/wmf_common/tests/includes/BaseWmfDrupalPhpUnitTestCase.php
+++ /dev/null
@@ -1,108 +0,0 @@
-<<<<<<< HEAD (f2fa7b Merge branch 'master' into deployment)
-=======
-<?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 );
- }
- }
-
- /**
- * 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);
- }
-
- /**
- * 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;
- }
-}
->>>>>>> BRANCH (d6775e Merge master into civi-4.6.9)
--
To view, visit https://gerrit.wikimedia.org/r/249559
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I73776589f7e9a39dcb81475c3e2352c425d8672e
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: civi-4.6.9-deployment
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits