*/
public function testSearchProfileHomeCityCRM14263() {
$contactID = $this->individualCreate();
- CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
+ Civi::settings()->set('defaultSearchProfileID', 1);
$this->callAPISuccess('address', 'create', [
'contact_id' => $contactID,
'city' => 'Cool City',
}
catch (PEAR_Exception $e) {
$err = $e->getCause();
- $this->fail('invalid SQL created' . $e->getMessage() . " " . $err->userinfo);
+ $this->fail('invalid SQL created' . $e->getMessage() . ' ' . $err->userinfo);
}
}
*/
public function testSearchProfileHomeCityNoResultsCRM14263() {
$contactID = $this->individualCreate();
- CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
+ Civi::settings()->set('defaultSearchProfileID', 1);
$this->callAPISuccess('address', 'create', [
'contact_id' => $contactID,
'city' => 'Cool City',
}
catch (PEAR_Exception $e) {
$err = $e->getCause();
- $this->fail('invalid SQL created' . $e->getMessage() . " " . $err->userinfo);
+ $this->fail('invalid SQL created' . $e->getMessage() . ' ' . $err->userinfo);
}
}
*/
public function testSearchProfilePrimaryCityCRM14263($params, $selectClause, $whereClause) {
$contactID = $this->individualCreate();
- CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
+ Civi::settings()->set('defaultSearchProfileID', 1);
$this->callAPISuccess('address', 'create', [
'contact_id' => $contactID,
'city' => 'Cool CITY',
'contact_sub_type' => 1,
'sort_name' => 1,
];
- $expectedSQL = "SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`, civicrm_address.id as address_id, " . $selectClause . " FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) WHERE ( ( " . $whereClause . " ) ) AND (contact_a.is_deleted = 0) ORDER BY `contact_a`.`sort_name` ASC, `contact_a`.`id` ";
+ $expectedSQL = 'SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`, civicrm_address.id as address_id, ' . $selectClause . " FROM civicrm_contact contact_a LEFT JOIN civicrm_address ON ( contact_a.id = civicrm_address.contact_id AND civicrm_address.is_primary = 1 ) WHERE ( ( " . $whereClause . " ) ) AND (contact_a.is_deleted = 0) ORDER BY `contact_a`.`sort_name` ASC, `contact_a`.`id` ";
$queryObj = new CRM_Contact_BAO_Query($params, $returnProperties);
try {
$this->assertLike($expectedSQL, $queryObj->getSearchSQL());
}
catch (PEAR_Exception $e) {
$err = $e->getCause();
- $this->fail('invalid SQL created' . $e->getMessage() . " " . $err->userinfo);
+ $this->fail('invalid SQL created' . $e->getMessage() . ' ' . $err->userinfo);
}
}
return [
[
[['city', '=', 'Cool City', 1, 0]],
- "civicrm_address.city as `city`",
+ 'civicrm_address.city as `city`',
"civicrm_address.city = 'Cool City'",
],
[
// it doesn't work on some charsets. However, the the lcasing affects more vars & we are looking to stagger removal of lcasing 'in case'
// (although we have been removing without blowback since 2017)
[['street_address', '=', 'Long Street', 1, 0]],
- "civicrm_address.street_address as `street_address`",
+ 'civicrm_address.street_address as `street_address`',
"civicrm_address.street_address LIKE '%Long Street%'",
],
];
TRUE, FALSE
);
- list($select) = $query->query(FALSE);
+ list($select) = $query->query();
$this->assertEquals('SELECT contact_a.id as contact_id', $select);
}
TRUE, FALSE
);
- $sql = $query->query(FALSE);
+ $sql = $query->query();
$result = CRM_Core_DAO::executeQuery(implode(' ', $sql));
$this->assertEquals(2, $result->N);
$query = new CRM_Contact_BAO_Query($params);
$dao = $query->searchQuery();
- $this->assertEquals('1', $dao->N, "Search query returns exactly 1 result?");
- $this->assertTrue($dao->fetch(), "Search query returns success?");
- $this->assertEquals($contactID_b, $dao->contact_id, "Search query returns parent of contact A?");
+ $this->assertEquals('1', $dao->N, 'Search query returns exactly 1 result?');
+ $this->assertTrue($dao->fetch(), 'Search query returns success?');
+ $this->assertEquals($contactID_b, $dao->contact_id, 'Search query returns parent of contact A?');
}
/**
* Relationship search with custom fields.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testReciprocalRelationshipWithCustomFields() {
$params = [
$query = new CRM_Contact_BAO_Query($params);
$dao = $query->searchQuery();
- $this->assertEquals('1', $dao->N, "Search query returns exactly 1 result?");
- $this->assertTrue($dao->fetch(), "Search query returns success?");
- $this->assertEquals($contactID_b, $dao->contact_id, "Search query returns spouse of contact A?");
+ $this->assertEquals('1', $dao->N, 'Search query returns exactly 1 result?');
+ $this->assertTrue($dao->fetch(), 'Search query returns success?');
+ $this->assertEquals($contactID_b, $dao->contact_id, 'Search query returns spouse of contact A?');
}
+ /**
+ * Test correct temporary table in reciprocal relationship search.
+ *
+ * @throws \CRM_Core_Exception
+ */
public function testReciprocalRelationshipTargetGroupUsesTempTable() {
$groupID = $this->groupCreate();
$params = [
],
];
$sql = CRM_Contact_BAO_Query::getQuery($params);
- $this->assertContains('INNER JOIN civicrm_tmp_e', $sql, "Query appears to use temporary table of compiled relationships?", TRUE);
+ $this->assertContains('INNER JOIN civicrm_tmp_e', $sql, 'Query appears to use temporary table of compiled relationships?', TRUE);
}
/**
*/
public function testRelationshipClause() {
$today = date('Ymd');
- $from1 = " FROM civicrm_contact contact_a LEFT JOIN civicrm_relationship ON (civicrm_relationship.contact_id_a = contact_a.id ) LEFT JOIN civicrm_contact contact_b ON (civicrm_relationship.contact_id_b = contact_b.id )";
- $from2 = " FROM civicrm_contact contact_a LEFT JOIN civicrm_relationship ON (civicrm_relationship.contact_id_b = contact_a.id ) LEFT JOIN civicrm_contact contact_b ON (civicrm_relationship.contact_id_a = contact_b.id )";
+ $from1 = ' FROM civicrm_contact contact_a LEFT JOIN civicrm_relationship ON (civicrm_relationship.contact_id_a = contact_a.id ) LEFT JOIN civicrm_contact contact_b ON (civicrm_relationship.contact_id_b = contact_b.id )';
+ $from2 = ' FROM civicrm_contact contact_a LEFT JOIN civicrm_relationship ON (civicrm_relationship.contact_id_b = contact_a.id ) LEFT JOIN civicrm_contact contact_b ON (civicrm_relationship.contact_id_a = contact_b.id )';
$where1 = "WHERE ( (
civicrm_relationship.is_active = 1 AND
( civicrm_relationship.end_date IS NULL OR civicrm_relationship.end_date >= {$today} ) AND
TRUE,
TRUE, FALSE
);
- $sql1 = $query1->query(FALSE);
+ $sql1 = $query1->query();
$this->assertLike($from1, $sql1[1]);
$this->assertLike($where1, $sql1[2]);
// Test single relationship type selected in multiple select.
TRUE,
TRUE, FALSE
);
- $sql4 = $query4->query(FALSE);
+ $sql4 = $query4->query();
$this->assertLike($from1, $sql4[1]);
$this->assertLike($where2, $sql4[2]);
/**
* CRM-19562 ensure that only ids are used for contact_id searching.
- *
- * @throws \CRM_Core_Exception
*/
public function testContactIDClause() {
$params = [
* Test relative date filters to ensure they generate correct SQL.
*
* @dataProvider relativeDateFilters
+ *
+ * @param string $filter
+ * @param string $expectedWhere
+ *
+ * @throws \CRM_Core_Exception
*/
public function testRelativeDateFilters($filter, $expectedWhere) {
$params = [['created_date_relative', '=', $filter, 0, 0]];
$this->assertEquals($expectedWhere, $where);
}
+ /**
+ * Data provider to relative date filter configurations.
+ *
+ * @return array
+ */
public function relativeDateFilters() {
$dataProvider[] = ['this.year', "WHERE ( contact_a.created_date BETWEEN 'date0' AND 'date1' ) AND (contact_a.is_deleted = 0)"];
$dataProvider[] = ['greater.day', "WHERE ( contact_a.created_date >= 'date0' ) AND (contact_a.is_deleted = 0)"];
*/
public function testGenericWhereHandling() {
$query = new CRM_Contact_BAO_Query([['suffix_id', '=', 2, 0]]);
- $this->assertEquals("contact_a.suffix_id = 2", $query->_where[0][0]);
+ $this->assertEquals('contact_a.suffix_id = 2', $query->_where[0][0]);
$this->assertEquals('Individual Suffix = Sr.', $query->_qill[0][0]);
$this->assertNotTrue(isset($query->_tables['civicrm_activity']));
* @param int $version
*
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testCreateWithCustom($version) {
$this->_apiversion = $version;
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $description = "This demonstrates setting a custom field through the API.";
+ $description = 'This demonstrates setting a custom field through the API.';
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description);
$check = $this->callAPISuccess($this->_entity, 'get', [
/**
* CRM-12773 - expectation is that civicrm quietly ignores fields without values.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreateWithNULLCustomCRM12773() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
* @param int $version
*
* @dataProvider versionThreeAndFour
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreatePreferredLanguageUnset($version) {
$this->_apiversion = $version;
* @param int $version
*
* @dataProvider versionThreeAndFour
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreatePreferredLanguageSet($version) {
$this->_apiversion = $version;
/**
* CRM-14232 test preferred language returns setting if not passed where setting is NULL.
* TODO: Api4
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreatePreferredLanguageNull() {
$this->callAPISuccess('Setting', 'create', ['contact_default_language' => 'null']);
* @param int $version
*
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testCreatePreferredLanguagePassed($version) {
$this->_apiversion = $version;
/**
* CRM-15792 - create/update datetime field for contact.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreateContactCustomFldDateTime() {
$customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'datetime_test_group']);
* @param int $version
*
* @dataProvider versionThreeAndFour
+ *
+ * @throws \CRM_Core_Exception
*/
public function testGetDeceasedRetrieved($version) {
$this->_apiversion = $version;
/**
* Test that sort works - old syntax.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testGetSort() {
$c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params);
* @param int $version
*
* @dataProvider versionThreeAndFour
+ *
+ * @throws \CRM_Core_Exception
*/
public function testGetINIDArray($version) {
$this->_apiversion = $version;
/**
* Test variants on deleted behaviour.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testGetDeleted() {
$params = $this->_params;
* @param int $version
*
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testSortLimitChainedRelationshipGetCRM15983($version) {
$this->_apiversion = $version;
* @param int $version
*
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testGetCreatedDateByOperators($version) {
$this->_apiversion = $version;
/**
* CRM-14263 check that API is not affected by search profile related bug.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testReturnCityProfile() {
$contactID = $this->individualCreate();
- CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
+ Civi::settings()->set('defaultSearchProfileID', 1);
$this->callAPISuccess('address', 'create', [
'contact_id' => $contactID,
'city' => 'Cool City',
* Tests the following formats
* contact.get group=array('title1', title1)
* contact.get group=array('IN' => array('title1', 'title2)
+ *
+ * @throws \CRM_Core_Exception
*/
public function testContactGetWithGroupTitleMultipleGroups() {
- $description = "Get all from group and display contacts.";
- $subFile = "GroupFilterUsingContactAPI";
+ $description = 'Get all from group and display contacts.';
+ $subFile = 'GroupFilterUsingContactAPI';
// Set up a contact, asser that they were created.
$contact_params = [
'contact_type' => 'Individual',
'last_name' => 'Groupmember',
'email' => 'test@example.org',
];
- $create_contact = $this->callApiSuccess('Contact', 'create', $contact_params);
+ $create_contact = $this->callAPISuccess('Contact', 'create', $contact_params);
$created_contact_id = $create_contact['id'];
- $createdGroupsTitles = $createdGroupsIds = [];
+ $createdGroupsIds = [];
// Set up multiple groups, add the contact to the groups.
$test_groups = ['Test group C', 'Test group D'];
foreach ($test_groups as $title) {
'title' => $title,
'created_id' => $created_contact_id,
];
- $create_group = $this->callApiSuccess('Group', 'create', $group_params);
- $created_group_id = $create_group['id'];
+ $create_group = $this->callAPISuccess('Group', 'create', $group_params);
$createdGroupsIds[] = $create_group['id'];
$createdGroupTitles[] = $title;
// Add contact to the new group.
'contact_id' => $created_contact_id,
'group_id' => $create_group['id'],
];
- $create_group_contact = $this->callApiSuccess('GroupContact', 'create', $group_contact_params);
+ $this->callAPISuccess('GroupContact', 'create', $group_contact_params);
}
$contact_get = $this->callAPISuccess('contact', 'get', ['group' => $createdGroupTitles, 'return' => 'group']);
$this->assertEquals(1, $contact_get['count']);
foreach ($createdGroupsIds as $id) {
$this->assertContains((string) $id, $contact_groups);
}
- $contact_get2 = $this->callAPIAndDocument('contact', 'get', ['group' => ['IN' => $createdGroupTitles]], __FUNCTION__, __FILE__, $description, $subFile);
+ $this->callAPIAndDocument('contact', 'get', ['group' => ['IN' => $createdGroupTitles]], __FUNCTION__, __FILE__, $description, $subFile);
$contact_get2 = $this->callAPISuccess('contact', 'get', ['group' => ['IN' => $createdGroupTitles], 'return' => 'group']);
$this->assertEquals($created_contact_id, $contact_get2['id']);
$contact_groups2 = explode(',', $contact_get2['values'][$created_contact_id]['groups']);
* contact.get group=array('titke1' => 1, 'title2' => 1)
* contact.get group=array('id1' => 1)
* contact.get group=array('id1' => 1, id2 => 1)
+ *
+ * @throws \CRM_Core_Exception
*/
public function testContactGetWithGroupTitleMultipleGroupsLegacyFormat() {
// Set up a contact, asser that they were created.
'created_id' => $created_contact_id,
];
$create_group = $this->callApiSuccess('Group', 'create', $group_params);
- $created_group_id = $create_group['id'];
$createdGroupsIds[] = $create_group['id'];
$createdGroupTitles[] = $title;
// Add contact to the new group.
'contact_id' => $created_contact_id,
'group_id' => $create_group['id'],
];
- $create_group_contact = $this->callApiSuccess('GroupContact', 'create', $group_contact_params);
+ $this->callApiSuccess('GroupContact', 'create', $group_contact_params);
}
$contact_get = $this->callAPISuccess('contact', 'get', ['group' => [$createdGroupTitles[0] => 1], 'return' => 'group']);
$this->assertEquals(1, $contact_get['count']);
*
* This is primarily testing functionality in the BAO_Query object that 'happens to be'
* accessible via the api.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testContactGetProximity() {
CRM_Core_Config::singleton()->geocodeMethod = 'CRM_Utils_MockGeocoder';
}
public function testLoggedInUserAPISupportToken() {
- $description = "Get contact id of the current logged in user";
- $subFile = "ContactIDOfLoggedInUserContactAPI";
+ $description = 'Get contact id of the current logged in user';
+ $subFile = 'ContactIDOfLoggedInUserContactAPI';
$cid = $this->createLoggedInUser();
$contact = $this->callAPIAndDocument('contact', 'get', ['id' => 'user_contact_id'], __FUNCTION__, __FILE__, $description, $subFile);
$this->assertEquals($cid, $contact['id']);
/**
* API test to retrieve contact from group having different group title and name.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testContactGetFromGroup() {
$groupId = $this->groupCreate([
'group_id' => $groupId,
'status' => 'Pending',
];
- $groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
- $groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
- $this->CallAPISuccess('Contact', 'getcount', [
- 'group' => "Test_Group",
- ]);
+ $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
+ $this->callAPISuccess('groupContact', 'get', $groupContactCreateParams);
+ $this->callAPISuccess('Contact', 'getcount', ['group' => 'Test_Group']);
}
/**
* Test the related contacts filter.
*
- * @throws \Exception
+ * @throws \CRM_Core_Exception
*/
public function testSmartGroupsForRelatedContacts() {
$rtype1 = $this->callAPISuccess('relationship_type', 'create', [
/**
* Test creating a note from the contact.create API call when only passing the note as a string.
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testCreateNoteinCreate() {
+ public function testCreateNoteInCreate() {
$loggedInContactID = $this->createLoggedInUser();
- $this->_params['note'] = "Test note created by API Call as a String";
+ $this->_params['note'] = 'Test note created by API Call as a String';
$contact = $this->callAPISuccess('Contact', 'create', $this->_params);
$note = $this->callAPISuccess('Note', 'get', ['contact_id' => $loggedInContactID]);
$this->assertEquals($note['values'][$note['id']]['note'], "Test note created by API Call as a String");
/**
* Test Creating a note from the contact.create api call when passing the note params as an array.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreateNoteinCreateArrayFormat() {
$contact1 = $this->callAPISuccess('Contact', 'create', ['first_name' => 'Alan', 'last_name' => 'MouseMouse', 'contact_type' => 'Individual']);
* - Contact.get tag='id1'
* - Contact.get tag='id1,id2'
* - Contact.get tag='id1, id2'
+ *
+ * @throws \CRM_Core_Exception
*/
public function testContactGetWithTag() {
$contact = $this->callApiSuccess('Contact', 'create', [
*
* @return array
*
+ * @throws \API_Exception
* @throws \CRM_Core_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
protected function createDeeplyConflictedContacts(): array {
$this->createCustomGroupWithFieldOfType();
return [$contact1, $contact2];
}
+ /**
+ * Combinations of versions and privacy choices.
+ *
+ * @return array
+ */
public function versionAndPrivacyOption() {
$version = [3, 4];
$fields = ['do_not_mail', 'do_not_email', 'do_not_sms', 'is_opt_out', 'do_not_trade'];
* @param $expected
*
* @throws \CRM_Core_Exception
+ *
* @dataProvider versionAndPrivacyOption
*/
public function testGetContactsByPrivacyFlag($version, $query, $field, $expected) {