From eaefbeb210c369333bfe69590ad79fc7b0d2737d Mon Sep 17 00:00:00 2001 From: Nileema Date: Wed, 7 May 2014 19:50:12 +0530 Subject: [PATCH] CRM-14475 Create basic CRUD API for CaseType ---------------------------------------- * CRM-14475: Create basic CRUD API for CaseType https://issues.civicrm.org/jira/browse/CRM-14475 --- api/v3/CaseType.php | 86 +++++++++++++++ tests/phpunit/api/v3/CaseTypeTest.php | 148 ++++++++++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 api/v3/CaseType.php create mode 100644 tests/phpunit/api/v3/CaseTypeTest.php diff --git a/api/v3/CaseType.php b/api/v3/CaseType.php new file mode 100644 index 0000000000..e3a137c47a --- /dev/null +++ b/api/v3/CaseType.php @@ -0,0 +1,86 @@ +_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() { + $result = $this->callAPIFailure('CaseType', 'create', array()); + } + + /** + * check if required fields are not passed + */ + function testCaseTypeCreateWithoutRequired() { + $params = array( + 'name' => 'this case should fail', + ); + $result = $this->callAPIFailure('CaseType', 'create', $params); + + $params = array( + 'name' => 'this case should fail', + 'weight' => 4, + ); + $result = $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'; + $result = $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']; + $result = $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']); + } +} + -- 2.25.1