*/
protected function setUp() {
parent::setUp();
-
-# //Event set initial params
-# $daoEvent = new CRM_Event_DAO_Event();
-# $daoEvent->title = 'Test event for Recurring Entity';
-# $daoEvent->event_type_id = 3;
-# $daoEvent->is_public = 1;
-# $daoEvent->start_date = date('YmdHis', strtotime('2014-09-24 10:30:00'));
-# $daoEvent->end_date = date('YmdHis', strtotime('2014-09-26 10:30:00'));
-# $daoEvent->created_date = date('YmdHis');
-# $eventResult = $daoEvent->save();
-#
-# $this->assertDBNotNull('CRM_Event_DAO_Event', $eventResult->id, 'id',
-# 'id', 'Check DB if event was created'
-# );
-# $this->_eventParentID = $eventResult->id;
-# $this->start_date = $eventResult->start_date;
-# $this->end_date = $eventResult->end_date;
}
/**
* Testing Activity Generation through Entity Recursion
*/
function testActivityGeneration() {
- //Activity set initial params
+ //create an activity
$daoActivity = new CRM_Activity_DAO_Activity();
$daoActivity->activity_type_id = 1;
$daoActivity->subject = "Initial Activity";
);
$recursion = new CRM_Core_BAO_RecurringEntity();
- $recursion->entityId($daoActivity->id);
- $recursion->entityTable('civicrm_activity');
- $recursion->dateColumns(array('activity_date_time'));
- $recursion->scheduleDBParams(array(
+ $recursion->entity_id = $daoActivity->id;
+ $recursion->entity_table = 'civicrm_activity';
+ $recursion->dateColumns = array('activity_date_time');
+ $recursion->scheduleDBParams = array(
'entity_value' => $daoActivity->id,
'entity_status' => $daoActivity->activity_date_time,
'start_action_date' => 'fourth saturday',
'repetition_frequency_unit' => 'month',
'repetition_frequency_interval' => 3,
'start_action_offset' => 5,
- //'used_for' => 'activity'
- ));
-
- // skip copying these column when creating new daos
- // or populate with values provided here
- //$recursion->overwriteColumns = array();
- //$recursion->intervalDateColumns = array('end_date' => '1 day');
-
+ 'used_for' => 'activity'
+ );
$generatedEntities = $recursion->generate();
-
foreach ($generatedEntities as $entityID) {
$this->assertDBNotNull('CRM_Activity_DAO_Activity', $entityID, 'id',
'id', 'Check DB if repeating activities were created'
}
// try changing something
- $recursion->setMode(3); // sets ->mode var & saves in DB
+ $recursion->mode(3); // sets ->mode var & saves in DB
// lets change subject of initial activity that we created in begining
$daoActivity->find(TRUE);
- $daoActivity->subject = 'Need to change the subject for activities';
+ $daoActivity->subject = 'Changed Activity';
$daoActivity->save();
- $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $daoActivity->id, 'subject', 'id', 'Need to change the subject for activities', 'Check if subject was updated');
// check if other activities were affected
foreach ($generatedEntities as $entityID) {
- $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $entityID, 'subject', 'id', 'Need to change the subject for activities', 'Check if subject was updated');
+ $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $entityID, 'subject', 'id', 'Changed Activity', 'Check if subject was updated');
}
}
-# /**
-# * Testing Event Generation through Entity Recursion
-# */
-# function testEventGeneration(){
-# if( $this->_eventParentID ){
-# //Add parent to civicrm_recurring_entity table
-# $newCreatedParentID = CRM_Core_BAO_RecurringEntity::quickAdd($this->_eventParentID, $this->_eventParentID, 'civicrm_event');
-#
-# //Check if there was a new record created in civicrm_recurring_entity
-# $this->assertDBRowExist('CRM_Core_DAO_RecurringEntity', $newCreatedParentID->id, 'Check Db for parent entry');
-#
-# //Check if parent_id and entity_id column are same for this event id
-# $this->assertEquals($newCreatedParentID->parent_id, $newCreatedParentID->entity_id, 'Check if parent id is equal to entity id');
-#
-# //Lets assume you saved the repeat configuration with these criterias
-# /**
-# * Event occurs every 2 weeks
-# * on monday, wednesday and friday
-# * for 4 times
-# * For eg - A small course on art and craft
-# */
-# $dbParams = array (
-# 'entity_value' => $this->_eventParentID,
-# 'entity_status' => $this->start_date,
-# 'start_action_condition' => 'monday,wednesday,friday',
-# 'repetition_frequency_unit' => 'week',
-# 'repetition_frequency_interval' => 2,
-# 'start_action_offset' => 4,
-# 'used_for' => 'event'
-# );
-# $actionSchedule = new CRM_Core_DAO_ActionSchedule();
-# $actionSchedule->copyValues($dbParams);
-# $actionSchedule->save();
-#
-# //Check if repeat configuration got saved in civicrm_action_schedule table
-# $this->assertDBNotNull('CRM_Core_DAO_ActionSchedule', $this->_eventParentID, 'id',
-# 'entity_value', 'Check there was an entry for repeat configuration with this new event id'
-# );
-#
-# //getRecursionFromReminder builds recursion object for you
-# if( $actionSchedule->id ){
-# $recursionObject = CRM_Core_BAO_RecurringEntity::getRecursionFromReminder($actionSchedule->id);
-#
-# //Check if this is an object of When class
-# $this->assertInstanceOf('When', $recursionObject, 'Check for created object');
-# }
-#
-# // Recursion library has returned an array based on the repeat configuration you provided
-# $params = array();
-# $params['interval'] = 2;
-# $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params);
-#
-# //Store children events in an array
-# $storeNewEvents = array();
-# //You can now create event recursively
-# foreach( $recurResult as $val ){
-# $eventNew = new CRM_Event_DAO_Event();
-# $eventNew->title = 'Common title for all events';
-# $eventNew->event_type_id = 3;
-# $eventNew->is_public = 1;
-# $eventNew->start_date = CRM_Utils_Date::processDate($val['start_date']);
-# $eventNew->end_date = CRM_Utils_Date::processDate($val['end_date']);
-# $eventNew->save();
-#
-# //Add children to civicrm_recurring_entity table
-# CRM_Core_BAO_RecurringEntity::quickAdd($this->_eventParentID, $eventNew->id, 'civicrm_event');
-# $storeNewEvents[] = $eventNew->id;
-# }
-# foreach($storeNewAcitivities as $val){
-# $this->assertDBNotNull('CRM_Event_DAO_Event', $val, 'id',
-# 'id', 'Check DB if events were created'
-# );
-# }
-# }
-#
-# /**
-# * Lets modify an event and see if other related events get cascaded
-# */
-# $daoRecurringEntity = new CRM_Core_DAO_RecurringEntity();
-# $daoRecurringEntity->entity_id = $this->_eventParentID;
-# $daoRecurringEntity->entity_table = 'civicrm_event';
-# $daoRecurringEntity->find(TRUE);
-# $daoRecurringEntity->mode = 2;
-# $daoRecurringEntity->save();
-# //Check if mode was _eventParentID
-# $this->assertDBCompareValue('CRM_Core_DAO_RecurringEntity', $daoRecurringEntity->id, 'mode', 'id', 2, 'Check if mode was updated');
-#
-# $daoEvent = new CRM_Event_DAO_Event();
-# $daoEvent->id = $this->_eventParentID;
-# $daoEvent->find(TRUE);
-# $daoEvent->title = 'Need to change the title for events';
-# $daoEvent->save();
-# $this->assertDBCompareValue('CRM_Event_DAO_Event', $daoEvent->id, 'title', 'id', 'Need to change the title for events', 'Check if title was updated');
-#
-# //Changing any information in parent should change this and following events, given mode 2
-# $children = array();
-# $children = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($this->_eventParentID, 'civicrm_event', FALSE);
-# foreach( $children as $key => $val ){
-# //Check if all the children have their subject updated as that of a parent
-# $this->assertDBCompareValue('CRM_Event_DAO_Event', $val['id'], 'title', 'id', 'Need to change the title for events', 'Check if title was updated for all the children');
-# }
-# }
+ /**
+ * Testing Event Generation through Entity Recursion
+ */
+ function testEventGeneration() {
+ //Event set initial params
+ $daoEvent = new CRM_Event_DAO_Event();
+ $daoEvent->title = 'Test event for Recurring Entity';
+ $daoEvent->event_type_id = 3;
+ $daoEvent->is_public = 1;
+ $daoEvent->start_date = date('YmdHis', strtotime('2014-09-24 10:30:00'));
+ $daoEvent->end_date = date('YmdHis', strtotime('2014-09-26 10:30:00'));
+ $daoEvent->created_date = date('YmdHis');
+ $daoEvent->is_active = 1;
+ $daoEvent->save();
+
+ $recursion = new CRM_Core_BAO_RecurringEntity();
+ $recursion->entity_id = $daoEvent->id;
+ $recursion->entity_table = 'civicrm_event';
+ $recursion->dateColumns = array('start_date');
+ $recursion->scheduleDBParams = array (
+ 'entity_value' => $daoEvent->id,
+ 'entity_status' => $daoEvent->start_date,
+ 'start_action_condition' => 'wednesday',
+ 'repetition_frequency_unit' => 'week',
+ 'repetition_frequency_interval' => 1,
+ 'start_action_offset' => 4,
+ 'used_for' => 'event'
+ );
+
+ //$interval = $recursion->getInterval($daoEvent->start_date, $daoEvent->end_date);
+ //$recursion->intervalDateColumns = array('end_date' => $interval);
+
+ //$recursion->excludeDates = array(date('Ymd', strtotime('2014-10-02')), '20141008');// = array('date1', date2, date2)
+ //$recursion->excludeDateRangeColumns = array('start_date', 'end_date');
+
+ $generatedEntities = $recursion->generate();
+ CRM_Core_Error::debug_var('$generatedEntities', $generatedEntities);
+
+ // try changing something
+ $recursion->mode(3); // sets ->mode var & saves in DB
+
+ $daoEvent->find(TRUE);
+ $daoEvent->title = 'Event Changed';
+ $daoEvent->save();
+
+ // check if other events were affected
+ foreach ($generatedEntities as $entityID) {
+ $this->assertDBCompareValue('CRM_Event_DAO_Event', $entityID, 'title', 'id', 'Event Changed', 'Check if title was updated');
+ }
+ }
}