From 93ac19cd9462a3a83d98c85123c15accfadb9876 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 27 Apr 2016 15:38:32 +1200 Subject: [PATCH] Test clean up. Standardise delete contact calls. There are 2 different methods in play for deleting contacts in tests. The one I'm removing uses a non-standard path & sometimes causes loading issues when run in isolation, as well as being the less used. Other functions could do with the same treatment. Some unused vars removed too --- .../phpunit/CRM/Activity/BAO/ActivityTest.php | 26 ++++++------- tests/phpunit/CRM/Contact/BAO/ContactTest.php | 38 +++++++++---------- .../CRM/Contribute/BAO/ContributionTest.php | 24 ++++++------ tests/phpunit/CRM/Core/BAO/AddressTest.php | 14 +++---- .../phpunit/CRM/Core/BAO/CustomGroupTest.php | 2 +- .../Core/BAO/CustomValueTableMultipleTest.php | 8 ++-- .../Core/BAO/CustomValueTableSetGetTest.php | 4 +- .../CRM/Core/BAO/CustomValueTableTest.php | 14 +++---- tests/phpunit/CRM/Core/BAO/EmailTest.php | 7 ++-- tests/phpunit/CRM/Core/BAO/IMTest.php | 4 +- tests/phpunit/CRM/Core/BAO/LocationTest.php | 15 +++----- tests/phpunit/CRM/Core/BAO/OpenIDTest.php | 1 - tests/phpunit/CRM/Core/BAO/PhoneTest.php | 4 +- tests/phpunit/CRM/Dedupe/DedupeFinderTest.php | 5 +-- tests/phpunit/CRM/Dedupe/MergerTest.php | 6 ++- .../phpunit/CRM/Event/BAO/ParticipantTest.php | 30 +++++++-------- .../phpunit/CRM/Member/BAO/MembershipTest.php | 28 +++++++------- tests/phpunit/CiviTest/Contact.php | 13 ------- 18 files changed, 112 insertions(+), 131 deletions(-) diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index 199b4c19d0..7e3bf5f1d6 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -52,7 +52,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { ); $this->assertEquals($activityTypeId, 3, 'Verify activity type id is 3.'); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -87,8 +87,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->assertEquals($activities[$activityId]['subject'], 'Scheduling Meeting', 'Verify activity subject is correct.'); - Contact::delete($contactId); - Contact::delete($targetContactId); + $this->contactDelete($contactId); + $this->contactDelete($targetContactId); } /** @@ -136,8 +136,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { $this->assertEquals($defaults['target_contact'][0], $targetContactId, 'Verify target contact id is correct.'); - Contact::delete($contactId); - Contact::delete($targetContactId); + $this->contactDelete($contactId); + $this->contactDelete($targetContactId); } /** @@ -179,13 +179,13 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'activity_type_id' => 2, ); - $result = CRM_Activity_BAO_Activity::deleteActivity($params); + CRM_Activity_BAO_Activity::deleteActivity($params); - $activityId = $this->assertDBNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id', + $this->assertDBNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id', 'subject', 'Database check for deleted activity.' ); - Contact::delete($contactId); - Contact::delete($targetContactId); + $this->contactDelete($contactId); + $this->contactDelete($targetContactId); } /** @@ -226,8 +226,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'contact_id', 'Database check for deleted activity target.' ); - Contact::delete($contactId); - Contact::delete($targetContactId); + $this->contactDelete($contactId); + $this->contactDelete($targetContactId); } /** @@ -268,8 +268,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { 'contact_id', 'Database check for deleted activity assignment.' ); - Contact::delete($contactId); - Contact::delete($assigneeContactId); + $this->contactDelete($contactId); + $this->contactDelete($assigneeContactId); } /** diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index f95785c25d..38188bb6d6 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -67,7 +67,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($firstName, $contact->first_name, 'Check for updated first name.'); $contactId = $contact->id; - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -210,7 +210,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { } $this->assertAttributesEquals($checkPrefComm, $prefComm); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -242,7 +242,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($firstName, $contact->first_name, 'Check for updated first name.'); $contactId = $contact->id; - Contact::delete($contactId); + $this->contactDelete($contactId); $householdName = 'Adams house'; $params = array( @@ -262,7 +262,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { ); $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($householdName, $contact->sort_name, 'Check for updated household.'); - Contact::delete($contactId); + $this->contactDelete($contactId); $organizationName = 'My Organization'; $params = array( @@ -282,7 +282,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { ); $contact = CRM_Contact_BAO_Contact::add($params); $this->assertEquals($organizationName, $contact->sort_name, 'Check for updated organization.'); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -493,7 +493,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { CRM_Core_BAO_Note::cleanContactNotes($contactId); // Cleanup DB by deleting the contact. - Contact::delete($contactId); + $this->contactDelete($contactId); $this->quickCleanup(array('civicrm_contact', 'civicrm_note')); } @@ -624,14 +624,14 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //Now check values of Relationship type. $this->assertEquals('Employee of', $val['relation'], 'Check for relationship type'); //delete the organization. - Contact::delete(CRM_Utils_Array::value('contact_id_b', $val)); + $this->contactDelete(CRM_Utils_Array::value('contact_id_b', $val)); } //delete all notes related to contact CRM_Core_BAO_Note::cleanContactNotes($contactId); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); $this->quickCleanup(array('civicrm_contact')); } @@ -893,7 +893,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //Now check values of Relationship type. $this->assertEquals('Employee of', $val['relation'], 'Check for relationship type'); //delete the organization. - Contact::delete(CRM_Utils_Array::value('cid', $val)); + $this->contactDelete(CRM_Utils_Array::value('cid', $val)); } //Now check values of tag ids. @@ -1096,7 +1096,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { //Now check values of Relationship type. $this->assertEquals('Employee of', $val['relation'], 'Check for relationship type'); //delete the organization. - Contact::delete(CRM_Utils_Array::value('cid', $val)); + $this->contactDelete(CRM_Utils_Array::value('cid', $val)); } //Now check values of tag ids. @@ -1107,7 +1107,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertAttributesEquals($updatePfParams['tag'], $tagIds); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -1132,7 +1132,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertAttributesEquals($compareParams, $contactDetails); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); $this->quickCleanup(array('civicrm_contact')); } @@ -1180,7 +1180,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($email, CRM_Utils_Array::value('email', $params['email'][2]), 'Check Primary Email'); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); $this->quickCleanup(array('civicrm_contact')); } @@ -1205,7 +1205,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($openID, strtolower($params['openid'][2]['openid']), 'Check Primary OpenID'); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -1225,7 +1225,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($contactId, $match->contact_id, 'Check For Matching Contact'); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); $this->quickCleanup(array('civicrm_contact')); } @@ -1244,7 +1244,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($contactType, $params['contact_type'], 'Check For Contact Type'); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); $this->quickCleanup(array('civicrm_contact')); } @@ -1271,7 +1271,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($dbDisplayName, $paramsDisplayName, 'Check For Display Name'); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); $this->quickCleanup(array('civicrm_contact')); } @@ -1301,7 +1301,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals($image, $checkImage, 'Check For Image'); //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -1560,7 +1560,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $prevTimestamps = $newTimestamps; } - Contact::delete($contactId); + $this->contactDelete($contactId); } } diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index f7e8603c78..b5f030aa0e 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -78,7 +78,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->contributionDelete($contribution->id); //Delete Contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -148,7 +148,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->contributionDelete($contribution->id); Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -187,7 +187,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->assertDBNull('CRM_Contribute_DAO_Contribution', $contribution->trxn_id, 'id', 'trxn_id', 'Database check for deleted Contribution.' ); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -278,13 +278,13 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { ); //Delete honor contact - Contact::delete($honoreeContactId); + $this->contactDelete($honoreeContactId); //Delete Contribution record $this->contributionDelete($contribution->id); //Delete contributor contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -340,7 +340,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { //Delete Contribution $this->contributionDelete($contribution->id); //Delete Contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -414,7 +414,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { //Delete Contribution $this->contributionDelete($contribution->id); //Delete Contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -461,7 +461,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { // Delete Contribution $this->contributionDelete($contribution->id); // Delete Contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -501,7 +501,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { // Delete Contribution $this->contributionDelete($contribution->id); // Delete Contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -564,7 +564,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->contributionDelete($contribution->id); //Delete Contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -631,7 +631,7 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { $this->contributionDelete($contribution->id); //Delete Contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -665,7 +665,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $this->assertEquals($dao->amount, array_pop($amounts), 'Mismatch of amount proportionally assigned to financial item'); } - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } diff --git a/tests/phpunit/CRM/Core/BAO/AddressTest.php b/tests/phpunit/CRM/Core/BAO/AddressTest.php index 8d2cdc801d..e16dbafbeb 100644 --- a/tests/phpunit/CRM/Core/BAO/AddressTest.php +++ b/tests/phpunit/CRM/Core/BAO/AddressTest.php @@ -89,13 +89,13 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { $block = CRM_Core_BAO_Address::create($params, $fixAddress, $entity = NULL); - $cid = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', + $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id', 'Database check for updated address by contactId.' ); - $addressId = $this->assertDBNotNull('CRM_Core_DAO_Address', '120 Terminal Road', 'id', 'street_address', + $this->assertDBNotNull('CRM_Core_DAO_Address', '120 Terminal Road', 'id', 'street_address', 'Database check for updated address by street_name.' ); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -134,7 +134,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { $this->assertEquals($addAddress->geo_code_1, '31.694842', 'In line' . __LINE__); $this->assertEquals($addAddress->geo_code_2, '-106.29998', 'In line' . __LINE__); $this->assertEquals($addAddress->country_id, '1228', 'In line' . __LINE__); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -192,7 +192,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { $this->assertEquals(count($allAddress), 2, 'Checking number of returned addresses.'); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -230,7 +230,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { $this->assertEquals($allAddress, NULL, 'Checking null for returned addresses.'); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -270,7 +270,7 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { $this->assertEquals($address[1]['id'], $addressId); $this->assertEquals($address[1]['contact_id'], $contactId); $this->assertEquals($address[1]['street_address'], 'Oberoi Garden'); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** diff --git a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php index ac6962f058..07467efdd4 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php @@ -449,7 +449,7 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { } Custom::deleteGroup($customGroup); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTableMultipleTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTableMultipleTest.php index 524da4a74d..9b17c612bf 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTableMultipleTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTableMultipleTest.php @@ -38,7 +38,7 @@ class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } public function testCustomGroupMultipleDouble() { @@ -71,7 +71,7 @@ class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } public function testCustomGroupMultipleUpdate() { @@ -113,7 +113,7 @@ class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } public function testCustomGroupMultipleOldFormate() { @@ -144,7 +144,7 @@ class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } } diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php index 7644e85d29..e633279f9a 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php @@ -106,7 +106,7 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Cleanup Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } /** @@ -192,7 +192,7 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Cleanup Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } } diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTableTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTableTest.php index c1cd9673f3..f8846716e5 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTableTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTableTest.php @@ -43,7 +43,7 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } /** @@ -78,7 +78,7 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } /** @@ -112,7 +112,7 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } /** @@ -147,7 +147,7 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } /** @@ -182,7 +182,7 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } /** @@ -223,7 +223,7 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { ); Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } public function testCustomGroupMultiple() { @@ -256,7 +256,7 @@ class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { Custom::deleteField($customField); Custom::deleteGroup($customGroup); - Contact::delete($contactID); + $this->contactDelete($contactID); } } diff --git a/tests/phpunit/CRM/Core/BAO/EmailTest.php b/tests/phpunit/CRM/Core/BAO/EmailTest.php index 0adb529215..4dbe37c5cd 100644 --- a/tests/phpunit/CRM/Core/BAO/EmailTest.php +++ b/tests/phpunit/CRM/Core/BAO/EmailTest.php @@ -50,7 +50,7 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { ); $this->assertEquals($isBulkMail, 1, 'Verify bulkmail value is 1.'); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -59,7 +59,6 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { public function testHoldEmail() { $contactId = Contact::createIndividual(); - $params = array(); $params = array( 'email' => 'jane.doe@example.com', 'is_primary' => 1, @@ -123,7 +122,7 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { 'Compare reset_date (' . $resetDate . ') in DB to current year.' ); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -149,7 +148,7 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { $this->assertEquals('alan.smith1@example.com', $firstEmailValue[0]['email'], 'Confirm primary email address value.'); $this->assertEquals(1, $firstEmailValue[0]['is_primary'], 'Confirm first email address is primary.'); - Contact::delete($contactId); + $this->contactDelete($contactId); } } diff --git a/tests/phpunit/CRM/Core/BAO/IMTest.php b/tests/phpunit/CRM/Core/BAO/IMTest.php index 39b81a2831..d9797ff1a4 100644 --- a/tests/phpunit/CRM/Core/BAO/IMTest.php +++ b/tests/phpunit/CRM/Core/BAO/IMTest.php @@ -47,7 +47,7 @@ class CRM_Core_BAO_IMTest extends CiviUnitTestCase { $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'name', 'id', 'Database check on updated IM name record.'); $this->assertEquals($isEditIM, 'doe.jane', 'Verify IM provider_id value is doe.jane.'); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -70,7 +70,7 @@ class CRM_Core_BAO_IMTest extends CiviUnitTestCase { $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); + $this->contactDelete($contactId); } } diff --git a/tests/phpunit/CRM/Core/BAO/LocationTest.php b/tests/phpunit/CRM/Core/BAO/LocationTest.php index 696c3d693a..3d6d037e2f 100644 --- a/tests/phpunit/CRM/Core/BAO/LocationTest.php +++ b/tests/phpunit/CRM/Core/BAO/LocationTest.php @@ -78,8 +78,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { 'Database check, Address created successfully.' ); - //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -201,9 +200,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { //delete the location block CRM_Core_BAO_Location::deleteLocBlock($locBlockId); - - //cleanup DB by deleting the contact - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -354,7 +351,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { //cleanup DB by deleting the record. Event::delete($eventId); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); } /** @@ -442,7 +439,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { //cleanup DB by deleting the record. Event::delete($eventId); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); //Now check DB for Event $this->assertDBNull('CRM_Event_DAO_Event', $eventId, 'id', 'id', @@ -549,9 +546,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $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); + $this->contactDelete($contactId); } } diff --git a/tests/phpunit/CRM/Core/BAO/OpenIDTest.php b/tests/phpunit/CRM/Core/BAO/OpenIDTest.php index dbf8d55fe1..3531bc8293 100644 --- a/tests/phpunit/CRM/Core/BAO/OpenIDTest.php +++ b/tests/phpunit/CRM/Core/BAO/OpenIDTest.php @@ -167,7 +167,6 @@ class CRM_Core_BAO_OpenIDTest extends CiviUnitTestCase { $this->assertEquals(0, $openIds[$openIdTwo]['is_primary'], 'Confirm is_primary field value for second openid.'); $this->assertEquals(0, $openIds[$openIdTwo]['allowed_to_login'], 'Confirm allowed_to_login field value for second openid.'); - //Contact::delete($contactId); $this->contactDelete($contactId); $this->assertDBRowNotExist('CRM_Contact_DAO_Contact', $contactId); } diff --git a/tests/phpunit/CRM/Core/BAO/PhoneTest.php b/tests/phpunit/CRM/Core/BAO/PhoneTest.php index 4d6940e34f..4f1779cd14 100644 --- a/tests/phpunit/CRM/Core/BAO/PhoneTest.php +++ b/tests/phpunit/CRM/Core/BAO/PhoneTest.php @@ -75,7 +75,7 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase { "Check if phone field has expected value in updated record ( civicrm_phone.id={$phoneId} )." ); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -102,7 +102,7 @@ class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase { $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); + $this->contactDelete($contactId); } /** diff --git a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php index b624c1ad5e..7f2be57ed3 100644 --- a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php +++ b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php @@ -113,9 +113,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { // so 1 pair for - first + last + mail $this->assertEquals(count($foundDupes), 1, 'Check Individual-Fuzzy dupe rule for dupesInGroup().'); - // delete all created contacts foreach ($contactIds as $contactId) { - Contact::delete($contactId); + $this->contactDelete($contactId); } // delete dupe group $params = array('id' => $groupId, 'version' => 3); @@ -220,7 +219,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { // delete all created contacts foreach ($contactIds as $contactId) { - Contact::delete($contactId); + $this->contactDelete($contactId); } } diff --git a/tests/phpunit/CRM/Dedupe/MergerTest.php b/tests/phpunit/CRM/Dedupe/MergerTest.php index 27680ae0d0..c8f02362ff 100644 --- a/tests/phpunit/CRM/Dedupe/MergerTest.php +++ b/tests/phpunit/CRM/Dedupe/MergerTest.php @@ -109,10 +109,12 @@ class CRM_Dedupe_MergerTest extends CiviUnitTestCase { } } + /** + * Delete all created contacts. + */ public function deleteDupeContacts() { - // delete all created contacts foreach ($this->_contactIds as $contactId) { - Contact::delete($contactId); + $this->contactDelete($contactId); } // delete dupe group diff --git a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php index 3f883e9557..858be899c5 100644 --- a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php @@ -80,7 +80,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'id', 3, 'Check DB for updated status id of the participant' ); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -125,7 +125,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { } Participant::delete($participantId); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -134,11 +134,11 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { */ public function testgetValuesWithoutValidParams() { $params = $values = $ids = array(); - $participantId = Participant::create($this->_contactId, $this->_eventId); + Participant::create($this->_contactId, $this->_eventId); $fetchParticipant = CRM_Event_BAO_Participant::getValues($params, $values, $ids); $this->assertNull($fetchParticipant); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -158,7 +158,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $this->assertEquals($eventFull, 'This event is full.', 'Checking if Event is full.'); Participant::delete($participantId); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -169,7 +169,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $importableFields = CRM_Event_BAO_Participant::importableFields(); $this->assertNotEquals(count($importableFields), 0, 'Checking array not to be empty.'); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -187,7 +187,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $this->assertEquals($participantDetails['title'], $params['title'], 'Checking Event Title in which participant is enroled.'); Participant::delete($participantId); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -218,10 +218,10 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'id', $this->_contactId, 'Check DB for contact of the participant' ); - $deleteParticipant = CRM_Event_BAO_Participant::deleteParticipant($participant->id); + CRM_Event_BAO_Participant::deleteParticipant($participant->id); $this->assertDBNull('CRM_Event_BAO_Participant', $participant->id, 'contact_id', 'id', 'Check DB for deleted Participant.'); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -251,7 +251,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $partidel[] = Participant::delete($partiId[$i]); } - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -320,7 +320,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'contact_id', 'Check DB for deleted participant. Should be NULL.' ); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -331,7 +331,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $exportableFields = CRM_Event_BAO_Participant::exportableFields(); $this->assertNotEquals(count($exportableFields), 0, 'Checking array not to be empty.'); - Contact::delete($this->_contactId); + $this->contactDelete($this->_contactId); Event::delete($this->_eventId); } @@ -411,18 +411,18 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']); } - $deletePricefield = CRM_Price_BAO_PriceField::deleteField($pricefield->id); + 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); + 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); + $this->contactDelete($this->_contactId); Event::delete($eventId); } diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index 30fb7af85a..e5eca8705a 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -63,7 +63,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { public function tearDown() { $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); $this->membershipStatusDelete($this->_membershipStatusID); - Contact::delete($this->_contactID); + $this->contactDelete($this->_contactID); $this->_contactID = $this->_membershipStatusID = $this->_membershipTypeID = NULL; } @@ -114,7 +114,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $this->assertEquals($membershipTypeId, $this->_membershipTypeID, 'Verify membership type id is fetched.'); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } public function testGetValues() { @@ -172,7 +172,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $this->membershipDelete($membershipId1); $this->membershipDelete($membershipId2); - Contact::delete($contactId); + $this->contactDelete($contactId); } public function testRetrieve() { @@ -260,7 +260,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $this->membershipDelete($membershipId1); $this->membershipDelete($membershipId2); - Contact::delete($contactId); + $this->contactDelete($contactId); } public function testDeleteMembership() { @@ -284,10 +284,10 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { ); CRM_Member_BAO_Membership::del($membershipId); - $membershipId = $this->assertDBNull('CRM_Member_BAO_Membership', $contactId, 'id', + $this->assertDBNull('CRM_Member_BAO_Membership', $contactId, 'id', 'contact_id', 'Database check for deleted membership.' ); - Contact::delete($contactId); + $this->contactDelete($contactId); } public function testGetContactMembership() { @@ -315,7 +315,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $this->assertEquals($membership['id'], $membershipId, 'Verify membership record is retrieved.'); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } @@ -345,7 +345,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $membership[$membershipId]['renewPageId'] = CRM_Member_BAO_Membership::getContributionPageId($membershipId); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -377,7 +377,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { CRM_Member_BAO_Membership::getMembershipStarts($this->_membershipTypeID, $yearStart, $currentDate); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -408,7 +408,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { CRM_Member_BAO_Membership::getMembershipCount($this->_membershipTypeID, $currentDate, $test); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } @@ -444,7 +444,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { ); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -474,7 +474,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -540,7 +540,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { $this->assertEquals($endDate, $MembershipRenew->end_date, 'Verify correct end date is calculated after membership renewal'); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } /** @@ -624,7 +624,7 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { ); $this->membershipDelete($membershipId); - Contact::delete($contactId); + $this->contactDelete($contactId); } } diff --git a/tests/phpunit/CiviTest/Contact.php b/tests/phpunit/CiviTest/Contact.php index 03c65c488d..5724e657bb 100644 --- a/tests/phpunit/CiviTest/Contact.php +++ b/tests/phpunit/CiviTest/Contact.php @@ -86,17 +86,4 @@ class Contact extends CiviUnitTestCase { return $organization->id; } - /** - * Helper function to delete a contact. - * - * @param int $contactID - * Id of the contact to delete. - * @return bool - * true if contact deleted, false otherwise - */ - public static function delete($contactID) { - require_once 'CRM/Contact/BAO/Contact.php'; - return CRM_Contact_BAO_Contact::deleteContact($contactID); - } - } -- 2.25.1