Skip to content

Commit

Permalink
api_v3_TaxContributionPageTest fix - remove hard coded processor id
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 16, 2020
1 parent 54625e2 commit 6f34ae9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 69 deletions.
14 changes: 14 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
api_v3_TaxContributionPageTest fix - remove hard coded processor id

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Thu Jul 16 19:12:54 2020 +1200
#
# On branch test
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# modified: tests/phpunit/api/v3/TaxContributionPageTest.php
#
122 changes: 53 additions & 69 deletions tests/phpunit/api/v3/TaxContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* @group headless
*/
class api_v3_TaxContributionPageTest extends CiviUnitTestCase {
protected $_apiversion = 3;
protected $params;
protected $financialtypeID;
protected $financialTypeID;
protected $financialAccountId;
protected $_entity = 'contribution_page';
protected $_priceSetParams = [];
Expand All @@ -25,39 +24,38 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase {
protected $paymentProceParams = [];
protected $settingValue = [];
protected $setInvoiceSettings;
protected $_ids = [];
protected $_individualId;
protected $financialAccHalftax;
protected $financialtypeHalftax;
protected $financialRelationHalftax;
protected $halfFinancialAccId;
protected $halfFinancialTypeId;
public $DBResetRequired = TRUE;

public function setUp() {
parent::setUp();
$this->_individualId = $this->individualCreate();
$this->_orgId = $this->organizationCreate(NULL);

$this->ids['PaymentProcessor'] = $this->paymentProcessorCreate();
$this->params = [
'title' => "Test Contribution Page" . substr(sha1(rand()), 0, 7),
'title' => 'Test Contribution Page' . substr(sha1(rand()), 0, 7),
'financial_type_id' => 1,
'payment_processor' => 1,
'payment_processor' => $this->ids['PaymentProcessor'],
'currency' => 'NZD',
'goal_amount' => 350,
'is_pay_later' => 1,
'pay_later_text' => 'I will pay later',
'pay_later_receipt' => "I will pay later",
'pay_later_receipt' => 'I will pay later',
'is_monetary' => TRUE,
'is_billing_required' => TRUE,
];

$this->_priceSetParams = [
'name' => 'tax_contribution' . substr(sha1(rand()), 0, 7),
'title' => 'contributiontax' . substr(sha1(rand()), 0, 7),
'title' => 'contribution tax' . substr(sha1(rand()), 0, 7),
'is_active' => 1,
'help_pre' => "Where does your goat sleep",
'help_post' => "thank you for your time",
'help_pre' => 'Where does your goat sleep',
'help_post' => 'thank you for your time',
'extends' => 2,
'financial_type_id' => 3,
'is_quick_config' => 0,
Expand All @@ -79,21 +77,19 @@ public function setUp() {
$financialAccount = $this->callAPISuccess('financial_account', 'create', $financialAccountSetparams);
$this->financialAccountId = $financialAccount['id'];

// Financial type having 'Sales Tax Account is' with liability financail account
$financialType = [
// Financial type having 'Sales Tax Account is' with liability financial account
$this->financialTypeID = $this->callAPISuccess('FinancialType', 'create', [
'name' => 'grassvariety1' . substr(sha1(rand()), 0, 7),
'is_reserved' => 0,
'is_active' => 1,
];
$priceField = $this->callAPISuccess('financial_type', 'create', $financialType);
$this->financialtypeID = $priceField['id'];
])['id'];
$financialRelationParams = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $this->financialtypeID,
'entity_id' => $this->financialTypeID,
'account_relationship' => 10,
'financial_account_id' => $this->financialAccountId,
];
$financialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationParams);
CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationParams);

// Financial type with 5% tax rate
$financialAccHalftax = [
Expand Down Expand Up @@ -123,31 +119,10 @@ public function setUp() {
'financial_account_id' => $this->halfFinancialAccId,
];

$halfFinancialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationHalftax);
CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationHalftax);

// Enable component contribute setting
$setInvoiceSettings = $this->enableTaxAndInvoicing();

// Payment Processor
$paymentProceParams = [
'domain_id' => 1,
'name' => 'dummy' . substr(sha1(rand()), 0, 7),
'payment_processor_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', 'Dummy'),
'financial_account_id' => 12,
'is_active' => 1,
'is_default' => 1,
'user_name' => 'dummy',
'url_site' => 'http://dummy.com',
'url_recur' => 'http://dummyrecur.com',
'class_name' => 'Payment_Dummy',
'billing_mode' => 1,
'is_recur' => 1,
'payment_type' => 1,
];
$result = $this->callAPISuccess('payment_processor', 'create', $paymentProceParams);
$this->_ids['paymentProcessID'] = $result['id'];
require_once 'api/v3/examples/PaymentProcessor/Create.ex.php';
$this->assertAPISuccess($result);
$this->enableTaxAndInvoicing();
}

/**
Expand All @@ -158,6 +133,9 @@ public function tearDown() {
parent::tearDown();
}

/**
* @throws \CRM_Core_Exception
*/
public function setUpContributionPage() {
$contributionPageResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
if (empty($this->_ids['price_set'])) {
Expand All @@ -181,7 +159,7 @@ public function setUpContributionPage() {
'price_field_id' => $priceField['id'],
'label' => 'Long Haired Goat',
'amount' => 100,
'financial_type_id' => $this->financialtypeID,
'financial_type_id' => $this->financialTypeID,
]);
$priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
Expand All @@ -202,6 +180,8 @@ public function setUpContributionPage() {
* punctuation used to refer to thousands.
*
* @dataProvider getThousandSeparators
*
* @throws \CRM_Core_Exception
*/
public function testCreateContributionOnline($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
Expand All @@ -210,9 +190,9 @@ public function testCreateContributionOnline($thousandSeparator) {
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => $this->formatMoneyInput(100.00),
'financial_type_id' => $this->financialtypeID,
'financial_type_id' => $this->financialTypeID,
'contribution_page_id' => $this->_ids['contribution_page'],
'payment_processor' => $this->_ids['paymentProcessID'],
'payment_processor' => $this->ids['PaymentProcessor'],
'trxn_id' => 12345,
'invoice_id' => 67890,
'source' => 'SSF',
Expand All @@ -223,7 +203,7 @@ public function testCreateContributionOnline($thousandSeparator) {
$this->_ids['contributionId'] = $contribution['id'];
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
$this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00);
$this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialtypeID);
$this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialTypeID);
$this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
$this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
$this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
Expand All @@ -239,6 +219,8 @@ public function testCreateContributionOnline($thousandSeparator) {
* punctuation used to refer to thousands.
*
* @dataProvider getThousandSeparators
*
* @throws \CRM_Core_Exception
*/
public function testCreateContributionChainedLineItems($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
Expand All @@ -247,7 +229,7 @@ public function testCreateContributionChainedLineItems($thousandSeparator) {
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 400.00,
'financial_type_id' => $this->financialtypeID,
'financial_type_id' => $this->financialTypeID,
'trxn_id' => 12345,
'invoice_id' => 67890,
'source' => 'SSF',
Expand All @@ -259,7 +241,7 @@ public function testCreateContributionChainedLineItems($thousandSeparator) {
'qty' => 1,
'line_total' => '100',
'unit_price' => '100',
'financial_type_id' => $this->financialtypeID,
'financial_type_id' => $this->financialTypeID,
],
[
'price_field_id' => $this->_ids['price_field'],
Expand Down Expand Up @@ -288,23 +270,24 @@ public function testCreateContributionPayLaterOnline() {
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => $this->financialtypeID,
'financial_type_id' => $this->financialTypeID,
'contribution_page_id' => $this->_ids['contribution_page'],
'trxn_id' => 12345,
'is_pay_later' => 1,
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 2,
];
$contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
$this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00);
$this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialtypeID);
$this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
$this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
$this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
$this->assertEquals($contribution['values'][$contribution['id']]['tax_amount'], 20);
$this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 2);
$contribution = $this->callAPISuccess('Contribution', 'create', $params);
$contribution = $contribution['values'][$contribution['id'];
$this->assertEquals($contribution['contact_id'], $this->_individualId);
$this->assertEquals($contribution['total_amount'], 120.00);
$this->assertEquals($contribution['financial_type_id'], $this->financialTypeID);
$this->assertEquals($contribution['trxn_id'], 12345);
$this->assertEquals($contribution['invoice_id'], 67890);
$this->assertEquals($contribution['source'], 'SSF');
$this->assertEquals($contribution['tax_amount'], 20);
$this->assertEquals($contribution['contribution_status_id'], 2);
$this->_checkFinancialRecords($contribution, 'payLater');
}

Expand All @@ -315,6 +298,8 @@ public function testCreateContributionPayLaterOnline() {
* punctuation used to refer to thousands.
*
* @dataProvider getThousandSeparators
*
* @throws \CRM_Core_Exception
*/
public function testCreateContributionPendingOnline($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
Expand All @@ -323,7 +308,7 @@ public function testCreateContributionPendingOnline($thousandSeparator) {
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => $this->formatMoneyInput(100.00),
'financial_type_id' => $this->financialtypeID,
'financial_type_id' => $this->financialTypeID,
'contribution_page_id' => $this->_ids['contribution_page'],
'trxn_id' => 12345,
'invoice_id' => 67890,
Expand All @@ -334,7 +319,7 @@ public function testCreateContributionPendingOnline($thousandSeparator) {
$contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
$this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00);
$this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialtypeID);
$this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialTypeID);
$this->assertEquals($contribution['values'][$contribution['id']]['trxn_id'], 12345);
$this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
$this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
Expand All @@ -355,7 +340,7 @@ public function testCreateUpdateContributionChangeTotal() {
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => $this->financialtypeID,
'financial_type_id' => $this->financialTypeID,
'source' => 'SSF',
'contribution_status_id' => 1,
];
Expand Down Expand Up @@ -403,8 +388,7 @@ public function _getFinancialTrxnAmount($contId) {
LEFT JOIN civicrm_entity_financial_trxn AS ceft ON ft.id = ceft.financial_trxn_id
WHERE ceft.entity_table = 'civicrm_contribution'
AND ceft.entity_id = {$contId}";
$result = CRM_Core_DAO::singleValueQuery($query);
return $result;
return CRM_Core_DAO::singleValueQuery($query);
}

/**
Expand Down Expand Up @@ -432,7 +416,7 @@ public function _checkFinancialRecords($params, $context) {
'entity_id' => $params['id'],
'entity_table' => 'civicrm_contribution',
];
if ($context == 'pending') {
if ($context === 'pending') {
$trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
$this->assertNull($trxn, 'No Trxn to be created until IPN callback');
return;
Expand All @@ -441,21 +425,21 @@ public function _checkFinancialRecords($params, $context) {
$trxnParams = [
'id' => $trxn['financial_trxn_id'],
];
if ($context != 'online' && $context != 'payLater') {
if ($context !== 'online' && $context !== 'payLater') {
$compareParams = [
'to_financial_account_id' => 6,
'total_amount' => 120,
'status_id' => 1,
];
}
if ($context == 'online') {
if ($context === 'online') {
$compareParams = [
'to_financial_account_id' => 12,
'total_amount' => 120,
'status_id' => 1,
];
}
elseif ($context == 'payLater') {
elseif ($context === 'payLater') {
$compareParams = [
'to_financial_account_id' => 7,
'total_amount' => 120,
Expand All @@ -474,13 +458,13 @@ public function _checkFinancialRecords($params, $context) {
$compareParams = [
'amount' => 100,
'status_id' => 1,
'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID),
'financial_account_id' => $this->_getFinancialAccountId($this->financialTypeID),
];
if ($context == 'payLater') {
if ($context === 'payLater') {
$compareParams = [
'amount' => 100,
'status_id' => 3,
'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID),
'financial_account_id' => $this->_getFinancialAccountId($this->financialTypeID),
];
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
Expand Down Expand Up @@ -514,7 +498,7 @@ public function testDeleteContribution() {
$contributionID = $this->contributionCreate([
'contact_id' => $this->_individualId,
'trxn_id' => 12389,
'financial_type_id' => $this->financialtypeID,
'financial_type_id' => $this->financialTypeID,
'invoice_id' => 'dfsdf',
]);
$this->callAPISuccess('contribution', 'delete', ['id' => $contributionID]);
Expand Down

0 comments on commit 6f34ae9

Please sign in to comment.