Delete linked entities test case
authorunknown <priyanka.karan26@gmail.com>
Sat, 18 Oct 2014 21:20:05 +0000 (22:20 +0100)
committerunknown <priyanka.karan26@gmail.com>
Sat, 18 Oct 2014 21:20:05 +0000 (22:20 +0100)
tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php

index 2d888bc297a1119c60c08dc040f44f0a72cdb3fe..8e7c6a86afb0c72965583d8720b83a09b94bd3b5 100644 (file)
@@ -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);
   }
 }