Skip to content

Commit

Permalink
CIVICRM-1290 CIVICRM-967 Add unit test: Migrate custom file attachmen…
Browse files Browse the repository at this point in the history
…ts to new case on reassignment

Add unit test from PR civicrm#14213 Migrate custom file attachments to new case on reassignment. civicrm#14213
  • Loading branch information
agileware-justin committed Aug 16, 2019
1 parent 2f00392 commit 2a7b052
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/phpunit/CRM/Case/BAO/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,64 @@ public function testRetrieveCaseIdsByContactId() {
$this->assertEquals(array(1), $caseIds);
}

/**
* Test that all custom files are migrated to new case when case is assigned to new client.
*/
public function testCaseReassignForCustomFiles() {
$individual = $this->individualCreate();
$customGroup = $this->customGroupCreate(array(
'extends' => 'Case',
));
$customGroup = $customGroup['values'][$customGroup['id']];
$customFileFieldA = $this->customFieldCreate(array(
'custom_group_id' => $customGroup['id'],
'html_type' => 'File',
'is_active' => 1,
'default_value' => 'null',
'label' => 'Custom File A',
'data_type' => 'File',
));
$customFileFieldB = $this->customFieldCreate(array(
'custom_group_id' => $customGroup['id'],
'html_type' => 'File',
'is_active' => 1,
'default_value' => 'null',
'label' => 'Custom File B',
'data_type' => 'File',
));

$fileA = $this->callAPISuccess('File', 'create', array(
'uri' => 'test_file_uri',
));
$fileB = $this->callAPISuccess('File', 'create', array(
'uri' => 'test_file_uri_2',
));

$caseObj = $this->createCase($individual);

$this->callAPISuccess('Case', 'create', array(
'id' => $caseObj->id,
'custom_' . $customFileFieldA['id'] => $fileA['id'],
'custom_' . $customFileFieldB['id'] => $fileB['id'],
));

$reassignIndividual = $this->individualCreate();
$this->createLoggedInUser();
$newCase = CRM_Case_BAO_Case::mergeCases($reassignIndividual, $caseObj->id, $individual, NULL, TRUE);

$entityFiles = new CRM_Core_DAO_EntityFile();
$entityFiles->entity_id = $newCase[0];
$entityFiles->entity_table = $customGroup['table_name'];
$entityFiles->find();

$totalEntityFiles = 0;
while ($entityFiles->fetch()) {
$totalEntityFiles++;
}

$this->assertEquals(2, $totalEntityFiles, 'Two files should be attached with new case.');
}

/**
* FIXME: need to create an activity to run this test
* function testGetCases() {
Expand Down

0 comments on commit 2a7b052

Please sign in to comment.