cvs: pear /Payment_Process2/tests AllTests.php Payment_Process2_ANZTest.php Payment_Process2_Result_ANZTest.php

From: Date: Wed, 06 May 2009 02:13:44 +0000
Subject: cvs: pear /Payment_Process2/tests AllTests.php Payment_Process2_ANZTest.php Payment_Process2_Result_ANZTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-56039@lists.php.net to get a copy of this message
clockwerx Wed May 6 02:13:44 2009 UTC Added files: /pear/Payment_Process2/tests Payment_Process2_ANZTest.php Payment_Process2_Result_ANZTest.php Modified files: /pear/Payment_Process2/tests AllTests.php Log: Added tests for ANZ driver

http://cvs.php.net/viewvc.cgi/pear/Payment_Process2/tests/AllTests.php?r1=1.5&r2=1.6&diff_format=u Index: pear/Payment_Process2/tests/AllTests.php diff -u pear/Payment_Process2/tests/AllTests.php:1.5 pear/Payment_Process2/tests/AllTests.php:1.6 --- pear/Payment_Process2/tests/AllTests.php:1.5 Tue Mar 17 01:55:13 2009 +++ pear/Payment_Process2/tests/AllTests.php Wed May 6 02:13:44 2009 @@ -37,7 +37,7 @@ * @package Payment_Process2 * @author Daniel O'Connor <daniel.oconnor@valex.com.au> * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: AllTests.php,v 1.5 2009/03/17 01:55:13 dbezborodov Exp $ + * @version CVS: $Id: AllTests.php,v 1.6 2009/05/06 02:13:44 clockwerx Exp $ * @link http://pear.php.net/package/Payment_Process2 */ @@ -61,6 +61,7 @@ require_once dirname(__FILE__) . '/Payment_Process2_Result_BibitTest.php'; require_once dirname(__FILE__) . '/Payment_Process2_Result_PayPalTest.php'; require_once dirname(__FILE__) . '/Payment_Process2_Result_TransfirstTest.php'; +require_once dirname(__FILE__) . '/Payment_Process2_Result_ANZTest.php'; require_once dirname(__FILE__) . '/Payment_Process2_TypeTest.php'; @@ -75,6 +76,7 @@ require_once dirname(__FILE__) . '/Payment_Process2_BibitTest.php'; require_once dirname(__FILE__) . '/Payment_Process2_PayPalTest.php'; require_once dirname(__FILE__) . '/Payment_Process2_TransfirstTest.php'; +require_once dirname(__FILE__) . '/Payment_Process2_ANZTest.php'; class Payment_Process2_AllTests { @@ -102,6 +104,7 @@ $suite->addTestSuite('Payment_Process2_BibitTest'); $suite->addTestSuite('Payment_Process2_PayPalTest'); $suite->addTestSuite('Payment_Process2_TransfirstTest'); + $suite->addTestSuite('Payment_Process2_ANZTest'); $suite->addTestSuite('Payment_Process2_ResultTest'); $suite->addTestSuite('Payment_Process2_Result_AuthorizeNetTest'); @@ -111,6 +114,7 @@ $suite->addTestSuite('Payment_Process2_Result_BibitTest'); $suite->addTestSuite('Payment_Process2_Result_PayPalTest'); $suite->addTestSuite('Payment_Process2_Result_TransfirstTest'); + $suite->addTestSuite('Payment_Process2_Result_ANZTest'); return $suite; } http://cvs.php.net/viewvc.cgi/pear/Payment_Process2/tests/Payment_Process2_ANZTest.php?view=markup&rev=1.1 Index: pear/Payment_Process2/tests/Payment_Process2_ANZTest.php +++ pear/Payment_Process2/tests/Payment_Process2_ANZTest.php <?php require_once 'PHPUnit/Framework/TestCase.php'; require_once 'HTTP/Request2/Adapter/Mock.php'; require_once 'Payment/Process2.php'; class Payment_Process2_ANZTest extends PHPUnit_Framework_TestCase { public static function errorProvider() { return self::dataProviderHelper('error'); } public static function successProvider() { return self::dataProviderHelper('success'); } public static function sandboxDataProviderHelper() { if (!defined('ANZ_GATEWAY_LOGIN') || !defined('ANZ_GATEWAY_PASSWORD')) { return null; } $process = self::aProcessor(); $process->login = ANZ_GATEWAY_LOGIN; $process->password = ANZ_GATEWAY_PASSWORD; if (OS_WINDOWS) { // stupid root certificates on Windows! $request = new HTTP_Request2(); $request->setConfig('ssl_verify_peer', false); } else { $request = new HTTP_Request2(); $request->setConfig('ssl_cafile', '/etc/ssl/certs/ca-certificates.crt'); } $process->setRequest($request); return array($process); } public static function mockDataProviderHelper($file) { $process = self::aProcessor(); $mock = new HTTP_Request2_Adapter_Mock(); $mock->addResponse(self::aResponse($file)); $request = new HTTP_Request2(); $request->setAdapter($mock); $process->setRequest($request); return array($process); } public static function dataProviderHelper($file) { $data = array(); if ($mock = self::mockDataProviderHelper($file)) { $data[] = $mock; } if ($sandbox = self::sandboxDataProviderHelper()) { $data[] = $sandbox; } return $data; } public static function aProcessor() { $process = Payment_Process2::factory('ANZ'); $process->action = Payment_Process2::ACTION_NORMAL; return $process; } public static function aResponse($file) { $fp = fopen(dirname(__FILE__) .'/data/ANZ/'. $file .'.html', 'r'); return HTTP_Request2_Adapter_Mock::createResponseFromFile($fp); } /** * @dataProvider successProvider * @param Payment_Process2_ANZ $process */ public function testShouldProcessPaymentSuccessfully(Payment_Process2_ANZ $process) { $cc = $this->aMockANZCard(); $process->invoiceNumber = '123'; $process->transactionReference = '123/2'; $process->amount = 1.00; $process->setPayment($cc); $result = $process->process(); $this->assertTrue($result instanceOf Payment_Process2_Result_ANZ); $this->assertSame(Payment_Process2::RESULT_APPROVED, $result->getCode(), $result->getMessage()); } /** * @dataProvider errorProvider * @param Payment_Process2_ANZ $process */ public function testShouldReturnErrorOnPaymentFailure(Payment_Process2_ANZ $process) { $cc = $this->aMockANZCard(); $process->invoiceNumber = '123'; $process->transactionReference = '123/4'; $process->amount = 1.33; $process->setPayment($cc); $result = $process->process(); $this->assertTrue($result instanceOf Payment_Process2_Result_ANZ); $this->assertSame(Payment_Process2::RESULT_DECLINED, $result->getCode(), $result->getMessage()); } public function testShouldMapCardExpiryDataCorrectly() { $processor = self::aProcessor(); $cc = $this->aMockANZCard(); $cc->expDate = '12/2013'; $processor->setPayment($cc); $changed_data = $processor->prepareRequestData(); $this->assertSame('1312', $changed_data["vpc_CardExp"], "Didn't correctly map into YYMM format"); } public function testShouldAlwaysRequireATransactionReference() { $payment = Payment_Process2::factory('ANZ'); $payment->action = Payment_Process2::ACTION_NORMAL; $payment->amount = 123.00; $payment->setPayment($this->aMockANZCard()); try { $payment->validate(); $this->fail("Expected an exception because we haven't got anything for vpc_MerchTxnRef"); } catch (Payment_Process2_Exception $ppe) { $this->assertSame("Missing transaction reference", $ppe->getMessage()); } } /** * Test not sending the security code * * @dataProvider successProvider * @param Payment_Process2_ANZ $process */ public function testShouldAllowTheSecurityCodeToBeSetOptionally(Payment_Process2_ANZ $process) { $cc = $this->aMockANZCard(); $cc->cvv = null; $process->invoiceNumber = '123'; $process->transactionReference = '123/2'; $process->amount = 1.00; $process->setPayment($cc); $result = $process->process(); $this->assertTrue($result instanceOf Payment_Process2_Result_ANZ); $this->assertSame(Payment_Process2::RESULT_APPROVED, $result->getCode(), $result->getMessage()); } /** * @dataProvider successProvider * @param Payment_Process2_ANZ $process */ public function testShouldNotAllowNegativeCharges(Payment_Process2_ANZ $process) { $cc = $this->aMockANZCard(); $process->invoiceNumber = '123'; $process->transactionReference = '123/2'; $process->amount = -1.00; $process->setPayment($cc); try { $process->process(); } catch (Payment_Process2_Exception $e) { $this->assertSame('Invalid amount', $e->getMessage()); } } /** * @deprecated * * @return Payment_Process2_Type_CreditCard */ public function aMockANZCard() { /* @var Payment_Process2_Type_CreditCard $cc */ $cc = Payment_Process2_Type::factory('MockCreditCard'); $cc->type = Payment_Process2_Type::CC_MASTERCARD; $cc->cardNumber = '5123456789012346'; $cc->expDate = '13/2005'; $cc->cvv = '123'; return $cc; } } http://cvs.php.net/viewvc.cgi/pear/Payment_Process2/tests/Payment_Process2_Result_ANZTest.php?view=markup&rev=1.1 Index: pear/Payment_Process2/tests/Payment_Process2_Result_ANZTest.php +++ pear/Payment_Process2/tests/Payment_Process2_Result_ANZTest.php <?php require_once 'PHPUnit/Framework/TestCase.php'; require_once 'Payment/Process2.php'; class Payment_Process2_Result_ANZTest extends PHPUnit_Framework_TestCase { public function fetchData($file) { $path = dirname(__FILE__) . '/data/ANZ/' . $file . '.html'; return file_get_contents($path); } public function aResult($case) { $result = Payment_Process2_Result::factory('ANZ', $this->fetchData($case), new Payment_Process2_Common()); $result->parse(); return $result; } public function testShouldCorrectlyUnderstandSuccessResponse() { $result = $this->aResult('success'); $this->assertSame(Payment_Process2::RESULT_APPROVED, $result->getCode()); $this->assertSame("Approved", $result->getMessage()); } public function testShouldCorrectlyUnderstandCouldNotBeProcessedResponse() { $result = $this->aResult('not_processed'); $this->assertSame(Payment_Process2::RESULT_OTHER, $result->getCode()); $this->assertSame("Transaction could not be processed", $result->getMessage()); } public function testShouldCorrectlyUnderstandDeclinedResponse() { $result = $this->aResult('declined'); $this->assertSame(Payment_Process2::RESULT_DECLINED, $result->getCode()); $this->assertSame("Transaction declined - contact issuing bank", $result->getMessage()); } public function testShouldCorrectlyUnderstandNoReplyFromProcessingHostResponse() { $result = $this->aResult('no_reply'); $this->assertSame(Payment_Process2::RESULT_OTHER, $result->getCode()); $this->assertSame("No reply from processing host", $result->getMessage()); } public function testShouldCorrectlyUnderstandCardHasExpiredResponse() { $result = $this->aResult('expired'); $this->assertSame(Payment_Process2::RESULT_DECLINED, $result->getCode()); $this->assertSame("Card has expired", $result->getMessage()); } public function testShouldCorrectlyUnderstandInsufficientCreditResponse() { $result = $this->aResult('insufficient_credit'); $this->assertSame(Payment_Process2::RESULT_DECLINED, $result->getCode()); $this->assertSame("Insufficient credit", $result->getMessage()); } public function testShouldCorrectlyUnderstandCommunicationErrorResponse() { $result = $this->aResult('communication'); $this->assertSame(Payment_Process2::RESULT_OTHER, $result->getCode()); $this->assertSame("Error communicating with bank", $result->getMessage()); } public function testShouldCorrectlyUnderstandInvalidPanResponse() { $result = $this->aResult('invalid_pan'); $this->assertSame(Payment_Process2::RESULT_DECLINED, $result->getCode()); $this->assertSame("Message detail error", $result->getMessage()); } public function testShouldCorrectlyUnderstandInvalidExpiryResponse() { $result = $this->aResult('invalid_expiry'); $this->assertSame(Payment_Process2::RESULT_DECLINED, $result->getCode()); $this->assertSame("Message detail error", $result->getMessage()); } public function testShouldCorrectlyUnderstandInvalidTransactionTypeResponse() { $result = $this->aResult('invalid_transaction'); $this->assertSame(Payment_Process2::RESULT_DECLINED, $result->getCode()); $this->assertSame("Transaction declined - transaction type not supported", $result->getMessage()); } public function testShouldCorrectlyUnderstandInvalidBankDeclinedGoAwayResponse() { $result = $this->aResult('declined_go_away'); $this->assertSame(Payment_Process2::RESULT_DECLINED, $result->getCode()); $this->assertSame("Bank declined transaction - do not contact bank", $result->getMessage()); } }
« previous php.pear.cvs (#56039) next »