From ec5da26ad10dc2ad664e9cc7952d7031f01e6569 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 28 Oct 2016 21:41:09 +0530 Subject: [PATCH] CRM-17807: unit test to check if invoice is created for paypal std. --- .../phpunit/CRM/Core/Payment/PayPalPNTest.php | 21 ++++++++++++++++++- tests/phpunit/CiviTest/CiviUnitTestCase.php | 21 +++++++++++++++++++ .../api/v3/TaxContributionPageTest.php | 13 +----------- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/CRM/Core/Payment/PayPalPNTest.php b/tests/phpunit/CRM/Core/Payment/PayPalPNTest.php index b8c5f507e7..145e8748c4 100644 --- a/tests/phpunit/CRM/Core/Payment/PayPalPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/PayPalPNTest.php @@ -67,7 +67,15 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { $this->quickCleanUpFinancialEntities(); } - public function testIPNPaymentSuccess() { + /** + * Test IPN response updates contribution and invoice is attached in mail reciept + * + * The scenario is that a pending contribution exists and the IPN call will update it to completed. + * And also if Tax and Invoicing is enabled, this unit test ensure that invoice pdf is attached with email recipet + */ + public function testInvoiceSentOnIPNPaymentSuccess() { + $this->enableTaxAndInvoicing(); + $pendingStatusID = CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name'); $completedStatusID = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); $params = array( @@ -76,6 +84,7 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { 'trxn_id' => NULL, 'invoice_id' => $this->_invoiceID, 'contribution_status_id' => $pendingStatusID, + 'is_email_receipt' => TRUE, ); $this->_contributionID = $this->contributionCreate($params); $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1)); @@ -86,10 +95,19 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { global $_REQUEST; $_REQUEST = array('q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)) + $this->getPaypalTransaction(); + $mut = new CiviMailUtils($this, TRUE); $paymentProcesors = civicrm_api3('PaymentProcessor', 'getsingle', array('id' => $this->_paymentProcessorID)); $payment = Civi\Payment\System::singleton()->getByProcessor($paymentProcesors); $payment->handlePaymentNotification(); + // Check if invoice pdf is attached with contribution mail reciept + $mut->checkMailLog(array( + 'Content-Transfer-Encoding: base64', + 'Content-Type: application/pdf', + 'filename=Invoice.pdf', + )); + $mut->stop(); + $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1)); // assert that contribution is completed after getting response from paypal standard which has transaction id set and completed status $this->assertEquals($_REQUEST['txn_id'], $contribution['values'][0]['trxn_id']); @@ -204,6 +222,7 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase { 'first_name' => 'Robert', 'txn_id' => '8XA571746W2698126', 'residence_country' => 'US', + 'custom' => '[]', ); } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 86cda4b725..73fa71aa9f 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3624,4 +3624,25 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) } } + /** + * Enable Tax and Invoicing + */ + protected function enableTaxAndInvoicing($params = array()) { + // Enable component contribute setting + $contributeSetting = array_merge($params, + array( + 'invoicing' => 1, + 'invoice_prefix' => 'INV_', + 'credit_notes_prefix' => 'CN_', + 'due_date' => 10, + 'due_date_period' => 'days', + 'notes' => '', + 'is_email_pdf' => 1, + 'tax_term' => 'Sales Tax', + 'tax_display_settings' => 'Inclusive', + ) + ); + return Civi::settings()->set('contribution_invoice_settings', $contributeSetting); + } + } diff --git a/tests/phpunit/api/v3/TaxContributionPageTest.php b/tests/phpunit/api/v3/TaxContributionPageTest.php index c897e8bb5b..8ac272cc90 100644 --- a/tests/phpunit/api/v3/TaxContributionPageTest.php +++ b/tests/phpunit/api/v3/TaxContributionPageTest.php @@ -142,18 +142,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { $halfFinancialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationHalftax); // Enable component contribute setting - $contributeSetting = array( - 'invoicing' => 1, - 'invoice_prefix' => 'INV_', - 'credit_notes_prefix' => 'CN_', - 'due_date' => 10, - 'due_date_period' => 'days', - 'notes' => '', - 'is_email_pdf' => 1, - 'tax_term' => 'Sales Tax', - 'tax_display_settings' => 'Inclusive', - ); - $setInvoiceSettings = Civi::settings()->set('contribution_invoice_settings', $contributeSetting); + $setInvoiceSettings = $this->enableTaxAndInvoicing(); // Payment Processor $paymentProceParams = array( -- 2.25.1