_entity = 'CaseType'; 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'); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * */ function tearDown() { $this->quickCleanup($this->tablesToTruncate, TRUE); } /** * check with empty array */ function testCaseTypeCreateEmpty() { $this->callAPIFailure('CaseType', 'create', array()); } /** * check if required fields are not passed */ function testCaseTypeCreateWithoutRequired() { $params = array( 'name' => 'this case should fail', ); $this->callAPIFailure('CaseType', 'create', $params); $params = array( 'name' => 'this case should fail', 'weight' => 4, ); $this->callAPIFailure('CaseType', 'create', $params); } /** * test create methods with valid data * success expected */ function testCaseTypeCreate() { // Create Case Type $params = array( 'title' => 'Application', 'name' => 'Application', 'is_active' => 1, 'weight' => 4, ); $result = $this->callAPISuccess('CaseType', 'create', $params); $id = $result['id']; // Check result $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); $this->assertEquals($result['values'][$id]['id'], $id, 'in line ' . __LINE__); $this->assertEquals($result['values'][$id]['title'], $params['title'], 'in line ' . __LINE__); } /** * Test update (create with id) function with valid parameters */ function testCaseTypeUpdate() { // Create Case Type $params = array( 'title' => 'Application', 'name' => 'Application', 'is_active' => 1, 'weight' => 4, ); $result = $this->callAPISuccess('CaseType', 'create', $params); $id = $result['id']; $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); $caseType = $result['values'][$id]; // Update Case Type $params = array('id' => $id); $params['title'] = $caseType['title'] = 'Something Else'; $this->callAPISuccess('CaseType', 'create', $params); // Verify that updated case Type is exactly equal to the original with new title $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); $this->assertEquals($result['values'][$id], $caseType, 'in line ' . __LINE__); } /** * Test delete function with valid parameters */ function testCaseTypeDelete() { // Create Case Type $params = array( 'title' => 'Application', 'name' => 'Application', 'is_active' => 1, 'weight' => 4, ); $result = $this->callAPISuccess('CaseType', 'create', $params); $id = $result['id']; $this->callAPISuccess('CaseType', 'delete', array('id' => $id)); // Check result - case type should no longer exist $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id)); $this->assertEquals(0, $result['count']); } /** * test create methods with xml file * success expected */ function testCaseTypeCreateWithXML() { $caseXMLFile = dirname(__FILE__) . '/dataset/sample_case.xml'; // Create Case Type $params = array( 'title' => 'Application with XML', 'name' => 'Application_with_XML', 'is_active' => 1, 'weight' => 4, 'definition' => file_get_contents($caseXMLFile), ); $result = $this->callAPISuccess('CaseType', 'create', $params); $id = $result['id']; // Check result $result = $this->callAPISuccess('CaseType', 'get', array('id' => $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]['xml_definition'], $params['xml_definition'], 'in line ' . __LINE__); } }