diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index a6107e464dcb..ad9eb22559ff 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -2,6 +2,7 @@ /** * Class CRM_Core_DAOTest + * * @group headless */ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { @@ -65,12 +66,14 @@ public function tearDown() { /** * Basic test to ensure the exportComponents function completes without error. + * + * @throws \CRM_Core_Exception */ public function testExportComponentsNull() { list($tableName) = CRM_Export_BAO_Export::exportComponents( TRUE, - array(), - array(), + [], + [], NULL, NULL, NULL, @@ -79,10 +82,10 @@ public function testExportComponentsNull() { NULL, FALSE, FALSE, - array( + [ 'exportOption' => 1, 'suppress_csv_for_testing' => TRUE, - ) + ] ); // delete the export temp table and component table @@ -95,22 +98,22 @@ public function testExportComponentsNull() { */ public function testExportComponentsContribution() { $this->setUpContributionExportData(); - $selectedFields = array( - array('Individual', 'first_name'), - array('Individual', 'last_name'), - array('Contribution', 'receive_date'), - array('Contribution', 'contribution_source'), - array('Individual', 'street_address', 1), - array('Individual', 'city', 1), - array('Individual', 'country', 1), - array('Individual', 'email', 1), - array('Contribution', 'trxn_id'), - ); + $selectedFields = [ + ['Individual', 'first_name'], + ['Individual', 'last_name'], + ['Contribution', 'receive_date'], + ['Contribution', 'contribution_source'], + ['Individual', 'street_address', 1], + ['Individual', 'city', 1], + ['Individual', 'country', 1], + ['Individual', 'email', 1], + ['Contribution', 'trxn_id'], + ]; list($tableName) = CRM_Export_BAO_Export::exportComponents( TRUE, $this->contributionIDs, - array(), + [], 'receive_date desc', $selectedFields, NULL, @@ -119,10 +122,10 @@ public function testExportComponentsContribution() { NULL, FALSE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::CONTRIBUTE_EXPORT, 'suppress_csv_for_testing' => TRUE, - ) + ] ); // delete the export temp table and component table @@ -147,10 +150,10 @@ public function testExportComponentsMembership() { NULL, FALSE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::MEMBER_EXPORT, 'suppress_csv_for_testing' => TRUE, - ) + ] ); $dao = CRM_Core_DAO::executeQuery('SELECT * from ' . $tableName); @@ -170,15 +173,15 @@ public function testExportComponentsMembership() { */ public function testExportComponentsActivity() { $this->setUpActivityExportData(); - $selectedFields = array( - array('Individual', 'display_name'), - array('Individual', '5_a_b', 'display_name'), - ); + $selectedFields = [ + ['Individual', 'display_name'], + ['Individual', '5_a_b', 'display_name'], + ]; list($tableName) = CRM_Export_BAO_Export::exportComponents( FALSE, $this->activityIDs, - array(), + [], '`activity_date_time` desc', $selectedFields, NULL, @@ -187,10 +190,10 @@ public function testExportComponentsActivity() { NULL, FALSE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::ACTIVITY_EXPORT, 'suppress_csv_for_testing' => TRUE, - ) + ] ); // delete the export temp table and component table @@ -210,13 +213,13 @@ public function testExportComponentsActivity() { */ public function testGetExportStructureArrays() { // This is how return properties are formatted internally within the function for passing to the BAO query. - $returnProperties = array( + $returnProperties = [ 'first_name' => 1, 'last_name' => 1, 'receive_date' => 1, 'contribution_source' => 1, - 'location' => array( - 'Home' => array( + 'location' => [ + 'Home' => [ 'street_address' => 1, 'city' => 1, 'country' => 1, @@ -224,12 +227,12 @@ public function testGetExportStructureArrays() { 'im-1' => 1, 'im_provider' => 1, 'phone-1' => 1, - ), - ), + ], + ], 'phone' => 1, 'trxn_id' => 1, 'contribution_id' => 1, - ); + ]; $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType( NULL, @@ -241,14 +244,14 @@ public function testGetExportStructureArrays() { FALSE ); - $query = new CRM_Contact_BAO_Query(array(), $returnProperties, NULL, + $query = new CRM_Contact_BAO_Query([], $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE, FALSE, TRUE, TRUE, NULL, 'AND' ); list($select) = $query->query(); $pattern = '/as `?([^`,]*)/'; - $queryFieldAliases = array(); + $queryFieldAliases = []; preg_match_all($pattern, $select, $queryFieldAliases, PREG_PATTERN_ORDER); $processor = new CRM_Export_BAO_ExportProcessor(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, NULL, 'AND'); $processor->setQueryFields($query->_fields); @@ -270,8 +273,8 @@ public function testGetExportStructureArrays() { */ public function setUpContributionExportData() { $this->setUpContactExportData(); - $this->contributionIDs[] = $this->contributionCreate(array('contact_id' => $this->contactIDs[0], 'trxn_id' => 'null', 'invoice_id' => 'null')); - $this->contributionIDs[] = $this->contributionCreate(array('contact_id' => $this->contactIDs[1], 'trxn_id' => 'null', 'invoice_id' => 'null')); + $this->contributionIDs[] = $this->contributionCreate(['contact_id' => $this->contactIDs[0], 'trxn_id' => 'null', 'invoice_id' => 'null']); + $this->contributionIDs[] = $this->contributionCreate(['contact_id' => $this->contactIDs[1], 'trxn_id' => 'null', 'invoice_id' => 'null']); } /** @@ -283,10 +286,10 @@ public function setUpMembershipExportData() { $this->contactMembershipCreate(['contact_id' => $this->contactIDs[0]]); $this->membershipIDs[] = $this->contactMembershipCreate(['contact_id' => $this->contactIDs[0]]); $this->setUpContributionExportData(); - $this->callAPISuccess('membership_payment', 'create', array( + $this->callAPISuccess('membership_payment', 'create', [ 'contribution_id' => $this->contributionIDs[0], 'membership_id' => $this->membershipIDs[0], - )); + ]); $this->callAPISuccess('LineItem', 'get', [ 'entity_table' => 'civicrm_membership', 'membership_id' => $this->membershipIDs[0], @@ -299,13 +302,13 @@ public function setUpMembershipExportData() { */ public function setupCaseExportData() { $contactID1 = $this->individualCreate(); - $contactID2 = $this->individualCreate(array(), 1); + $contactID2 = $this->individualCreate([], 1); - $case = $this->callAPISuccess('case', 'create', array( + $case = $this->callAPISuccess('case', 'create', [ 'case_type_id' => 1, 'subject' => 'blah', 'contact_id' => $contactID1, - )); + ]); $this->callAPISuccess('CaseContact', 'create', [ 'case_id' => $case['id'], 'contact_id' => $contactID2, @@ -317,7 +320,7 @@ public function setupCaseExportData() { */ public function setUpActivityExportData() { $this->setUpContactExportData(); - $this->activityIDs[] = $this->activityCreate(array('contact_id' => $this->contactIDs[0]))['id']; + $this->activityIDs[] = $this->activityCreate(['contact_id' => $this->contactIDs[0]])['id']; } /** @@ -326,7 +329,7 @@ public function setUpActivityExportData() { public function setUpContactExportData() { $this->contactIDs[] = $contactA = $this->individualCreate(['gender_id' => 'Female']); // Create address for contact A. - $params = array( + $params = [ 'contact_id' => $contactA, 'location_type_id' => 'Home', 'street_address' => 'Ambachtstraat 23', @@ -334,28 +337,28 @@ public function setUpContactExportData() { 'country_id' => '1152', 'city' => 'Brummen', 'is_primary' => 1, - ); + ]; $result = $this->callAPISuccess('address', 'create', $params); $addressId = $result['id']; - $this->callAPISuccess('email', 'create', array( + $this->callAPISuccess('email', 'create', [ 'id' => $this->callAPISuccessGetValue('Email', ['contact_id' => $params['contact_id'], 'return' => 'id']), 'location_type_id' => 'Home', 'email' => 'home@example.com', 'is_primary' => 1, - )); - $this->callAPISuccess('email', 'create', array('contact_id' => $params['contact_id'], 'location_type_id' => 'Work', 'email' => 'work@example.com', 'is_primary' => 0)); + ]); + $this->callAPISuccess('email', 'create', ['contact_id' => $params['contact_id'], 'location_type_id' => 'Work', 'email' => 'work@example.com', 'is_primary' => 0]); $params['is_primary'] = 0; $params['location_type_id'] = 'Work'; $this->callAPISuccess('address', 'create', $params); $this->contactIDs[] = $contactB = $this->individualCreate(); - $this->callAPISuccess('address', 'create', array( + $this->callAPISuccess('address', 'create', [ 'contact_id' => $contactB, 'location_type_id' => "Home", 'master_id' => $addressId, - )); + ]); $this->masterAddressID = $addressId; } @@ -385,10 +388,10 @@ public function testExportPrimaryAddress($isPrimaryOnly) { NULL, FALSE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT, 'suppress_csv_for_testing' => TRUE, - ) + ] ); $dao = CRM_Core_DAO::executeQuery('SELECT * from ' . $tableName); @@ -405,6 +408,8 @@ public function testExportPrimaryAddress($isPrimaryOnly) { * * ie. we have a contact WITH a gender & one without - make sure the latter one * does NOT retain the gender of the former. + * + * @throws \CRM_Core_Exception */ public function testExportPseudoField() { $this->setUpContactExportData(); @@ -426,7 +431,7 @@ public function testExportPseudoFieldCampaign() { list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents( TRUE, $this->contactIDs[1], - array(), + [], NULL, $selectedFields, NULL, @@ -435,10 +440,10 @@ public function testExportPseudoFieldCampaign() { NULL, FALSE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT, 'suppress_csv_for_testing' => TRUE, - ) + ] ); $this->assertEquals('Big campaign,', CRM_Core_DAO::singleValueQuery("SELECT GROUP_CONCAT(contribution_campaign_title) FROM {$tableName}")); } @@ -1030,13 +1035,13 @@ public function testExportMasterAddress() { $this->setUpContactExportData(); //export the master address for contact B - $selectedFields = array( - array('Individual', 'master_id', 1), - ); + $selectedFields = [ + ['Individual', 'master_id', 1], + ]; list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents( TRUE, - array($this->contactIDs[1]), - array(), + [$this->contactIDs[1]], + [], NULL, $selectedFields, NULL, @@ -1045,10 +1050,10 @@ public function testExportMasterAddress() { NULL, FALSE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT, 'suppress_csv_for_testing' => TRUE, - ) + ] ); $field = key($sqlColumns); @@ -1069,13 +1074,15 @@ public function testExportMasterAddress() { * * @param array $reason * @param array $addressReason + * + * @throws \CRM_Core_Exception */ public function testExportDeceasedDoNotMail($reason, $addressReason) { - $contactA = $this->callAPISuccess('contact', 'create', array( + $contactA = $this->callAPISuccess('contact', 'create', [ 'first_name' => 'John', 'last_name' => 'Doe', 'contact_type' => 'Individual', - )); + ]); $contactB = $this->callAPISuccess('contact', 'create', array_merge([ 'first_name' => 'Jane', @@ -1108,8 +1115,8 @@ public function testExportDeceasedDoNotMail($reason, $addressReason) { //export and merge contacts with same address list($tableName, $sqlColumns, $headerRows, $processor) = CRM_Export_BAO_Export::exportComponents( TRUE, - array($contactA['id'], $contactB['id']), - array(), + [$contactA['id'], $contactB['id']], + [], NULL, NULL, NULL, @@ -1118,14 +1125,14 @@ public function testExportDeceasedDoNotMail($reason, $addressReason) { NULL, TRUE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT, 'mergeOption' => TRUE, 'suppress_csv_for_testing' => TRUE, - 'postal_mailing_export' => array( + 'postal_mailing_export' => [ 'postal_mailing_export' => TRUE, - ), - ) + ], + ] ); $this->assertTrue(!in_array('state_province_id', $processor->getHeaderRows())); @@ -1141,6 +1148,7 @@ public function testExportDeceasedDoNotMail($reason, $addressReason) { /** * Get reasons that a contact is not postalable. + * * @return array */ public function getReasonsNotToMail() { @@ -1152,7 +1160,10 @@ public function getReasonsNotToMail() { } /** + * Set up household for tests. + * * @return array + * @throws \Exception */ protected function setUpHousehold() { $this->setUpContactExportData(); @@ -1182,25 +1193,26 @@ protected function setUpHousehold() { 'contact_id_b' => $householdID, 'relationship_type_id' => $houseHoldTypeID, ]); - return array($householdID, $houseHoldTypeID); + return [$householdID, $houseHoldTypeID]; } /** * Do a CiviCRM export. * - * @param $selectedFields + * @param array $selectedFields * @param int $id * * @param int $exportMode * * @return array + * @throws \CRM_Core_Exception */ protected function doExport($selectedFields, $id, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT) { $ids = (array) $id; list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents( TRUE, $ids, - array(), + [], NULL, $selectedFields, NULL, @@ -1209,12 +1221,12 @@ protected function doExport($selectedFields, $id, $exportMode = CRM_Export_Form_ NULL, FALSE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT, 'suppress_csv_for_testing' => TRUE, - ) + ] ); - return array($tableName, $sqlColumns); + return [$tableName, $sqlColumns]; } /** @@ -1232,6 +1244,7 @@ public function ensureComponentIsEnabled($exportMode) { * Test our export all field metadata retrieval. * * @dataProvider additionalFieldsDataProvider + * * @param int $exportMode * @param $expected */ @@ -1246,6 +1259,7 @@ public function testAdditionalReturnProperties($exportMode, $expected) { * Test our export all field metadata retrieval. * * @dataProvider allFieldsDataProvider + * * @param int $exportMode * @param $expected */ @@ -1661,6 +1675,7 @@ public function getContributionReturnProperties() { * @param array $expected * @param array $expectedHeaders * + * @throws \CRM_Core_Exception * @dataProvider getSqlColumnsOutput */ public function testGetSQLColumnsAndHeaders($exportMode, $expected, $expectedHeaders) { @@ -1683,10 +1698,10 @@ public function testGetSQLColumnsAndHeaders($exportMode, $expected, $expectedHea NULL, FALSE, FALSE, - array( + [ 'exportOption' => CRM_Export_Form_Select::CONTRIBUTE_EXPORT, 'suppress_csv_for_testing' => TRUE, - ) + ] ); $this->assertEquals($expected, $result[1]); $this->assertEquals($expectedHeaders, $result[2]); @@ -1743,9 +1758,10 @@ public function textExportParticipantSpecifyFieldsNoPayment() { } /** - * Get all return fields (@todo - still being built up. + * Get all return fields (@return array + * + * @todo - still being built up. * - * @return array */ public function getAllSpecifiableReturnFields() { return [ diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 78293ed7b497..117e25f7453b 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -37,14 +37,19 @@ * @group headless */ class api_v3_ContactTest extends CiviUnitTestCase { + use CRMTraits_Custom_CustomDataTrait; public $DBResetRequired = FALSE; + protected $_apiversion; + protected $_entity; + protected $_params; protected $_contactID; + protected $_financialTypeId = 1; @@ -65,11 +70,11 @@ public function setUp() { // Connect to the database. parent::setUp(); $this->_entity = 'contact'; - $this->_params = array( + $this->_params = [ 'first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', - ); + ]; } /** @@ -79,9 +84,9 @@ public function setUp() { */ public function tearDown() { $this->_apiversion = 3; - $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => TRUE]); // truncate a few tables - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_email', 'civicrm_contribution', 'civicrm_line_item', @@ -98,7 +103,7 @@ public function tearDown() { 'civicrm_saved_search', 'civicrm_group_contact_cache', 'civicrm_prevnext_cache', - ); + ]; $this->quickCleanup($tablesToTruncate, TRUE); parent::tearDown(); @@ -111,16 +116,17 @@ public function tearDown() { * first and last names succeeds * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testAddCreateIndividual($version) { $this->_apiversion = $version; $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_contact'); - $params = array( + $params = [ 'first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $this->assertTrue(is_numeric($contact['id'])); @@ -146,13 +152,13 @@ public function testCreateIndividualNoCacheClear() { $this->putGroupContactCacheInClearableState($groupID, $contact); - $this->callAPISuccess('contact', 'create', array('id' => $contact['id'])); + $this->callAPISuccess('contact', 'create', ['id' => $contact['id']]); $this->assertEquals(0, CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_group_contact_cache")); // Rinse & repeat, but with the option. $this->putGroupContactCacheInClearableState($groupID, $contact); CRM_Core_Config::setPermitCacheFlushMode(FALSE); - $this->callAPISuccess('contact', 'create', array('id' => $contact['id'])); + $this->callAPISuccess('contact', 'create', ['id' => $contact['id']]); $this->assertEquals(1, CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_group_contact_cache")); CRM_Core_Config::setPermitCacheFlushMode(TRUE); } @@ -173,16 +179,16 @@ public function testCreateIndividualNoCacheClear() { public function testInternationalStrings($string) { $this->callAPISuccess('Contact', 'create', array_merge( $this->_params, - array('first_name' => $string) + ['first_name' => $string] )); - $result = $this->callAPISuccessGetSingle('Contact', array('first_name' => $string)); + $result = $this->callAPISuccessGetSingle('Contact', ['first_name' => $string]); $this->assertEquals($string, $result['first_name']); - $organizationParams = array( + $organizationParams = [ 'organization_name' => $string, 'contact_type' => 'Organization', - ); + ]; $this->callAPISuccess('Contact', 'create', $organizationParams); $result = $this->callAPISuccessGetSingle('Contact', $organizationParams); @@ -193,11 +199,11 @@ public function testInternationalStrings($string) { * Get international string data for testing against api calls. */ public function getInternationalStrings() { - $invocations = array(); - $invocations[] = array('Scarabée'); - $invocations[] = array('Iñtërnâtiônàlizætiøn'); - $invocations[] = array('これは日本語のテキストです。読めますか'); - $invocations[] = array('देखें हिन्दी कैसी नजर आती है। अरे वाह ये तो नजर आती है।'); + $invocations = []; + $invocations[] = ['Scarabée']; + $invocations[] = ['Iñtërnâtiônàlizætiøn']; + $invocations[] = ['これは日本語のテキストです。読めますか']; + $invocations[] = ['देखें हिन्दी कैसी नजर आती है। अरे वाह ये तो नजर आती है।']; return $invocations; } @@ -205,17 +211,19 @@ public function getInternationalStrings() { * Test civicrm_contact_create. * * Verify that preferred language can be set. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testAddCreateIndividualWithPreferredLanguage($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', 'preferred_language' => 'es_ES', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $this->getAndCheck($params, $contact['id'], 'Contact'); @@ -227,28 +235,29 @@ public function testAddCreateIndividualWithPreferredLanguage($version) { * Verify that sub-types are created successfully and not deleted by subsequent updates. * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testIndividualSubType($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'first_name' => 'test abc', 'contact_type' => 'Individual', 'last_name' => 'test xyz', - 'contact_sub_type' => array('Student', 'Staff'), - ); + 'contact_sub_type' => ['Student', 'Staff'], + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $cid = $contact['id']; - $params = array( + $params = [ 'id' => $cid, 'middle_name' => 'foo', - ); + ]; $this->callAPISuccess('contact', 'create', $params); $contact = $this->callAPISuccess('contact', 'get', ['id' => $cid]); - $this->assertEquals(array('Student', 'Staff'), $contact['values'][$cid]['contact_sub_type']); + $this->assertEquals(['Student', 'Staff'], $contact['values'][$cid]['contact_sub_type']); $this->callAPISuccess('Contact', 'create', [ 'id' => $cid, @@ -261,7 +270,9 @@ public function testIndividualSubType($version) { /** * Verify that we can retreive contacts of different sub types + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetMultipleContactSubTypes($version) { @@ -270,27 +281,27 @@ public function testGetMultipleContactSubTypes($version) { // This test presumes that there are no parents or students in the dataset // create a student - $student = $this->callAPISuccess('contact', 'create', array( + $student = $this->callAPISuccess('contact', 'create', [ 'email' => 'student@example.com', 'contact_type' => 'Individual', 'contact_sub_type' => 'Student', - )); + ]); // create a parent - $parent = $this->callAPISuccess('contact', 'create', array( + $parent = $this->callAPISuccess('contact', 'create', [ 'email' => 'parent@example.com', 'contact_type' => 'Individual', 'contact_sub_type' => 'Parent', - )); + ]); // create a parent - $this->callAPISuccess('contact', 'create', array( + $this->callAPISuccess('contact', 'create', [ 'email' => 'parent@example.com', 'contact_type' => 'Individual', - )); + ]); // get all students and parents - $getParams = array('contact_sub_type' => array('IN' => array('Parent', 'Student'))); + $getParams = ['contact_sub_type' => ['IN' => ['Parent', 'Student']]]; $result = civicrm_api3('contact', 'get', $getParams); // check that we retrieved the student and the parent @@ -304,17 +315,17 @@ public function testGetMultipleContactSubTypes($version) { * Verify that attempt to create contact with empty params fails. */ public function testCreateEmptyContact() { - $this->callAPIFailure('contact', 'create', array()); + $this->callAPIFailure('contact', 'create', []); } /** * Verify that attempt to create contact with bad contact type fails. */ public function testCreateBadTypeContact() { - $params = array( + $params = [ 'email' => 'man1@yahoo.com', 'contact_type' => 'Does not Exist', - ); + ]; $this->callAPIFailure('contact', 'create', $params, "'Does not Exist' is not a valid option for field contact_type"); } @@ -322,10 +333,10 @@ public function testCreateBadTypeContact() { * Verify that attempt to create individual contact without required fields fails. */ public function testCreateBadRequiredFieldsIndividual() { - $params = array( + $params = [ 'middle_name' => 'This field is not required', 'contact_type' => 'Individual', - ); + ]; $this->callAPIFailure('contact', 'create', $params); } @@ -333,10 +344,10 @@ public function testCreateBadRequiredFieldsIndividual() { * Verify that attempt to create household contact without required fields fails. */ public function testCreateBadRequiredFieldsHousehold() { - $params = array( + $params = [ 'middle_name' => 'This field is not required', 'contact_type' => 'Household', - ); + ]; $this->callAPIFailure('contact', 'create', $params); } @@ -346,10 +357,10 @@ public function testCreateBadRequiredFieldsHousehold() { * Verify that attempt to create organization contact without required fields fails. */ public function testCreateBadRequiredFieldsOrganization() { - $params = array( + $params = [ 'middle_name' => 'This field is not required', 'contact_type' => 'Organization', - ); + ]; $this->callAPIFailure('contact', 'create', $params); } @@ -360,33 +371,33 @@ public function testCreateBadRequiredFieldsOrganization() { public function testCreateEmailIndividual() { $primaryEmail = 'man3@yahoo.com'; $notPrimaryEmail = 'man4@yahoo.com'; - $params = array( + $params = [ 'email' => $primaryEmail, 'contact_type' => 'Individual', 'location_type_id' => 1, - ); + ]; $contact1 = $this->callAPISuccess('contact', 'create', $params); $this->assertEquals(3, $contact1['id']); - $email1 = $this->callAPISuccess('email', 'get', array('contact_id' => $contact1['id'])); + $email1 = $this->callAPISuccess('email', 'get', ['contact_id' => $contact1['id']]); $this->assertEquals(1, $email1['count']); $this->assertEquals($primaryEmail, $email1['values'][$email1['id']]['email']); - $email2 = $this->callAPISuccess('email', 'create', array('contact_id' => $contact1['id'], 'is_primary' => 0, 'email' => $notPrimaryEmail)); + $email2 = $this->callAPISuccess('email', 'create', ['contact_id' => $contact1['id'], 'is_primary' => 0, 'email' => $notPrimaryEmail]); // Case 1: Check with criteria primary 'email' => array('IS NOT NULL' => 1) - $result = $this->callAPISuccess('contact', 'get', array('email' => array('IS NOT NULL' => 1))); + $result = $this->callAPISuccess('contact', 'get', ['email' => ['IS NOT NULL' => 1]]); $primaryEmailContactIds = array_keys($result['values']); $this->assertEquals($primaryEmail, $email1['values'][$email1['id']]['email']); // Case 2: Check with criteria primary 'email' => array('<>' => '') - $result = $this->callAPISuccess('contact', 'get', array('email' => array('<>' => ''))); + $result = $this->callAPISuccess('contact', 'get', ['email' => ['<>' => '']]); $primaryEmailContactIds = array_keys($result['values']); $this->assertEquals($primaryEmail, $email1['values'][$email1['id']]['email']); // Case 3: Check with email_id='primary email id' - $result = $this->callAPISuccess('contact', 'get', array('email_id' => $email1['id'])); + $result = $this->callAPISuccess('contact', 'get', ['email_id' => $email1['id']]); $this->assertEquals(1, $result['count']); $this->assertEquals($contact1['id'], $result['id']); @@ -397,16 +408,18 @@ public function testCreateEmailIndividual() { * Test creating individual by name. * * Verify create individual contact with only first and last names succeeds. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateNameIndividual($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', - ); + ]; $this->callAPISuccess('contact', 'create', $params); } @@ -415,15 +428,17 @@ public function testCreateNameIndividual($version) { * Test creating individual by display_name. * * Display name & sort name should be set. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateDisplayNameIndividual($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'display_name' => 'abc1', 'contact_type' => 'Individual', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); $params['sort_name'] = 'abc1'; @@ -432,7 +447,9 @@ public function testCreateDisplayNameIndividual($version) { /** * Test that name searches are case insensitive. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetNameVariantsCaseInsensitive($version) { @@ -456,16 +473,16 @@ public function testGetNameVariantsCaseInsensitive($version) { * first and last names and old key values works */ public function testCreateNameIndividualOldKeys() { - $params = array( + $params = [ 'individual_prefix' => 'Dr.', 'first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', 'individual_suffix' => 'Jr.', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); - $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contact['id'])); + $result = $this->callAPISuccess('contact', 'getsingle', ['id' => $contact['id']]); $this->assertArrayKeyExists('prefix_id', $result); $this->assertArrayKeyExists('suffix_id', $result); @@ -481,17 +498,17 @@ public function testCreateNameIndividualOldKeys() { * first and last names and old key values works */ public function testCreateNameIndividualRecommendedKeys2() { - $params = array( + $params = [ 'prefix_id' => 'Dr.', 'first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', 'suffix_id' => 'Jr.', 'gender_id' => 'Male', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); - $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contact['id'])); + $result = $this->callAPISuccess('contact', 'getsingle', ['id' => $contact['id']]); $this->assertArrayKeyExists('prefix_id', $result); $this->assertArrayKeyExists('suffix_id', $result); @@ -505,15 +522,17 @@ public function testCreateNameIndividualRecommendedKeys2() { * * Verify that attempt to create household contact with only * household name succeeds + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateNameHousehold($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'household_name' => 'The abc Household', 'contact_type' => 'Household', - ); + ]; $this->callAPISuccess('contact', 'create', $params); } @@ -522,15 +541,17 @@ public function testCreateNameHousehold($version) { * * Verify that attempt to create organization contact with only * organization name succeeds. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateNameOrganization($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'organization_name' => 'The abc Organization', 'contact_type' => 'Organization', - ); + ]; $this->callAPISuccess('contact', 'create', $params); } @@ -538,10 +559,10 @@ public function testCreateNameOrganization($version) { * Verify that attempt to create organization contact without organization name fails. */ public function testCreateNoNameOrganization() { - $params = array( + $params = [ 'first_name' => 'The abc Organization', 'contact_type' => 'Organization', - ); + ]; $this->callAPIFailure('contact', 'create', $params); } @@ -549,70 +570,71 @@ public function testCreateNoNameOrganization() { * Check that permissions on API key are restricted (CRM-18112). * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateApiKey($version) { $this->_apiversion = $version; $config = CRM_Core_Config::singleton(); - $contactId = $this->individualCreate(array( + $contactId = $this->individualCreate([ 'first_name' => 'A', 'last_name' => 'B', - )); + ]); // Allow edit -- because permissions aren't being checked - $config->userPermissionClass->permissions = array(); - $result = $this->callAPISuccess('Contact', 'create', array( + $config->userPermissionClass->permissions = []; + $result = $this->callAPISuccess('Contact', 'create', [ 'id' => $contactId, 'api_key' => 'original', - )); + ]); $this->assertEquals('original', $result['values'][$contactId]['api_key']); // Allow edit -- because we have adequate permission - $config->userPermissionClass->permissions = array('access CiviCRM', 'edit all contacts', 'edit api keys'); - $result = $this->callAPISuccess('Contact', 'create', array( + $config->userPermissionClass->permissions = ['access CiviCRM', 'edit all contacts', 'edit api keys']; + $result = $this->callAPISuccess('Contact', 'create', [ 'check_permissions' => 1, 'id' => $contactId, 'api_key' => 'abcd1234', - )); + ]); $this->assertEquals('abcd1234', $result['values'][$contactId]['api_key']); // Disallow edit -- because we don't have permission - $config->userPermissionClass->permissions = array('access CiviCRM', 'edit all contacts'); - $result = $this->callAPIFailure('Contact', 'create', array( + $config->userPermissionClass->permissions = ['access CiviCRM', 'edit all contacts']; + $result = $this->callAPIFailure('Contact', 'create', [ 'check_permissions' => 1, 'id' => $contactId, 'api_key' => 'defg4321', - )); + ]); $this->assertRegExp(';Permission denied to modify api key;', $result['error_message']); // Return everything -- because permissions are not being checked - $config->userPermissionClass->permissions = array(); - $result = $this->callAPISuccess('Contact', 'create', array( + $config->userPermissionClass->permissions = []; + $result = $this->callAPISuccess('Contact', 'create', [ 'id' => $contactId, 'first_name' => 'A2', - )); + ]); $this->assertEquals('A2', $result['values'][$contactId]['first_name']); $this->assertEquals('B', $result['values'][$contactId]['last_name']); $this->assertEquals('abcd1234', $result['values'][$contactId]['api_key']); // Return everything -- because we have adequate permission - $config->userPermissionClass->permissions = array('access CiviCRM', 'edit all contacts', 'edit api keys'); - $result = $this->callAPISuccess('Contact', 'create', array( + $config->userPermissionClass->permissions = ['access CiviCRM', 'edit all contacts', 'edit api keys']; + $result = $this->callAPISuccess('Contact', 'create', [ 'check_permissions' => 1, 'id' => $contactId, 'first_name' => 'A3', - )); + ]); $this->assertEquals('A3', $result['values'][$contactId]['first_name']); $this->assertEquals('B', $result['values'][$contactId]['last_name']); $this->assertEquals('abcd1234', $result['values'][$contactId]['api_key']); // Restricted return -- because we don't have permission - $config->userPermissionClass->permissions = array('access CiviCRM', 'edit all contacts'); - $result = $this->callAPISuccess('Contact', 'create', array( + $config->userPermissionClass->permissions = ['access CiviCRM', 'edit all contacts']; + $result = $this->callAPISuccess('Contact', 'create', [ 'check_permissions' => 1, 'id' => $contactId, 'first_name' => 'A4', - )); + ]); $this->assertEquals('A4', $result['values'][$contactId]['first_name']); $this->assertEquals('B', $result['values'][$contactId]['last_name']); $this->assertTrue(empty($result['values'][$contactId]['api_key'])); @@ -624,7 +646,9 @@ public function testCreateApiKey($version) { * Note that the test is written on purpose without any * variables specific to participant so it can be replicated into other entities * and / or moved to the automated test suite + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateWithCustom($version) { @@ -636,10 +660,10 @@ public function testCreateWithCustom($version) { $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', array( + $check = $this->callAPISuccess($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id'], - )); + ]); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]); $this->customFieldDelete($ids['custom_field_id']); @@ -660,34 +684,38 @@ public function testCreateWithNULLCustomCRM12773() { /** * CRM-14232 test preferred language set to site default if not passed. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreatePreferredLanguageUnset($version) { $this->_apiversion = $version; - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'first_name' => 'Snoop', 'last_name' => 'Dog', 'contact_type' => 'Individual', - )); - $result = $this->callAPISuccessGetSingle('Contact', array('last_name' => 'Dog')); + ]); + $result = $this->callAPISuccessGetSingle('Contact', ['last_name' => 'Dog']); $this->assertEquals('en_US', $result['preferred_language']); } /** * CRM-14232 test preferred language returns setting if not passed. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreatePreferredLanguageSet($version) { $this->_apiversion = $version; - $this->callAPISuccess('Setting', 'create', array('contact_default_language' => 'fr_FR')); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Setting', 'create', ['contact_default_language' => 'fr_FR']); + $this->callAPISuccess('Contact', 'create', [ 'first_name' => 'Snoop', 'last_name' => 'Dog', 'contact_type' => 'Individual', - )); - $result = $this->callAPISuccessGetSingle('Contact', array('last_name' => 'Dog')); + ]); + $result = $this->callAPISuccessGetSingle('Contact', ['last_name' => 'Dog']); $this->assertEquals('fr_FR', $result['preferred_language']); } @@ -696,31 +724,33 @@ public function testCreatePreferredLanguageSet($version) { * TODO: Api4 */ public function testCreatePreferredLanguageNull() { - $this->callAPISuccess('Setting', 'create', array('contact_default_language' => 'null')); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Setting', 'create', ['contact_default_language' => 'null']); + $this->callAPISuccess('Contact', 'create', [ 'first_name' => 'Snoop', 'last_name' => 'Dog', 'contact_type' => 'Individual', - )); - $result = $this->callAPISuccessGetSingle('Contact', array('last_name' => 'Dog')); + ]); + $result = $this->callAPISuccessGetSingle('Contact', ['last_name' => 'Dog']); $this->assertEquals(NULL, $result['preferred_language']); } /** * CRM-14232 test preferred language returns setting if not passed where setting is NULL. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreatePreferredLanguagePassed($version) { $this->_apiversion = $version; - $this->callAPISuccess('Setting', 'create', array('contact_default_language' => 'null')); - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Setting', 'create', ['contact_default_language' => 'null']); + $this->callAPISuccess('Contact', 'create', [ 'first_name' => 'Snoop', 'last_name' => 'Dog', 'contact_type' => 'Individual', 'preferred_language' => 'en_AU', - )); - $result = $this->callAPISuccessGetSingle('Contact', array('last_name' => 'Dog')); + ]); + $result = $this->callAPISuccessGetSingle('Contact', ['last_name' => 'Dog']); $this->assertEquals('en_AU', $result['preferred_language']); } @@ -728,15 +758,15 @@ public function testCreatePreferredLanguagePassed($version) { * CRM-15792 - create/update datetime field for contact. */ public function testCreateContactCustomFldDateTime() { - $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'datetime_test_group')); + $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'datetime_test_group']); $dateTime = CRM_Utils_Date::currentDBDate(); //check date custom field is saved along with time when time_format is set - $params = array( + $params = [ 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', 'email' => 'man3@yahoo.com', - 'api.CustomField.create' => array( + 'api.CustomField.create' => [ 'custom_group_id' => $customGroup['id'], 'name' => 'test_datetime', 'label' => 'Demo Date', @@ -747,19 +777,19 @@ public function testCreateContactCustomFldDateTime() { 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1, - ), - ); + ], + ]; $result = $this->callAPISuccess('Contact', 'create', $params); $customFldId = $result['values'][$result['id']]['api.CustomField.create']['id']; $this->assertNotNull($result['id']); $this->assertNotNull($customFldId); - $params = array( + $params = [ 'id' => $result['id'], "custom_{$customFldId}" => $dateTime, 'api.CustomValue.get' => 1, - ); + ]; $result = $this->callAPISuccess('Contact', 'create', $params); $this->assertNotNull($result['id']); @@ -769,21 +799,21 @@ public function testCreateContactCustomFldDateTime() { $customValueId = $result['values'][$result['id']]['api.CustomValue.get']['values'][0]['id']; $dateTime = date('Ymd'); //date custom field should not contain time part when time_format is null - $params = array( + $params = [ 'id' => $result['id'], - 'api.CustomField.create' => array( + 'api.CustomField.create' => [ 'id' => $customFldId, 'html_type' => 'Select Date', 'data_type' => 'Date', 'time_format' => '', - ), - 'api.CustomValue.create' => array( + ], + 'api.CustomValue.create' => [ 'id' => $customValueId, 'entity_id' => $result['id'], "custom_{$customFldId}" => $dateTime, - ), + ], 'api.CustomValue.get' => 1, - ); + ]; $result = $this->callAPISuccess('Contact', 'create', $params); $this->assertNotNull($result['id']); $customFldDate = date("Ymd", strtotime($result['values'][$result['id']]['api.CustomValue.get']['values'][0]['latest'])); @@ -799,28 +829,28 @@ public function testCreateContactCustomFldDateTime() { */ public function testContactCreateCurrentEmployer() { // Here we will just do the get for set-up purposes. - $count = $this->callAPISuccess('contact', 'getcount', array( + $count = $this->callAPISuccess('contact', 'getcount', [ 'organization_name' => 'new employer org', 'contact_type' => 'Organization', - )); + ]); $this->assertEquals(0, $count); - $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( + $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, [ 'current_employer' => 'new employer org', - ))); + ])); // do it again as an update to check it doesn't cause an error - $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( + $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, [ 'current_employer' => 'new employer org', 'id' => $employerResult['id'], - ))); + ])); $expectedCount = 1; - $this->callAPISuccess('contact', 'getcount', array( + $this->callAPISuccess('contact', 'getcount', [ 'organization_name' => 'new employer org', 'contact_type' => 'Organization', - ), $expectedCount); + ], $expectedCount); - $result = $this->callAPISuccess('contact', 'getsingle', array( + $result = $this->callAPISuccess('contact', 'getsingle', [ 'id' => $employerResult['id'], - )); + ]); $this->assertEquals('new employer org', $result['current_employer']); @@ -833,31 +863,26 @@ public function testContactCreateCurrentEmployer() { */ public function testContactCreateDuplicateCurrentEmployerEnables() { // Set up - create employer relationship. - $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( - 'current_employer' => 'new employer org', - ) - )); - $relationship = $this->callAPISuccess('relationship', 'get', array( + $employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, ['current_employer' => 'new employer org'])); + $relationship = $this->callAPISuccess('relationship', 'get', [ 'contact_id_a' => $employerResult['id'], - )); + ]); //disable & check it is disabled - $this->callAPISuccess('relationship', 'create', array('id' => $relationship['id'], 'is_active' => 0)); - $this->callAPISuccess('relationship', 'getvalue', array( + $this->callAPISuccess('relationship', 'create', ['id' => $relationship['id'], 'is_active' => 0]); + $this->callAPISuccess('relationship', 'getvalue', [ 'id' => $relationship['id'], 'return' => 'is_active', - ), 0); + ], 0); // Re-set the current employer - thus enabling the relationship. - $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( - 'current_employer' => 'new employer org', - 'id' => $employerResult['id'], - ) + $this->callAPISuccess('contact', 'create', array_merge($this->_params, [ + 'current_employer' => 'new employer org', + 'id' => $employerResult['id'], + ] )); //check is_active is now 1 - $relationship = $this->callAPISuccess('relationship', 'getsingle', array( - 'return' => 'is_active', - )); + $relationship = $this->callAPISuccess('relationship', 'getsingle', ['return' => 'is_active']); $this->assertEquals(1, $relationship['is_active']); } @@ -865,19 +890,21 @@ public function testContactCreateDuplicateCurrentEmployerEnables() { * Check deceased contacts are not retrieved. * * Note at time of writing the default is to return default. This should possibly be changed & test added. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetDeceasedRetrieved($version) { $this->_apiversion = $version; $this->callAPISuccess($this->_entity, 'create', $this->_params); - $c2 = $this->callAPISuccess($this->_entity, 'create', array( + $c2 = $this->callAPISuccess($this->_entity, 'create', [ 'first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual', 'is_deceased' => 1, - )); - $result = $this->callAPISuccess($this->_entity, 'get', array('is_deceased' => 0)); + ]); + $result = $this->callAPISuccess($this->_entity, 'get', ['is_deceased' => 0]); $this->assertFalse(array_key_exists($c2['id'], $result['values'])); } @@ -886,58 +913,60 @@ public function testGetDeceasedRetrieved($version) { */ public function testGetSort() { $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $c2 = $this->callAPISuccess($this->_entity, 'create', array( + $c2 = $this->callAPISuccess($this->_entity, 'create', [ 'first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual', - )); - $result = $this->callAPISuccess($this->_entity, 'get', array( + ]); + $result = $this->callAPISuccess($this->_entity, 'get', [ 'sort' => 'first_name ASC', 'return.first_name' => 1, 'sequential' => 1, 'rowCount' => 1, 'contact_type' => 'Individual', - )); + ]); $this->assertEquals('abc1', $result['values'][0]['first_name']); - $result = $this->callAPISuccess($this->_entity, 'get', array( + $result = $this->callAPISuccess($this->_entity, 'get', [ 'sort' => 'first_name DESC', 'return.first_name' => 1, 'sequential' => 1, 'rowCount' => 1, - )); + ]); $this->assertEquals('bb', $result['values'][0]['first_name']); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $c1['id'])); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $c2['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $c1['id']]); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $c2['id']]); } /** * Test that we can retrieve contacts using array syntax. * * I.e 'id' => array('IN' => array('3,4')). + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetINIDArray($version) { $this->_apiversion = $version; $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $c2 = $this->callAPISuccess($this->_entity, 'create', array( + $c2 = $this->callAPISuccess($this->_entity, 'create', [ 'first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual', - )); - $c3 = $this->callAPISuccess($this->_entity, 'create', array( + ]); + $c3 = $this->callAPISuccess($this->_entity, 'create', [ 'first_name' => 'hh', 'last_name' => 'll', 'contact_type' => 'Individual', - )); - $result = $this->callAPISuccess($this->_entity, 'get', array('id' => array('IN' => array($c1['id'], $c3['id'])))); + ]); + $result = $this->callAPISuccess($this->_entity, 'get', ['id' => ['IN' => [$c1['id'], $c3['id']]]]); $this->assertEquals(2, $result['count']); - $this->assertEquals(array($c1['id'], $c3['id']), array_keys($result['values'])); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $c1['id'])); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $c2['id'])); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $c3['id'])); + $this->assertEquals([$c1['id'], $c3['id']], array_keys($result['values'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $c1['id']]); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $c2['id']]); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $c3['id']]); } /** @@ -949,23 +978,23 @@ public function testGetDeleted() { $params['is_deleted'] = 1; $params['last_name'] = 'bcd'; $contact2 = $this->callAPISuccess('contact', 'create', $params); - $countActive = $this->callAPISuccess('contact', 'getcount', array( + $countActive = $this->callAPISuccess('contact', 'getcount', [ 'showAll' => 'active', 'contact_type' => 'Individual', - )); - $countAll = $this->callAPISuccess('contact', 'getcount', array('showAll' => 'all', 'contact_type' => 'Individual')); - $countTrash = $this->callAPISuccess('contact', 'getcount', array('showAll' => 'trash', 'contact_type' => 'Individual')); - $countDefault = $this->callAPISuccess('contact', 'getcount', array('contact_type' => 'Individual')); - $countDeleted = $this->callAPISuccess('contact', 'getcount', array( + ]); + $countAll = $this->callAPISuccess('contact', 'getcount', ['showAll' => 'all', 'contact_type' => 'Individual']); + $countTrash = $this->callAPISuccess('contact', 'getcount', ['showAll' => 'trash', 'contact_type' => 'Individual']); + $countDefault = $this->callAPISuccess('contact', 'getcount', ['contact_type' => 'Individual']); + $countDeleted = $this->callAPISuccess('contact', 'getcount', [ 'contact_type' => 'Individual', 'contact_is_deleted' => 1, - )); - $countNotDeleted = $this->callAPISuccess('contact', 'getcount', array( + ]); + $countNotDeleted = $this->callAPISuccess('contact', 'getcount', [ 'contact_is_deleted' => 0, 'contact_type' => 'Individual', - )); - $this->callAPISuccess('contact', 'delete', array('id' => $contact1['id'])); - $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); + ]); + $this->callAPISuccess('contact', 'delete', ['id' => $contact1['id']]); + $this->callAPISuccess('contact', 'delete', ['id' => $contact2['id']]); $this->assertEquals(1, $countNotDeleted, 'contact_is_deleted => 0 is respected'); $this->assertEquals(1, $countActive); $this->assertEquals(1, $countTrash); @@ -976,39 +1005,41 @@ public function testGetDeleted() { /** * Test that sort works - new syntax. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetSortNewSyntax($version) { $this->_apiversion = $version; $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $c2 = $this->callAPISuccess($this->_entity, 'create', array( + $c2 = $this->callAPISuccess($this->_entity, 'create', [ 'first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual', - )); - $result = $this->callAPISuccess($this->_entity, 'getvalue', array( + ]); + $result = $this->callAPISuccess($this->_entity, 'getvalue', [ 'return' => 'first_name', 'contact_type' => 'Individual', - 'options' => array( + 'options' => [ 'limit' => 1, 'sort' => 'first_name', - ), - )); + ], + ]); $this->assertEquals('abc1', $result); - $result = $this->callAPISuccess($this->_entity, 'getvalue', array( + $result = $this->callAPISuccess($this->_entity, 'getvalue', [ 'return' => 'first_name', 'contact_type' => 'Individual', - 'options' => array( + 'options' => [ 'limit' => 1, 'sort' => 'first_name DESC', - ), - )); + ], + ]); $this->assertEquals('bb', $result); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $c1['id'])); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $c2['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $c1['id']]); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $c2['id']]); } /** @@ -1016,24 +1047,25 @@ public function testGetSortNewSyntax($version) { * * https://issues.civicrm.org/jira/browse/CRM-15983 * @param int $version + * * @dataProvider versionThreeAndFour */ public function testSortLimitChainedRelationshipGetCRM15983($version) { $this->_apiversion = $version; // Some contact - $create_result_1 = $this->callAPISuccess('contact', 'create', array( + $create_result_1 = $this->callAPISuccess('contact', 'create', [ 'first_name' => 'Jules', 'last_name' => 'Smos', 'contact_type' => 'Individual', - )); + ]); // Create another contact with two relationships. - $create_params = array( + $create_params = [ 'first_name' => 'Jos', 'last_name' => 'Smos', 'contact_type' => 'Individual', - 'api.relationship.create' => array( - array( + 'api.relationship.create' => [ + [ 'contact_id_a' => '$value.id', 'contact_id_b' => $create_result_1['id'], // spouse of: @@ -1041,8 +1073,8 @@ public function testSortLimitChainedRelationshipGetCRM15983($version) { 'start_date' => '2005-01-12', 'end_date' => '2006-01-11', 'description' => 'old', - ), - array( + ], + [ 'contact_id_a' => '$value.id', 'contact_id_b' => $create_result_1['id'], // spouse of (was married twice :)) @@ -1050,29 +1082,29 @@ public function testSortLimitChainedRelationshipGetCRM15983($version) { 'start_date' => '2006-07-01', 'end_date' => '2010-07-01', 'description' => 'new', - ), - ), - ); + ], + ], + ]; $create_result = $this->callAPISuccess('contact', 'create', $create_params); // Try to retrieve the contact and the most recent relationship. - $get_params = array( + $get_params = [ 'sequential' => 1, 'id' => $create_result['id'], - 'api.relationship.get' => array( + 'api.relationship.get' => [ 'contact_id_a' => '$value.id', - 'options' => array( + 'options' => [ 'limit' => '1', 'sort' => 'start_date DESC', - ), - ), - ); + ], + ], + ]; $get_result = $this->callAPISuccess('contact', 'getsingle', $get_params); // Clean up. - $this->callAPISuccess('contact', 'delete', array( + $this->callAPISuccess('contact', 'delete', [ 'id' => $create_result['id'], - )); + ]); // Assert. $this->assertEquals(1, $get_result['api.relationship.get']['count']); @@ -1081,17 +1113,19 @@ public function testSortLimitChainedRelationshipGetCRM15983($version) { /** * Test apostrophe works in get & create. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetApostropheCRM10857($version) { $this->_apiversion = $version; - $params = array_merge($this->_params, array('last_name' => "O'Connor")); + $params = array_merge($this->_params, ['last_name' => "O'Connor"]); $this->callAPISuccess($this->_entity, 'create', $params); - $result = $this->callAPISuccess($this->_entity, 'getsingle', array( + $result = $this->callAPISuccess($this->_entity, 'getsingle', [ 'last_name' => "O'Connor", 'sequential' => 1, - )); + ]); $this->assertEquals("O'Connor", $result['last_name']); } @@ -1099,7 +1133,9 @@ public function testGetApostropheCRM10857($version) { * Test between accepts zero. * * In the past it incorrectly required !empty. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetBetweenZeroWorks($version) { @@ -1161,10 +1197,10 @@ public function testGetWithCustom() { $subfile = "CustomFieldGet"; $result = $this->callAPISuccess($this->_entity, 'create', $params); - $check = $this->callAPIAndDocument($this->_entity, 'get', array( + $check = $this->callAPIAndDocument($this->_entity, 'get', [ 'return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id'], - ), __FUNCTION__, __FILE__, $description, $subfile); + ], __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]); $fields = ($this->callAPISuccess('contact', 'getfields', $params)); @@ -1202,7 +1238,7 @@ public function testGetWithCustomReturnSyntax() { $description = "This demonstrates setting a custom field through the API."; $subfile = "CustomFieldGetReturnSyntaxVariation"; $result = $this->callAPISuccess($this->_entity, 'create', $params); - $params = array('return' => 'custom_' . $ids['custom_field_id'], 'id' => $result['id']); + $params = ['return' => 'custom_' . $ids['custom_field_id'], 'id' => $result['id']]; $check = $this->callAPIAndDocument($this->_entity, 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]); @@ -1215,18 +1251,18 @@ public function testGetWithCustomReturnSyntax() { */ public function testGetReturnAddress() { $contactID = $this->individualCreate(); - $result = $this->callAPISuccess('address', 'create', array( + $result = $this->callAPISuccess('address', 'create', [ 'contact_id' => $contactID, 'address_name' => 'My house', 'location_type_id' => 'Home', 'street_address' => '1 my road', - )); + ]); $addressID = $result['id']; - $result = $this->callAPISuccessGetSingle('contact', array( + $result = $this->callAPISuccessGetSingle('contact', [ 'return' => 'address_name, street_address, address_id', 'id' => $contactID, - )); + ]); $this->assertEquals($addressID, $result['address_id']); $this->assertEquals('1 my road', $result['street_address']); $this->assertEquals('My house', $result['address_name']); @@ -1238,58 +1274,58 @@ public function testGetReturnAddress() { */ public function testGetGroupIDFromContact() { $groupId = $this->groupCreate(); - $params = array( + $params = [ 'email' => 'man2@yahoo.com', 'contact_type' => 'Individual', 'location_type_id' => 1, - 'api.group_contact.create' => array('group_id' => $groupId), - ); + 'api.group_contact.create' => ['group_id' => $groupId], + ]; $this->callAPISuccess('contact', 'create', $params); // testing as integer - $params = array( + $params = [ 'filter.group_id' => $groupId, 'contact_type' => 'Individual', - ); + ]; $result = $this->callAPISuccess('contact', 'get', $params); $this->assertEquals(1, $result['count']); // group 26 doesn't exist, but we can still search contacts in it. - $params = array( + $params = [ 'filter.group_id' => 26, 'contact_type' => 'Individual', - ); + ]; $this->callAPISuccess('contact', 'get', $params); // testing as string - $params = array( + $params = [ 'filter.group_id' => "$groupId, 26", 'contact_type' => 'Individual', - ); + ]; $result = $this->callAPISuccess('contact', 'get', $params); $this->assertEquals(1, $result['count']); - $params = array( + $params = [ 'filter.group_id' => "26,27", 'contact_type' => 'Individual', - ); + ]; $this->callAPISuccess('contact', 'get', $params); // testing as string - $params = array( - 'filter.group_id' => array($groupId, 26), + $params = [ + 'filter.group_id' => [$groupId, 26], 'contact_type' => 'Individual', - ); + ]; $result = $this->callAPISuccess('contact', 'get', $params); $this->assertEquals(1, $result['count']); //test in conjunction with other criteria - $params = array( - 'filter.group_id' => array($groupId, 26), + $params = [ + 'filter.group_id' => [$groupId, 26], 'contact_type' => 'Organization', - ); + ]; $this->callAPISuccess('contact', 'get', $params); - $params = array( - 'filter.group_id' => array(26, 27), + $params = [ + 'filter.group_id' => [26, 27], 'contact_type' => 'Individual', - ); + ]; $result = $this->callAPISuccess('contact', 'get', $params); $this->assertEquals(0, $result['count']); } @@ -1300,12 +1336,12 @@ public function testGetGroupIDFromContact() { public function testCreateIndividualWithContributionDottedSyntax() { $description = "This demonstrates the syntax to create 2 chained entities."; $subFile = "ChainTwoWebsites"; - $params = array( + $params = [ 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', 'email' => 'man3@yahoo.com', - 'api.contribution.create' => array( + 'api.contribution.create' => [ 'receive_date' => '2010-01-01', 'total_amount' => 100.00, 'financial_type_id' => $this->_financialTypeId, @@ -1318,14 +1354,14 @@ public function testCreateIndividualWithContributionDottedSyntax() { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipCleanMoney' => 1, - ), - 'api.website.create' => array( + ], + 'api.website.create' => [ 'url' => "http://civicrm.org", - ), - 'api.website.create.2' => array( + ], + 'api.website.create.2' => [ 'url' => "http://chained.org", - ), - ); + ], + ]; $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subFile); @@ -1342,12 +1378,12 @@ public function testCreateIndividualWithContributionDottedSyntax() { * Verify that attempt to create individual contact with chained contribution and website succeeds. */ public function testCreateIndividualWithContributionChainedArrays() { - $params = array( + $params = [ 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', 'email' => 'man3@yahoo.com', - 'api.contribution.create' => array( + 'api.contribution.create' => [ 'receive_date' => '2010-01-01', 'total_amount' => 100.00, 'financial_type_id' => $this->_financialTypeId, @@ -1360,17 +1396,17 @@ public function testCreateIndividualWithContributionChainedArrays() { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipCleanMoney' => 1, - ), - 'api.website.create' => array( - array( + ], + 'api.website.create' => [ + [ 'url' => "http://civicrm.org", - ), - array( + ], + [ 'url' => "http://chained.org", 'website_type_id' => 2, - ), - ), - ); + ], + ], + ]; $description = "Demonstrates creating two websites as an array."; $subfile = "ChainTwoWebsitesSyntax2"; @@ -1389,67 +1425,68 @@ public function testCreateIndividualWithContributionChainedArrays() { * * https://issues.civicrm.org/jira/browse/CRM-16084 * @param int $version + * * @dataProvider versionThreeAndFour */ public function testDirectionChainingRelationshipsCRM16084($version) { $this->_apiversion = $version; // Some contact, called Jules. - $create_result_1 = $this->callAPISuccess('contact', 'create', array( + $create_result_1 = $this->callAPISuccess('contact', 'create', [ 'first_name' => 'Jules', 'last_name' => 'Smos', 'contact_type' => 'Individual', - )); + ]); // Another contact: Jos, child of Jules. - $create_params = array( + $create_params = [ 'first_name' => 'Jos', 'last_name' => 'Smos', 'contact_type' => 'Individual', - 'api.relationship.create' => array( - array( + 'api.relationship.create' => [ + [ 'contact_id_a' => '$value.id', 'contact_id_b' => $create_result_1['id'], // child of 'relationship_type_id' => 1, - ), - ), - ); + ], + ], + ]; $create_result_2 = $this->callAPISuccess('contact', 'create', $create_params); // Mia is the child of Jos. - $create_params = array( + $create_params = [ 'first_name' => 'Mia', 'last_name' => 'Smos', 'contact_type' => 'Individual', - 'api.relationship.create' => array( - array( + 'api.relationship.create' => [ + [ 'contact_id_a' => '$value.id', 'contact_id_b' => $create_result_2['id'], // child of 'relationship_type_id' => 1, - ), - ), - ); + ], + ], + ]; $create_result_3 = $this->callAPISuccess('contact', 'create', $create_params); // Get Jos and his children. - $get_params = array( + $get_params = [ 'sequential' => 1, 'id' => $create_result_2['id'], - 'api.relationship.get' => array( + 'api.relationship.get' => [ 'contact_id_b' => '$value.id', 'relationship_type_id' => 1, - ), - ); + ], + ]; $get_result = $this->callAPISuccess('contact', 'getsingle', $get_params); // Clean up first. - $this->callAPISuccess('contact', 'delete', array( + $this->callAPISuccess('contact', 'delete', [ 'id' => $create_result_1['id'], - )); - $this->callAPISuccess('contact', 'delete', array( + ]); + $this->callAPISuccess('contact', 'delete', [ 'id' => $create_result_2['id'], - )); + ]); // Assert. $this->assertEquals(1, $get_result['api.relationship.get']['count']); @@ -1460,12 +1497,12 @@ public function testDirectionChainingRelationshipsCRM16084($version) { * Verify that attempt to create individual contact with first, and last names and email succeeds. */ public function testCreateIndividualWithNameEmail() { - $params = array( + $params = [ 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', 'email' => 'man3@yahoo.com', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); @@ -1476,9 +1513,9 @@ public function testCreateIndividualWithNameEmail() { * Verify that attempt to create individual contact with no data fails. */ public function testCreateIndividualWithOutNameEmail() { - $params = array( + $params = [ 'contact_type' => 'Individual', - ); + ]; $this->callAPIFailure('contact', 'create', $params); } @@ -1486,16 +1523,16 @@ public function testCreateIndividualWithOutNameEmail() { * Test create individual contact with first &last names, email and location type succeeds. */ public function testCreateIndividualWithNameEmailLocationType() { - $params = array( + $params = [ 'first_name' => 'abc4', 'last_name' => 'xyz4', 'email' => 'man4@yahoo.com', 'contact_type' => 'Individual', 'location_type_id' => 1, - ); + ]; $result = $this->callAPISuccess('contact', 'create', $params); - $this->callAPISuccess('contact', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('contact', 'delete', ['id' => $result['id']]); } /** @@ -1505,29 +1542,29 @@ public function testCreateIndividualWithEmployer() { $employer = $this->organizationCreate(); $employer2 = $this->organizationCreate(); - $params = array( + $params = [ 'email' => 'man4@yahoo.com', 'contact_type' => 'Individual', 'employer_id' => $employer, - ); + ]; $result = $this->callAPISuccess('contact', 'create', $params); - $relationships = $this->callAPISuccess('relationship', 'get', array( + $relationships = $this->callAPISuccess('relationship', 'get', [ 'contact_id_a' => $result['id'], 'sequential' => 1, - )); + ]); $this->assertEquals($employer, $relationships['values'][0]['contact_id_b']); // Add more random relationships to make the test more realistic - foreach (array('Employee of', 'Volunteer for') as $relationshipType) { + foreach (['Employee of', 'Volunteer for'] as $relationshipType) { $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $relationshipType, 'id', 'name_a_b'); - $this->callAPISuccess('relationship', 'create', array( + $this->callAPISuccess('relationship', 'create', [ 'contact_id_a' => $result['id'], 'contact_id_b' => $this->organizationCreate(), 'is_active' => 1, 'relationship_type_id' => $relTypeId, - )); + ]); } // Add second employer @@ -1535,11 +1572,11 @@ public function testCreateIndividualWithEmployer() { $params['id'] = $result['id']; $result = $this->callAPISuccess('contact', 'create', $params); - $relationships = $this->callAPISuccess('relationship', 'get', array( + $relationships = $this->callAPISuccess('relationship', 'get', [ 'contact_id_a' => $result['id'], 'sequential' => 1, 'is_active' => 0, - )); + ]); $this->assertEquals($employer, $relationships['values'][0]['contact_id_b']); } @@ -1548,12 +1585,12 @@ public function testCreateIndividualWithEmployer() { * Verify that attempt to create household contact with details succeeds. */ public function testCreateHouseholdDetails() { - $params = array( + $params = [ 'household_name' => 'abc8\'s House', 'nick_name' => 'x House', 'email' => 'man8@yahoo.com', 'contact_type' => 'Household', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); @@ -1564,11 +1601,11 @@ public function testCreateHouseholdDetails() { * Verify that attempt to create household contact with inadequate details fails. */ public function testCreateHouseholdInadequateDetails() { - $params = array( + $params = [ 'nick_name' => 'x House', 'email' => 'man8@yahoo.com', 'contact_type' => 'Household', - ); + ]; $this->callAPIFailure('contact', 'create', $params); } @@ -1631,44 +1668,44 @@ public function testUpdateOrganizationWithAll() { */ public function testMergeOrganizations() { $organizationID1 = $this->organizationCreate([], 0); - $organizationID2 = $this->organizationCreate(array(), 1); - $contact = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( + $organizationID2 = $this->organizationCreate([], 1); + $contact = $this->callAPISuccess('contact', 'create', array_merge($this->_params, [ 'employer_id' => $organizationID1, - ))); + ])); $contact = $contact["values"][$contact["id"]]; $membershipType = $this->createEmployerOfMembership(); - $membershipParams = array( + $membershipParams = [ 'membership_type_id' => $membershipType["id"], 'contact_id' => $organizationID1, 'start_date' => "01/01/2015", 'join_date' => "01/01/2010", 'end_date' => "12/31/2015", - ); + ]; $ownermembershipid = $this->contactMembershipCreate($membershipParams); - $contactmembership = $this->callAPISuccess("membership", "getsingle", array( + $contactmembership = $this->callAPISuccess("membership", "getsingle", [ "contact_id" => $contact["id"], - )); + ]); $this->assertEquals($ownermembershipid, $contactmembership["owner_membership_id"], "Contact membership must be inherited from Organization"); - CRM_Dedupe_Merger::moveAllBelongings($organizationID2, $organizationID1, array( - "move_rel_table_memberships" => "0", + CRM_Dedupe_Merger::moveAllBelongings($organizationID2, $organizationID1, [ + "move_rel_table_memberships" => "0", "move_rel_table_relationships" => "1", - "main_details" => array( - "contact_id" => $organizationID2, + "main_details" => [ + "contact_id" => $organizationID2, "contact_type" => "Organization", - ), - "other_details" => array( - "contact_id" => $organizationID1, + ], + "other_details" => [ + "contact_id" => $organizationID1, "contact_type" => "Organization", - ), - )); + ], + ]); - $contactmembership = $this->callAPISuccess("membership", "get", array( + $contactmembership = $this->callAPISuccess("membership", "get", [ "contact_id" => $contact["id"], - )); + ]); $this->assertEquals(0, $contactmembership["count"], "Contact membership must be deleted after merging organization without memberships."); } @@ -1736,7 +1773,7 @@ public function testMergeGetConflicts() { } private function createEmployerOfMembership() { - $params = array( + $params = [ 'domain_id' => CRM_Core_Config::domainID(), 'name' => 'Organization Membership', 'description' => NULL, @@ -1750,14 +1787,16 @@ private function createEmployerOfMembership() { 'relationship_direction' => 'b_a', 'visibility' => 'Public', 'is_active' => 1, - ); + ]; $membershipType = $this->callAPISuccess('membership_type', 'create', $params); return $membershipType["values"][$membershipType["id"]]; } /** * Verify successful update of household contact. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testUpdateHouseholdWithAll($version) { @@ -1765,7 +1804,7 @@ public function testUpdateHouseholdWithAll($version) { $contactID = $this->householdCreate(); $params = [ - 'id' => $contactID , + 'id' => $contactID, 'household_name' => 'ABC household', 'nick_name' => 'ABC House', 'contact_type' => 'Household', @@ -1789,7 +1828,9 @@ public function testUpdateHouseholdWithAll($version) { * Deliberately exclude contact_type as it should still cope using civicrm_api. * * CRM-7645. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testUpdateCreateWithID($version) { @@ -1804,55 +1845,63 @@ public function testUpdateCreateWithID($version) { /** * Test civicrm_contact_delete() with no contact ID. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactDeleteNoID($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'foo' => 'bar', - ); + ]; $this->callAPIFailure('contact', 'delete', $params); } /** * Test civicrm_contact_delete() with error. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactDeleteError($version) { $this->_apiversion = $version; - $params = array('contact_id' => 999); + $params = ['contact_id' => 999]; $this->callAPIFailure('contact', 'delete', $params); } /** * Test civicrm_contact_delete(). + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactDelete($version) { $this->_apiversion = $version; $contactID = $this->individualCreate(); - $params = array( + $params = [ 'id' => $contactID, - ); + ]; $this->callAPIAndDocument('contact', 'delete', $params, __FUNCTION__, __FILE__); } /** * Test civicrm_contact_get() return only first name. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetRetFirst($version) { $this->_apiversion = $version; $contact = $this->callAPISuccess('contact', 'create', $this->_params); - $params = array( + $params = [ 'contact_id' => $contact['id'], 'return_first_name' => TRUE, 'sort' => 'first_name', - ); + ]; $result = $this->callAPISuccess('contact', 'get', $params); $this->assertEquals(1, $result['count']); $this->assertEquals($contact['id'], $result['id']); @@ -1863,25 +1912,27 @@ public function testContactGetRetFirst($version) { * Test civicrm_contact_get() return only first name & last name. * * Use comma separated string return with a space. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetReturnFirstLast($version) { $this->_apiversion = $version; $contact = $this->callAPISuccess('contact', 'create', $this->_params); - $params = array( + $params = [ 'contact_id' => $contact['id'], 'return' => 'first_name, last_name', - ); + ]; $result = $this->callAPISuccess('contact', 'getsingle', $params); $this->assertEquals('abc1', $result['first_name']); $this->assertEquals('xyz1', $result['last_name']); //check that other defaults not returns $this->assertArrayNotHasKey('sort_name', $result); - $params = array( + $params = [ 'contact_id' => $contact['id'], 'return' => 'first_name,last_name', - ); + ]; $result = $this->callAPISuccess('contact', 'getsingle', $params); $this->assertEquals('abc1', $result['first_name']); $this->assertEquals('xyz1', $result['last_name']); @@ -1893,16 +1944,18 @@ public function testContactGetReturnFirstLast($version) { * Test civicrm_contact_get() return only first name & last name. * * Use comma separated string return without a space + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetReturnFirstLastNoComma($version) { $this->_apiversion = $version; $contact = $this->callAPISuccess('contact', 'create', $this->_params); - $params = array( + $params = [ 'contact_id' => $contact['id'], 'return' => 'first_name,last_name', - ); + ]; $result = $this->callAPISuccess('contact', 'getsingle', $params); $this->assertEquals('abc1', $result['first_name']); $this->assertEquals('xyz1', $result['last_name']); @@ -1915,10 +1968,10 @@ public function testContactGetReturnFirstLastNoComma($version) { */ public function testContactGetRetDefault() { $contactID = $this->individualCreate(); - $params = array( + $params = [ 'contact_id' => $contactID, 'sort' => 'first_name', - ); + ]; $result = $this->callAPISuccess('contact', 'get', $params); $this->assertEquals($contactID, $result['values'][$contactID]['contact_id']); $this->assertEquals('Anthony', $result['values'][$contactID]['first_name']); @@ -1942,7 +1995,9 @@ public function testContactGetQuick() { /** * Test civicrm_contact_get) with empty params. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetEmptyParams($version) { @@ -1952,7 +2007,9 @@ public function testContactGetEmptyParams($version) { /** * Test civicrm_contact_get(,true) with no matches. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetOldParamsNoMatches($version) { @@ -1977,17 +2034,17 @@ public function testContactGetOldParamsOneMatch() { * Test civicrm_contact_search_count(). */ public function testContactGetEmail() { - $params = array( + $params = [ 'email' => 'man2@yahoo.com', 'contact_type' => 'Individual', 'location_type_id' => 1, - ); + ]; $contact = $this->callAPISuccess('contact', 'create', $params); - $params = array( + $params = [ 'email' => 'man2@yahoo.com', - ); + ]; $result = $this->callAPIAndDocument('contact', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals('man2@yahoo.com', $result['values'][$result['id']]['email']); @@ -1996,27 +2053,29 @@ public function testContactGetEmail() { /** * Ensure consistent return format for option group fields. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testSetPreferredCommunicationNull($version) { $this->_apiversion = $version; - $contact = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( - 'preferred_communication_method' => array('Phone', 'SMS'), - ))); - $preferredCommunicationMethod = $this->callAPISuccessGetValue('Contact', array( + $contact = $this->callAPISuccess('contact', 'create', array_merge($this->_params, [ + 'preferred_communication_method' => ['Phone', 'SMS'], + ])); + $preferredCommunicationMethod = $this->callAPISuccessGetValue('Contact', [ 'id' => $contact['id'], 'return' => 'preferred_communication_method', - )); + ]); $this->assertNotEmpty($preferredCommunicationMethod); - $contact = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array( + $contact = $this->callAPISuccess('contact', 'create', array_merge($this->_params, [ 'preferred_communication_method' => 'null', 'id' => $contact['id'], - ))); - $preferredCommunicationMethod = $this->callAPISuccessGetValue('Contact', array( + ])); + $preferredCommunicationMethod = $this->callAPISuccessGetValue('Contact', [ 'id' => $contact['id'], 'return' => 'preferred_communication_method', - )); + ]); $this->assertEmpty($preferredCommunicationMethod); } @@ -2024,18 +2083,18 @@ public function testSetPreferredCommunicationNull($version) { * Ensure consistent return format for option group fields. */ public function testPseudoFields() { - $params = array( - 'preferred_communication_method' => array('Phone', 'SMS'), + $params = [ + 'preferred_communication_method' => ['Phone', 'SMS'], 'preferred_language' => 'en_US', 'gender_id' => 'Female', 'prefix_id' => 'Mrs.', 'suffix_id' => 'II', 'communication_style_id' => 'Formal', - ); + ]; $contact = $this->callAPISuccess('contact', 'create', array_merge($this->_params, $params)); - $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contact['id'])); + $result = $this->callAPISuccess('contact', 'getsingle', ['id' => $contact['id']]); $this->assertEquals('Both', $result['preferred_mail_format']); $this->assertEquals('en_US', $result['preferred_language']); @@ -2047,10 +2106,10 @@ public function testPseudoFields() { $this->assertEquals('II', $result['individual_suffix']); $this->assertEquals(CRM_Core_PseudoConstant::getKey("CRM_Contact_BAO_Contact", 'suffix_id', 'II'), $result['suffix_id']); $this->callAPISuccess('contact', 'delete', $contact); - $this->assertEquals(array( + $this->assertEquals([ CRM_Core_PseudoConstant::getKey("CRM_Contact_BAO_Contact", 'preferred_communication_method', 'Phone'), CRM_Core_PseudoConstant::getKey("CRM_Contact_BAO_Contact", 'preferred_communication_method', 'SMS'), - ), $result['preferred_communication_method']); + ], $result['preferred_communication_method']); } /** @@ -2060,28 +2119,28 @@ public function testPseudoFields() { * && deceased. */ public function testContactGetBirthDate() { - $contact1 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array('birth_date' => 'first day of next month - 2 years'))); - $contact2 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array('birth_date' => 'first day of next month - 5 years'))); - $contact3 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array('birth_date' => 'first day of next month -20 years'))); + $contact1 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, ['birth_date' => 'first day of next month - 2 years'])); + $contact2 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, ['birth_date' => 'first day of next month - 5 years'])); + $contact3 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, ['birth_date' => 'first day of next month -20 years'])); - $result = $this->callAPISuccess('contact', 'get', array()); + $result = $this->callAPISuccess('contact', 'get', []); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -2 years')), $result['values'][$contact1['id']]['birth_date']); - $result = $this->callAPISuccess('contact', 'get', array('birth_date' => 'first day of next month -5 years')); + $result = $this->callAPISuccess('contact', 'get', ['birth_date' => 'first day of next month -5 years']); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']); - $result = $this->callAPISuccess('contact', 'get', array('birth_date_high' => date('Y-m-d', strtotime('-6 years')))); + $result = $this->callAPISuccess('contact', 'get', ['birth_date_high' => date('Y-m-d', strtotime('-6 years'))]); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -20 years')), $result['values'][$contact3['id']]['birth_date']); - $result = $this->callAPISuccess('contact', 'get', array( + $result = $this->callAPISuccess('contact', 'get', [ 'birth_date_low' => date('Y-m-d', strtotime('-6 years')), 'birth_date_high' => date('Y-m-d', strtotime('- 3 years')), - )); + ]); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']); - $result = $this->callAPISuccess('contact', 'get', array( + $result = $this->callAPISuccess('contact', 'get', [ 'birth_date_low' => '-6 years', 'birth_date_high' => '- 3 years', - )); + ]); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']); } @@ -2092,45 +2151,45 @@ public function testContactGetBirthDate() { * This include state_province, state_province_name, country */ public function testContactGetWithAddressFields() { - $individuals = array( - array( + $individuals = [ + [ 'first_name' => 'abc1', 'contact_type' => 'Individual', 'last_name' => 'xyz1', - 'api.address.create' => array( + 'api.address.create' => [ 'country' => 'United States', 'state_province_id' => 'Michigan', 'location_type_id' => 1, - ), - ), - array( + ], + ], + [ 'first_name' => 'abc2', 'contact_type' => 'Individual', 'last_name' => 'xyz2', - 'api.address.create' => array( + 'api.address.create' => [ 'country' => 'United States', 'state_province_id' => 'Alabama', 'location_type_id' => 1, - ), - ), - ); + ], + ], + ]; foreach ($individuals as $params) { $contact = $this->callAPISuccess('contact', 'create', $params); } // Check whether Contact get API return successfully with below Address params. - $fieldsToTest = array( + $fieldsToTest = [ 'state_province_name' => 'Michigan', 'state_province' => 'Michigan', 'country' => 'United States', - 'state_province_name' => array('IN' => array('Michigan', 'Alabama')), - 'state_province' => array('IN' => array('Michigan', 'Alabama')), - ); + 'state_province_name' => ['IN' => ['Michigan', 'Alabama']], + 'state_province' => ['IN' => ['Michigan', 'Alabama']], + ]; foreach ($fieldsToTest as $field => $value) { - $getParams = array( + $getParams = [ 'id' => $contact['id'], $field => $value, - ); + ]; $result = $this->callAPISuccess('Contact', 'get', $getParams); $this->assertEquals(1, $result['count']); } @@ -2143,22 +2202,22 @@ public function testContactGetWithAddressFields() { * && deceased. */ public function testContactGetDeceasedDate() { - $contact1 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array('deceased_date' => 'first day of next month - 2 years'))); - $contact2 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array('deceased_date' => 'first day of next month - 5 years'))); - $contact3 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array('deceased_date' => 'first day of next month -20 years'))); + $contact1 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, ['deceased_date' => 'first day of next month - 2 years'])); + $contact2 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, ['deceased_date' => 'first day of next month - 5 years'])); + $contact3 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, ['deceased_date' => 'first day of next month -20 years'])); - $result = $this->callAPISuccess('contact', 'get', array()); + $result = $this->callAPISuccess('contact', 'get', []); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -2 years')), $result['values'][$contact1['id']]['deceased_date']); - $result = $this->callAPISuccess('contact', 'get', array('deceased_date' => 'first day of next month -5 years')); + $result = $this->callAPISuccess('contact', 'get', ['deceased_date' => 'first day of next month -5 years']); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['deceased_date']); - $result = $this->callAPISuccess('contact', 'get', array('deceased_date_high' => date('Y-m-d', strtotime('-6 years')))); + $result = $this->callAPISuccess('contact', 'get', ['deceased_date_high' => date('Y-m-d', strtotime('-6 years'))]); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -20 years')), $result['values'][$contact3['id']]['deceased_date']); - $result = $this->callAPISuccess('contact', 'get', array( + $result = $this->callAPISuccess('contact', 'get', [ 'deceased_date_low' => '-6 years', 'deceased_date_high' => date('Y-m-d', strtotime('- 3 years')), - )); + ]); $this->assertEquals(1, $result['count']); $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['deceased_date']); } @@ -2168,24 +2227,24 @@ public function testContactGetDeceasedDate() { */ public function testContactGetByUsername() { // Setup - create contact with a uf-match. - $cid = $this->individualCreate(array( + $cid = $this->individualCreate([ 'contact_type' => 'Individual', 'first_name' => 'testGetByUsername', 'last_name' => 'testGetByUsername', - )); + ]); - $ufMatchParams = array( + $ufMatchParams = [ 'domain_id' => CRM_Core_Config::domainID(), 'uf_id' => 99, 'uf_name' => 'the-email-matching-key-is-not-really-the-username', 'contact_id' => $cid, - ); + ]; $ufMatch = CRM_Core_BAO_UFMatch::create($ufMatchParams); $this->assertTrue(is_numeric($ufMatch->id)); // setup - mock the calls to CRM_Utils_System_*::getUfId $mockFunction = $this->mockMethod; - $userSystem = $this->$mockFunction('CRM_Utils_System_UnitTests', array('getUfId')); + $userSystem = $this->$mockFunction('CRM_Utils_System_UnitTests', ['getUfId']); $userSystem->expects($this->once()) ->method('getUfId') ->with($this->equalTo('exampleUser')) @@ -2193,9 +2252,9 @@ public function testContactGetByUsername() { CRM_Core_Config::singleton()->userSystem = $userSystem; // perform a lookup - $result = $this->callAPISuccess('Contact', 'get', array( + $result = $this->callAPISuccess('Contact', 'get', [ 'id' => '@user:exampleUser', - )); + ]); $this->assertEquals('testGetByUsername', $result['values'][$cid]['first_name']); // Check search of contacts with & without uf records @@ -2210,23 +2269,23 @@ public function testContactGetByUsername() { * Test to check return works OK. */ public function testContactGetReturnValues() { - $extraParams = array( + $extraParams = [ 'nick_name' => 'Bob', 'phone' => '456', 'email' => 'e@mail.com', - ); + ]; $contactID = $this->individualCreate($extraParams); //actually it turns out the above doesn't create a phone - $this->callAPISuccess('phone', 'create', array('contact_id' => $contactID, 'phone' => '456')); - $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contactID)); + $this->callAPISuccess('phone', 'create', ['contact_id' => $contactID, 'phone' => '456']); + $result = $this->callAPISuccess('contact', 'getsingle', ['id' => $contactID]); foreach ($extraParams as $key => $value) { $this->assertEquals($result[$key], $value); } //now we check they are still returned with 'return' key - $result = $this->callAPISuccess('contact', 'getsingle', array( + $result = $this->callAPISuccess('contact', 'getsingle', [ 'id' => $contactID, 'return' => array_keys($extraParams), - )); + ]); foreach ($extraParams as $key => $value) { $this->assertEquals($result[$key], $value); } @@ -2235,33 +2294,34 @@ public function testContactGetReturnValues() { /** * Test creating multiple phones using chaining. * - * @throws \Exception * @param int $version + * * @dataProvider versionThreeAndFour + * @throws \Exception */ public function testCRM13252MultipleChainedPhones($version) { $this->_apiversion = $version; $contactID = $this->householdCreate(); - $this->callAPISuccessGetCount('phone', array('contact_id' => $contactID), 0); - $params = array( + $this->callAPISuccessGetCount('phone', ['contact_id' => $contactID], 0); + $params = [ 'contact_id' => $contactID, 'household_name' => 'Household 1', 'contact_type' => 'Household', - 'api.phone.create' => array( - 0 => array( + 'api.phone.create' => [ + 0 => [ 'phone' => '111-111-1111', 'location_type_id' => 1, 'phone_type_id' => 1, - ), - 1 => array( + ], + 1 => [ 'phone' => '222-222-2222', 'location_type_id' => 1, 'phone_type_id' => 2, - ), - ), - ); + ], + ], + ]; $this->callAPISuccess('contact', 'create', $params); - $this->callAPISuccessGetCount('phone', array('contact_id' => $contactID), 2); + $this->callAPISuccessGetCount('phone', ['contact_id' => $contactID], 2); } @@ -2271,7 +2331,7 @@ public function testCRM13252MultipleChainedPhones($version) { public function testContactGetByUnknownUsername() { // setup - mock the calls to CRM_Utils_System_*::getUfId $mockFunction = $this->mockMethod; - $userSystem = $this->$mockFunction('CRM_Utils_System_UnitTests', array('getUfId')); + $userSystem = $this->$mockFunction('CRM_Utils_System_UnitTests', ['getUfId']); $userSystem->expects($this->once()) ->method('getUfId') ->with($this->equalTo('exampleUser')) @@ -2279,15 +2339,17 @@ public function testContactGetByUnknownUsername() { CRM_Core_Config::singleton()->userSystem = $userSystem; // perform a lookup - $result = $this->callAPIFailure('Contact', 'get', array( + $result = $this->callAPIFailure('Contact', 'get', [ 'id' => '@user:exampleUser', - )); + ]); $this->assertRegExp('/cannot be resolved to a contact ID/', $result['error_message']); } /** * Verify attempt to create individual with chained arrays and sequential. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetIndividualWithChainedArraysAndSequential($version) { @@ -2296,26 +2358,26 @@ public function testGetIndividualWithChainedArraysAndSequential($version) { $params['custom_' . $ids['custom_field_id']] = "custom string"; $moreIDs = $this->CustomGroupMultipleCreateWithFields(); - $params = array( + $params = [ 'sequential' => 1, 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', 'email' => 'man3@yahoo.com', - 'api.website.create' => array( - array( + 'api.website.create' => [ + [ 'url' => "http://civicrm.org", - ), - array( + ], + [ 'url' => "https://civicrm.org", - ), - ), - ); + ], + ], + ]; $result = $this->callAPISuccess('Contact', 'create', $params); // delete the contact and custom groups - $this->callAPISuccess('contact', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('contact', 'delete', ['id' => $result['id']]); $this->customGroupDelete($ids['custom_group_id']); $this->customGroupDelete($moreIDs['custom_group_id']); @@ -2333,12 +2395,12 @@ public function testGetIndividualWithChainedArrays() { $moreIDs = $this->CustomGroupMultipleCreateWithFields(); $description = "This demonstrates the usage of chained api functions.\nIn this case no notes or custom fields have been created."; $subfile = "APIChainedArray"; - $params = array( + $params = [ 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', 'email' => 'man3@yahoo.com', - 'api.contribution.create' => array( + 'api.contribution.create' => [ 'receive_date' => '2010-01-01', 'total_amount' => 100.00, 'financial_type_id' => 1, @@ -2350,8 +2412,8 @@ public function testGetIndividualWithChainedArrays() { 'invoice_id' => 67890, 'source' => 'SSF', 'contribution_status_id' => 1, - ), - 'api.contribution.create.1' => array( + ], + 'api.contribution.create.1' => [ 'receive_date' => '2011-01-01', 'total_amount' => 120.00, 'financial_type_id' => $this->_financialTypeId = 1, @@ -2363,24 +2425,24 @@ public function testGetIndividualWithChainedArrays() { 'invoice_id' => 67830, 'source' => 'SSF', 'contribution_status_id' => 1, - ), - 'api.website.create' => array( - array( + ], + 'api.website.create' => [ + [ 'url' => "http://civicrm.org", - ), - ), - ); + ], + ], + ]; $result = $this->callAPISuccess('Contact', 'create', $params); - $params = array( + $params = [ 'id' => $result['id'], - 'api.website.get' => array(), - 'api.Contribution.get' => array( + 'api.website.get' => [], + 'api.Contribution.get' => [ 'total_amount' => '120.00', - ), + ], 'api.CustomValue.get' => 1, 'api.Note.get' => 1, - ); + ]; $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); // delete the contact $this->callAPISuccess('contact', 'delete', $result); @@ -2394,37 +2456,39 @@ public function testGetIndividualWithChainedArrays() { * Verify attempt to create individual with chained arrays and sequential. * * @see https://issues.civicrm.org/jira/browse/CRM-15815 + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateIndividualWithChainedArrayAndSequential($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'sequential' => 1, 'first_name' => 'abc5', 'last_name' => 'xyz5', 'contact_type' => 'Individual', 'email' => 'woman5@yahoo.com', - 'api.phone.create' => array( - array('phone' => '03-231 07 95'), - array('phone' => '03-232 51 62'), - ), - 'api.website.create' => array( + 'api.phone.create' => [ + ['phone' => '03-231 07 95'], + ['phone' => '03-232 51 62'], + ], + 'api.website.create' => [ 'url' => 'http://civicrm.org', - ), - ); + ], + ]; $result = $this->callAPISuccess('Contact', 'create', $params); // I could try to parse the result to see whether the two phone numbers // and the website are there, but I am not sure about the correct format. // So I will just fetch it again before checking. // See also http://forum.civicrm.org/index.php/topic,35393.0.html - $params = array( + $params = [ 'sequential' => 1, 'id' => $result['id'], - 'api.website.get' => array(), - 'api.phone.get' => array(), - ); + 'api.website.get' => [], + 'api.phone.get' => [], + ]; $result = $this->callAPISuccess('Contact', 'get', $params); // delete the contact @@ -2444,12 +2508,12 @@ public function testGetIndividualWithChainedArraysFormats() { $params['custom_' . $ids['custom_field_id']] = "custom string"; $moreIDs = $this->CustomGroupMultipleCreateWithFields(); - $params = array( + $params = [ 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', 'email' => 'man3@yahoo.com', - 'api.contribution.create' => array( + 'api.contribution.create' => [ 'receive_date' => '2010-01-01', 'total_amount' => 100.00, 'financial_type_id' => $this->_financialTypeId, @@ -2460,8 +2524,8 @@ public function testGetIndividualWithChainedArraysFormats() { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipCleanMoney' => 1, - ), - 'api.contribution.create.1' => array( + ], + 'api.contribution.create.1' => [ 'receive_date' => '2011-01-01', 'total_amount' => 120.00, 'financial_type_id' => $this->_financialTypeId, @@ -2472,23 +2536,23 @@ public function testGetIndividualWithChainedArraysFormats() { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipCleanMoney' => 1, - ), - 'api.website.create' => array( - array( + ], + 'api.website.create' => [ + [ 'url' => "http://civicrm.org", - ), - ), - ); + ], + ], + ]; $result = $this->callAPISuccess('Contact', 'create', $params); - $params = array( + $params = [ 'id' => $result['id'], - 'api.website.getValue' => array('return' => 'url'), - 'api.Contribution.getCount' => array(), + 'api.website.getValue' => ['return' => 'url'], + 'api.Contribution.getCount' => [], 'api.CustomValue.get' => 1, 'api.Note.get' => 1, - 'api.Membership.getCount' => array(), - ); + 'api.Membership.getCount' => [], + ]; $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(2, $result['values'][$result['id']]['api.Contribution.getCount']); $this->assertEquals(0, $result['values'][$result['id']]['api.Note.get']['is_error']); @@ -2506,18 +2570,18 @@ public function testGetIndividualWithChainedArraysAndMultipleCustom() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $params['custom_' . $ids['custom_field_id']] = "custom string"; $moreIDs = $this->CustomGroupMultipleCreateWithFields(); - $andMoreIDs = $this->CustomGroupMultipleCreateWithFields(array( + $andMoreIDs = $this->CustomGroupMultipleCreateWithFields([ 'title' => "another group", 'name' => 'another name', - )); + ]); $description = "This demonstrates the usage of chained api functions with multiple custom fields."; $subfile = "APIChainedArrayMultipleCustom"; - $params = array( + $params = [ 'first_name' => 'abc3', 'last_name' => 'xyz3', 'contact_type' => 'Individual', 'email' => 'man3@yahoo.com', - 'api.contribution.create' => array( + 'api.contribution.create' => [ 'receive_date' => '2010-01-01', 'total_amount' => 100.00, 'financial_type_id' => 1, @@ -2530,8 +2594,8 @@ public function testGetIndividualWithChainedArraysAndMultipleCustom() { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipCleanMoney' => 1, - ), - 'api.contribution.create.1' => array( + ], + 'api.contribution.create.1' => [ 'receive_date' => '2011-01-01', 'total_amount' => 120.00, 'financial_type_id' => 1, @@ -2544,34 +2608,34 @@ public function testGetIndividualWithChainedArraysAndMultipleCustom() { 'source' => 'SSF', 'contribution_status_id' => 1, 'skipCleanMoney' => 1, - ), - 'api.website.create' => array( - array( + ], + 'api.website.create' => [ + [ 'url' => "http://civicrm.org", - ), - ), + ], + ], 'custom_' . $ids['custom_field_id'] => "value 1", 'custom_' . $moreIDs['custom_field_id'][0] => "value 2", 'custom_' . $moreIDs['custom_field_id'][1] => "warm beer", 'custom_' . $andMoreIDs['custom_field_id'][1] => "vegemite", - ); + ]; $result = $this->callAPISuccess('Contact', 'create', $params); - $result = $this->callAPISuccess('Contact', 'create', array( + $result = $this->callAPISuccess('Contact', 'create', [ 'contact_type' => 'Individual', 'id' => $result['id'], 'custom_' . $moreIDs['custom_field_id'][0] => "value 3", 'custom_' . $ids['custom_field_id'] => "value 4", - )); + ]); - $params = array( + $params = [ 'id' => $result['id'], - 'api.website.getValue' => array('return' => 'url'), - 'api.Contribution.getCount' => array(), + 'api.website.getValue' => ['return' => 'url'], + 'api.Contribution.getCount' => [], 'api.CustomValue.get' => 1, - ); + ]; $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->customGroupDelete($ids['custom_group_id']); @@ -2590,31 +2654,33 @@ public function testChainingValuesCreate() { $description = "This demonstrates the usage of chained api functions. Specifically it has one 'parent function' & 2 child functions - one receives values from the parent (Contact) and the other child (Tag)."; $subfile = "APIChainedArrayValuesFromSiblingFunction"; - $params = array( + $params = [ 'display_name' => 'batman', 'contact_type' => 'Individual', - 'api.tag.create' => array( + 'api.tag.create' => [ 'name' => '$value.id', 'description' => '$value.display_name', 'format.only_id' => 1, - ), - 'api.entity_tag.create' => array('tag_id' => '$value.api.tag.create'), - ); + ], + 'api.entity_tag.create' => ['tag_id' => '$value.api.tag.create'], + ]; $result = $this->callAPIAndDocument('Contact', 'Create', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(0, $result['values'][$result['id']]['api.entity_tag.create']['is_error']); - $tablesToTruncate = array( + $tablesToTruncate = [ 'civicrm_contact', 'civicrm_activity', 'civicrm_entity_tag', 'civicrm_tag', - ); + ]; $this->quickCleanup($tablesToTruncate, TRUE); } /** * Test TrueFalse format - I couldn't come up with an easy way to get an error on Get. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetFormatIsSuccessTrue($version) { @@ -2631,7 +2697,9 @@ public function testContactGetFormatIsSuccessTrue($version) { /** * Test TrueFalse format. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactCreateFormatIsSuccessFalse($version) { @@ -2640,7 +2708,7 @@ public function testContactCreateFormatIsSuccessFalse($version) { $description = "This demonstrates use of the 'format.is_success' param. This param causes only the success or otherwise of the function to be returned as BOOLEAN"; $subfile = "FormatIsSuccess_Fail"; - $params = array('id' => 500, 'format.is_success' => 1); + $params = ['id' => 500, 'format.is_success' => 1]; $result = $this->callAPIAndDocument('Contact', 'Create', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(0, $result); } @@ -2649,16 +2717,18 @@ public function testContactCreateFormatIsSuccessFalse($version) { * Test long display names. * * CRM-21258 + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactCreateLongDisplayName($version) { $this->_apiversion = $version; - $result = $this->callAPISuccess('Contact', 'Create', array( + $result = $this->callAPISuccess('Contact', 'Create', [ 'first_name' => str_pad('a', 64, 'a'), 'last_name' => str_pad('a', 64, 'a'), 'contact_type' => 'Individual', - )); + ]); $this->assertEquals('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', $result['values'][$result['id']]['display_name']); $this->assertEquals('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', $result['values'][$result['id']]['sort_name']); } @@ -2667,7 +2737,9 @@ public function testContactCreateLongDisplayName($version) { * Test that we can set the sort name via the api or alter it via a hook. * * As of writing this is being fixed for Organization & Household but it makes sense to do for individuals too. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateAlterSortName($version) { @@ -2676,7 +2748,7 @@ public function testCreateAlterSortName($version) { $organization = $this->callAPISuccessGetSingle('Contact', ['return' => ['sort_name', 'display_name'], 'id' => $organizationID]); $this->assertEquals('Justice League, The', $organization['sort_name']); $this->assertEquals('The Justice League', $organization['display_name']); - $this->hookClass->setHook('civicrm_pre', array($this, 'killTheJusticeLeague')); + $this->hookClass->setHook('civicrm_pre', [$this, 'killTheJusticeLeague']); $this->organizationCreate(['id' => $organizationID, 'sort_name' => 'Justice League, The']); $organization = $this->callAPISuccessGetSingle('Contact', ['return' => ['sort_name', 'display_name', 'is_deceased'], 'id' => $organizationID]); $this->assertEquals('Steppenwolf wuz here', $organization['display_name']); @@ -2700,7 +2772,9 @@ public function killTheJusticeLeague($op, $entity, $id, &$params) { /** * Test Single Entity format. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetSingleEntityArray($version) { @@ -2717,7 +2791,9 @@ public function testContactGetSingleEntityArray($version) { /** * Test Single Entity format. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetFormatCountOnly($version) { @@ -2734,7 +2810,9 @@ public function testContactGetFormatCountOnly($version) { /** * Test id only format. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetFormatIDOnly($version) { @@ -2752,7 +2830,9 @@ public function testContactGetFormatIDOnly($version) { /** * Test id only format. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactGetFormatSingleValue($version) { @@ -2770,23 +2850,25 @@ public function testContactGetFormatSingleValue($version) { /** * Test that permissions are respected when creating contacts. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactCreationPermissions($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_type' => 'Individual', 'first_name' => 'Foo', 'last_name' => 'Bear', 'check_permissions' => TRUE, - ); + ]; $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array('access CiviCRM'); + $config->userPermissionClass->permissions = ['access CiviCRM']; $result = $this->callAPIFailure('contact', 'create', $params); $this->assertContains('failed', $result['error_message'], 'lacking permissions should not be enough to create a contact'); - $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts'); + $config->userPermissionClass->permissions = ['access CiviCRM', 'add contacts', 'import contacts']; $this->callAPISuccess('contact', 'create', $params); } @@ -2796,52 +2878,54 @@ public function testContactCreationPermissions($version) { */ public function testContactDeletePermissions() { $contactID = $this->individualCreate(); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); - $this->callAPIFailure('Contact', 'delete', array( + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; + $this->callAPIFailure('Contact', 'delete', [ 'id' => $contactID, 'check_permissions' => 1, 'skip_undelete' => 1, - )); - $this->callAPISuccess('Contact', 'delete', array( + ]); + $this->callAPISuccess('Contact', 'delete', [ 'id' => $contactID, 'check_permissions' => 0, 'skip_undelete' => 1, - )); + ]); } /** * Test update with check permissions set. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testContactUpdatePermissions($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_type' => 'Individual', 'first_name' => 'Foo', 'last_name' => 'Bear', 'check_permissions' => TRUE, - ); + ]; $result = $this->callAPISuccess('contact', 'create', $params); $config = CRM_Core_Config::singleton(); - $params = array( + $params = [ 'id' => $result['id'], 'contact_type' => 'Individual', 'last_name' => 'Bar', 'check_permissions' => TRUE, - ); + ]; - $config->userPermissionClass->permissions = array('access CiviCRM'); + $config->userPermissionClass->permissions = ['access CiviCRM']; $result = $this->callAPIFailure('contact', 'update', $params); $this->assertEquals('Permission denied to modify contact record', $result['error_message']); - $config->userPermissionClass->permissions = array( + $config->userPermissionClass->permissions = [ 'access CiviCRM', 'add contacts', 'view all contacts', 'edit all contacts', 'import contacts', - ); + ]; $this->callAPISuccess('contact', 'update', $params); } @@ -2854,7 +2938,7 @@ public function testContactProximity() { $contactID = $this->organizationCreate(); // now create the address - $params = array( + $params = [ 'street_address' => '123 Main Street', 'city' => 'San Francisco', 'is_primary' => 1, @@ -2864,19 +2948,19 @@ public function testContactProximity() { 'geo_code_2' => '-122.40', 'location_type_id' => 1, 'contact_id' => $contactID, - ); + ]; $result = $this->callAPISuccess('address', 'create', $params); $this->assertEquals(1, $result['count']); // now do a proximity search with a close enough geocode and hope to match // that specific contact only! - $proxParams = array( + $proxParams = [ 'latitude' => 37.7, 'longitude' => -122.3, 'unit' => 'mile', 'distance' => 10, - ); + ]; $result = $this->callAPISuccess('contact', 'proximity', $proxParams); $this->assertEquals(1, $result['count']); } @@ -2887,12 +2971,12 @@ public function testContactProximity() { * (note that getquick api is required for autocomplete & has ACL permissions applied) */ public function testGetquickPermissionCRM13744() { - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviEvent'); - $this->callAPIFailure('contact', 'getquick', array('name' => 'b', 'check_permissions' => TRUE)); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); - $this->callAPISuccess('contact', 'getquick', array('name' => 'b', 'check_permissions' => TRUE)); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access AJAX API'); - $this->callAPISuccess('contact', 'getquick', array('name' => 'b', 'check_permissions' => TRUE)); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviEvent']; + $this->callAPIFailure('contact', 'getquick', ['name' => 'b', 'check_permissions' => TRUE]); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; + $this->callAPISuccess('contact', 'getquick', ['name' => 'b', 'check_permissions' => TRUE]); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access AJAX API']; + $this->callAPISuccess('contact', 'getquick', ['name' => 'b', 'check_permissions' => TRUE]); } /** @@ -2909,7 +2993,7 @@ public function testGetQuickExactFirst($searchParameters, $settings, $firstConta $result = $this->callAPISuccess('contact', 'getquick', $searchParameters); $this->assertEquals($firstContact, $result['values'][0]['sort_name']); $this->assertEquals($secondContact, $result['values'][1]['sort_name']); - $this->callAPISuccess('Setting', 'create', array('includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE)); + $this->callAPISuccess('Setting', 'create', ['includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE]); } public function getSearchSortOptions() { @@ -2917,38 +3001,38 @@ public function getSearchSortOptions() { $secondAlphabeticalContactBySortName = 'Aadvark, Bob'; $secondAlphabeticalContactWithEmailBySortName = 'Bob, Bob'; $firstAlphabeticalContactFirstNameBob = 'Aadvark, Bob'; - $secondAlphabeticalContactFirstNameBob = 'Bob, Bob'; + $secondAlphabeticalContactFirstNameBob = 'Bob, Bob'; $firstByIDContactFirstNameBob = 'Bob, Bob'; - $secondByIDContactFirstNameBob = 'K Bobby, Bob'; + $secondByIDContactFirstNameBob = 'K Bobby, Bob'; $firstContactByID = 'Bob, Bob'; $secondContactByID = 'E Bobby, Bobby'; $bobLikeEmail = 'A Bobby, Bobby'; - return array( - 'empty_search_basic' => array( - 'search_parameters' => array('name' => '%'), - 'settings' => array('includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE), + return [ + 'empty_search_basic' => [ + 'search_parameters' => ['name' => '%'], + 'settings' => ['includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE], 'first_contact' => $firstAlphabeticalContactBySortName, 'second_contact' => $secondAlphabeticalContactBySortName, - ), - 'empty_search_basic_no_wildcard' => array( - 'search_parameters' => array('name' => '%'), - 'settings' => array('includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE), + ], + 'empty_search_basic_no_wildcard' => [ + 'search_parameters' => ['name' => '%'], + 'settings' => ['includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE], 'first_contact' => $firstAlphabeticalContactBySortName, 'second_contact' => $secondAlphabeticalContactBySortName, - ), - 'single_letter_search_basic' => array( - 'search_parameters' => array('name' => 'b'), - 'settings' => array('includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE), + ], + 'single_letter_search_basic' => [ + 'search_parameters' => ['name' => 'b'], + 'settings' => ['includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE], 'first_contact' => $firstAlphabeticalContactBySortName, 'second_contact' => $secondAlphabeticalContactBySortName, - ), - 'bob_search_basic' => array( - 'search_parameters' => array('name' => 'bob'), - 'settings' => array('includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE), + ], + 'bob_search_basic' => [ + 'search_parameters' => ['name' => 'bob'], + 'settings' => ['includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE], 'first_contact' => $firstAlphabeticalContactBySortName, 'second_contact' => $secondAlphabeticalContactBySortName, - ), + ], // This test has been disabled as is proving to be problematic to reproduce due to MySQL sorting issues between different versions // 'bob_search_no_orderby' => array( // 'search_parameters' => array('name' => 'bob'), @@ -2956,32 +3040,32 @@ public function getSearchSortOptions() { // 'first_contact' => $firstContactByID, // 'second_contact' => $secondContactByID, //), - 'bob_search_no_wildcard' => array( - 'search_parameters' => array('name' => 'bob'), - 'settings' => array('includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE), + 'bob_search_no_wildcard' => [ + 'search_parameters' => ['name' => 'bob'], + 'settings' => ['includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE], 'second_contact' => $bobLikeEmail, 'first_contact' => $secondAlphabeticalContactFirstNameBob, - ), + ], // This should be the same as just no wildcard as if we had an exactMatch while searching by // sort name it would rise to the top CRM-19547 - 'bob_search_no_wildcard_no_orderby' => array( - 'search_parameters' => array('name' => 'bob'), - 'settings' => array('includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE), + 'bob_search_no_wildcard_no_orderby' => [ + 'search_parameters' => ['name' => 'bob'], + 'settings' => ['includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE], 'second_contact' => $bobLikeEmail, 'first_contact' => $secondAlphabeticalContactFirstNameBob, - ), - 'first_name_search_basic' => array( - 'search_parameters' => array('name' => 'bob', 'field_name' => 'first_name'), - 'settings' => array('includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE), + ], + 'first_name_search_basic' => [ + 'search_parameters' => ['name' => 'bob', 'field_name' => 'first_name'], + 'settings' => ['includeWildCardInName' => TRUE, 'includeOrderByClause' => TRUE], 'first_contact' => $firstAlphabeticalContactFirstNameBob, 'second_contact' => $secondAlphabeticalContactFirstNameBob, - ), - 'first_name_search_no_wildcard' => array( - 'search_parameters' => array('name' => 'bob', 'field_name' => 'first_name'), - 'settings' => array('includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE), + ], + 'first_name_search_no_wildcard' => [ + 'search_parameters' => ['name' => 'bob', 'field_name' => 'first_name'], + 'settings' => ['includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE], 'first_contact' => $firstAlphabeticalContactFirstNameBob, 'second_contact' => $secondAlphabeticalContactFirstNameBob, - ), + ], // This test has been disabled as is proving to be problematic to reproduce due to MySQL sorting issues between different versions //'first_name_search_no_orderby' => array( // 'search_parameters' => array('name' => 'bob', 'field_name' => 'first_name'), @@ -2989,13 +3073,13 @@ public function getSearchSortOptions() { // 'first_contact' => $firstByIDContactFirstNameBob, // 'second_contact' => $secondByIDContactFirstNameBob, //), - 'email_search_basic' => array( - 'search_parameters' => array('name' => 'bob', 'field_name' => 'email', 'table_name' => 'eml'), - 'settings' => array('includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE), + 'email_search_basic' => [ + 'search_parameters' => ['name' => 'bob', 'field_name' => 'email', 'table_name' => 'eml'], + 'settings' => ['includeWildCardInName' => FALSE, 'includeOrderByClause' => TRUE], 'first_contact' => $firstAlphabeticalContactBySortName, 'second_contact' => $secondAlphabeticalContactWithEmailBySortName, - ), - ); + ], + ]; } /** @@ -3004,35 +3088,35 @@ public function getSearchSortOptions() { public function testGetQuickEmail() { $this->getQuickSearchSampleData(); $loggedInContactID = $this->createLoggedInUser(); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'c', - )); - $expectedData = array( + ]); + $expectedData = [ 'A Bobby, Bobby :: bob@bobby.com', 'Bob, Bob :: bob@bob.com', 'C Bobby, Bobby', 'H Bobby, Bobby :: bob@h.com', 'Second Domain', - $this->callAPISuccessGetValue('Contact', array('id' => $loggedInContactID, 'return' => 'last_name')) . ', Logged In :: anthony_anderson@civicrm.org', - ); + $this->callAPISuccessGetValue('Contact', ['id' => $loggedInContactID, 'return' => 'last_name']) . ', Logged In :: anthony_anderson@civicrm.org', + ]; $this->assertEquals(6, $result['count']); foreach ($expectedData as $index => $value) { $this->assertEquals($value, $result['values'][$index]['data']); } - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'h.', - )); - $expectedData = array( + ]); + $expectedData = [ 'H Bobby, Bobby :: bob@h.com', - ); + ]; foreach ($expectedData as $index => $value) { $this->assertEquals($value, $result['values'][$index]['data']); } - $this->callAPISuccess('Setting', 'create', array('includeWildCardInName' => FALSE)); - $result = $this->callAPISuccess('contact', 'getquick', array( + $this->callAPISuccess('Setting', 'create', ['includeWildCardInName' => FALSE]); + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'h.', - )); - $this->callAPISuccess('Setting', 'create', array('includeWildCardInName' => TRUE)); + ]); + $this->callAPISuccess('Setting', 'create', ['includeWildCardInName' => TRUE]); $this->assertEquals(0, $result['count']); } @@ -3042,27 +3126,27 @@ public function testGetQuickEmail() { public function testGetQuickEmailACL() { $this->getQuickSearchSampleData(); $loggedInContactID = $this->createLoggedInUser(); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); - $result = $this->callAPISuccess('contact', 'getquick', array( + CRM_Core_Config::singleton()->userPermissionClass->permissions = []; + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'c', - )); + ]); $this->assertEquals(0, $result['count']); - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereNoBobH')); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereNoBobH']); CRM_Contact_BAO_Contact_Permission::cache($loggedInContactID, CRM_Core_Permission::VIEW, TRUE); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'c', - )); + ]); // Without the acl it would be 6 like the previous email getquick test. $this->assertEquals(5, $result['count']); - $expectedData = array( + $expectedData = [ 'A Bobby, Bobby :: bob@bobby.com', 'Bob, Bob :: bob@bob.com', 'C Bobby, Bobby', 'Second Domain', - $this->callAPISuccessGetValue('Contact', array('id' => $loggedInContactID, 'return' => 'last_name')) . ', Logged In :: anthony_anderson@civicrm.org', - ); + $this->callAPISuccessGetValue('Contact', ['id' => $loggedInContactID, 'return' => 'last_name']) . ', Logged In :: anthony_anderson@civicrm.org', + ]; foreach ($expectedData as $index => $value) { $this->assertEquals($value, $result['values'][$index]['data']); } @@ -3073,17 +3157,17 @@ public function testGetQuickEmailACL() { */ public function testGetQuickExternalID() { $this->getQuickSearchSampleData(); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'b', 'field_name' => 'external_identifier', 'table_name' => 'cc', - )); + ]); $this->assertEquals(0, $result['count']); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'abc', 'field_name' => 'external_identifier', 'table_name' => 'cc', - )); + ]); $this->assertEquals(1, $result['count']); $this->assertEquals('Bob, Bob', $result['values'][0]['sort_name']); } @@ -3094,18 +3178,18 @@ public function testGetQuickExternalID() { public function testGetQuickID() { $max = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_contact"); $this->getQuickSearchSampleData(); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => $max + 2, 'field_name' => 'id', 'table_name' => 'cc', - )); + ]); $this->assertEquals(1, $result['count']); $this->assertEquals('E Bobby, Bobby', $result['values'][0]['sort_name']); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => $max + 2, 'field_name' => 'contact_id', 'table_name' => 'cc', - )); + ]); $this->assertEquals(1, $result['count']); $this->assertEquals('E Bobby, Bobby', $result['values'][0]['sort_name']); } @@ -3117,24 +3201,24 @@ public function testGetQuickID() { */ public function testGetQuickFirstName() { $this->getQuickSearchSampleData(); - $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => TRUE)); - $result = $this->callAPISuccess('contact', 'getquick', array( + $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => TRUE]); + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'Bob', 'field_name' => 'first_name', 'table_name' => 'cc', - )); - $expected = array( + ]); + $expected = [ 'Aadvark, Bob', 'Bob, Bob', 'K Bobby, Bob', 'A Bobby, Bobby', - ); + ]; foreach ($expected as $index => $value) { $this->assertEquals($value, $result['values'][$index]['sort_name']); } - $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => FALSE)); - $result = $this->callAPISuccess('contact', 'getquick', array('name' => 'bob')); + $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => FALSE]); + $result = $this->callAPISuccess('contact', 'getquick', ['name' => 'bob']); $this->assertEquals('Bob, Bob', $result['values'][0]['sort_name']); // This test has been disabled as is proving to be problematic to reproduce due to MySQL sorting issues between different versions //$this->assertEquals('E Bobby, Bobby', $result['values'][1]['sort_name']); @@ -3146,22 +3230,22 @@ public function testGetQuickFirstName() { public function testGetQuickFirstNameACLs() { $this->getQuickSearchSampleData(); $userID = $this->createLoggedInUser(); - $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => TRUE, 'search_autocomplete_count' => 15)); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); - $result = $this->callAPISuccess('contact', 'getquick', array( + $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => TRUE, 'search_autocomplete_count' => 15]); + CRM_Core_Config::singleton()->userPermissionClass->permissions = []; + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'Bob', 'field_name' => 'first_name', 'table_name' => 'cc', - )); + ]); $this->assertEquals(0, $result['count']); - $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereNoBobH')); + $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereNoBobH']); CRM_Contact_BAO_Contact_Permission::cache($userID, CRM_Core_Permission::VIEW, TRUE); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'Bob', 'field_name' => 'first_name', 'table_name' => 'cc', - )); + ]); $this->assertEquals('K Bobby, Bob', $result['values'][2]['sort_name']); // Without the ACL 9 would be bob@h.com. $this->assertEquals('I Bobby, Bobby', $result['values'][10]['sort_name']); @@ -3169,6 +3253,7 @@ public function testGetQuickFirstNameACLs() { /** * Full results returned. + * * @implements CRM_Utils_Hook::aclWhereClause * * @param string $type @@ -3187,23 +3272,23 @@ public function aclWhereNoBobH($type, &$tables, &$whereTables, &$contactID, &$wh */ public function testGetQuickLastName() { $this->getQuickSearchSampleData(); - $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => TRUE)); - $result = $this->callAPISuccess('contact', 'getquick', array( + $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => TRUE]); + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'Bob', 'field_name' => 'last_name', 'table_name' => 'cc', - )); - $expected = array( + ]); + $expected = [ 'Bob, Bob', 'A Bobby, Bobby', 'B Bobby, Bobby', - ); + ]; foreach ($expected as $index => $value) { $this->assertEquals($value, $result['values'][$index]['sort_name']); } - $this->callAPISuccess('Setting', 'create', array('includeOrderByClause' => FALSE)); - $result = $this->callAPISuccess('contact', 'getquick', array('name' => 'bob')); + $this->callAPISuccess('Setting', 'create', ['includeOrderByClause' => FALSE]); + $result = $this->callAPISuccess('contact', 'getquick', ['name' => 'bob']); $this->assertEquals('Bob, Bob :: bob@bob.com', $result['values'][0]['data']); } @@ -3212,17 +3297,17 @@ public function testGetQuickLastName() { */ public function testGetQuickCity() { $this->getQuickSearchSampleData(); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'o', 'field_name' => 'city', 'table_name' => 'sts', - )); + ]); $this->assertEquals('B Bobby, Bobby :: Toronto', $result['values'][0]['data']); - $result = $this->callAPISuccess('contact', 'getquick', array( + $result = $this->callAPISuccess('contact', 'getquick', [ 'name' => 'n', 'field_name' => 'city', 'table_name' => 'sts', - )); + ]); $this->assertEquals('B Bobby, Bobby :: Toronto', $result['values'][0]['data']); $this->assertEquals('C Bobby, Bobby :: Whanganui', $result['values'][1]['data']); } @@ -3231,39 +3316,39 @@ public function testGetQuickCity() { * Set up some sample data for testing quicksearch. */ public function getQuickSearchSampleData() { - $contacts = array( - array('first_name' => 'Bob', 'last_name' => 'Bob', 'external_identifier' => 'abc', 'email' => 'bob@bob.com'), - array('first_name' => 'Bobby', 'last_name' => 'E Bobby', 'external_identifier' => 'abcd'), - array( + $contacts = [ + ['first_name' => 'Bob', 'last_name' => 'Bob', 'external_identifier' => 'abc', 'email' => 'bob@bob.com'], + ['first_name' => 'Bobby', 'last_name' => 'E Bobby', 'external_identifier' => 'abcd'], + [ 'first_name' => 'Bobby', 'last_name' => 'B Bobby', 'external_identifier' => 'bcd', - 'api.address.create' => array( + 'api.address.create' => [ 'street_address' => 'Sesame Street', 'city' => 'Toronto', 'location_type_id' => 1, - ), - ), - array( + ], + ], + [ 'first_name' => 'Bobby', 'last_name' => 'C Bobby', 'external_identifier' => 'bcde', - 'api.address.create' => array( + 'api.address.create' => [ 'street_address' => 'Te huarahi', 'city' => 'Whanganui', 'location_type_id' => 1, - ), - ), - array('first_name' => 'Bobby', 'last_name' => 'D Bobby', 'external_identifier' => 'efg'), - array('first_name' => 'Bobby', 'last_name' => 'A Bobby', 'external_identifier' => 'hij', 'email' => 'bob@bobby.com'), - array('first_name' => 'Bobby', 'last_name' => 'F Bobby', 'external_identifier' => 'klm'), - array('first_name' => 'Bobby', 'last_name' => 'G Bobby', 'external_identifier' => 'nop'), - array('first_name' => 'Bobby', 'last_name' => 'H Bobby', 'external_identifier' => 'qrs', 'email' => 'bob@h.com'), - array('first_name' => 'Bobby', 'last_name' => 'I Bobby'), - array('first_name' => 'Bobby', 'last_name' => 'J Bobby'), - array('first_name' => 'Bob', 'last_name' => 'K Bobby', 'external_identifier' => 'bcdef'), - array('first_name' => 'Bob', 'last_name' => 'Aadvark'), - ); + ], + ], + ['first_name' => 'Bobby', 'last_name' => 'D Bobby', 'external_identifier' => 'efg'], + ['first_name' => 'Bobby', 'last_name' => 'A Bobby', 'external_identifier' => 'hij', 'email' => 'bob@bobby.com'], + ['first_name' => 'Bobby', 'last_name' => 'F Bobby', 'external_identifier' => 'klm'], + ['first_name' => 'Bobby', 'last_name' => 'G Bobby', 'external_identifier' => 'nop'], + ['first_name' => 'Bobby', 'last_name' => 'H Bobby', 'external_identifier' => 'qrs', 'email' => 'bob@h.com'], + ['first_name' => 'Bobby', 'last_name' => 'I Bobby'], + ['first_name' => 'Bobby', 'last_name' => 'J Bobby'], + ['first_name' => 'Bob', 'last_name' => 'K Bobby', 'external_identifier' => 'bcdef'], + ['first_name' => 'Bob', 'last_name' => 'Aadvark'], + ]; foreach ($contacts as $type => $contact) { $contact['contact_type'] = 'Individual'; $this->callAPISuccess('Contact', 'create', $contact); @@ -3274,37 +3359,37 @@ public function getQuickSearchSampleData() { * Test get ref api - gets a list of references to an entity. */ public function testGetReferenceCounts() { - $result = $this->callAPISuccess('Contact', 'create', array( + $result = $this->callAPISuccess('Contact', 'create', [ 'first_name' => 'Testily', 'last_name' => 'McHaste', 'contact_type' => 'Individual', - 'api.Address.replace' => array( - 'values' => array(), - ), - 'api.Email.replace' => array( - 'values' => array( - array( + 'api.Address.replace' => [ + 'values' => [], + ], + 'api.Email.replace' => [ + 'values' => [ + [ 'email' => 'spam@dev.null', 'is_primary' => 0, 'location_type_id' => 1, - ), - ), - ), - 'api.Phone.replace' => array( - 'values' => array( - array( + ], + ], + ], + 'api.Phone.replace' => [ + 'values' => [ + [ 'phone' => '234-567-0001', 'is_primary' => 1, 'location_type_id' => 1, - ), - array( + ], + [ 'phone' => '234-567-0002', 'is_primary' => 0, 'location_type_id' => 1, - ), - ), - ), - )); + ], + ], + ], + ]); //$dao = new CRM_Contact_BAO_Contact(); //$dao->id = $result['id']; @@ -3314,10 +3399,10 @@ public function testGetReferenceCounts() { //$this->assertTrue(is_array($refCounts)); //$refCountsIdx = CRM_Utils_Array::index(array('name'), $refCounts); - $refCounts = $this->callAPISuccess('Contact', 'getrefcount', array( + $refCounts = $this->callAPISuccess('Contact', 'getrefcount', [ 'id' => $result['id'], - )); - $refCountsIdx = CRM_Utils_Array::index(array('name'), $refCounts['values']); + ]); + $refCountsIdx = CRM_Utils_Array::index(['name'], $refCounts['values']); $this->assertEquals(1, $refCountsIdx['sql:civicrm_email:contact_id']['count']); $this->assertEquals('civicrm_email', $refCountsIdx['sql:civicrm_email:contact_id']['table']); @@ -3328,7 +3413,9 @@ public function testGetReferenceCounts() { /** * Test the use of sql operators. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testSQLOperatorsOnContactAPI($version) { @@ -3336,15 +3423,17 @@ public function testSQLOperatorsOnContactAPI($version) { $this->individualCreate(); $this->organizationCreate(); $this->householdCreate(); - $contacts = $this->callAPISuccess('contact', 'get', array('legal_name' => array('IS NOT NULL' => TRUE))); + $contacts = $this->callAPISuccess('contact', 'get', ['legal_name' => ['IS NOT NULL' => TRUE]]); $this->assertEquals($contacts['count'], CRM_Core_DAO::singleValueQuery('select count(*) FROM civicrm_contact WHERE legal_name IS NOT NULL')); - $contacts = $this->callAPISuccess('contact', 'get', array('legal_name' => array('IS NULL' => TRUE))); + $contacts = $this->callAPISuccess('contact', 'get', ['legal_name' => ['IS NULL' => TRUE]]); $this->assertEquals($contacts['count'], CRM_Core_DAO::singleValueQuery('select count(*) FROM civicrm_contact WHERE legal_name IS NULL')); } /** * CRM-14743 - test api respects search operators. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetModifiedDateByOperators($version) { @@ -3359,15 +3448,17 @@ public function testGetModifiedDateByOperators($version) { $contact3 = $this->householdCreate(); $sql = "UPDATE civicrm_contact SET created_date = '2012-03-01', modified_date = '2013-03-01' WHERE id = " . $contact3; CRM_Core_DAO::executeQuery($sql); - $contacts = $this->callAPISuccess('contact', 'get', array('modified_date' => array('<' => '2014-01-01'))); + $contacts = $this->callAPISuccess('contact', 'get', ['modified_date' => ['<' => '2014-01-01']]); $this->assertEquals($contacts['count'], 3); - $contacts = $this->callAPISuccess('contact', 'get', array('modified_date' => array('>' => '2014-01-01'))); + $contacts = $this->callAPISuccess('contact', 'get', ['modified_date' => ['>' => '2014-01-01']]); $this->assertEquals($contacts['count'], $preExistingContactCount); } /** * CRM-14743 - test api respects search operators. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetCreatedDateByOperators($version) { @@ -3382,9 +3473,9 @@ public function testGetCreatedDateByOperators($version) { $contact3 = $this->householdCreate(); $sql = "UPDATE civicrm_contact SET created_date = '2012-03-01' WHERE id = " . $contact3; CRM_Core_DAO::executeQuery($sql); - $contacts = $this->callAPISuccess('contact', 'get', array('created_date' => array('<' => '2014-01-01'))); + $contacts = $this->callAPISuccess('contact', 'get', ['created_date' => ['<' => '2014-01-01']]); $this->assertEquals($contacts['count'], 3); - $contacts = $this->callAPISuccess('contact', 'get', array('created_date' => array('>' => '2014-01-01'))); + $contacts = $this->callAPISuccess('contact', 'get', ['created_date' => ['>' => '2014-01-01']]); $this->assertEquals($contacts['count'], $preExistingContactCount); } @@ -3394,12 +3485,12 @@ public function testGetCreatedDateByOperators($version) { public function testReturnCityProfile() { $contactID = $this->individualCreate(); CRM_Core_Config::singleton()->defaultSearchProfileID = 1; - $this->callAPISuccess('address', 'create', array( + $this->callAPISuccess('address', 'create', [ 'contact_id' => $contactID, 'city' => 'Cool City', 'location_type_id' => 1, - )); - $result = $this->callAPISuccess('contact', 'get', array('city' => 'Cool City', 'return' => 'contact_type')); + ]); + $result = $this->callAPISuccess('contact', 'get', ['city' => 'Cool City', 'return' => 'contact_type']); $this->assertEquals(1, $result['count']); } @@ -3408,17 +3499,17 @@ public function testReturnCityProfile() { */ public function testGetlistExcludeConditions() { $name = 'Scarabée'; - $contact = $this->individualCreate(array('last_name' => $name)); - $this->individualCreate(array('last_name' => $name, 'is_deceased' => 1)); - $this->individualCreate(array('last_name' => $name, 'is_deleted' => 1)); + $contact = $this->individualCreate(['last_name' => $name]); + $this->individualCreate(['last_name' => $name, 'is_deceased' => 1]); + $this->individualCreate(['last_name' => $name, 'is_deleted' => 1]); // We should get all but the deleted contact. - $result = $this->callAPISuccess('contact', 'getlist', array('input' => $name)); + $result = $this->callAPISuccess('contact', 'getlist', ['input' => $name]); $this->assertEquals(2, $result['count']); // Force-exclude the deceased contact. - $result = $this->callAPISuccess('contact', 'getlist', array( + $result = $this->callAPISuccess('contact', 'getlist', [ 'input' => $name, - 'params' => array('is_deceased' => 0), - )); + 'params' => ['is_deceased' => 0], + ]); $this->assertEquals(1, $result['count']); $this->assertEquals($contact, $result['values'][0]['id']); } @@ -3428,8 +3519,8 @@ public function testGetlistExcludeConditions() { */ public function testGetActions() { $description = "Getting the available actions for an entity."; - $result = $this->callAPIAndDocument($this->_entity, 'getactions', array(), __FUNCTION__, __FILE__, $description); - $expected = array( + $result = $this->callAPIAndDocument($this->_entity, 'getactions', [], __FUNCTION__, __FILE__, $description); + $expected = [ 'create', 'delete', 'get', @@ -3447,11 +3538,11 @@ public function testGetActions() { 'replace', 'setvalue', 'update', - ); - $deprecated = array( + ]; + $deprecated = [ 'update', 'getquick', - ); + ]; foreach ($expected as $action) { $this->assertTrue(in_array($action, $result['values']), "Expected action $action"); } @@ -3464,96 +3555,96 @@ public function testGetActions() { * Test the duplicate check function. */ public function testDuplicateCheck() { - $harry = array( + $harry = [ 'first_name' => 'Harry', 'last_name' => 'Potter', 'email' => 'harry@hogwarts.edu', 'contact_type' => 'Individual', - ); + ]; $this->callAPISuccess('Contact', 'create', $harry); - $result = $this->callAPISuccess('Contact', 'duplicatecheck', array( + $result = $this->callAPISuccess('Contact', 'duplicatecheck', [ 'match' => $harry, - )); + ]); $this->assertEquals(1, $result['count']); - $result = $this->callAPISuccess('Contact', 'duplicatecheck', array( - 'match' => array( + $result = $this->callAPISuccess('Contact', 'duplicatecheck', [ + 'match' => [ 'first_name' => 'Harry', 'last_name' => 'Potter', 'email' => 'no5@privet.drive', 'contact_type' => 'Individual', - ), - )); + ], + ]); $this->assertEquals(0, $result['count']); - $this->callAPIFailure('Contact', 'create', array_merge($harry, array('dupe_check' => 1))); + $this->callAPIFailure('Contact', 'create', array_merge($harry, ['dupe_check' => 1])); } /** * Test the duplicate check function. */ public function testDuplicateCheckRuleNotReserved() { - $harry = array( + $harry = [ 'first_name' => 'Harry', 'last_name' => 'Potter', 'email' => 'harry@hogwarts.edu', 'contact_type' => 'Individual', - ); - $defaultRule = $this->callAPISuccess('RuleGroup', 'getsingle', array('used' => 'Unsupervised', 'is_reserved' => 1)); - $this->callAPISuccess('RuleGroup', 'create', array('id' => $defaultRule['id'], 'is_reserved' => 0)); + ]; + $defaultRule = $this->callAPISuccess('RuleGroup', 'getsingle', ['used' => 'Unsupervised', 'is_reserved' => 1]); + $this->callAPISuccess('RuleGroup', 'create', ['id' => $defaultRule['id'], 'is_reserved' => 0]); $this->callAPISuccess('Contact', 'create', $harry); - $result = $this->callAPISuccess('Contact', 'duplicatecheck', array( + $result = $this->callAPISuccess('Contact', 'duplicatecheck', [ 'match' => $harry, - )); + ]); $this->assertEquals(1, $result['count']); - $this->callAPISuccess('RuleGroup', 'create', array('id' => $defaultRule['id'], 'is_reserved' => 1)); + $this->callAPISuccess('RuleGroup', 'create', ['id' => $defaultRule['id'], 'is_reserved' => 1]); } /** * Test variants on retrieving contact by type. */ public function testGetByContactType() { - $individual = $this->callAPISuccess('Contact', 'create', array( + $individual = $this->callAPISuccess('Contact', 'create', [ 'email' => 'individual@test.com', 'contact_type' => 'Individual', - )); - $household = $this->callAPISuccess('Contact', 'create', array( + ]); + $household = $this->callAPISuccess('Contact', 'create', [ 'household_name' => 'household@test.com', 'contact_type' => 'Household', - )); - $organization = $this->callAPISuccess('Contact', 'create', array( + ]); + $organization = $this->callAPISuccess('Contact', 'create', [ 'organization_name' => 'organization@test.com', 'contact_type' => 'Organization', - )); + ]); // Test with id - getsingle will throw an exception if not found - $this->callAPISuccess('Contact', 'getsingle', array( + $this->callAPISuccess('Contact', 'getsingle', [ 'id' => $individual['id'], 'contact_type' => 'Individual', - )); - $this->callAPISuccess('Contact', 'getsingle', array( + ]); + $this->callAPISuccess('Contact', 'getsingle', [ 'id' => $individual['id'], - 'contact_type' => array('IN' => array('Individual')), + 'contact_type' => ['IN' => ['Individual']], 'return' => 'id', - )); - $this->callAPISuccess('Contact', 'getsingle', array( + ]); + $this->callAPISuccess('Contact', 'getsingle', [ 'id' => $organization['id'], - 'contact_type' => array('IN' => array('Individual', 'Organization')), - )); + 'contact_type' => ['IN' => ['Individual', 'Organization']], + ]); // Test as array - $result = $this->callAPISuccess('Contact', 'get', array( - 'contact_type' => array('IN' => array('Individual', 'Organization')), - 'options' => array('limit' => 0), + $result = $this->callAPISuccess('Contact', 'get', [ + 'contact_type' => ['IN' => ['Individual', 'Organization']], + 'options' => ['limit' => 0], 'return' => 'id', - )); + ]); $this->assertContains($organization['id'], array_keys($result['values'])); $this->assertContains($individual['id'], array_keys($result['values'])); $this->assertNotContains($household['id'], array_keys($result['values'])); // Test as string - $result = $this->callAPISuccess('Contact', 'get', array( + $result = $this->callAPISuccess('Contact', 'get', [ 'contact_type' => 'Household', - 'options' => array('limit' => 0), + 'options' => ['limit' => 0], 'return' => 'id', - )); + ]); $this->assertNotContains($organization['id'], array_keys($result['values'])); $this->assertNotContains($individual['id'], array_keys($result['values'])); $this->assertContains($household['id'], array_keys($result['values'])); @@ -3571,10 +3662,10 @@ public function testMergeBizzareOldParams() { $this->createLoggedInUser(); $otherContact = $this->callAPISuccess('contact', 'create', $this->_params); $mainContact = $this->callAPISuccess('contact', 'create', $this->_params); - $this->callAPISuccess('contact', 'merge', array( + $this->callAPISuccess('contact', 'merge', [ 'main_id' => $mainContact['id'], 'other_id' => $otherContact['id'], - )); + ]); $contacts = $this->callAPISuccess('contact', 'get', $this->_params); $this->assertEquals($otherContact['id'], $contacts['id']); } @@ -3586,29 +3677,29 @@ public function testMerge() { $this->createLoggedInUser(); $otherContact = $this->callAPISuccess('contact', 'create', $this->_params); $retainedContact = $this->callAPISuccess('contact', 'create', $this->_params); - $this->callAPISuccess('contact', 'merge', array( + $this->callAPISuccess('contact', 'merge', [ 'to_keep_id' => $retainedContact['id'], 'to_remove_id' => $otherContact['id'], 'auto_flip' => FALSE, - )); + ]); $contacts = $this->callAPISuccess('contact', 'get', $this->_params); $this->assertEquals($retainedContact['id'], $contacts['id']); - $activity = $this->callAPISuccess('Activity', 'getsingle', array( + $activity = $this->callAPISuccess('Activity', 'getsingle', [ 'target_contact_id' => $retainedContact['id'], 'activity_type_id' => 'Contact Merged', - )); + ]); $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($activity['activity_date_time']))); - $activity2 = $this->callAPISuccess('Activity', 'getsingle', array( + $activity2 = $this->callAPISuccess('Activity', 'getsingle', [ 'target_contact_id' => $otherContact['id'], 'activity_type_id' => 'Contact Deleted by Merge', - )); + ]); $this->assertEquals($activity['id'], $activity2['parent_id']); - $this->assertEquals('Normal', civicrm_api3('option_value', 'getvalue', array( + $this->assertEquals('Normal', civicrm_api3('option_value', 'getvalue', [ 'value' => $activity['priority_id'], 'return' => 'label', 'option_group_id' => 'priority', - ))); + ])); } @@ -3705,15 +3796,15 @@ public function testMergedGet() { */ public function testMergeNoTrash() { $this->createLoggedInUser(); - $this->callAPISuccess('Setting', 'create', array('contact_undelete' => FALSE)); + $this->callAPISuccess('Setting', 'create', ['contact_undelete' => FALSE]); $otherContact = $this->callAPISuccess('contact', 'create', $this->_params); $retainedContact = $this->callAPISuccess('contact', 'create', $this->_params); - $this->callAPISuccess('contact', 'merge', array( + $this->callAPISuccess('contact', 'merge', [ 'to_keep_id' => $retainedContact['id'], 'to_remove_id' => $otherContact['id'], 'auto_flip' => FALSE, - )); - $this->callAPISuccess('Setting', 'create', array('contact_undelete' => TRUE)); + ]); + $this->callAPISuccess('Setting', 'create', ['contact_undelete' => TRUE]); } /** @@ -3723,12 +3814,12 @@ public function testMergeNoTrash() { */ public function testContactGetReturnGroup() { // Set up a contact, asser that they were created. - $contact_params = array( + $contact_params = [ 'contact_type' => 'Individual', 'first_name' => 'Test', 'last_name' => 'Groupmember', 'email' => 'test@example.org', - ); + ]; $create_contact = $this->callApiSuccess('Contact', 'create', $contact_params); $this->assertEquals(0, $create_contact['is_error']); $this->assertInternalType('int', $create_contact['id']); @@ -3736,13 +3827,13 @@ public function testContactGetReturnGroup() { $created_contact_id = $create_contact['id']; // Set up multiple groups, add the contact to the groups. - $test_groups = array('Test group A', 'Test group B'); + $test_groups = ['Test group A', 'Test group B']; foreach ($test_groups as $title) { // Use this contact as group owner, since we know they exist. - $group_params = array( + $group_params = [ 'title' => $title, 'created_id' => $created_contact_id, - ); + ]; $create_group = $this->callApiSuccess('Group', 'create', $group_params); $this->assertEquals(0, $create_group['is_error']); $this->assertInternalType('int', $create_group['id']); @@ -3750,20 +3841,20 @@ public function testContactGetReturnGroup() { $created_group_ids[] = $create_group['id']; // Add contact to the new group. - $group_contact_params = array( + $group_contact_params = [ 'contact_id' => $created_contact_id, 'group_id' => $create_group['id'], - ); + ]; $create_group_contact = $this->callApiSuccess('GroupContact', 'create', $group_contact_params); $this->assertEquals(0, $create_group_contact['is_error']); $this->assertInternalType('int', $create_group_contact['added']); } // Use the Contact,get API to retrieve the contact - $contact_get_params = array( + $contact_get_params = [ 'id' => $created_contact_id, 'return' => 'group', - ); + ]; $contact_get = $this->callApiSuccess('Contact', 'get', $contact_get_params); $this->assertInternalType('array', $contact_get['values'][$created_contact_id]); $this->assertInternalType('string', $contact_get['values'][$created_contact_id]['groups']); @@ -3783,42 +3874,42 @@ public function testContactGetReturnGroup() { */ public function testContactGetWithGroupTitle() { // Set up a contact, asser that they were created. - $contact_params = array( + $contact_params = [ 'contact_type' => 'Individual', 'first_name' => 'Test2', 'last_name' => 'Groupmember', 'email' => 'test@example.org', - ); + ]; $create_contact = $this->callApiSuccess('Contact', 'create', $contact_params); $created_contact_id = $create_contact['id']; // Set up multiple groups, add the contact to the groups. - $test_groups = array('Test group C', 'Test group D'); + $test_groups = ['Test group C', 'Test group D']; foreach ($test_groups as $title) { - $group_params = array( + $group_params = [ 'title' => $title, 'created_id' => $created_contact_id, - ); + ]; $create_group = $this->callApiSuccess('Group', 'create', $group_params); $created_group_id = $create_group['id']; // Add contact to the new group. - $group_contact_params = array( + $group_contact_params = [ 'contact_id' => $created_contact_id, 'group_id' => $create_group['id'], - ); + ]; $this->callApiSuccess('GroupContact', 'create', $group_contact_params); - $contact_get = $this->callAPISuccess('contact', 'get', array('group' => $title, 'return' => 'group')); + $contact_get = $this->callAPISuccess('contact', 'get', ['group' => $title, 'return' => 'group']); $this->assertEquals(1, $contact_get['count']); $this->assertEquals($created_contact_id, $contact_get['id']); $contact_groups = explode(',', $contact_get['values'][$created_contact_id]['groups']); $this->assertContains((string) $create_group['id'], $contact_groups); - $contact_get2 = $this->callAPISuccess('contact', 'get', array('group' => $created_group_id, 'return' => 'group')); + $contact_get2 = $this->callAPISuccess('contact', 'get', ['group' => $created_group_id, 'return' => 'group']); $this->assertEquals($created_contact_id, $contact_get2['id']); $contact_groups2 = explode(',', $contact_get2['values'][$created_contact_id]['groups']); $this->assertContains((string) $create_group['id'], $contact_groups2); - $this->callAPISuccess('group', 'delete', array('id' => $created_group_id)); + $this->callAPISuccess('group', 'delete', ['id' => $created_group_id]); } - $this->callAPISuccess('contact', 'delete', array('id' => $created_contact_id, 'skip_undelete' => TRUE)); + $this->callAPISuccess('contact', 'delete', ['id' => $created_contact_id, 'skip_undelete' => TRUE]); } /** @@ -3831,51 +3922,51 @@ public function testContactGetWithGroupTitleMultipleGroups() { $description = "Get all from group and display contacts."; $subFile = "GroupFilterUsingContactAPI"; // Set up a contact, asser that they were created. - $contact_params = array( + $contact_params = [ 'contact_type' => 'Individual', 'first_name' => 'Test2', 'last_name' => 'Groupmember', 'email' => 'test@example.org', - ); + ]; $create_contact = $this->callApiSuccess('Contact', 'create', $contact_params); $created_contact_id = $create_contact['id']; - $createdGroupsTitles = $createdGroupsIds = array(); + $createdGroupsTitles = $createdGroupsIds = []; // Set up multiple groups, add the contact to the groups. - $test_groups = array('Test group C', 'Test group D'); + $test_groups = ['Test group C', 'Test group D']; foreach ($test_groups as $title) { - $group_params = array( + $group_params = [ 'title' => $title, '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. - $group_contact_params = array( + $group_contact_params = [ 'contact_id' => $created_contact_id, 'group_id' => $create_group['id'], - ); + ]; $create_group_contact = $this->callApiSuccess('GroupContact', 'create', $group_contact_params); } - $contact_get = $this->callAPISuccess('contact', 'get', array('group' => $createdGroupTitles, 'return' => 'group')); + $contact_get = $this->callAPISuccess('contact', 'get', ['group' => $createdGroupTitles, 'return' => 'group']); $this->assertEquals(1, $contact_get['count']); $this->assertEquals($created_contact_id, $contact_get['id']); $contact_groups = explode(',', $contact_get['values'][$created_contact_id]['groups']); foreach ($createdGroupsIds as $id) { $this->assertContains((string) $id, $contact_groups); } - $contact_get2 = $this->callAPIAndDocument('contact', 'get', array('group' => array('IN' => $createdGroupTitles)), __FUNCTION__, __FILE__, $description, $subFile); - $contact_get2 = $this->callAPISuccess('contact', 'get', array('group' => array('IN' => $createdGroupTitles), 'return' => 'group')); + $contact_get2 = $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']); foreach ($createdGroupsIds as $id) { $this->assertContains((string) $id, $contact_groups2); } foreach ($createdGroupsIds as $id) { - $this->callAPISuccess('group', 'delete', array('id' => $id)); + $this->callAPISuccess('group', 'delete', ['id' => $id]); } - $this->callAPISuccess('contact', 'delete', array('id' => $created_contact_id, 'skip_undelete' => TRUE)); + $this->callAPISuccess('contact', 'delete', ['id' => $created_contact_id, 'skip_undelete' => TRUE]); } /** @@ -3888,63 +3979,63 @@ public function testContactGetWithGroupTitleMultipleGroups() { */ public function testContactGetWithGroupTitleMultipleGroupsLegacyFormat() { // Set up a contact, asser that they were created. - $contact_params = array( + $contact_params = [ 'contact_type' => 'Individual', 'first_name' => 'Test2', 'last_name' => 'Groupmember', 'email' => 'test@example.org', - ); + ]; $create_contact = $this->callApiSuccess('Contact', 'create', $contact_params); $created_contact_id = $create_contact['id']; - $createdGroupsTitles = $createdGroupsIds = array(); + $createdGroupsTitles = $createdGroupsIds = []; // Set up multiple groups, add the contact to the groups. - $test_groups = array('Test group C', 'Test group D'); + $test_groups = ['Test group C', 'Test group D']; foreach ($test_groups as $title) { - $group_params = array( + $group_params = [ 'title' => $title, '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. - $group_contact_params = array( + $group_contact_params = [ 'contact_id' => $created_contact_id, 'group_id' => $create_group['id'], - ); + ]; $create_group_contact = $this->callApiSuccess('GroupContact', 'create', $group_contact_params); } - $contact_get = $this->callAPISuccess('contact', 'get', array('group' => array($createdGroupTitles[0] => 1), 'return' => 'group')); + $contact_get = $this->callAPISuccess('contact', 'get', ['group' => [$createdGroupTitles[0] => 1], 'return' => 'group']); $this->assertEquals(1, $contact_get['count']); $this->assertEquals($created_contact_id, $contact_get['id']); $contact_groups = explode(',', $contact_get['values'][$created_contact_id]['groups']); foreach ($createdGroupsIds as $id) { $this->assertContains((string) $id, $contact_groups); } - $contact_get2 = $this->callAPISuccess('contact', 'get', array('group' => array($createdGroupTitles[0] => 1, $createdGroupTitles[1] => 1), 'return' => 'group')); + $contact_get2 = $this->callAPISuccess('contact', 'get', ['group' => [$createdGroupTitles[0] => 1, $createdGroupTitles[1] => 1], 'return' => 'group']); $this->assertEquals(1, $contact_get2['count']); $this->assertEquals($created_contact_id, $contact_get2['id']); $contact_groups2 = explode(',', $contact_get2['values'][$created_contact_id]['groups']); foreach ($createdGroupsIds as $id) { $this->assertContains((string) $id, $contact_groups2); } - $contact_get3 = $this->callAPISuccess('contact', 'get', array('group' => array($createdGroupsIds[0] => 1), 'return' => 'group')); + $contact_get3 = $this->callAPISuccess('contact', 'get', ['group' => [$createdGroupsIds[0] => 1], 'return' => 'group']); $this->assertEquals($created_contact_id, $contact_get3['id']); $contact_groups3 = explode(',', $contact_get3['values'][$created_contact_id]['groups']); foreach ($createdGroupsIds as $id) { $this->assertContains((string) $id, $contact_groups3); } - $contact_get4 = $this->callAPISuccess('contact', 'get', array('group' => array($createdGroupsIds[0] => 1, $createdGroupsIds[1] => 1), 'return' => 'group')); + $contact_get4 = $this->callAPISuccess('contact', 'get', ['group' => [$createdGroupsIds[0] => 1, $createdGroupsIds[1] => 1], 'return' => 'group']); $this->assertEquals($created_contact_id, $contact_get4['id']); $contact_groups4 = explode(',', $contact_get4['values'][$created_contact_id]['groups']); foreach ($createdGroupsIds as $id) { $this->assertContains((string) $id, $contact_groups4); } foreach ($createdGroupsIds as $id) { - $this->callAPISuccess('group', 'delete', array('id' => $id)); + $this->callAPISuccess('group', 'delete', ['id' => $id]); } - $this->callAPISuccess('contact', 'delete', array('id' => $created_contact_id, 'skip_undelete' => TRUE)); + $this->callAPISuccess('contact', 'delete', ['id' => $created_contact_id, 'skip_undelete' => TRUE]); } /** @@ -3979,7 +4070,7 @@ public function testLoggedInUserAPISupportToken() { $description = "Get contact id of the current logged in user"; $subFile = "ContactIDOfLoggedInUserContactAPI"; $cid = $this->createLoggedInUser(); - $contact = $this->callAPIAndDocument('contact', 'get', array('id' => 'user_contact_id'), __FUNCTION__, __FILE__, $description, $subFile); + $contact = $this->callAPIAndDocument('contact', 'get', ['id' => 'user_contact_id'], __FUNCTION__, __FILE__, $description, $subFile); $this->assertEquals($cid, $contact['id']); } @@ -4001,37 +4092,42 @@ protected function putGroupContactCacheInClearableState($groupID, $contact) { /** * CRM-21041 Test if 'communication style' is set to site default if not passed. + * * @param int $version + * * @dataProvider versionThreeAndFour + * @throws \CRM_Core_Exception */ public function testCreateCommunicationStyleUnset($version) { $this->_apiversion = $version; - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'first_name' => 'John', 'last_name' => 'Doe', 'contact_type' => 'Individual', - ) - ); - $result = $this->callAPISuccessGetSingle('Contact', array('last_name' => 'Doe')); + ]); + $result = $this->callAPISuccessGetSingle('Contact', ['last_name' => 'Doe']); $this->assertEquals(1, $result['communication_style_id']); } /** * CRM-21041 Test if 'communication style' is set if value is passed. + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public function testCreateCommunicationStylePassed() { - $this->callAPISuccess('Contact', 'create', array( + $this->callAPISuccess('Contact', 'create', [ 'first_name' => 'John', 'last_name' => 'Doe', 'contact_type' => 'Individual', 'communication_style_id' => 'Familiar', - )); - $result = $this->callAPISuccessGetSingle('Contact', array('last_name' => 'Doe')); - $params = array( + ]); + $result = $this->callAPISuccessGetSingle('Contact', ['last_name' => 'Doe']); + $params = [ 'option_group_id' => 'communication_style', 'label' => 'Familiar', 'return' => 'value', - ); + ]; $optionResult = civicrm_api3('OptionValue', 'get', $params); $communicationStyle = reset($optionResult['values']); $this->assertEquals($communicationStyle['value'], $result['communication_style_id']); @@ -4042,16 +4138,16 @@ public function testCreateCommunicationStylePassed() { * V3 Only. */ public function testContactGreetingsCreate() { - $contact = $this->callAPISuccess('Contact', 'create', array('first_name' => 'Alan', 'last_name' => 'MouseMouse', 'contact_type' => 'Individual')); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $contact['id'], 'return' => 'postal_greeting')); + $contact = $this->callAPISuccess('Contact', 'create', ['first_name' => 'Alan', 'last_name' => 'MouseMouse', 'contact_type' => 'Individual']); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $contact['id'], 'return' => 'postal_greeting']); $this->assertEquals('Dear Alan', $contact['postal_greeting_display']); - $contact = $this->callAPISuccess('Contact', 'create', array('id' => $contact['id'], 'postal_greeting_id' => 2)); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $contact['id'], 'return' => 'postal_greeting')); + $contact = $this->callAPISuccess('Contact', 'create', ['id' => $contact['id'], 'postal_greeting_id' => 2]); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $contact['id'], 'return' => 'postal_greeting']); $this->assertEquals('Dear Alan MouseMouse', $contact['postal_greeting_display']); - $contact = $this->callAPISuccess('Contact', 'create', array('organization_name' => 'Alan\'s Show', 'contact_type' => 'Organization')); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $contact['id'], 'return' => 'postal_greeting, addressee, email_greeting')); + $contact = $this->callAPISuccess('Contact', 'create', ['organization_name' => 'Alan\'s Show', 'contact_type' => 'Organization']); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $contact['id'], 'return' => 'postal_greeting, addressee, email_greeting']); $this->assertEquals('', $contact['postal_greeting_display']); $this->assertEquals('', $contact['email_greeting_display']); $this->assertEquals('Alan\'s Show', $contact['addressee_display']); @@ -4062,28 +4158,28 @@ public function testContactGreetingsCreate() { */ public function testContactGreetingsCreateWithCustomField() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); - $contact = $this->callAPISuccess('Contact', 'create', array('first_name' => 'Alan', 'contact_type' => 'Individual', 'custom_' . $ids['custom_field_id'] => 'Mice')); + $contact = $this->callAPISuccess('Contact', 'create', ['first_name' => 'Alan', 'contact_type' => 'Individual', 'custom_' . $ids['custom_field_id'] => 'Mice']); // Change postal greeting to involve a custom field. - $postalOption = $this->callAPISuccessGetSingle('OptionValue', array('option_group_id' => 'postal_greeting', 'filter' => 1, 'is_default' => 1)); - $this->callAPISuccess('OptionValue', 'create', array( + $postalOption = $this->callAPISuccessGetSingle('OptionValue', ['option_group_id' => 'postal_greeting', 'filter' => 1, 'is_default' => 1]); + $this->callAPISuccess('OptionValue', 'create', [ 'id' => $postalOption['id'], 'name' => 'Dear {contact.first_name} {contact.custom_' . $ids['custom_field_id'] . '}', 'label' => 'Dear {contact.first_name} {contact.custom_' . $ids['custom_field_id'] . '}', - )); + ]); // Update contact & see if postal greeting now reflects the new string. - $this->callAPISuccess('Contact', 'create', array('id' => $contact['id'], 'last_name' => 'MouseyMousey')); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $contact['id'], 'return' => 'postal_greeting')); + $this->callAPISuccess('Contact', 'create', ['id' => $contact['id'], 'last_name' => 'MouseyMousey']); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $contact['id'], 'return' => 'postal_greeting']); $this->assertEquals('Dear Alan Mice', $contact['postal_greeting_display']); // Set contact to have no postal greeting & check it is correct. - $this->callAPISuccess('Contact', 'create', array('id' => $contact['id'], 'postal_greeting_id' => 'null')); - $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $contact['id'], 'return' => 'postal_greeting')); + $this->callAPISuccess('Contact', 'create', ['id' => $contact['id'], 'postal_greeting_id' => 'null']); + $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $contact['id'], 'return' => 'postal_greeting']); $this->assertEquals('', $contact['postal_greeting_display']); //Cleanup - $this->callAPISuccess('OptionValue', 'create', array('id' => $postalOption['id'], 'name' => 'Dear {contact.first_name}')); + $this->callAPISuccess('OptionValue', 'create', ['id' => $postalOption['id'], 'name' => 'Dear {contact.first_name}']); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); } @@ -4092,9 +4188,9 @@ public function testContactGreetingsCreateWithCustomField() { * Test getunique api call for Contact entity */ public function testContactGetUnique() { - $result = $this->callAPIAndDocument($this->_entity, 'getunique', array(), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'getunique', [], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); - $this->assertEquals(array('external_identifier'), $result['values']['UI_external_identifier']); + $this->assertEquals(['external_identifier'], $result['values']['UI_external_identifier']); } /** @@ -4110,11 +4206,11 @@ public function testContactGetFromGroup() { 'visibility' => 'User and User Admin Only', ]); $contact = $this->callAPISuccess('contact', 'create', $this->_params); - $groupContactCreateParams = array( + $groupContactCreateParams = [ 'contact_id' => $contact['id'], 'group_id' => $groupId, 'status' => 'Pending', - ); + ]; $groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams); $groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams); $this->CallAPISuccess('Contact', 'getcount', [ @@ -4128,66 +4224,66 @@ public function testContactGetFromGroup() { * @throws \Exception */ public function testSmartGroupsForRelatedContacts() { - $rtype1 = $this->callAPISuccess('relationship_type', 'create', array( + $rtype1 = $this->callAPISuccess('relationship_type', 'create', [ "name_a_b" => uniqid() . " Child of", "name_b_a" => uniqid() . " Parent of", - )); - $rtype2 = $this->callAPISuccess('relationship_type', 'create', array( + ]); + $rtype2 = $this->callAPISuccess('relationship_type', 'create', [ "name_a_b" => uniqid() . " Household Member of", "name_b_a" => uniqid() . " Household Member is", - )); + ]); $h1 = $this->householdCreate(); - $c1 = $this->individualCreate(array('last_name' => 'Adams')); - $c2 = $this->individualCreate(array('last_name' => 'Adams')); - $this->callAPISuccess('relationship', 'create', array( + $c1 = $this->individualCreate(['last_name' => 'Adams']); + $c2 = $this->individualCreate(['last_name' => 'Adams']); + $this->callAPISuccess('relationship', 'create', [ 'contact_id_a' => $c1, 'contact_id_b' => $c2, 'is_active' => 1, // Child of 'relationship_type_id' => $rtype1['id'], - )); - $this->callAPISuccess('relationship', 'create', array( + ]); + $this->callAPISuccess('relationship', 'create', [ 'contact_id_a' => $c1, 'contact_id_b' => $h1, 'is_active' => 1, // Household Member of 'relationship_type_id' => $rtype2['id'], - )); - $this->callAPISuccess('relationship', 'create', array( + ]); + $this->callAPISuccess('relationship', 'create', [ 'contact_id_a' => $c2, 'contact_id_b' => $h1, 'is_active' => 1, // Household Member of 'relationship_type_id' => $rtype2['id'], - )); + ]); - $ssParams = array( - 'formValues' => array( + $ssParams = [ + 'formValues' => [ // Child of 'display_relationship_type' => $rtype1['id'] . '_a_b', 'sort_name' => 'Adams', - ), - ); - $g1ID = $this->smartGroupCreate($ssParams, array('name' => uniqid(), 'title' => uniqid())); - $ssParams = array( - 'formValues' => array( + ], + ]; + $g1ID = $this->smartGroupCreate($ssParams, ['name' => uniqid(), 'title' => uniqid()]); + $ssParams = [ + 'formValues' => [ // Household Member of 'display_relationship_type' => $rtype2['id'] . '_a_b', - ), - ); - $g2ID = $this->smartGroupCreate($ssParams, array('name' => uniqid(), 'title' => uniqid())); - $ssParams = array( - 'formValues' => array( + ], + ]; + $g2ID = $this->smartGroupCreate($ssParams, ['name' => uniqid(), 'title' => uniqid()]); + $ssParams = [ + 'formValues' => [ // Household Member is 'display_relationship_type' => $rtype2['id'] . '_b_a', - ), - ); + ], + ]; // the reverse of g2 which adds another layer for overlap at related contact filter - $g3ID = $this->smartGroupCreate($ssParams, array('name' => uniqid(), 'title' => uniqid())); + $g3ID = $this->smartGroupCreate($ssParams, ['name' => uniqid(), 'title' => uniqid()]); CRM_Contact_BAO_GroupContactCache::loadAll(); - $g1Contacts = $this->callAPISuccess('contact', 'get', array('group' => $g1ID)); - $g2Contacts = $this->callAPISuccess('contact', 'get', array('group' => $g2ID)); - $g3Contacts = $this->callAPISuccess('contact', 'get', array('group' => $g3ID)); + $g1Contacts = $this->callAPISuccess('contact', 'get', ['group' => $g1ID]); + $g2Contacts = $this->callAPISuccess('contact', 'get', ['group' => $g2ID]); + $g3Contacts = $this->callAPISuccess('contact', 'get', ['group' => $g3ID]); $this->assertTrue($g1Contacts['count'] == 1); $this->assertTrue($g2Contacts['count'] == 2); $this->assertTrue($g3Contacts['count'] == 1); @@ -4211,7 +4307,7 @@ public function testCreateNoteinCreate() { * Test Creating a note from the contact.create api call when passing the note params as an array. */ public function testCreateNoteinCreateArrayFormat() { - $contact1 = $this->callAPISuccess('Contact', 'create', array('first_name' => 'Alan', 'last_name' => 'MouseMouse', 'contact_type' => 'Individual')); + $contact1 = $this->callAPISuccess('Contact', 'create', ['first_name' => 'Alan', 'last_name' => 'MouseMouse', 'contact_type' => 'Individual']); $this->_params['note'] = [['note' => "Test note created by API Call as array", 'contact_id' => $contact1['id']]]; $contact2 = $this->callAPISuccess('Contact', 'create', $this->_params); $note = $this->callAPISuccess('Note', 'get', ['contact_id' => $contact1['id']]);