+--------------------------------------------------------------------+
*/
-require_once 'CiviTest/CiviUnitTestCase.php';
+require_once 'CiviTest/CiviCaseTestCase.php';
/**
* Class api_v3_CaseTypeTest
*/
-class api_v3_CaseTypeTest extends CiviUnitTestCase {
- protected $_apiversion = 3;
+class api_v3_CaseTypeTest extends CiviCaseTestCase {
function setUp() {
- $this->_entity = 'CaseType';
-
+ $this->quickCleanup(array('civicrm_case_type'));
parent::setUp();
- $this->_apiversion = 3;
- $this->tablesToTruncate = array(
- 'civicrm_case_type',
- );
- $this->quickCleanup($this->tablesToTruncate);
- $this->createLoggedInUser();
- $session = CRM_Core_Session::singleton();
- $this->_loggedInUser = $session->get('userID');
+ $this->fixtures['Application_with_Definition'] = array(
+ 'title' => 'Application with Definition',
+ 'name' => 'Application_with_Definition',
+ 'is_active' => 1,
+ 'weight' => 4,
+ 'definition' => array(
+ 'activityTypes' => array(
+ array('name' => 'First act'),
+ ),
+ 'activitySets' => array(
+ array(
+ 'name' => 'set1',
+ 'label' => 'Label 1',
+ 'timeline' => 1,
+ 'activityTypes' => array(
+ array('name' => 'Open Case', 'status' => 'Completed'),
+ ),
+ ),
+ ),
+ 'caseRoles' => array(
+ array('name' => 'First role', 'creator' => 1, 'manager' => 1),
+ ),
+ )
+ );
}
/**
*
*/
function tearDown() {
- $this->quickCleanup($this->tablesToTruncate, TRUE);
+ parent::tearDown();
+ $this->quickCleanup(array('civicrm_case_type'));
}
/**
/**
* Test delete function with valid parameters
*/
- function testCaseTypeDelete() {
+ function testCaseTypeDelete_New() {
// Create Case Type
$params = array(
'title' => 'Application',
*/
function testCaseTypeCreateWithDefinition() {
// Create Case Type
- $params = array(
- 'title' => 'Application with Definition',
- 'name' => 'Application_with_Definition',
- 'is_active' => 1,
- 'weight' => 4,
- 'definition' => array(
- 'activityTypes' => array(
- array('name' => 'First act'),
- ),
- 'activitySets' => array(
- array(
- 'name' => 'set1',
- 'label' => 'Label 1',
- 'timeline' => 1,
- 'activityTypes' => array(
- array('name' => 'Open Case', 'status' => 'Completed'),
- ),
- ),
- ),
- 'caseRoles' => array(
- array('name' => 'First role', 'creator' => 1, 'manager' => 1),
- ),
- )
- );
-
+ $params = $this->fixtures['Application_with_Definition'];
$result = $this->callAPISuccess('CaseType', 'create', $params);
$id = $result['id'];
$this->assertEquals($result['values'][$id]['id'], $id, 'in line ' . __LINE__);
$this->assertEquals($result['values'][$id]['title'], $params['title'], 'in line ' . __LINE__);
$this->assertEquals($result['values'][$id]['definition'], $params['definition'], 'in line ' . __LINE__);
+
+ $caseXml = CRM_Case_XMLRepository::singleton()->retrieve('Application_with_Definition');
+ $this->assertTrue($caseXml instanceof SimpleXMLElement);
+ }
+
+ /**
+ * Create a CaseType+case then delete the CaseType.
+ */
+ function testCaseTypeDelete_InUse() {
+ // Create Case Type
+ $params = $this->fixtures['Application_with_Definition'];
+ $createCaseType = $this->callAPISuccess('CaseType', 'create', $params);
+
+ $createCase = $this->callAPISuccess('Case', 'create', array(
+ 'case_type_id' => $createCaseType['id'],
+ 'contact_id' => $this->_loggedInUser,
+ 'subject' => 'Example',
+ ));
+
+ // Deletion fails while case-type is in-use
+ $deleteCaseType = $this->callAPIFailure('CaseType', 'delete', array('id' => $createCaseType['id']));
+ $this->assertEquals("Cannot delete case type -- 1 record(s) depend on it", $deleteCaseType['error_message']);
+ $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
+ $this->assertEquals(1, $getCaseType['count']);
+
+ // Deletion succeeds when it's not in-use
+ $this->callAPISuccess('Case', 'delete', array('id' => $createCase['id']));
+
+ // Check result - case type should no longer exist
+ $this->callAPISuccess('CaseType', 'delete', array('id' => $createCaseType['id']));
+ $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
+ $this->assertEquals(0, $getCaseType['count']);
}
}