From be84446f2e00e41554cfe76bd4d20783ea332a12 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Wed, 15 Nov 2017 20:50:12 +0000 Subject: [PATCH] Add unit test for CaseContact.create --- tests/phpunit/api/v3/CaseContactTest.php | 21 ++++++++++++++++++ tests/phpunit/api/v3/CaseTest.php | 27 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tests/phpunit/api/v3/CaseContactTest.php b/tests/phpunit/api/v3/CaseContactTest.php index 6e8782699e..cdfb5c0ed3 100644 --- a/tests/phpunit/api/v3/CaseContactTest.php +++ b/tests/phpunit/api/v3/CaseContactTest.php @@ -9,6 +9,7 @@ class api_v3_CaseContactTest extends CiviCaseTestCase { protected $_params; protected $_entity; protected $_cid; + protected $_cid2; /** * Activity ID of created case. * @@ -28,12 +29,18 @@ class api_v3_CaseContactTest extends CiviCaseTestCase { parent::setUp(); $this->_cid = $this->individualCreate(); + $this->_cid2 = $this->individualCreate(array(), 1); $this->_case = $this->callAPISuccess('case', 'create', array( 'case_type_id' => $this->caseTypeId, 'subject' => __CLASS__, 'contact_id' => $this->_cid, )); + + $this->_params = array( + 'case_id' => $this->_case['id'], + 'contact_id' => $this->_cid2, + ); } public function testCaseContactGet() { @@ -43,4 +50,18 @@ class api_v3_CaseContactTest extends CiviCaseTestCase { $this->assertEquals($this->_case['id'], $result['id']); } + /** + * Test create function with valid parameters. + */ + public function testCaseContactCreate() { + $params = $this->_params; + $result = $this->callAPIAndDocument('CaseContact', 'create', $params, __FUNCTION__, __FILE__); + $id = $result['id']; + + // Check result + $result = $this->callAPISuccess('CaseContact', 'get', array('id' => $id)); + $this->assertEquals($result['values'][$id]['case_id'], $params['case_id']); + $this->assertEquals($result['values'][$id]['contact_id'], $params['contact_id']); + } + } diff --git a/tests/phpunit/api/v3/CaseTest.php b/tests/phpunit/api/v3/CaseTest.php index 9330a6958e..0e34acd9a7 100644 --- a/tests/phpunit/api/v3/CaseTest.php +++ b/tests/phpunit/api/v3/CaseTest.php @@ -203,6 +203,33 @@ class api_v3_CaseTest extends CiviCaseTestCase { $this->assertAPIArrayComparison($result, $case); } + /** + * Test update (create with id) function with valid parameters. + */ + public function testCaseUpdateWithExistingCaseContact() { + $params = $this->_params; + // Test using name instead of value + unset($params['case_type_id']); + $params['case_type'] = $this->caseType; + $result = $this->callAPISuccess('case', 'create', $params); + $id = $result['id']; + $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id)); + + // Update Case, we specify existing case ID and existing contact ID to verify that CaseContact.create is not called + $params = $this->_params; + $params['id'] = $id; + $this->callAPISuccess('case', 'create', $params); + + // Verify that updated case is equal to the original with new subject. + $result = $this->callAPISuccessGetSingle('Case', array('case_id' => $id)); + // Modification dates are likely to differ by 0-2 sec. Check manually. + $this->assertGreaterThanOrEqual($result['modified_date'], $case['modified_date']); + unset($result['modified_date']); + unset($case['modified_date']); + // Everything else should be identical. + $this->assertAPIArrayComparison($result, $case); + } + /** * Test case update with custom data */ -- 2.25.1