From 5c2a4a7bd42f9d26b7cda2aedce62ca6b24de1df Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Thu, 19 Jul 2018 23:00:04 +0530 Subject: [PATCH] added api test --- tests/phpunit/api/v3/FinancialTypeTest.php | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/phpunit/api/v3/FinancialTypeTest.php diff --git a/tests/phpunit/api/v3/FinancialTypeTest.php b/tests/phpunit/api/v3/FinancialTypeTest.php new file mode 100644 index 00000000000..4e87bfdaa88 --- /dev/null +++ b/tests/phpunit/api/v3/FinancialTypeTest.php @@ -0,0 +1,100 @@ +CustomGroupMultipleCreateWithFields([ + 'name' => 'Test_Group_Financial_type', + 'title' => 'Test_Group_Financial_type', + 'extends' => 'FinancialType', + 'is_multiple' => FALSE, + ]); + $financialTypeData = [ + 'Financial Type' . substr(sha1(rand()), 0, 4) => [ + ['Test-1', 'Test-2', NULL], + [NULL, '', 'Test_3'], + ], + 'Financial Type' . substr(sha1(rand()), 0, 4) => [ + [NULL, NULL, NULL], + ['Test_1', NULL, 'Test_3'], + ], + ]; + foreach ($financialTypeData as $financialTypeName => $data) { + $params = [ + 'name' => $financialTypeName, + 'is_deductible' => '1', + 'is_reserved' => '0', + 'is_active' => '1', + ]; + $customFields = []; + foreach ($data[0] as $key => $value) { + $customFields['custom_' . $customFieldIds['custom_field_id'][$key]] = $value; + } + + // create financial type with custom field + $financialType = $this->callAPISuccess('FinancialType', 'create', array_merge($params, $customFields)); + + // get financial type to check custom field value + $expectedResult = array_filter(array_merge($params, $customFields), function($var) { + return (!is_null($var) && $var != ''); + }); + $result = $this->callAPISuccessGetSingle('FinancialType', [ + 'id' => $financialType['id'], + ], $expectedResult); + + // updated financial type with custom field + $updateCustomFields = []; + foreach ($data[1] as $key => $value) { + $updateCustomFields['custom_' . $customFieldIds['custom_field_id'][$key]] = $value; + if (!is_null($value)) { + $customFields['custom_' . $customFieldIds['custom_field_id'][$key]] = $value; + } + } + $this->callAPISuccess('FinancialType', 'create', array_merge([ + 'id' => $financialType['id'], + ], $updateCustomFields)); + + // get financial type to check custom field value + $expectedResult = array_filter(array_merge($params, $customFields), function($var) { + return (!is_null($var) && $var != ''); + }); + $result = $this->callAPISuccessGetSingle('FinancialType', [ + 'id' => $financialType['id'], + ], $expectedResult); + } + } + +}