Commit 2ef8ea5a authored by Pradeep Nayak's avatar Pradeep Nayak Committed by eileen

dev/financial/issues/24, Add unit test for Link payment method to financial...

dev/financial/issues/24, Add unit test for Link payment method to financial account when created using api (#12365)

* Added api test to create new payment method

* updated api test
parent af52a180
......@@ -427,4 +427,86 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
);
}
/**
* Test to create and update payment method with financial account.
*/
public function testCreateUpdateOptionValueForPaymentInstrument() {
$assetFinancialAccountId = $this->callAPISuccessGetValue('FinancialAccount', [
'return' => "id",
'financial_account_type_id' => "Asset",
'options' => ['limit' => 1],
]);
// create new payment method with financial account
$ov = $this->callAPISuccess('OptionValue', 'create', [
'financial_account_id' => $assetFinancialAccountId,
'option_group_id' => "payment_instrument",
'label' => "Dummy Payment Method",
]);
//check if relationship is created between Payment method and Financial Account
$this->checkPaymentMethodFinancialAccountRelationship($ov['id'], $assetFinancialAccountId);
// update payment method to have different non-asset financial Account
$nonAssetFinancialAccountId = $this->callAPISuccessGetValue('FinancialAccount', [
'return' => "id",
'financial_account_type_id' => ['NOT IN' => ["Asset"]],
'options' => ['limit' => 1],
]);
try {
$result = $this->callAPISuccess('OptionValue', 'create', [
'financial_account_id' => $nonAssetFinancialAccountId,
'id' => $ov['id'],
]);
throw new API_Exception(ts('Should throw error.'));
}
catch (Exception $e) {
try {
$assetAccountRelValue = $this->callAPISuccessGetValue('EntityFinancialAccount', [
'return' => "account_relationship",
'entity_table' => "civicrm_option_value",
'entity_id' => $ov['id'],
'financial_account_id' => $nonAssetFinancialAccountId,
]);
throw new API_Exception(ts('Should throw error.'));
}
catch (Exception $e) {
$this->checkPaymentMethodFinancialAccountRelationship($ov['id'], $assetFinancialAccountId);
}
}
// update payment method to have different asset financial Account
$assetFinancialAccountId = $this->callAPISuccessGetValue('FinancialAccount', [
'return' => "id",
'financial_account_type_id' => "Asset",
'options' => ['limit' => 1],
'id' => ['NOT IN' => [$assetFinancialAccountId]],
]);
$result = $this->callAPISuccess('OptionValue', 'create', [
'financial_account_id' => $assetFinancialAccountId,
'id' => $ov['id'],
]);
//check if relationship is updated between Payment method and Financial Account
$this->checkPaymentMethodFinancialAccountRelationship($ov['id'], $assetFinancialAccountId);
}
/**
* Function to check relationship between FA and Payment method.
*
* @param int $paymentMethodId
* @param int $financialAccountId
*/
protected function checkPaymentMethodFinancialAccountRelationship($paymentMethodId, $financialAccountId) {
$assetAccountRelValue = $this->callAPISuccessGetValue('EntityFinancialAccount', [
'return' => "account_relationship",
'entity_table' => "civicrm_option_value",
'entity_id' => $paymentMethodId,
'financial_account_id' => $financialAccountId,
]);
$checkAssetAccountIs = $this->callAPISuccessGetValue('OptionValue', [
'return' => "id",
'option_group_id' => "account_relationship",
'name' => "Asset Account is",
'value' => $assetAccountRelValue,
]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment