From fb2120e7af0ec6bf700bc67db8bf7d4b25e33902 Mon Sep 17 00:00:00 2001 From: priyankakaran26 Date: Sat, 13 Sep 2014 20:55:15 +0100 Subject: [PATCH] linked entities test case --- .../CRM/Core/BAO/RecurringEntityTest.php | 76 +++---------------- 1 file changed, 9 insertions(+), 67 deletions(-) diff --git a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php index be20d54eca..42ff0071ff 100644 --- a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php +++ b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php @@ -123,25 +123,16 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { $daoEvent->save(); $this->assertDBNotNull('CRM_Event_DAO_Event', $daoEvent->id, 'id', 'id', 'Check DB if event was created'); - //Create profile for event - $daoUF = new CRM_Core_DAO_UFJoin(); - $daoUF->is_active = 1; - $daoUF->entity_table = 'civicrm_event'; - $daoUF->entity_id = $daoEvent->id; - $daoUF->uf_group_id = 12; - $daoUF->module = 'Test'; - $daoUF->save(); - $this->assertDBNotNull('CRM_Core_DAO_UFJoin', $daoUF->id, 'id', 'id', 'Check DB if profile was created'); - //Create tell a friend for event $daoTellAFriend = new CRM_Friend_DAO_Friend(); $daoTellAFriend->entity_table = 'civicrm_event'; - $daoTellAFriend->entity_id = $daoEvent->id; + $daoTellAFriend->entity_id = $daoEvent->id; // join with event $daoTellAFriend->title = 'Testing tell a friend'; $daoTellAFriend->is_active = 1; $daoTellAFriend->save(); $this->assertDBNotNull('CRM_Friend_DAO_Friend', $daoTellAFriend->id, 'id', 'id', 'Check DB if tell a freind was created'); + // time to use recursion $recursion = new CRM_Core_BAO_RecurringEntity(); $recursion->entity_id = $daoEvent->id; $recursion->entity_table = 'civicrm_event'; @@ -157,24 +148,6 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { ); $recursion->linkedEntities = array( - array( - 'table' => 'civicrm_price_set_entity', - 'findCriteria' => array( - 'entity_id' => $recursion->entity_id, - 'entity_table' => 'civicrm_event' - ), - 'linkedColumns' => array('entity_id'), - 'isRecurringEntityRecord' => FALSE, - ), - array( - 'table' => 'civicrm_uf_join', - 'findCriteria' => array( - 'entity_id' => $recursion->entity_id, - 'entity_table' => 'civicrm_event' - ), - 'linkedColumns' => array('entity_id'), - 'isRecurringEntityRecord' => FALSE, - ), array( 'table' => 'civicrm_tell_friend', 'findCriteria' => array( @@ -184,53 +157,22 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => TRUE, ), - array( - 'table' => 'civicrm_pcp_block', - 'findCriteria' => array( - 'entity_id' => $recursion->entity_id, - 'entity_table' => 'civicrm_event' - ), - 'linkedColumns' => array('entity_id'), - 'isRecurringEntityRecord' => TRUE, - ), ); $generatedEntities = $recursion->generate(); $this->assertArrayHasKey('civicrm_event', $generatedEntities, 'Check if generatedEntities has civicrm_event as required key'); - if(CRM_Utils_Array::value('civicrm_event', $generatedEntities)){ - $expCountEvent = count($generatedEntities['civicrm_event']); - $actCountEvent = 0; - foreach($generatedEntities['civicrm_event'] as $key => $val){ - $this->assertDBNotNull('CRM_Event_DAO_Event', $val, 'id', 'id', 'Check if events were created in loop'); - $actCountEvent++; - } - $this->assertCount($expCountEvent, $actCountEvent, 'Check if the number of events created are right'); + $this->assertCount($recursion->schedule['start_action_offset'], $generatedEntities['civicrm_event'], 'Check if the number of events created are right'); + foreach($generatedEntities['civicrm_event'] as $key => $val) { + $this->assertDBNotNull('CRM_Event_DAO_Event', $val, 'id', 'id', 'Check if repeating events were created.'); } - if(CRM_Utils_Array::value('civicrm_uf_join', $generatedEntities) && CRM_Utils_Array::value('civicrm_event', $generatedEntities)){ - $expCountUFJoin = count($generatedEntities['civicrm_uf_join']); - $actCountUFJoin = 0; - foreach($generatedEntities['civicrm_uf_join'] as $key => $val){ - $this->assertDBNotNull('CRM_Core_DAO_UFJoin', $val, 'id', 'id', 'Check if profile were created in loop'); - $this->assertDBCompareValue('CRM_Core_DAO_UFJoin', $val, 'entity_id', 'id', $generatedEntities['civicrm_event'][$key], 'Check DB if correct FK was maintained with event for UF Join'); - $actCountUFJoin++; - } - $this->assertCount($expCountUFJoin, $actCountUFJoin, 'Check if the number of profiles created are right'); + foreach($generatedEntities['civicrm_tell_friend'] as $key => $val){ + $this->assertDBNotNull('CRM_Friend_DAO_Friend', $val, 'id', 'id', 'Check if friends were created in loop'); + $this->assertDBCompareValue('CRM_Friend_DAO_Friend', $val, 'entity_id', 'id', $generatedEntities['civicrm_event'][$key], 'Check DB if correct FK was maintained with event for Friend'); } + $this->assertCount($recursion->schedule['start_action_offset'], $generatedEntities['civicrm_tell_friend'], 'Check if the number of tell a friend records are right'); - if(CRM_Utils_Array::value('civicrm_tell_friend', $generatedEntities) && CRM_Utils_Array::value('civicrm_event', $generatedEntities)){ - $expCountTellAFriend = count($generatedEntities['civicrm_tell_friend']); - $actCountTellAFriend = 0; - foreach($generatedEntities['civicrm_tell_friend'] as $key => $val){ - $this->assertDBNotNull('CRM_Friend_DAO_Friend', $val, 'id', 'id', 'Check if friends were created in loop'); - $this->assertDBCompareValue('CRM_Friend_DAO_Friend', $val, 'entity_id', 'id', $generatedEntities['civicrm_event'][$key], 'Check DB if correct FK was maintained with event for Friend'); - $actCountTellAFriend++; - } - $this->assertCount($expCountTellAFriend, $actCountTellAFriend, 'Check if the number of friends created are right'); - } - - // set mode to ALL, i.e any change to changing event affects all related recurring activities $recursion->mode(3); -- 2.25.1