From 2eac52b6faea20fd85007e7532373147ffafe1d5 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 18 Oct 2014 22:20:05 +0100 Subject: [PATCH] Delete linked entities test case --- .../CRM/Core/BAO/RecurringEntityTest.php | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php index 2d888bc297..8e7c6a86af 100644 --- a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php +++ b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php @@ -124,7 +124,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { * Testing Event Generation through Entity Recursion */ function testEventGeneration() { - //Event set initial params + //Event set initial params $daoEvent = new CRM_Event_DAO_Event(); $daoEvent->title = 'Test event for Recurring Entity'; $daoEvent->event_type_id = 3; @@ -212,5 +212,55 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { foreach ($generatedEntities['civicrm_event'] as $entityID) { $this->assertDBCompareValue('CRM_Event_DAO_Event', $entityID, 'title', 'id', 'Event Changed', 'Check if title was updated'); } + + end($generatedEntities['civicrm_event']); + $key = key($generatedEntities['civicrm_event']); + + end($generatedEntities['civicrm_tell_friend']); + $actKey = key($generatedEntities['civicrm_tell_friend']); + + //Check if both(event/tell a friend) keys are same + $this->assertEquals($key, $actKey, "Check if both the keys are same"); + + //Cross check event exists before we test deletion + $searchParamsEventBeforeDelete = array('entity_id' => $generatedEntities['civicrm_event'][$key], + 'entity_table' => 'civicrm_event' + ); + $expectedValuesEventBeforeDelete = array('entity_id' => $generatedEntities['civicrm_event'][$key], + 'entity_table' => 'civicrm_event' + ); + $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsEventBeforeDelete, $expectedValuesEventBeforeDelete); + + //Cross check event exists before we test deletion + $searchParamsTellAFriendBeforeDelete = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], + 'entity_table' => 'civicrm_tell_friend' + ); + $expectedValuesTellAFriendBeforeDelete = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], + 'entity_table' => 'civicrm_tell_friend' + ); + $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsTellAFriendBeforeDelete, $expectedValuesTellAFriendBeforeDelete); + + //Delete an event from recurring set and respective linked entity should be deleted from civicrm_recurring_entity_table + $daoRecurEvent = new CRM_Event_DAO_Event(); + $daoRecurEvent->id = $generatedEntities['civicrm_event'][$key]; + if ($daoRecurEvent->find(TRUE)) { + $daoRecurEvent->delete(); + $daoRecurEvent->free(); + } + + //Check if this event_id was deleted + $this->assertDBNull('CRM_Event_DAO_Event', $generatedEntities['civicrm_event'][$key], 'id', 'id', 'Check if event was deleted'); + $searchParams = array('entity_id' => $generatedEntities['civicrm_event'][$key], + 'entity_table' => 'civicrm_event' + ); + $compareParams = array(); + $this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParams, $compareParams); + + //Find tell_a_friend id if that was deleted from civicrm + $searchActParams = array('entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey], + 'entity_table' => 'civicrm_tell_friend' + ); + $compareActParams = array(); + $this->assertDBCompareValues('CRM_Friend_DAO_Friend', $searchActParams, $compareActParams); } } -- 2.25.1