/** * Integration test to verify that the Amazon gateway converts Canadian * dollars before redirecting * * @dataProvider canadaLanguageProvider */ function testCanadianDollarConversion($language) { $init = $this->getDonorTestData('CA'); unset($init['order_id']); $init['payment_method'] = 'amazon'; $init['ffname'] = 'amazon'; $init['language'] = $language; $rates = CurrencyRates::getCurrencyRates(); $cadRate = $rates['CAD']; $expectedAmount = floor($init['amount'] / $cadRate); TestingAmazonAdapter::$fakeGlobals = array('FallbackCurrency' => 'USD', 'NotifyOnConvert' => true); $expectedNotification = wfMessage('donate_interface-fallback-currency-notice', 'USD')->inLanguage($language)->text(); $locale = $init['language'] . '_' . $init['country']; $expectedDisplayAmount = Amount::format($expectedAmount, 'USD', $locale); $that = $this; //needed for PHP pre-5.4 $convertTest = function ($amountString) use($expectedDisplayAmount, $that) { $that->assertEquals($expectedDisplayAmount, trim($amountString), 'Displaying wrong amount'); }; $assertNodes = array('selected-amount' => array('innerhtml' => $convertTest), 'mw-content-text' => array('innerhtmlmatches' => "/.*{$expectedNotification}.*/")); $this->verifyFormOutput('AmazonGateway', $init, $assertNodes, false); }
/** * Make sure Canadian CC form loads in English and French * @dataProvider canadaLanguageProvider */ public function testGlobalCollectFormLoad_CA($language) { $init = $this->getDonorTestData('CA'); unset($init['order_id']); $init['payment_method'] = 'cc'; $init['payment_submethod'] = 'visa'; $init['ffname'] = 'cc-vma'; $init['language'] = $language; $locale = $language . '_CA'; $assertNodes = array('selected-amount' => array('nodename' => 'span', 'innerhtmlmatches' => '/^\\s*' . str_replace('$', '\\$', Amount::format(1.55, 'CAD', $init['language'] . '_' . $init['country'])) . '\\s*$/'), 'fname' => array('nodename' => 'input', 'placeholder' => wfMessage('donate_interface-donor-fname')->inLanguage($language)->text()), 'lname' => array('nodename' => 'input', 'placeholder' => wfMessage('donate_interface-donor-lname')->inLanguage($language)->text()), 'informationsharing' => array('nodename' => 'p', 'innerhtml' => wfMessage('donate_interface-informationsharing', '.*')->inLanguage($language)->text()), 'state' => array('nodename' => 'select', 'selected' => 'SK'), 'zip' => array('nodename' => 'input', 'value' => $init['zip']), 'country' => array('nodename' => 'input', 'value' => 'CA')); $this->verifyFormOutput('GlobalCollectGateway', $init, $assertNodes, true); }
protected function addCurrencyData(&$data) { $supportedCurrencies = $this->gateway->getCurrencies(); if (count($supportedCurrencies) === 1) { $data['show_currency_selector'] = false; // The select input will be hidden, but posting the form will use its only value // Display the same currency code $data['currency_code'] = $supportedCurrencies[0]; } else { $data['show_currency_selector'] = true; } foreach ($supportedCurrencies as $currency) { $data['currencies'][] = array('code' => $currency, 'selected' => $currency === $data['currency_code']); } $data['display_amount'] = Amount::format($data['amount'], $data['currency_code'], $data['language'] . '_' . $data['country']); }
public function testGCFormLoad() { $init = $this->getDonorTestData('US'); unset($init['order_id']); $init['payment_method'] = 'cc'; $init['payment_submethod'] = 'visa'; $init['ffname'] = 'cc-vmad'; $assertNodes = array('submethod-mc' => array('nodename' => 'input'), 'selected-amount' => array('nodename' => 'span', 'innerhtmlmatches' => '/^\\s*' . str_replace('$', '\\$', Amount::format(1.55, 'USD', $init['language'] . '_' . $init['country'])) . '\\s*$/'), 'state' => array('nodename' => 'select', 'selected' => 'CA')); $this->verifyFormOutput('GlobalCollectGateway', $init, $assertNodes, true); }
public function testTooLittleBbd() { $this->normalized['currency_code'] = 'BBD'; $this->normalized['amount'] = '2.95'; $this->validate(); $this->assertNotEmpty($this->errors, 'No error for diminutive amount (BBD)'); $formattedMin = Amount::format(3.0, 'BBD', 'en_US'); $expected = WmfFramework::formatMessage('donate_interface-smallamount-error', $formattedMin); $this->assertEquals($expected, $this->errors['amount'], 'Wrong error message for diminutive amount (BBD)'); }