<?php
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
* @access public
*
* @example ActivityTypeGet.php
- * @deprecated - use constant_get
+ * @deprecated - use getoptions
*/
function civicrm_api3_activity_type_get($params) {
-
$activityTypes = CRM_Core_OptionGroup::values('activity_type');
return civicrm_api3_create_success($activityTypes, $params, 'activity_type', 'get');
}
*
* @access public
*
- *{@schema Activity/ActivityType.xml}
- *
- * {@example ActivityTypeCreate.php 0}
* @deprecated - we will introduce OptionValue Create - plse consider helping with this if not done
*/
function civicrm_api3_activity_type_create($params) {
-
$action = 1;
$groupParams = array('name' => 'activity_type');
/**
* Function to delete activity type
*
- * @param activityTypeId int activity type id to delete
- *
- * @return boolen
+ * @param array $params array including id of activity_type to delete
+
+ * @return array API result array
*
* @access public
*
* @deprecated - we will introduce OptionValue Delete- plse consider helping with this if not done
- * {@example ActivityTypeDelete.php 0}
*/
function civicrm_api3_activity_type_delete($params) {
-
- civicrm_api3_verify_mandatory($params, NULL, array('activity_type_id'));
-
- $activityTypeId = $params['activity_type_id'];
-
- return CRM_Core_BAO_OptionValue::del($activityTypeId);
+ return civicrm_api3_create_success(CRM_Core_BAO_OptionValue::del($params['id']), $params);
}
class api_v3_ACLCachingTest extends CiviUnitTestCase {
protected $_apiversion = 3;
protected $_params;
-
public $_eNoticeCompliant = TRUE;
+ public $DBResetRequired = FALSE;
function setUp() {
parent::setUp();
<?php
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
*/
class api_v3_ACLPermissionTest extends CiviUnitTestCase {
- protected $_apiversion;
+ protected $_apiversion = 3;
protected $_params;
protected $hookClass = null;
+ public $DBResetRequired = FALSE;
public $_eNoticeCompliant = TRUE;
protected $_entity;
function setUp() {
- $this->_apiversion = 3;
-
parent::setUp();
$baoObj = new CRM_Core_DAO();
$baoObj->createTestObject('CRM_Pledge_BAO_Pledge', array(), 1, 0);
*/
function testContactGetNoResultsHook(){
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults'));
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPISuccess('contact', 'get', array(
'check_permissions' => 1,
'return' => 'display_name',
));
-
- $this->assertAPISuccess($result,"this should succeed but return no results. line " . __LINE__);
$this->assertEquals(0, $result['count']);
}
*/
function testContactGetAllResultsHook(){
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPISuccess('contact', 'get', array(
'check_permissions' => 1,
'return' => 'display_name',
));
- $this->assertAPISuccess($result,"this should succeed but return no results. line " . __LINE__);
$this->assertEquals(2, $result['count']);
}
/**
* Function just tests that an empty where hook returns the 2 expected results
*/
function testContactGetPermissionHookNoDeleted(){
- civicrm_api('contact', 'create', array('id' => 2, 'version' => $this->_apiversion, 'is_deleted' => 1));
+ $this->callAPISuccess('contact', 'create', array('id' => 2, 'is_deleted' => 1));
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPISuccess('contact', 'get', array(
'check_permissions' => 1,
'return' => 'display_name',
));
-
- $this->assertAPISuccess($result,"this should succeed but return one results. line " . __LINE__);
$this->assertEquals(1, $result['count']);
}
function testContactGetHookLimitingHook(){
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPISuccess('contact', 'get', array(
'check_permissions' => 1,
'return' => 'display_name',
));
- $this->assertAPISuccess($result, 'api call succeeded');
$this->assertEquals(1, $result['count']);
}
*/
function testContactGetHookLimitingHookDontCheck(){
//
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
- 'check_permissions' => 0,
- 'return' => 'display_name',
+ $result = $this->callAPISuccess('contact', 'get', array(
+ 'check_permissions' => 0,
+ 'return' => 'display_name',
));
- $this->assertAPISuccess($result, 'api call succeeded');
$this->assertEquals(2, $result['count']);
}
/**
*/
function testContactGetIDFilter(){
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPISuccess('contact', 'get', array(
'sequential' => 1,
'id' => 2,
'check_permissions' => 1,
));
- $this->assertAPISuccess($result, 'api call succeeded');
$this->assertEquals(1, $result['count']);
$this->assertEquals(2, $result['id']);
}
*/
function testContactGetAddressReturned(){
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
- $fullresult = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $fullresult = $this->callAPISuccess('contact', 'get', array(
'sequential' => 1,
));
//return doesn't work for all keys - can't fix that here so let's skip ...
'worldregion_id',
'world_region');
$expectedReturnElements = array_diff(array_keys($fullresult['values'][0]),$elementsReturnDoesntSupport);
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPISuccess('contact', 'get', array(
'check_permissions' => 1,
'return' => $expectedReturnElements,
'sequential' => 1,
));
- $this->assertAPISuccess($result, 'api call succeeded');
$this->assertEquals(1, $result['count']);
foreach ($expectedReturnElements as $element){
$this->assertArrayHasKey($element, $result['values'][0]);
*/
function testContactGetPledgeIDNotReturned(){
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
- $fullresult = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $fullresult = $this->callAPISuccess('contact', 'get', array(
'sequential' => 1,
));
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPISuccess('contact', 'get', array(
'check_permissions' => 1,
'return' => 'pledge_id',
'sequential' => 1,
));
- $this->assertAPISuccess($result);
$this->assertArrayNotHasKey('pledge_id', $result['values'][0]);
}
*/
function testContactGetPledgeIDNotFiltered(){
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
- $fullresult = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $fullresult = $this->callAPISuccess('contact', 'get', array(
'sequential' => 1,
));
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPISuccess('contact', 'get', array(
'check_permissions' => 1,
'pledge_id' => 1,
'sequential' => 1,
));
- $this->assertAPISuccess($result, 'api call succeeded');
$this->assertEquals(2, $result['count']);
}
*/
function testContactGetPledgeNotChainable(){
$this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
- $fullresult = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $fullresult = $this->callAPISuccess('contact', 'get', array(
'sequential' => 1,
));
- $result = civicrm_api('contact', 'get', array(
- 'version' => $this->_apiversion,
+ $result = $this->callAPIFailure('contact', 'get', array(
'check_permissions' => 1,
'api.pledge.get' => 1,
'sequential' => 1,
- ));
- $this->assertEquals('Error in call to pledge_get : API permission check failed for pledge/get call; missing permission: access CiviCRM.', $result['error_message']);
+ ),
+ 'Error in call to pledge_get : API permission check failed for pledge/get call; missing permission: access CiviCRM.'
+ );
}
/**
try {
$result = $function($params);
} catch ( Exception $e ) {
- $this->assertEquals("Input variable `params` is not an array", $e->getMessage());
continue;
}
- $this->assertEquals(1,
- $result['is_error'],
- $function . " does not return error in line " . __LINE__);
- $this->assertEquals('Input variable `params` is not an array',
- $result['error_message'],
- "$function does not return correct error when a non-array is submitted in line " . __LINE__ );
}*/
}
<?php
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
public $DBResetRequired = FALSE;
public $_eNoticeCompliant = TRUE;
- protected $_apiversion;
+ protected $_apiversion =3;
/**
* Sets up the fixture, for example, opens a network connection.
*/
protected function setUp() {
parent::setUp();
- $this->_apiversion = 3;
}
/**
function testAPIWrapperIncludeNoFile() {
- $result = civicrm_api('RandomFile', 'get', array('version' => 3));
- $this->assertAPIFailure($result);
- $this->assertEquals($result['error_message'], 'API (RandomFile,get) does not exist (join the API team and implement it!)');
+ $result = $this->callAPIFailure('RandomFile', 'get', array(), 'API (RandomFile,get) does not exist (join the API team and implement it!)');
}
function testAPIWrapperCamelCaseFunction() {
- $result = civicrm_api('OptionGroup', 'Get', array(
- 'version' => 3,
- ));
- $this->assertEquals(0, $result['is_error']);
+ $result = $this->callAPISuccess('OptionGroup', 'Get', array());
}
function testAPIWrapperLcaseFunction() {
- $result = civicrm_api('OptionGroup', 'get', array(
- 'version' => 3,
- ));
- $this->assertEquals(0, $result['is_error']);
+ $result = $this->callAPISuccess('OptionGroup', 'get', array());
}
function testAPIResolver() {
$oldpath = get_include_path();
set_include_path($oldpath . PATH_SEPARATOR . dirname(__FILE__) . '/dataset/resolver');
- $result = civicrm_api('contact', 'example_action1', array(
- 'version' => 3,
- ));
+ $result = $this->callAPISuccess('contact', 'example_action1', array());
$this->assertEquals($result['values'][0], 'civicrm_api3_generic_example_action1 is ok');
- $result = civicrm_api('contact', 'example_action2', array(
- 'version' => 3,
- ));
+ $result = $this->callAPISuccess('contact', 'example_action2', array());
$this->assertEquals($result['values'][0], 'civicrm_api3_contact_example_action2 is ok');
- $result = civicrm_api('test_entity', 'example_action3', array(
- 'version' => 3,
- ));
+ $result = $this->callAPISuccess('test_entity', 'example_action3', array());
$this->assertEquals($result['values'][0], 'civicrm_api3_test_entity_example_action3 is ok');
set_include_path($oldpath);
* Test civicrm_activity_type_get()
*/
function testActivityTypeGet() {
- $params = array('version' => $this->_apiversion);
- $result = civicrm_api('activity_type', 'get', $params);
- $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+ $params = array();
+ $result = $this->callAPIAndDocument('activity_type', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values']['1'], 'Meeting', 'In line ' . __LINE__);
$this->assertEquals($result['values']['13'], 'Open Case', 'In line ' . __LINE__);
}
$params = array(
'weight' => '2',
'label' => 'send out letters',
- 'version' => $this->_apiversion,
'filter' => 0,
'is_active' => 1,
'is_optgroup' => 1,
'is_default' => 0,
);
- $result = civicrm_api('activity_type', 'create', $params);
- $this->documentMe($params, $result, __FUNCTION__, __FILE__);
- $this->assertAPISuccess($result);
+ $result = $this->callAPIAndDocument('activity_type', 'create', $params, __FUNCTION__, __FILE__);
}
/**
$params = array(
'label' => 'type_create',
'weight' => '2',
- 'version' => $this->_apiversion,
);
- $activitycreate = civicrm_api('activity_type', 'create', $params);
- $activityID = $activitycreate['id'];
- $this->assertAPISuccess($activitycreate, "in line " . __LINE__);
+ $activitycreate = $this->callAPISuccess('activity_type', 'create', $params);
$this->assertArrayHasKey('id', $activitycreate);
$this->assertArrayHasKey('option_group_id', $activitycreate['values'][$activitycreate['id']]);
}
$params = array(
'label' => 'type_create_delete',
'weight' => '2',
- 'version' => $this->_apiversion,
);
- $activitycreate = civicrm_api('activity_type', 'create', $params);
+ $activitycreate = $this->callAPISuccess('activity_type', 'create', $params);
$params = array(
'activity_type_id' => $activitycreate['id'],
- 'version' => $this->_apiversion,
);
- $result = civicrm_api('activity_type', 'delete', $params);
- $this->documentMe($params, $result, __FUNCTION__, __FILE__);
- $this->assertAPIFailure($result, 'In line ' . __LINE__);
+ $result = $this->callAPISuccess('activity_type', 'delete', $params, __FUNCTION__, __FILE__);
}
}
<?php
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
require_once 'CiviTest/CiviUnitTestCase.php';
class api_v3_AddressTest extends CiviUnitTestCase {
- protected $_apiversion;
+ protected $_apiversion =3;
protected $_contactID;
protected $_locationType;
protected $_params;
protected $_entity;
function setUp() {
- $this->_apiversion = 3;
$this->_entity = 'Address';
parent::setUp();
'country_id' => '1152',
'city' => 'Brummen',
'is_primary' => 1,
- 'version' => $this->_apiversion,
);
}
}
public function testCreateAddress() {
-
- $result = civicrm_api('address', 'create', $this->_params);
- $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
- $this->assertAPISuccess($result, 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('address', 'create', $this->_params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
$this->getAndCheck($this->_params, $result['id'], 'address');
}
+
public function testCreateAddressParsing() {
$params = array(
- 'version' => $this->_apiversion,
'street_parsing' => 1,
'street_address' => '54A Excelsior Ave. Apt 1C',
'location_type_id' => $this->_locationType->id,
);
$subfile = "AddressParse";
$description = "Demonstrates Use of address parsing param";
- $result = civicrm_api('address', 'create', $params);
- $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
- $this->assertAPISuccess($result, 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('address', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(54, $result['values'][$result['id']]['street_number'], 'In line ' . __LINE__);
$this->assertEquals('A', $result['values'][$result['id']]['street_number_suffix'], 'In line ' . __LINE__);
$this->assertEquals('Excelsior Ave.', $result['values'][$result['id']]['street_name'], 'In line ' . __LINE__);
$this->assertEquals('Apt 1C', $result['values'][$result['id']]['street_unit'], 'In line ' . __LINE__);
- civicrm_api('address', 'delete', array('version' => 3, 'id' => $result['id']));
+ $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
}
public function testCreateAddressTestDefaults() {
$params = $this->_params;
unset($params['is_primary']);
- $result = civicrm_api('address', 'create', $params);
- $this->assertAPISuccess($result, 'In line ' . __LINE__);
+ $result = $this->callAPISuccess('address', 'create', $params);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertEquals(1, $result['values'][$result['id']]['is_primary'], 'In line ' . __LINE__);
$this->getAndCheck($this->_params, $result['id'], 'address');
$params = $this->_params;
$params['street_number_suffix'] = 'really long string';
$result = $this->callAPIFailure('address', 'create', $params);
- $this->assertEquals(2100, $result['error_code']);
- }
+ }
/*
* is_primary shoule be set as a default. ie. create the address, unset the params & recreate.
* is_primary should be 0 before & after the update. ie - having no other address
public function testCreateAddressTestDefaultWithID() {
$params = $this->_params;
$params['is_primary'] = 0;
- $result = civicrm_api('address', 'create', $params);
+ $result = $this->callAPISuccess('address', 'create', $params);
unset($params['is_primary']);
$params['id'] = $result['id'];
- $result = civicrm_api('address', 'create', $params);
- $address = civicrm_api('address', 'get', array('version' => 3, 'contact_id' => $params['contact_id']));
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
- $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
+ $result = $this->callAPISuccess('address', 'create', $params);
+ $address = $this->callAPISuccess('address', 'get', array('contact_id' => $params['contact_id']));
+ $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertEquals(1, $result['values'][$result['id']]['is_primary'], 'In line ' . __LINE__);
$this->getAndCheck($params, $result['id'], 'address', __FUNCTION__);
}
public function testDeleteAddress() {
//check there are no addresss to start with
- $get = civicrm_api('address', 'get', array(
- 'version' => 3,
- 'location_type_id' => $this->_locationType->id,
- ));
- $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__);
+ $get = $this->callAPISuccess('address', 'get', array(
+ 'location_type_id' => $this->_locationType->id,
+ ));
$this->assertEquals(0, $get['count'], 'Contact already exists ' . __LINE__);
//create one
- $create = civicrm_api('address', 'create', $this->_params);
-
- $this->assertEquals(0, $create['is_error'], 'In line ' . __LINE__);
+ $create = $this->callAPISuccess('address', 'create', $this->_params);
- $result = civicrm_api('address', 'delete', array('id' => $create['id'], 'version' => 3));
- $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('address', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
- $get = civicrm_api('address', 'get', array(
- 'version' => 3,
- 'location_type_id' => $this->_locationType->id,
- ));
- $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__);
+ $get = $this->callAPISuccess('address', 'get', array(
+ 'location_type_id' => $this->_locationType->id,
+ ));
$this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
}
* Test civicrm_address_get - success expected.
*/
public function testGetAddress() {
- $address = civicrm_api('address', 'create', $this->_params);
- $this->assertAPISuccess($address, 'In line ' . __LINE__);
+ $address = $this->callAPISuccess('address', 'create', $this->_params);
$params = array(
'contact_id' => $this->_contactID,
'street_name' => $address['values'][$address['id']]['street_name'],
- 'version' => $this->_apiversion,
);
- $result = civicrm_api('Address', 'Get', ($params));
- $this->documentMe($params, $result, __FUNCTION__, __FILE__);
- civicrm_api('Address', 'delete', array('version' => 3, 'id' => $result['id']));
- $this->assertAPISuccess($result, 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__);
+ $this->callAPISuccess('Address', 'delete', array('id' => $result['id']));
$this->assertEquals($address['values'][$address['id']]['location_type_id'], $result['values'][$address['id']]['location_type_id'], 'In line ' . __LINE__);
$this->assertEquals($address['values'][$address['id']]['is_primary'], $result['values'][$address['id']]['is_primary'], 'In line ' . __LINE__);
$this->assertEquals($address['values'][$address['id']]['street_address'], $result['values'][$address['id']]['street_address'], 'In line ' . __LINE__);
* Test civicrm_address_get - success expected.
*/
public function testGetSingleAddress() {
- civicrm_api('address', 'create', $this->_params);
+ $this->callAPISuccess('address', 'create', $this->_params);
$params = array(
'contact_id' => $this->_contactID,
- 'version' => $this->_apiversion,
);
- $address = civicrm_api('Address', 'getsingle', ($params));
+ $address = $this->callAPISuccess('Address', 'getsingle', ($params));
$this->assertEquals($address['location_type_id'], $this->_params['location_type_id'], 'In line ' . __LINE__);
- civicrm_api('address', 'delete', array('version' => 3, 'id' => $address['id']));
+ $this->callAPISuccess('address', 'delete', array('id' => $address['id']));
}
/**
* Test civicrm_address_get with sort option- success expected.
*/
public function testGetAddressSort() {
- $create = civicrm_api('address', 'create', $this->_params);
+ $create = $this->callAPISuccess('address', 'create', $this->_params);
$subfile = "AddressSort";
$description = "Demonstrates Use of sort filter";
$params = array(
'sort' => 'street_address DESC',
'limit' => 2,
),
- 'version' => $this->_apiversion,
'sequential' => 1,
);
- $result = civicrm_api('Address', 'Get', ($params));
- $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(2, $result['count'], 'In line ' . __LINE__);
$this->assertEquals('Ambachtstraat 23', $result['values'][0]['street_address'], 'In line ' . __LINE__);
- civicrm_api('address', 'delete', array('version' => 3, 'id' => $create['id']));
+ $this->callAPISuccess('address', 'delete', array('id' => $create['id']));
}
/**
* Test civicrm_address_get with sort option- success expected.
*/
public function testGetAddressLikeSuccess() {
- civicrm_api('address', 'create', $this->_params);
+ $this->callAPISuccess('address', 'create', $this->_params);
$subfile = "AddressLike";
$description = "Demonstrates Use of Like";
$params = array('street_address' => array('LIKE' => '%mb%'),
- 'version' => $this->_apiversion,
'sequential' => 1,
);
- $result = civicrm_api('Address', 'Get', ($params));
- $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertEquals('Ambachtstraat 23', $result['values'][0]['street_address'], 'In line ' . __LINE__);
- civicrm_api('address', 'delete', array('version' => 3, 'id' => $result['id']));
+ $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
}
/**
* Test civicrm_address_get with sort option- success expected.
*/
public function testGetAddressLikeFail() {
- $create = civicrm_api('address', 'create', $this->_params);
+ $create = $this->callAPISuccess('address', 'create', $this->_params);
$subfile = "AddressLike";
$description = "Demonstrates Use of Like";
$params = array('street_address' => array('LIKE' => "'%xy%'"),
- 'version' => $this->_apiversion,
'sequential' => 1,
);
- $result = civicrm_api('Address', 'Get', ($params));
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPISuccess('Address', 'Get', ($params));
$this->assertEquals(0, $result['count'], 'In line ' . __LINE__);
- civicrm_api('address', 'delete', array('version' => 3, 'id' => $create['id']));
+ $this->callAPISuccess('address', 'delete', array('id' => $create['id']));
}
function testGetWithCustom() {
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $result = civicrm_api($this->_entity, 'create', $params);
- $this->assertAPISuccess($result, ' in line ' . __LINE__);
+ $result = $this->callAPISuccess($this->_entity, 'create', $params);
- $getParams = array('version' => 3, 'id' => $result['id'], 'return' => array('custom'));
- $check = civicrm_api($this->_entity, 'get', $getParams);
+ $getParams = array('id' => $result['id'], 'return' => array('custom'));
+ $check = $this->callAPISuccess($this->_entity, 'get', $getParams);
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
- civicrm_api('address', 'delete', array('version' => 3, 'id' => $result['id']));
+ $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
}
public function testCreateAddressPrimaryHandlingChangeToPrimary() {
$params = $this->_params;
unset($params['is_primary']);
- $address1 = civicrm_api('address', 'create', $params);
+ $address1 = $this->callAPISuccess('address', 'create', $params);
$this->assertApiSuccess($address1, 'In line ' . __LINE__);
//now we check & make sure it has been set to primary
- $check = civicrm_api('address', 'getcount', array(
- 'version' => 3,
+ $check = $this->callAPISuccess('address', 'getcount', array(
'is_primary' => 1,
'id' => $address1['id'],
));
$this->assertEquals(1, $check);
- civicrm_api('address', 'delete', array('version' => 3, 'id' => $address1['id']));
+ $this->callAPISuccess('address', 'delete', array('id' => $address1['id']));
}
public function testCreateAddressPrimaryHandlingChangeExisting() {
- $address1 = civicrm_api('address', 'create', $this->_params);
- $this->assertApiSuccess($address1, 'In line ' . __LINE__);
- $address2 = civicrm_api('address', 'create', $this->_params);
- $this->assertApiSuccess($address2, 'In line ' . __LINE__);
- $check = civicrm_api('address', 'getcount', array(
- 'version' => 3,
+ $address1 = $this->callAPISuccess('address', 'create', $this->_params);
+ $address2 = $this->callAPISuccess('address', 'create', $this->_params);
+ $check = $this->callAPISuccess('address', 'getcount', array(
'is_primary' => 1,
'contact_id' => $this->_contactID,
));
$this->assertEquals(1, $check);
- civicrm_api('address', 'delete', array('version' => 3, 'id' => $address1['id']));
+ $this->callAPISuccess('address', 'delete', array('id' => $address1['id']));
}
}
}
function _testCRM11793ContactType($contactType) {
- $result = civicrm_api(
+ $result = $this->callAPISuccess(
'contact',
'get',
array(
- 'version' => 3,
'contact_type' => $contactType
)
);
- $this->assertAPISuccess($result, "In line " . __LINE__);
foreach ($result['values'] as $idx => $contact) {
$this->assertEquals($contact['contact_type'], $contactType, "In line " . __LINE__);
}
<?php
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
function setUp() {
$this->_apiversion = 3;
$this->params = array(
- 'version' => 3,
'title' => "campaign title",
'description' => "Call people, ask for money",
'created_date' => 'first sat of July 2008',
public function testCreateCampaign() {
$description = "Create a campaign - Note use of relative dates here http://www.php.net/manual/en/datetime.formats.relative.php";
- $result = civicrm_api('campaign', 'create', $this->params);
- $this->documentMe($this->params, $result, __FUNCTION__, __FILE__, $description);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('campaign', 'create', $this->params, __FUNCTION__, __FILE__, $description);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
$this->getAndCheck(array_merge($this->params, array('created_date' => '2008-07-05 00:00:00')), $result['id'], 'campaign', TRUE);
}
public function testGetCampaign() {
- $result = civicrm_api('campaign', 'create', $this->params);
- $result = civicrm_api('campaign', 'get', ($this->params));
- $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPISuccess('campaign', 'create', $this->params);
+ $result = $this->callAPIAndDocument('campaign', 'get', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
- $this->id = $result['id'];
}
public function testDeleteCampaign() {
- $entity = civicrm_api('campaign', 'get', ($this->params));
- $delete = array('version' => 3, 'id' => $entity['id']);
- $result = civicrm_api('campaign', 'delete', $delete);
- $this->documentMe($delete, $result, __FUNCTION__, __FILE__);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $entity = $this->callAPISuccess('campaign', 'get', ($this->params));
+ $delete = array('id' => $entity['id']);
+ $result = $this->callAPIAndDocument('campaign', 'delete', $delete, __FUNCTION__, __FILE__);
- $checkDeleted = civicrm_api('campaign', 'get', array(
- 'version' => 3,
- ));
+ $checkDeleted = $this->callAPISuccess('campaign', 'get', array());
$this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
}
}
class api_v3_CaseTest extends CiviUnitTestCase {
protected $_params;
protected $_entity;
- protected $_apiversion;
+ protected $_apiversion =3;
protected $followup_activity_type_value;
protected $caseTypeId;
protected $caseStatusGroup;
* and redirect stdin to a temporary file
*/
public function setUp() {
- $this->_apiversion = 3;
$this->_entity = 'case';
parent::setUp();
//. Using XML was causing breakage as id numbers were changing over time
// & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
// state where tests could run afterwards without re-loading.
- $this->caseStatusGroup = civicrm_api('option_group', 'get', array('version' => API_LATEST_VERSION, 'name' => 'case_status', 'format.only_id' => 1));
- $this->caseTypeGroup = civicrm_api('option_group', 'get', array('version' => API_LATEST_VERSION, 'name' => 'case_type', 'format.only_id' => 1));
- $caseTypes = civicrm_api('option_value', 'Create', array(
- 'version' => API_LATEST_VERSION,
+ $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array(
+ 'name' => 'case_status',
+ 'format.only_id' => 1)
+ );
+ $this->caseTypeGroup = $this->callAPISuccess('option_group', 'get', array(
+ 'name' => 'case_type',
+ 'format.only_id' => 1)
+ );
+ $caseTypes = $this->callAPISuccess('option_value', 'Create', array(
'option_group_id' => $this->caseTypeGroup,
'name' => 'housing_support',
'label' => "Housing Support",
'Income and benefits stabilization' => 'Income and benefits stabilization',
);
foreach ($optionValues as $name => $label) {
- $activityTypes = civicrm_api('option_value', 'Create', array(
- 'version' => API_LATEST_VERSION,
+ $activityTypes = $this->callAPISuccess('option_value', 'Create', array(
'option_group_id' => 2,
'name' => $name,
'label' => $label,
$this->quickCleanup($tablesToTruncate);
- $activityTypes = civicrm_api('option_value', 'get', array(
- 'version' => API_LATEST_VERSION, 'option_group_id' => 2,
- 'name' => 'Follow Up',
- 'label' => 'Follow Up',
- 'sequential' => 1,
- ));
+ $activityTypes = $this->callAPISuccess('option_value', 'get', array(
+ 'option_group_id' => 2,
+ 'name' => 'Follow Up',
+ 'label' => 'Follow Up',
+ 'sequential' => 1,
+ ));
$this->followup_activity_type_value = $activityTypes['values'][0]['value'];
// Insert a row in civicrm_contact creating contact 17
$op = new PHPUnit_Extensions_Database_Operation_Insert();
'contact_type_b' => 'Individual',
'is_reserved' => 0,
'is_active' => 1,
- 'version' => $this->_apiversion,
);
$this->relationshipTypeCreate($relTypeParams);
'contact_type_b' => 'Individual',
'is_reserved' => 0,
'is_active' => 1,
- 'version' => $this->_apiversion,
);
$this->relationshipTypeCreate($relTypeParams);
'contact_type_b' => 'Individual',
'is_reserved' => 0,
'is_active' => 1,
- 'version' => $this->_apiversion,
);
$this->relationshipTypeCreate($relTypeParams);
'contact_type_b' => 'Individual',
'is_reserved' => 0,
'is_active' => 1,
- 'version' => $this->_apiversion,
);
$this->relationshipTypeCreate($relTypeParams);
'contact_type_b' => 'Individual',
'is_reserved' => 0,
'is_active' => 1,
- 'version' => $this->_apiversion,
);
$this->relationshipTypeCreate($relTypeParams);
$this->customDirectories(array('template_path' => TRUE));
// case is not enabled by default
- require_once 'CRM/Core/BAO/ConfigSetting.php';
$enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
$this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
'case_type_id' => $this->caseTypeId,
'subject' => 'Test case',
'contact_id' => 17,
- 'version' => $this->_apiversion,
);
// create a logged in USER since the code references it for source_contact_id
*/
function tearDown() {
foreach ($this->optionValues as $id) {
- civicrm_api('option_value', 'delete', array('version' => API_LATEST_VERSION, 'id' => $id));
+ $this->callAPISuccess('option_value', 'delete', array('id' => $id));
}
$tablesToTruncate = array(
'civicrm_contact',
* check with empty array
*/
function testCaseCreateEmpty() {
- $params = array('version' => $this->_apiversion);
- $result = civicrm_api('case', 'create', $params);
- $this->assertAPIFailure($result,
- "In line " . __LINE__
- );
+ $result = $this->callAPIFailure('case', 'create', array());
}
/**
$params = array(
'subject' => 'this case should fail',
'case_type_id' => 1,
- 'version' => $this->_apiversion,
);
- $result = civicrm_api('case', 'create', $params);
- $this->assertAPIFailure($result,
- "In line " . __LINE__
- );
+ $result = $this->callAPIFailure('case', 'create', $params);
}
/**
// Test using label instead of value
unset($params['case_type_id']);
$params['case_type'] = 'Housing Support';
- $result = civicrm_api('case', 'create', $params);
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'create', $params);
$id = $result['id'];
// Check result
- $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'id' => $id));
+ $result = $this->callAPISuccess('case', 'get', array('id' => $id));
$this->assertEquals($result['values'][$id]['id'], 1, 'in line ' . __LINE__);
$this->assertEquals($result['values'][$id]['case_type_id'], $this->caseTypeId, 'in line ' . __LINE__);
$this->assertEquals($result['values'][$id]['subject'], $params['subject'], 'in line ' . __LINE__);
$params = $this->_params;
// Test using name instead of value
$params['case_type_id'] = 'housing_support';
- $result = civicrm_api('case', 'create', $params);
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'create', $params);
$id = $result['id'];
- $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'id' => $id));
+ $result = $this->callAPISuccess('case', 'get', array('id' => $id));
$case = $result['values'][$id];
// Update Case
- $params = array('id' => $id, 'version' => $this->_apiversion);
+ $params = array('id' => $id);
$params['subject'] = $case['subject'] = 'Something Else';
- $result = civicrm_api('case', 'create', $params);
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'create', $params);
// Verify that updated case is exactly equal to the original with new subject
- $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'case_id' => $id));
+ $result = $this->callAPISuccess('case', 'get', array('case_id' => $id));
$this->assertEquals($result['values'][$id], $case, 'in line ' . __LINE__);
}
*/
function testCaseDelete() {
// Create Case
- $result = civicrm_api('case', 'create', $this->_params);
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'create', $this->_params);
// Move Case to Trash
$id = $result['id'];
- $result = civicrm_api('case', 'delete', array('version' => $this->_apiversion, 'id' => $id, 'move_to_trash' => 1));
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'delete', array('id' => $id, 'move_to_trash' => 1));
// Check result - also check that 'case_id' works as well as 'id'
- $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'case_id' => $id));
+ $result = $this->callAPISuccess('case', 'get', array('case_id' => $id));
$this->assertEquals(1, $result['values'][$id]['is_deleted'], 'in line ' . __LINE__);
// Delete Case Permanently - also check that 'case_id' works as well as 'id'
- $result = civicrm_api('case', 'delete', array('version' => $this->_apiversion, 'case_id' => $id));
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'delete', array('case_id' => $id));
// Check result - case should no longer exist
- $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'id' => $id));
- $this->assertEquals(0, $result['count'], 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'get', array('id' => $id));
+ $this->assertEquals(0, $result['count']);
}
/**
*/
function testCaseGetByActivity() {
// Create Case
- $result = civicrm_api('case', 'create', $this->_params);
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'create', $this->_params);
$id = $result['id'];
// Check result - we should get a list of activity ids
- $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'id' => $id));
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'get', array('id' => $id));
$case = $result['values'][$id];
$activity = $case['activities'][0];
// Fetch case based on an activity id
- $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'activity_id' => $activity, 'return' => 'activities,contacts'));
+ $result = $this->callAPISuccess('case', 'get', array('activity_id' => $activity, 'return' => 'activities,contacts'));
$this->assertEquals(FALSE, empty($result['values'][$id]), 'in line ' . __LINE__);
$this->assertEquals($result['values'][$id], $case, 'in line ' . __LINE__);
}
*/
function testCaseGetByContact() {
// Create Case
- $result = civicrm_api('case', 'create', $this->_params);
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'create', $this->_params);
$id = $result['id'];
// Store result for later
- $case = civicrm_api('case', 'getsingle', array('version' => $this->_apiversion, 'id' => $id));
+ $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id));
// Fetch case based on client contact id
- $result = civicrm_api('case', 'get', array('version' => $this->_apiversion, 'client_id' => $this->_params['contact_id'], 'return' => array('activities', 'contacts')));
- $this->assertEquals($result['values'][$id], $case, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'get', array('client_id' => $this->_params['contact_id'], 'return' => array('activities', 'contacts')));
+ $this->assertAPIArrayComparison($result['values'][$id], $case);
}
/**
function testCaseActivityCreate() {
// Create a case first
$params = $this->_params;
- $result = civicrm_api('case', 'create', $params);
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('case', 'create', $params);
$params = array(
'case_id' => 1,
// follow up
'subject' => 'Test followup',
'source_contact_id' => $this->_loggedInUser,
'target_contact_id' => $this->_params['contact_id'],
- 'version' => $this->_apiversion,
);
- $result = civicrm_api('activity', 'create', $params);
- $this->assertAPISuccess($result, 'in line ' . __LINE__);
+ $result = $this->callAPISuccess('activity', 'create', $params);
$this->assertEquals($result['values'][$result['id']]['activity_type_id'], $params['activity_type_id'], 'in line ' . __LINE__);
// might need this for other tests that piggyback on this one
$this->_caseActivityId = $result['values'][$result['id']]['id'];
// Check other DB tables populated properly - is there a better way to do this? assertDBState() requires that we know the id already.
- require_once 'CRM/Case/DAO/CaseActivity.php';
- $dao = new CRM_Case_DAO_CaseActivity();
- $dao->case_id = 1;
+ $dao = new CRM_Case_DAO_CaseActivity();
+ $dao->case_id = 1;
$dao->activity_id = $this->_caseActivityId;
$this->assertEquals($dao->find(), 1, 'case_activity table not populated correctly in line ' . __LINE__);
$dao->free();
- require_once 'CRM/Activity/DAO/ActivityContact.php';
$dao = new CRM_Activity_DAO_ActivityContact();
$dao->activity_id = $this->_caseActivityId;
$dao->contact_id = $this->_params['contact_id'];
'activity_type_id' => 14,
'source_contact_id' => $this->_loggedInUser,
'subject' => 'New subject',
- 'version' => $this->_apiversion,
);
- $result = civicrm_api('activity', 'create', $params);
+ $result = $this->callAPISuccess('activity', 'create', $params);
- $this->assertAPISuccess($result,
- "Error message: " . CRM_Utils_Array::value('error_message', $result) . ' in line ' . __LINE__
- );
$this->assertEquals($result['values'][$result['id']]['subject'], $params['subject'], 'in line ' . __LINE__);
// id should be one greater, since this is a new revision
// Check revision is as expected
$revParams = array(
'activity_id' => $this->_caseActivityId,
- 'version' => $this->_apiversion,
);
- $revActivity = civicrm_api('activity', 'get', $revParams);
+ $revActivity = $this->callAPISuccess('activity', 'get', $revParams);
$this->assertEquals($revActivity['values'][$this->_caseActivityId]['is_current_revision'],
- 0,
- 'in line ' . __LINE__
- );
+ 0);
$this->assertEquals($revActivity['values'][$this->_caseActivityId]['is_deleted'],
- 0,
- 'in line ' . __LINE__
+ 0
);
//TODO: check some more things
function testCaseActivityUpdateCustom() {
// Create a case first
- $params = $this->_params;
- $result = civicrm_api('case', 'create', $params);
+ $result = $this->callAPISuccess('case', 'create', $this->_params);
// Create custom field group
// Note the second parameter is Activity on purpose, not Case.
// create activity
$params = array(
- 'case_id' => 1,
+ 'case_id' => $result['id'],
// follow up
'activity_type_id' => 14,
'subject' => 'Test followup',
'source_contact_id' => $this->_loggedInUser,
'target_contact_id' => $this->_params['contact_id'],
'custom_' . $custom_ids['custom_field_id'] => "custom string",
- 'version' => $this->_apiversion,
- );
- $result = civicrm_api('activity', 'create', $params);
-
- $this->assertAPISuccess($result,
- "Error message: " . CRM_Utils_Array::value('error_message', $result) . ' in line ' . __LINE__
);
+ $result = $this->callAPISuccess('activity', 'create', $params);
$aid = $result['values'][$result['id']]['id'];
'activity_type_id' => 14,
'source_contact_id' => $this->_loggedInUser,
'subject' => 'New subject',
- 'version' => $this->_apiversion,
- );
- $revAct = civicrm_api('activity', 'create', $params);
-
- $this->assertEquals($revAct['is_error'], 0,
- "Error message: " . CRM_Utils_Array::value('error_message', $revAct) . ' in line ' . __LINE__
);
+ $revAct = $this->callAPISuccess('activity', 'create', $params);
// Retrieve revision and check custom fields got copied
$revParams = array(
'activity_id' => $aid + 1,
- 'version' => $this->_apiversion,
'return.custom_' . $custom_ids['custom_field_id'] => 1,
);
- $revAct = civicrm_api('activity', 'get', $revParams);
+ $revAct = $this->callAPISuccess('activity', 'get', $revParams);
- $this->assertEquals($revAct['is_error'], 0,
- "Error message: " . CRM_Utils_Array::value('error_message', $revAct) . ' in line ' . __LINE__
- );
$this->assertEquals($revAct['values'][$aid + 1]['custom_' . $custom_ids['custom_field_id']], "custom string",
"Error message: " . CRM_Utils_Array::value('error_message', $revAct) . ' in line ' . __LINE__
);