/** * tests the stage_repost function * Assertions: * Garbage in, defaults out. * The recurring_paypal key is treated like a boolean */ function testStageRepost() { $start = array('bears' => 'green', 'emus' => 'purple'); ContributionTrackingProcessor::getLanguage(array('language' => 'en')); $expected = ContributionTrackingProcessor::getRepostDefaults(); $expected['item_name'] = 'One-time donation'; $expected['notify_url'] = 'https://civicrm.wikimedia.org/fundcore_gateway/paypal'; $result = ContributionTrackingProcessor::stage_repost($start); $this->assertEquals($expected, $result, "Staged Repost with no defined fields should be exactly all the default values."); $additional = array('gateway' => 'testgateway', 'recurring_paypal' => 'raspberries', 'amount' => '6.60'); $expected = array('gateway' => 'testgateway', 'tshirt' => false, 'size' => false, 'premium_language' => false, 'currency_code' => 'USD', 'return' => 'Donate-thanks/en', 'fname' => '', 'lname' => '', 'email' => '', 'recurring_paypal' => '1', 'amount' => '6.60', 'amount_given' => '', 'contribution_tracking_id' => '', 'notify_url' => 'https://civicrm.wikimedia.org/fundcore_gateway/paypal', 'item_name' => 'Recurring monthly donation'); $result = ContributionTrackingProcessor::stage_repost($additional); $this->assertEquals($expected, $result, "Repost not staging properly."); unset($additional['recurring_paypal']); $expected['recurring_paypal'] = 0; $expected['item_name'] = 'One-time donation'; $result = ContributionTrackingProcessor::stage_repost($additional); $this->assertEquals($expected, $result, "Repost not staging properly."); }
/** * Stages the relevent data that will be sent to the gateway * @global string $wgContributionTrackingPayPalRecurringIPN URL for paypal * recurring donations : Defined in ContributionTracking.php * @global string $wgContributionTrackingPayPalIPN URL for paypal recurring * donations : Defined in ContributionTracking.php * @param array $params Parameters to post to the gateway * @return array Staged array */ static function stage_repost($params) { global $wgContributionTrackingPayPalRecurringIPN, $wgContributionTrackingPayPalIPN; //TODO: assert that gateway makes The Sense here. //change the posted names to match the db where necessary ContributionTrackingProcessor::rekey($params, 'amountGiven', 'amount_given'); ContributionTrackingProcessor::rekey($params, 'returnto', 'return'); //booleanize! ContributionTrackingProcessor::stage_checkbox($params, 'recurring_paypal'); //poke our language function with the current parameters - this sets the static var correctly $params['language'] = ContributionTrackingProcessor::getLanguage($params); if (array_key_exists('recurring_paypal', $params) && $params['recurring_paypal']) { $params['notify_url'] = $wgContributionTrackingPayPalRecurringIPN; $params['item_name'] = ContributionTrackingProcessor::msg('contrib-tracking-item-name-recurring'); } else { $params['notify_url'] = $wgContributionTrackingPayPalIPN; $params['item_name'] = ContributionTrackingProcessor::msg('contrib-tracking-item-name-onetime'); } $repost_params = ContributionTrackingProcessor::mergeArrayDefaults($params, ContributionTrackingProcessor::getRepostDefaults(), true); return $repost_params; }