_apiversion = 3; $this->_params = array( 'version' => $this->_apiversion, ); parent::setUp(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @access protected */ protected function tearDown() {} /** * Create a sample batch */ function batchCreate() { $params = $this->_params; $params['name'] = $params['title'] = 'Batch_' . mt_rand(0, 999999); $params['status_id'] = 1; $result = civicrm_api('batch', 'create', $params); return $result['id']; } ///////////////// civicrm_batch_get methods /** * Test civicrm_batch_get with wrong params type. */ public function testGetWrongParamsType() { $params = 'is_string'; $result = $this->callAPIFailure('batch', 'get', $params); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } /** * Test civicrm_batch_get - success expected. */ public function testGet() { $params = array( 'id' => $this->batchCreate(), 'version' => $this->_apiversion, ); $result = civicrm_api('batch', 'get', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); $this->assertEquals($params['id'], $result['id'], 'In line ' . __LINE__); } ///////////////// civicrm_batch_create methods /** * Test civicrm_batch_create with empty params. */ function testCreateEmptyParams() { $this->callAPIFailure('batch', 'create', $this->_params); } /** * Test civicrm_batch_create - success expected. */ function testCreate() { $params = array( 'name' => 'New_Batch_03', 'title' => 'New Batch 03', 'description' => 'This is description for New Batch 03', 'total' => '300.33', 'item_count' => 3, 'status_id' => 1, 'version' => $this->_apiversion, ); $result = civicrm_api('batch', 'create', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); $this->assertNotNull($result['id'], 'In line ' . __LINE__); // Fetch batch and compare values $saved = civicrm_api('batch', 'getSingle', $result); unset($params['version']); foreach ($params as $key => $value) { $this->assertEquals($value, $saved[$key], 'In line ' . __LINE__); } } /** * Test civicrm_batch_create with id. */ function testUpdate() { $params = array( 'name' => 'New_Batch_04', 'title' => 'New Batch 04', 'description' => 'This is description for New Batch 04', 'total' => '400.44', 'item_count' => 4, 'version' => $this->_apiversion, 'id' => $this->batchCreate(), ); $result = civicrm_api('batch', 'create', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); $this->assertNotNull($result['id'], 'In line ' . __LINE__); // Fetch batch and compare values $saved = civicrm_api('batch', 'getSingle', $result); unset($params['version']); foreach ($params as $key => $value) { $this->assertEquals($value, $saved[$key], 'In line ' . __LINE__); } } ///////////////// civicrm_batch_delete methods /** * Test civicrm_batch_delete without batch id. */ function testDeleteWithoutBatchId() { $result = civicrm_api('batch', 'delete', array('version' => $this->_apiversion)); $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); $this->assertEquals('Mandatory key(s) missing from params array: id', $result['error_message'], 'In line ' . __LINE__); } /** * Test civicrm_batch_delete with wrong batch id type. */ function testDeleteWrongParams() { $result = $this->callAPIFailure('batch', 'delete', 'tyttyd'); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } /** * Test civicrm_batch_delete using the old $params['batch_id'] syntax. */ function testBatchDeleteOldSyntax() { $batchID = $this->batchCreate(); $params = array( 'batch_id' => $batchID, 'version' => $this->_apiversion, ); $result = civicrm_api('batch', 'delete', $params); $this->assertAPISuccess($result, 'In line ' . __LINE__); } /** * Test civicrm_batch_delete using the new $params['id'] syntax */ function testBatchDeleteCorrectSyntax() { $batchID = $this->batchCreate(); $params = array( 'id' => $batchID, 'version' => $this->_apiversion, ); $result = civicrm_api('batch', 'delete', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); } }