Skip to content

Commit

Permalink
Merge pull request #11268 from mattwire/CRM-21421_allow_updating_exis…
Browse files Browse the repository at this point in the history
…ting_casecontact

CRM-21421 Fix to allow updating an existing CaseContact record
  • Loading branch information
colemanw authored Nov 17, 2017
2 parents e35945c + be84446 commit b8dd91f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/phpunit/api/v3/CaseContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class api_v3_CaseContactTest extends CiviCaseTestCase {
protected $_params;
protected $_entity;
protected $_cid;
protected $_cid2;
/**
* Activity ID of created case.
*
Expand All @@ -28,12 +29,18 @@ public function setUp() {
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() {
Expand All @@ -43,4 +50,18 @@ public function testCaseContactGet() {
$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']);
}

}
27 changes: 27 additions & 0 deletions tests/phpunit/api/v3/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,33 @@ public function testCaseUpdate() {
$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
*/
Expand Down

0 comments on commit b8dd91f

Please sign in to comment.