Testcase: merged activity and event
authorunknown <priyanka.karan26@gmail.com>
Thu, 11 Sep 2014 16:39:35 +0000 (17:39 +0100)
committerdeepak-srivastava <deepak.srivastava.0303@gmail.com>
Fri, 3 Oct 2014 08:55:17 +0000 (09:55 +0100)
tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php
tests/phpunit/CRM/Event/BAO/RecurringEntityForEventTest.php [deleted file]

index aaf3390989ca92fac9966212a1fe489fa825005f..c02387782f2707786e681dfa7c846f0925ee36ec 100644 (file)
@@ -43,28 +43,60 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase {
     );
   }
 
-  function setUp() {
+  /**
+   * Sets up the fixture, for example, opens a network connection.
+   * This method is called before a test is executed.
+   *
+   * @access protected
+   */
+  protected function setUp() {
     parent::setUp();
-    $activity = new CRM_Activity_DAO_Activity();
-    $activity->activity_type_id = 7;
-    $activity->subject = "Testing activity with recursion";
-    $activity->activity_date_time = date('YmdHis');
-    $result = $activity->save();
+    //Activity set initial params
+    $daoActivity = new CRM_Activity_DAO_Activity();
+    $daoActivity->activity_type_id = 7;
+    $daoActivity->subject = "Testing activity with recursion";
+    $daoActivity->activity_date_time = date('YmdHis');
+    $actResult = $daoActivity->save();
  
-    $this->assertDBNotNull('CRM_Activity_DAO_Activity', $result->id, 'id',
+    $this->assertDBNotNull('CRM_Activity_DAO_Activity', $actResult->id, 'id',
       'id', 'Check DB if activity was created'
     );
-    $this->_parentID = $result->id;
-    $this->_activityDateTime = $result->activity_date_time;
+    $this->_actParentID = $actResult->id;
+    $this->_activityDateTime = $actResult->activity_date_time;
+    
+    //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;
   }
+  
+  /**
+   * Tears down the fixture, for example, closes a network connection.
+   * This method is called after a test is executed.
+   *
+   * @access protected
+   */
+  protected function tearDown() {}
 
   /**
-   * quickAdd() method for RecurringEntity 
+   * Testing Activity Generation through Entity Recursion
    */
-  function testAdd() {
-    if( $this->_parentID ){
+  function testActivityGeneration() {
+    if( $this->_actParentID ){
       //Add parent to civicrm_recurring_entity table
-      $newCreatedParentID = CRM_Core_BAO_RecurringEntity::quickAdd($this->_parentID, $this->_parentID, 'civicrm_activity');
+      $newCreatedParentID = CRM_Core_BAO_RecurringEntity::quickAdd($this->_actParentID, $this->_actParentID, 'civicrm_activity');
       
       //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');
@@ -80,7 +112,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase {
        * For eg - Employee performance review recruited on a temporary basis
        */
       $dbParams = array (
-                    'entity_value'                  => $this->_parentID,
+                    'entity_value'                  => $this->_actParentID,
                     'entity_status'                 => $this->_activityDateTime,
                     'start_action_date'             => 'fourth saturday',
                     'repetition_frequency_unit'     => 'month',
@@ -93,7 +125,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase {
       $actionSchedule->save();
       
       //Check if repeat configuration got saved in civicrm_action_schedule table
-      $this->assertDBNotNull('CRM_Core_DAO_ActionSchedule', $this->_parentID, 'id',
+      $this->assertDBNotNull('CRM_Core_DAO_ActionSchedule', $this->_actParentID, 'id',
       'entity_value', 'Check there was an entry for repeat configuration with this new activity id'
       );
  
@@ -119,7 +151,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase {
         $activityNew->save();
         
         //Add children to civicrm_recurring_entity table
-        CRM_Core_BAO_RecurringEntity::quickAdd($this->_parentID, $activityNew->id, 'civicrm_activity');
+        CRM_Core_BAO_RecurringEntity::quickAdd($this->_actParentID, $activityNew->id, 'civicrm_activity');
         $storeNewAcitivities[] = $activityNew->id;
       }
       foreach($storeNewAcitivities as $val){
@@ -128,17 +160,12 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase {
         );
       }
     }
-  }
-  
-  /**
-   * Check change occurs across related entities for RecurringEntity 
-   */
-  function testModifyEntity() {
+    
     /**
      * Lets modify an activity and see if other related activities get cascaded
      */
     $daoRecurringEntity = new CRM_Core_DAO_RecurringEntity();
-    $daoRecurringEntity->entity_id = $this->_parentID;
+    $daoRecurringEntity->entity_id = $this->_actParentID;
     $daoRecurringEntity->entity_table = 'civicrm_activity';
     $daoRecurringEntity->find(TRUE);
     $daoRecurringEntity->mode = 2;
@@ -147,7 +174,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase {
     $this->assertDBCompareValue('CRM_Core_DAO_RecurringEntity', $daoRecurringEntity->id, 'mode', 'id', 2, 'Check if mode was updated');
 
     $daoActivity = new CRM_Activity_DAO_Activity();
-    $daoActivity->id = $this->_parentID;
+    $daoActivity->id = $this->_actParentID;
     $daoActivity->find(TRUE);
     $daoActivity->subject = 'Need to change the subject for activities';
     $daoActivity->save();
@@ -155,13 +182,116 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase {
 
     //Changing any information in parent should change this and following activities given mode 2
     $children = array();
-    $children = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($this->_parentID, 'civicrm_activity', FALSE);
+    $children = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($this->_actParentID, 'civicrm_activity', FALSE);
     foreach( $children as $key => $val ){
       //Check if all the children have their subject updated as that of a parent
       $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $val['id'], 'subject', 'id', 'Need to change the subject for activities', 'Check if subject was updated forr all the children');
     } 
   }
   
+  /**
+   * 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');
+    } 
+  }
+  
 }
 
   
diff --git a/tests/phpunit/CRM/Event/BAO/RecurringEntityForEventTest.php b/tests/phpunit/CRM/Event/BAO/RecurringEntityForEventTest.php
deleted file mode 100644 (file)
index f938463..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-<?php
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
- |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
- |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
- +--------------------------------------------------------------------+
-*/
-
-require_once 'CiviTest/CiviUnitTestCase.php';
-require_once 'CRM/Core/BAO/RecurringEntity.php';
-
-/**
- * Class CRM_Event_BAO_RecurringEntityForEventTest
- */
-class CRM_Event_BAO_RecurringEntityForEventTest extends CiviUnitTestCase {
-  /**
-   * @return array
-   */
-  function get_info() {
-    return array(
-      'name' => 'Recurring Entity BAOs',
-      'description' => 'Test RecurringEntity for Events.',
-      'group' => 'CiviCRM BAO Tests',
-    );
-  }
-
-  /**
-   * Sets up the fixture, for example, opens a network connection.
-   * This method is called before a test is executed.
-   *
-   * @access protected
-   */
-  protected function setUp() {
-    parent::setUp();
-    $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');
-    $result = $daoEvent->save();
-    $this->assertDBNotNull('CRM_Event_DAO_Event', $result->id, 'id',
-      'id', 'Check DB if event was created'
-    );
-    $this->_parentID = $result->id;
-    $this->start_date = $result->start_date;
-    $this->end_date = $result->end_date;
-  }
-  
-   /**
-   * Tears down the fixture, for example, closes a network connection.
-   * This method is called after a test is executed.
-   *
-   * @access protected
-   */
-  protected function tearDown() {}
-
-  /**
-   * quickAdd() method for RecurringEntity 
-   */
-  function testAdd() {
-    if( $this->_parentID ){
-      //Add parent to civicrm_recurring_entity table
-      $newCreatedParentID = CRM_Core_BAO_RecurringEntity::quickAdd($this->_parentID, $this->_parentID, '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->_parentID,
-                    '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->_parentID, '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->_parentID, $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'
-        );
-      }
-    }
-  }
-  
-  /**
-   * Check change occurs across related entities for RecurringEntity 
-   */
-  function testModifyEntity() {
-    /**
-     * Lets modify an event and see if other related events get cascaded
-     */
-    $daoRecurringEntity = new CRM_Core_DAO_RecurringEntity();
-    $daoRecurringEntity->entity_id = $this->_parentID;
-    $daoRecurringEntity->entity_table = 'civicrm_event';
-    $daoRecurringEntity->find(TRUE);
-    $daoRecurringEntity->mode = 2;
-    $daoRecurringEntity->save();
-    //Check if mode was changed
-    $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->_parentID;
-    $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->_parentID, '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 forr all the children');
-    } 
-  }
-  
-}
-
-