/** * allOpenIDs() method - get all OpenIDs for the given contact */ function testAllOpenIDs() { $contactId = Contact::createIndividual(); // create first openid $params = array('contact_id' => $contactId, 'location_type_id' => 1, 'endpoint_url' => $openid['endpoint_url'], 'claimed_id' => $openid['claimed_id'], 'display_id' => $openid['display_id'], 'is_primary' => 1, 'allowed_to_login' => 1); require_once 'CRM/Core/BAO/OpenID.php'; $openObjectOne = CRM_Core_BAO_OpenID::add($params); $openIdOne_id = $openObjectOne->id; $this->assertDBCompareValues('CRM_Core_DAO_OpenID', array('id' => $openIdOne_id), $openid); // create second openid $params = array('contact_id' => $contactId, 'location_type_id' => 1, 'endpoint_url' => $openid_two['endpoint_url'], 'claimed_id' => $openid_two['claimed_id'], 'display_id' => $openid_two['display_id']); $openObjectTwo = CRM_Core_BAO_OpenID::add($params); $openIdTwo_id = $openObjectTwo->id; $this->assertDBCompareValues('CRM_Core_DAO_OpenID', array('id' => $openIdTwo_id), $openid_two); // obtain all openids for the contact $openIds = CRM_Core_BAO_OpenID::allOpenIDs($contactId); // check number of openids for the contact $this->assertEquals(count($openIds), 2, 'Checking number of returned OpenIDs.'); // check first openid values $this->assertAttributesEquals($openid, $openIds[$openIdOne_id]); $this->assertEquals(1, $openIds[$openIdOne_id]['is_primary'], 'Confirm is_primary field value.'); $this->assertEquals(1, $openIds[$openIdOne_id]['allowed_to_login'], 'Confirm allowed_to_login field value.'); // check second openid values $this->assertAttributesEquals($openid_two, $openIds[$openIdTwo_id]); $this->assertEquals(0, $openIds[$openIdTwo_id]['is_primary'], 'Confirm is_primary field value for second openid.'); $this->assertEquals(0, $openIds[$openIdTwo_id]['allowed_to_login'], 'Confirm allowed_to_login field value for second openid.'); Contact::delete($contactId); }
function delete($id) { if ($id) { $rs = new Contact($id); $rs->delete(); set_notify('success', lang('delete_data_complete')); } redirect($_SERVER['HTTP_REFERER']); }
public function deleteDupeContacts() { // delete all created contacts foreach ($this->_contactIds as $contactId) { Contact::delete($contactId); } // delete dupe group $params = array('id' => $this->_groupId, 'version' => 3); civicrm_api('group', 'delete', $params); }
/** * AllEmails() method - get all emails for our contact, with primary email first */ public function testAllEmails() { $contactParams = array('first_name' => 'Alan', 'last_name' => 'Smith', 'email-1' => '*****@*****.**', 'email-2' => '*****@*****.**', 'email-3' => '*****@*****.**'); $contactId = Contact::createIndividual($contactParams); $emails = CRM_Core_BAO_Email::allEmails($contactId); $this->assertEquals(count($emails), 3, 'Checking number of returned emails.'); $firstEmailValue = array_slice($emails, 0, 1); $this->assertEquals('*****@*****.**', $firstEmailValue[0]['email'], 'Confirm primary email address value.'); $this->assertEquals(1, $firstEmailValue[0]['is_primary'], 'Confirm first email address is primary.'); Contact::delete($contactId); }
/** * AllIMs() method - get all IMs for our contact, with primary IM first */ public function testAllIMs() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/im_test.xml')); $contactId = 69; $IMs = CRM_Core_BAO_IM::allIMs($contactId); $this->assertEquals(count($IMs), 3, 'Checking number of returned IMs.'); $firstIMValue = array_slice($IMs, 0, 1); $this->assertEquals('alan1.smith1', $firstIMValue[0]['name'], 'Confirm primary IM value.'); $this->assertEquals(1, $firstIMValue[0]['is_primary'], 'Confirm first IM is primary.'); Contact::delete($contactId); }
/** * AllPhones() method - get all Phones for our contact, with primary Phone first */ public function testAllPhones() { $contactParams = array('first_name' => 'Alan', 'last_name' => 'Smith', 'phone-1' => '(415) 222-1011 x 221', 'phone-2' => '(415) 222-5432'); $contactId = Contact::createIndividual($contactParams); $Phones = CRM_Core_BAO_Phone::allPhones($contactId); $this->assertEquals(count($Phones), 2, 'Checking number of returned Phones.'); $firstPhoneValue = array_slice($Phones, 0, 1); // Since we're not passing in a location type to createIndividual above, CRM_Contact_BAO_Contact::createProfileContact uses default location // type for first phone and sets that to primary. $this->assertEquals('(415) 222-1011 x 221', $firstPhoneValue[0]['phone'], "Confirm primary Phone value ( {$firstPhoneValue[0]['phone']} )."); $this->assertEquals(1, $firstPhoneValue[0]['is_primary'], 'Confirm first Phone is primary.'); Contact::delete($contactId); }
/** * Delete contact * * @param int $id Contact ID * @return array * * @url DELETE contact/{id} */ function delete($id) { if (!DolibarrApiAccess::$user->rights->contact->supprimer) { throw new RestException(401); } $result = $this->contact->fetch($id); if (!$result) { throw new RestException(404, 'Contact not found'); } if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) { throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); } return $this->contact->delete($id); }
public function testCustomGroupMultipleOldFormate() { $params = array(); $contactID = Contact::createIndividual(); $customGroup = Custom::createGroup($params, 'Individual', TRUE); $fields = array('groupId' => $customGroup->id, 'dataType' => 'String', 'htmlType' => 'Text'); $customField = Custom::createField($params, $fields); $params = array('entityID' => $contactID, "custom_{$customField->id}" => 'First String'); $error = CRM_Core_BAO_CustomValueTable::setValues($params); $newParams = array('entityID' => $contactID, "custom_{$customField->id}" => 1); $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); $this->assertEquals($params["custom_{$customField->id}"], $result["custom_{$customField->id}_1"]); $this->assertEquals($params['entityID'], $result['entityID']); Custom::deleteField($customField); Custom::deleteGroup($customGroup); Contact::delete($contactID); }
/** * Renew stale membership. */ public function testStaleMembership() { $statusId = 3; $contactId = Contact::createIndividual(); $joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -1 year -15 days")); $endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day")); $params = array('contact_id' => $contactId, 'membership_type_id' => $this->_membershipTypeID, 'join_date' => $joinDate, 'start_date' => $startDate, 'end_date' => $endDate, 'source' => 'Payment', 'status_id' => $statusId); $ids = array(); $membership = CRM_Member_BAO_Membership::create($params, $ids); $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for created membership.'); $this->assertEquals($membership->status_id, $statusId, 'Verify correct status id is calculated.'); $this->assertEquals($membership->membership_type_id, $this->_membershipTypeID, 'Verify correct membership type id.'); //verify all dates. $dates = array('startDate' => 'start_date', 'joinDate' => 'join_date', 'endDate' => 'end_date'); foreach ($dates as $date => $dbDate) { $this->assertEquals($membership->{$dbDate}, ${$date}, "Verify correct {$date} is present."); } $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', $membership->id, 'id', 'membership_id', 'Database checked on membershiplog record.'); // this is a test and we dont want qfKey generation / validation // easier to suppress it, than change core code $config = CRM_Core_Config::singleton(); $config->keyDisable = TRUE; $membershipRenewal = new CRM_Core_Form(); $membershipRenewal->controller = new CRM_Core_Controller(); list($MembershipRenew) = CRM_Member_BAO_Membership::renewMembership($contactId, $this->_membershipTypeID, FALSE, $membershipRenewal, NULL, NULL, NULL, 1, NULL, NULL, NULL, FALSE, NULL); $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', $MembershipRenew->id, 'id', 'membership_id', 'Database checked on membershiplog record.'); $this->membershipDelete($membershipId); Contact::delete($contactId); }
/** * FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method */ public function testfixEventLevel() { $paramsSet['title'] = 'Price Set'; $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); $paramsSet['is_active'] = FALSE; $paramsSet['extends'] = 1; $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset'); $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => 10, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => 10), 'option_name' => array('1' => 10), 'option_weight' => array('1' => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1); $ids = array(); $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids); //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield'); $eventId = $this->_eventId; $participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55'); $participant = CRM_Event_BAO_Participant::add($participantParams); //Checking for participant added in the table. $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId, 'id', 'contact_id', $participant->id, 'Check DB for created participant'); $values = array(); $ids = array(); $params = array('id' => $participant->id); CRM_Event_BAO_Participant::getValues($params, $values, $ids); $this->assertNotEquals(count($values), 0, 'Checking for empty array.'); CRM_Event_BAO_Participant::resolveDefaults($values[$participant->id]); if ($values[$participant->id]['fee_level']) { CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']); } $deletePricefield = CRM_Price_BAO_PriceField::deleteField($pricefield->id); $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id, 'name', 'id', 'Check DB for non-existence of Price Field.'); $deletePriceset = CRM_Price_BAO_PriceSet::deleteSet($priceset->id); $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', 'Check DB for non-existence of Price Set.'); Participant::delete($participant->id); Contact::delete($this->_contactId); Event::delete($eventId); }
function testGetActiveGroups() { $contactId = Contact::createIndividual(); $customGrouptitle = 'Test Custom Group'; $groupParams = array('title' => $customGrouptitle, 'name' => 'test_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'weight' => 10, 'is_active' => 1); $customGroup = Custom::createGroup($groupParams); require_once 'CRM/Core/BAO/CustomGroup.php'; $activeGroup = CRM_Core_BAO_CustomGroup::getActiveGroups('Individual', 'civicrm/contact/view/cd', $contactId); foreach ($activeGroup as $key => $value) { if ($value['id'] == $customGroup->id) { $this->assertEquals($value['path'], 'civicrm/contact/view/cd'); $this->assertEquals($value['title'], $customGrouptitle); $query = 'reset=1&gid=' . $customGroup->id . '&cid=' . $contactId; $this->assertEquals($value['query'], $query); } } Custom::deleteGroup($customGroup); Contact::delete($contactId); }
/** * @covers Moneybird\Contact::delete */ public function testDelete() { $this->object->delete($this->service); $this->setExpectedException('Moneybird\\NotFoundException'); $this->service->getById(self::$contactId); }
$contact->check($_GET["id"], READ); $contact->generateVcard(); } else { if (isset($_POST["add"])) { $contact->check(-1, CREATE, $_POST); if ($newID = $contact->add($_POST)) { Event::log($newID, "contacts", 4, "financial", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])); if ($_SESSION['glpibackcreated']) { Html::redirect($contact->getFormURL() . "?id=" . $newID); } } Html::back(); } else { if (isset($_POST["delete"])) { $contact->check($_POST["id"], DELETE); if ($contact->delete($_POST)) { Event::log($_POST["id"], "contacts", 4, "financial", sprintf(__('%s deletes an item'), $_SESSION["glpiname"])); } $contact->redirectToList(); } else { if (isset($_POST["restore"])) { $contact->check($_POST["id"], DELETE); if ($contact->restore($_POST)) { Event::log($_POST["id"], "contacts", 4, "financial", sprintf(__('%s restores an item'), $_SESSION["glpiname"])); } $contact->redirectToList(); } else { if (isset($_POST["purge"])) { $contact->check($_POST["id"], PURGE); if ($contact->delete($_POST, 1)) { Event::log($_POST["id"], "contacts", 4, "financial", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
/** * Check duplicate contribution id * during the contribution import * checkDuplicateIds(); */ function testcheckDuplicateIds() { $contactId = Contact::createIndividual(); $ids = array('contribution' => null); $param = array('contact_id' => $contactId, 'currency' => 'USD', 'contribution_type_id' => 1, 'contribution_status_id' => 1, 'payment_instrument_id' => 1, 'source' => 'STUDENT', 'receive_date' => '20080522000000', 'receipt_date' => '20080522000000', 'id' => null, 'non_deductible_amount' => 0.0, 'total_amount' => 300.0, 'fee_amount' => 5, 'net_amount' => 295, 'trxn_id' => '22ereerwww323', 'invoice_id' => '22ed39c9e9ee621ce0eafe6da70', 'thankyou_date' => '20080522'); require_once 'CRM/Contribute/BAO/Contribution.php'; $contribution = CRM_Contribute_BAO_Contribution::create($param, $ids); $this->assertEquals($param['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.'); $this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.'); $data = array('id' => $contribution->id, 'trxn_id' => $contribution->trxn_id, 'invoice_id' => $contribution->invoice_id); $contributionID = CRM_Contribute_BAO_Contribution::checkDuplicateIds($data); $this->assertEquals($contributionID, $contribution->id, 'Check for duplicate transcation id .'); Contact::delete($contactId); }
/** * Delete third party in database * @param id id de la societe a supprimer */ function delete() { $result = parent::delete(); return $result; }
/** * Check credit note id creation * when a contribution is cancelled or refunded * createCreditNoteId(); */ public function testCreateCreditNoteId() { $contactId = Contact::createIndividual(); $ids = array('contribution' => NULL); $param = array('contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, 'contribution_status_id' => 3, 'payment_instrument_id' => 1, 'source' => 'STUDENT', 'receive_date' => '20080522000000', 'receipt_date' => '20080522000000', 'id' => NULL, 'non_deductible_amount' => 0.0, 'total_amount' => 300.0, 'fee_amount' => 5, 'net_amount' => 295, 'trxn_id' => '76ereeswww835', 'invoice_id' => '93ed39a9e9hd621bs0eafe3da82', 'thankyou_date' => '20080522'); $creditNoteId = CRM_Contribute_BAO_Contribution::createCreditNoteId(); $contribution = CRM_Contribute_BAO_Contribution::create($param, $ids); $this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.'); $this->assertEquals($creditNoteId, $contribution->creditnote_id, 'Check if credit note id is created correctly.'); // Delete Contribution $this->contributionDelete($contribution->id); // Delete Contact Contact::delete($contactId); }
* * Removes the contact from the database * * @author Angus Vine <*****@*****.**> * @version 1.0 * @since 5.5 (The php version used) */ require_once 'core/init.php'; //check if get variable exists if (Input::exists('get')) { $contact = new Contact(); //check if contact exists if ($contact->exists($_GET['id'])) { try { $id = $_GET['id']; $contact->delete($id); //remove contact Session::flash('home', 'The contact has been deleted successfully'); Redirect::to('index.php'); //redirect the user to the home page and display the message } catch (Exception $e) { die($e->getMessage()); Session::flash('home', $e->getMessage()); Redirect::to('index.php'); //redirect the user to the home page and display the error exit; } } else { Redirect::to('index.php'); } } else {
/** * GetValues() method (get Address fields) */ public function testGetValues() { $contactId = Contact::createIndividual(); $params = array(); $params['address']['1'] = array('street_address' => 'Oberoi Garden', 'supplemental_address_1' => 'Attn: Accounting', 'supplemental_address_2' => 'Powai', 'city' => 'Athens', 'postal_code' => '01903', 'state_province_id' => '1000', 'country_id' => '1228', 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973', 'location_type_id' => '1', 'is_primary' => '1', 'is_billing' => '0'); $params['contact_id'] = $contactId; $fixAddress = TRUE; CRM_Core_BAO_Address::create($params, $fixAddress, $entity = NULL); $addressId = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for created address.'); $entityBlock = array('contact_id' => $contactId); $address = CRM_Core_BAO_Address::getValues($entityBlock); $this->assertEquals($address[1]['id'], $addressId); $this->assertEquals($address[1]['contact_id'], $contactId); $this->assertEquals($address[1]['street_address'], 'Oberoi Garden'); Contact::delete($contactId); }
public function testContactDelete() { //Creating contact... Client::relateIQ(GlobalVar::KEY, GlobalVar::SECRET); $contact = new Contact([]); $contact->name("James McSales"); $contact->email(["*****@*****.**", "*****@*****.**"]); $contact->phone(["(888) 555-1234", "(888) 555-0000"]); $contact->address("123 Main St, USA"); $contact->company("RelateIQ"); $contact->title("Noob"); $contact->twhan("@jamesmcsales"); $res = $contact->create(); $id = $res->id(); $this->assertNotNull($id); // "Deleting contact..." $res2 = $contact->delete(); $this->assertEquals(true, $res2); // "Verifying deletion..." $contact2 = new Contact(["id" => $id]); $res3 = $contact2->exists(); $this->assertEquals(false, $res3); }
/** * checks db values for financial item */ public function checkItemValues($contribution) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType(4, $relationTypeId); $query = "SELECT eft1.entity_id, ft.total_amount, eft1.amount FROM civicrm_financial_trxn ft INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution') \nINNER JOIN civicrm_entity_financial_trxn eft1 ON (eft1.financial_trxn_id = eft.financial_trxn_id AND eft1.entity_table = 'civicrm_financial_item')\nWHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $queryParams[1] = array($contribution->id, 'Integer'); $queryParams[2] = array($toFinancialAccount, 'Integer'); $dao = CRM_Core_DAO::executeQuery($query, $queryParams); $amounts = array(100.0, 50.0); while ($dao->fetch()) { $this->assertEquals(150.0, $dao->total_amount, 'Mismatch of total amount paid.'); $this->assertEquals($dao->amount, array_pop($amounts), 'Mismatch of amount proportionally assigned to financial item'); } Contact::delete($this->_contactId); Event::delete($this->_eventId); }
/** * Helper for testing timestamp manipulation. * * Create a contact and perform a series of steps with it; after each * step, ensure that the contact's modified_date has increased. * * @param array $callbacks * ($name => $callable). */ public function _testTimestamps($callbacks) { CRM_Core_DAO::triggerRebuild(); $contactId = Contact::createIndividual(); $origTimestamps = CRM_Contact_BAO_Contact::getTimestamps($contactId); $this->assertRegexp('/^\\d\\d\\d\\d-\\d\\d-\\d\\d /', $origTimestamps['created_date']); $this->assertRegexp('/^\\d\\d\\d\\d-\\d\\d-\\d\\d /', $origTimestamps['modified_date']); $this->assertTrue($origTimestamps['created_date'] <= $origTimestamps['modified_date']); $prevTimestamps = $origTimestamps; foreach ($callbacks as $callbackName => $callback) { sleep(1); // advance clock by 1 second to ensure timestamps change $callback($contactId); $newTimestamps = CRM_Contact_BAO_Contact::getTimestamps($contactId); $this->assertRegexp('/^\\d\\d\\d\\d-\\d\\d-\\d\\d /', $newTimestamps['created_date'], "Malformed created_date (after {$callbackName})"); $this->assertRegexp('/^\\d\\d\\d\\d-\\d\\d-\\d\\d /', $newTimestamps['modified_date'], "Malformed modified_date (after {$callbackName})"); $this->assertEquals($origTimestamps['created_date'], $newTimestamps['created_date'], "Changed created_date (after {$callbackName})"); $this->assertTrue($prevTimestamps['modified_date'] < $newTimestamps['modified_date'], "Misordered modified_date (after {$callbackName})"); $prevTimestamps = $newTimestamps; } Contact::delete($contactId); }
public function testDeleteContactCascadesToDeleteEverythingItShould() { Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals(6, count(ContactState::GetAll())); $manager = UserTestHelper::createBasicUser('Godzilla'); $this->assertTrue($manager->save()); $account = new Account(); $account->name = 'Os Drogas Mais Legais'; $this->assertTrue($account->save()); $contact = new Contact(); $contact->title->value = 'Senhor'; $contact->firstName = 'José'; $contact->lastName = 'Olivereira'; $contact->jobTitle = 'Traficante'; $contact->primaryAddress->street1 = 'R. das Mulheres, 69'; $contact->primaryAddress->street2 = ''; $contact->primaryAddress->city = 'Centro'; $contact->primaryAddress->state = 'RJ'; $contact->primaryAddress->postalCode = ''; $contact->primaryAddress->country = 'Brasil'; $contact->primaryEmail->emailAddress = '*****@*****.**'; $contact->primaryEmail->optOut = 1; $contact->primaryEmail->isInvalid = 0; $contact->secondaryAddress->street1 = 'Passagem do Comando Vermelho'; $contact->secondaryAddress->street2 = ''; $contact->secondaryAddress->city = 'Complexo do Alemão'; $contact->secondaryAddress->state = 'RJ'; $contact->secondaryAddress->postalCode = ''; $contact->secondaryAddress->country = 'Brasil'; $contact->account = $account; $contact->state->name = 'Novo Hermão'; $contact->state->order = 6; $this->assertTrue($contact->save()); $titleId = $contact->title->id; $primaryAddressId = $contact->primaryAddress->id; $primaryEmailId = $contact->primaryEmail->id; $secondaryAddressId = $contact->secondaryAddress->id; $accountId = $account->id; $stateId = $contact->state->id; $this->assertEquals(7, count(ContactState::GetAll())); //new state created. Confirm this $contact->delete(); unset($contact); unset($manager); unset($account); User::getByUsername('godzilla'); Account::getById($accountId); ContactState::getById($stateId); try { CustomField::getById($titleId); $this->fail("Title should have been deleted."); } catch (NotFoundException $e) { } try { Address::getById($primaryAddressId); $this->fail("Primary address should have been deleted."); } catch (NotFoundException $e) { } try { Email::getById($primaryEmailId); $this->fail("Primary email should have been deleted."); } catch (NotFoundException $e) { } try { Address::getById($secondaryAddressId); $this->fail("Secondary address should have been deleted."); } catch (NotFoundException $e) { } }
/** * Test setValues() and getValues() methods with custom field YesNo(Boolean) Radio */ public function testSetGetValuesYesNoRadio() { $params = array(); $contactID = Contact::createIndividual(); //create Custom Group $customGroup = Custom::createGroup($params, 'Individual', TRUE); //create Custom Field of type YesNo(Boolean) Radio $fields = array('groupId' => $customGroup->id, 'dataType' => 'Boolean', 'htmlType' => 'Radio'); $customField = Custom::createField($params, $fields); // Retrieve the field ID for sample custom field 'test_Boolean' $params = array('label' => 'test_Boolean'); $field = array(); //get field Id CRM_Core_BAO_CustomField::retrieve($params, $field); $fieldID = $field['id']; // valid boolean value '1' for Boolean Radio $yesNo = '1'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $yesNo); $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the YesNo radio value is stored $values = array(); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); $this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the boolean value is stored for contact ' . $contactID); // Now set YesNo radio to an invalid boolean value and try to reset $badYesNo = '20'; $params = array('entityID' => $contactID, 'custom_' . $fieldID => $badYesNo); $errorScope = CRM_Core_TemporaryErrorScope::useException(); $message = NULL; try { $result = CRM_Core_BAO_CustomValueTable::setValues($params); } catch (Exception $e) { $message = $e->getMessage(); } $errorScope = NULL; // Check that an exception has been thrown $this->assertNotNull($message, 'Verify than an exception is thrown when bad boolean is passed'); $params = array('entityID' => $contactID, 'custom_' . $fieldID => 1); $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, 'Verify that the date value has NOT been updated for contact ' . $contactID); // Cleanup Custom::deleteField($customField); Custom::deleteGroup($customGroup); Contact::delete($contactID); }
public function testDupesByParams() { // make dupe checks based on based on following contact sets: // FIRST - LAST - EMAIL // --------------------------------- // robin - hood - robin@example.com // robin - hood - hood@example.com // robin - dale - robin@example.com // little - dale - dale@example.com // will - dale - dale@example.com // will - dale - will@example.com // will - dale - will@example.com // contact data set // FIXME: move create params to separate function $params = array(array('first_name' => 'robin', 'last_name' => 'hood', 'email' => '*****@*****.**', 'contact_type' => 'Individual'), array('first_name' => 'robin', 'last_name' => 'hood', 'email' => '*****@*****.**', 'contact_type' => 'Individual'), array('first_name' => 'robin', 'last_name' => 'dale', 'email' => '*****@*****.**', 'contact_type' => 'Individual'), array('first_name' => 'little', 'last_name' => 'dale', 'email' => '*****@*****.**', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => '*****@*****.**', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => '*****@*****.**', 'contact_type' => 'Individual'), array('first_name' => 'will', 'last_name' => 'dale', 'email' => '*****@*****.**', 'contact_type' => 'Individual')); $count = 1; // TODO: This is not an API test!! foreach ($params as $param) { $param['version'] = 3; $contact = civicrm_api('contact', 'create', $param); $params = array('contact_id' => $contact['id'], 'street_address' => 'Ambachtstraat 23', 'location_type_id' => 1, 'version' => 3); $result = civicrm_api('address', 'create', $params); $contactIds[$count++] = $contact['id']; } // verify that all contacts have been created separately $this->assertEquals(count($contactIds), 7, 'Check for number of contacts.'); $dao = new CRM_Dedupe_DAO_RuleGroup(); $dao->contact_type = 'Individual'; $dao->used = 'General'; $dao->is_default = 1; $dao->find(TRUE); $fields = array('first_name' => 'robin', 'last_name' => 'hood', 'email' => '*****@*****.**', 'street_address' => 'Ambachtstraat 23'); $errorScope = CRM_Core_TemporaryErrorScope::useException(); $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual'); $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'General'); // Check with default Individual-General rule $this->assertEquals(count($ids), 2, 'Check Individual-General rule for dupesByParams().'); // delete all created contacts foreach ($contactIds as $contactId) { Contact::delete($contactId); } }
public function removeOrganization() { //delete organization roles $this->removeOrganizationRoles(); $instance = new Alias(); foreach ($this->getAliases() as $instance) { $instance->delete(); } $instance = new Contact(); foreach ($this->getContacts() as $instance) { $instance->removeContactRoles(); $instance->delete(); } $instance = new ExternalLogin(); foreach ($this->getExternalLogins() as $instance) { $instance->delete(); } $instance = new IssueLog(); foreach ($this->getIssueLog() as $instance) { $instance->delete(); } //delete parent and child relationships $this->removeOrganizationHierarchy(); $this->delete(); }
/** * Test case for deleteActivityAssignment() method. * * deleteActivityAssignment($activityId) method deletes activity assignment for given activity id. */ public function testDeleteActivityAssignment() { $contactId = Contact::createIndividual(); $params = array('first_name' => 'liz', 'last_name' => 'hurleey'); $assigneeContactId = Contact::createIndividual($params); $params = array('source_contact_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, 'assignee_contact_id' => array($assigneeContactId), 'activity_date_time' => date('Ymd')); CRM_Activity_BAO_Activity::create($params); $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id', 'subject', 'Database check for created activity.'); $activityAssignmentId = $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $assigneeContactId, 'id', 'contact_id', 'Database check for created activity assignment.'); CRM_Activity_BAO_Activity::deleteActivityContact($activityId, 1); $this->assertDBNull('CRM_Activity_DAO_ActivityContact', $assigneeContactId, 'id', 'contact_id', 'Database check for deleted activity assignment.'); Contact::delete($contactId); Contact::delete($assigneeContactId); }
/** * getValues() method * get the values of various location elements */ function testLocBlockgetValues() { $contactId = Contact::createIndividual(); //create various element of location block //like address, phone, email, openid, im. $params = array('address' => array('1' => array('street_address' => 'Saint Helier St', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', 'city' => 'Newark', 'postal_code' => '01903', 'country_id' => 1228, 'state_province_id' => 1029, 'geo_code_1' => '18.219023', 'geo_code_2' => '-105.00973', 'is_primary' => 1, 'location_type_id' => 1)), 'email' => array('1' => array('email' => '*****@*****.**', 'is_primary' => 1, 'location_type_id' => 1)), 'phone' => array('1' => array('phone_type_id' => 1, 'phone' => '303443689', 'is_primary' => 1, 'location_type_id' => 1), '2' => array('phone_type_id' => 2, 'phone' => '9833910234', 'location_type_id' => 1)), 'openid' => array('1' => array('openid' => 'http://civicrm.org/', 'location_type_id' => 1, 'is_primary' => 1)), 'im' => array('1' => array('name' => 'jane.doe', 'provider_id' => 1, 'location_type_id' => 1, 'is_primary' => 1))); $params['contact_id'] = $contactId; //create location elements. require_once 'CRM/Core/BAO/Location.php'; CRM_Core_BAO_Location::create($params); //get the values from DB $values = array(); $entityBlock = array('contact_id' => $contactId); $values = CRM_Core_BAO_Location::getValues($entityBlock); //Now check values of address $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['address']), CRM_Utils_Array::value('1', $values['address'])); //Now check values of email $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['email']), CRM_Utils_Array::value('1', $values['email'])); //Now check values of phone $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['phone']), CRM_Utils_Array::value('1', $values['phone'])); //Now check values of mobile $this->assertAttributesEquals(CRM_Utils_Array::value('2', $params['phone']), CRM_Utils_Array::value('2', $values['phone'])); //Now check values of openid $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['openid']), CRM_Utils_Array::value('1', $values['openid'])); //Now check values of im $this->assertAttributesEquals(CRM_Utils_Array::value('1', $params['im']), CRM_Utils_Array::value('1', $values['im'])); //cleanup DB by deleting the contact Contact::delete($contactId); }
function index_delete() { $models = json_decode($this->delete('models')); foreach ($models as $key => $value) { $obj = new Contact(null, $this->entity); $obj->where("id", $value->id)->get(); $data["results"][] = array("data" => $value, "status" => $obj->delete()); } //Response data $this->response($data, 200); }
/** * Transfer contacts of an enterprise * * @param $ID original ID of the enterprise * @param $newID new ID of the enterprise **/ function transferSupplierContacts($ID, $newID) { global $DB; $need_clean_process = false; // if keep if ($this->options['keep_contact']) { $contact = new Contact(); // Get contracts for the item $query = "SELECT *\n FROM `glpi_contacts_suppliers`\n WHERE `suppliers_id` = '{$ID}'\n AND `contacts_id` NOT IN " . $this->item_recurs['Contact']; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { // Foreach get item while ($data = $DB->fetch_array($result)) { $need_clean_process = false; $item_ID = $data['contacts_id']; $newcontactID = -1; // is already transfer ? if (isset($this->already_transfer['Contact'][$item_ID])) { $newcontactID = $this->already_transfer['Contact'][$item_ID]; if ($newcontactID != $item_ID) { $need_clean_process = true; } } else { $canbetransfer = true; // Transfer enterprise : is the contact used for another enterprise ? if ($ID == $newID) { $query_search = "SELECT count(*) AS CPT\n FROM `glpi_contacts_suppliers`\n WHERE `contacts_id` = '{$item_ID}'\n AND `suppliers_id`\n NOT IN " . $this->item_search['Supplier'] . "\n AND `suppliers_id`\n NOT IN " . $this->item_recurs['Supplier']; $result_search = $DB->query($query_search); if ($DB->result($result_search, 0, 'CPT') > 0) { $canbetransfer = false; } } // Yes : transfer if ($canbetransfer) { $this->transferItem('Contact', $item_ID, $item_ID); $newcontactID = $item_ID; } else { $need_clean_process = true; $contact->getFromDB($item_ID); // No : search contract $query = "SELECT *\n FROM `glpi_contacts`\n WHERE `entities_id` = '" . $this->to . "'\n AND `name` = '" . addslashes($contact->fields['name']) . "'\n AND `firstname`\n = '" . addslashes($contact->fields['firstname']) . "'"; if ($result_search = $DB->query($query)) { if ($DB->numrows($result_search) > 0) { $newcontactID = $DB->result($result_search, 0, 'id'); $this->addToAlreadyTransfer('Contact', $item_ID, $newcontactID); } } // found : use it // not found : copy contract if ($newcontactID < 0) { // 1 - create new item unset($contact->fields['id']); $input = $contact->fields; $input['entities_id'] = $this->to; unset($contact->fields); $newcontactID = $contact->add($input); // 2 - transfer as copy $this->transferItem('Contact', $item_ID, $newcontactID); } } } // Update links if ($ID == $newID) { if ($item_ID != $newcontactID) { $query = "UPDATE `glpi_contacts_suppliers`\n SET `contacts_id` = '{$newcontactID}'\n WHERE `id` = '" . $data['id'] . "'"; $DB->query($query); } // Same Item -> update links } else { // Copy Item -> copy links if ($item_ID != $newcontactID) { $query = "INSERT\n INTO `glpi_contacts_suppliers`\n (`contacts_id`, `suppliers_id`)\n VALUES ('{$newcontactID}','{$newID}')"; $DB->query($query); } else { // transfer contact but copy enterprise : update link $query = "UPDATE `glpi_contacts_suppliers`\n SET `suppliers_id` = '{$newID}'\n WHERE `id` = '" . $data['id'] . "'"; $DB->query($query); } } // If clean and unused -> if ($need_clean_process && $this->options['clean_contact']) { $query = "SELECT COUNT(*) AS CPT\n FROM `glpi_contacts_suppliers`\n WHERE `contacts_id` = '{$item_ID}'"; if ($result_remaining = $DB->query($query)) { if ($DB->result($result_remaining, 0, 'CPT') == 0) { if ($this->options['clean_contact'] == 1) { $contact->delete(array('id' => $item_ID)); } if ($this->options['clean_contact'] == 2) { // purge $contact->delete(array('id' => $item_ID), 1); } } } } } } } } else { // else unlink $query = "DELETE\n FROM `glpi_contacts_suppliers`\n WHERE `suppliers_id` = '{$ID}'"; $DB->query($query); } }
public function removeResource() { //delete data from child linked tables $this->removeResourceRelationships(); $this->removePurchaseSites(); $this->removeAuthorizedSites(); $this->removeAdministeringSites(); $this->removeResourceLicenses(); $this->removeResourceLicenseStatuses(); $this->removeResourceOrganizations(); $this->removeResourcePayments(); $this->removeAllSubjects(); $this->removeAllIsbnOrIssn(); $instance = new Contact(); foreach ($this->getContacts() as $instance) { $instance->removeContactRoles(); $instance->delete(); } $instance = new ExternalLogin(); foreach ($this->getExternalLogins() as $instance) { $instance->delete(); } $instance = new ResourceNote(); foreach ($this->getNotes() as $instance) { $instance->delete(); } $instance = new Attachment(); foreach ($this->getAttachments() as $instance) { $instance->delete(); } $instance = new Alias(); foreach ($this->getAliases() as $instance) { $instance->delete(); } $this->delete(); }