25b72113 |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | CiviCRM version 4.5 | |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | |
9 | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
11 | | under the terms of the GNU Affero General Public License | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
13 | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
17 | | See the GNU Affero General Public License for more details. | |
18 | | | |
19 | | You should have received a copy of the GNU Affero General Public | |
20 | | License and the CiviCRM Licensing Exception along | |
21 | | with this program; if not, contact CiviCRM LLC | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
25 | +--------------------------------------------------------------------+ |
26 | */ |
27 | |
25b72113 |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; |
060402a9 |
29 | require_once 'CRM/Core/BAO/RecurringEntity.php'; |
25b72113 |
30 | |
31 | /** |
060402a9 |
32 | * Class CRM_Core_BAO_RecurringEntityTest |
25b72113 |
33 | */ |
060402a9 |
34 | class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { |
25b72113 |
35 | /** |
36 | * @return array |
37 | */ |
38 | function get_info() { |
39 | return array( |
40 | 'name' => 'Recurring Entity BAOs', |
41 | 'description' => 'Test all CRM_Event_BAO_RecurringEntity methods.', |
42 | 'group' => 'CiviCRM BAO Tests', |
43 | ); |
44 | } |
45 | |
6caeea75 |
46 | /** |
47 | * Sets up the fixture, for example, opens a network connection. |
48 | * This method is called before a test is executed. |
49 | * |
50 | * @access protected |
51 | */ |
52 | protected function setUp() { |
25b72113 |
53 | parent::setUp(); |
25b72113 |
54 | } |
6caeea75 |
55 | |
56 | /** |
57 | * Tears down the fixture, for example, closes a network connection. |
58 | * This method is called after a test is executed. |
59 | * |
60 | * @access protected |
61 | */ |
62 | protected function tearDown() {} |
25b72113 |
63 | |
64 | /** |
6caeea75 |
65 | * Testing Activity Generation through Entity Recursion |
25b72113 |
66 | */ |
6caeea75 |
67 | function testActivityGeneration() { |
206c0c43 |
68 | //Activity set initial params |
37b28176 |
69 | $daoActivity = new CRM_Activity_DAO_Activity(); |
70 | $daoActivity->activity_type_id = 1; |
71 | $daoActivity->subject = "Initial Activity"; |
72 | $daoActivity->activity_date_time = date('YmdHis'); |
73 | $daoActivity->save(); |
25b72113 |
74 | |
37b28176 |
75 | $recursion = new CRM_Core_BAO_RecurringEntity(); |
690bf076 |
76 | $recursion->entity_id = $daoActivity->id; |
77 | $recursion->entity_table = 'civicrm_activity'; |
78 | $recursion->dateColumns = array('activity_date_time'); |
79 | $recursion->scheduleDBParams = array( |
72e95527 |
80 | 'entity_value' => $daoActivity->id, |
a1a821bc |
81 | 'start_action_date' => $daoActivity->activity_date_time, |
82 | 'entity_status' => 'fourth saturday', |
37b28176 |
83 | 'repetition_frequency_unit' => 'month', |
84 | 'repetition_frequency_interval' => 3, |
85 | 'start_action_offset' => 5, |
206c0c43 |
86 | 'used_for' => 'activity' |
690bf076 |
87 | ); |
206c0c43 |
88 | |
37b28176 |
89 | $generatedEntities = $recursion->generate(); |
37b28176 |
90 | foreach ($generatedEntities as $entityID) { |
91 | $this->assertDBNotNull('CRM_Activity_DAO_Activity', $entityID, 'id', |
92 | 'id', 'Check DB if repeating activities were created' |
93 | ); |
25b72113 |
94 | } |
25b72113 |
95 | |
206c0c43 |
96 | // set mode to ALL, i.e any change to changing activity affects all related recurring activities |
97 | $recursion->mode(3); |
37b28176 |
98 | |
99 | // lets change subject of initial activity that we created in begining |
25b72113 |
100 | $daoActivity->find(TRUE); |
690bf076 |
101 | $daoActivity->subject = 'Changed Activity'; |
25b72113 |
102 | $daoActivity->save(); |
25b72113 |
103 | |
37b28176 |
104 | // check if other activities were affected |
105 | foreach ($generatedEntities as $entityID) { |
690bf076 |
106 | $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $entityID, 'subject', 'id', 'Changed Activity', 'Check if subject was updated'); |
6caeea75 |
107 | } |
6caeea75 |
108 | } |
109 | |
690bf076 |
110 | /** |
111 | * Testing Event Generation through Entity Recursion |
112 | */ |
113 | function testEventGeneration() { |
114 | //Event set initial params |
115 | $daoEvent = new CRM_Event_DAO_Event(); |
116 | $daoEvent->title = 'Test event for Recurring Entity'; |
117 | $daoEvent->event_type_id = 3; |
118 | $daoEvent->is_public = 1; |
119 | $daoEvent->start_date = date('YmdHis', strtotime('2014-09-24 10:30:00')); |
206c0c43 |
120 | $daoEvent->end_date = date('YmdHis', strtotime('2014-09-26 10:30:00')); |
690bf076 |
121 | $daoEvent->created_date = date('YmdHis'); |
122 | $daoEvent->is_active = 1; |
123 | $daoEvent->save(); |
124 | |
125 | $recursion = new CRM_Core_BAO_RecurringEntity(); |
126 | $recursion->entity_id = $daoEvent->id; |
127 | $recursion->entity_table = 'civicrm_event'; |
128 | $recursion->dateColumns = array('start_date'); |
129 | $recursion->scheduleDBParams = array ( |
130 | 'entity_value' => $daoEvent->id, |
a1a821bc |
131 | 'start_action_date' => $daoEvent->start_date, |
690bf076 |
132 | 'start_action_condition' => 'wednesday', |
133 | 'repetition_frequency_unit' => 'week', |
134 | 'repetition_frequency_interval' => 1, |
135 | 'start_action_offset' => 4, |
136 | 'used_for' => 'event' |
137 | ); |
138 | |
690bf076 |
139 | $generatedEntities = $recursion->generate(); |
690bf076 |
140 | |
206c0c43 |
141 | // set mode to ALL, i.e any change to changing event affects all related recurring activities |
142 | $recursion->mode(3); |
690bf076 |
143 | |
144 | $daoEvent->find(TRUE); |
145 | $daoEvent->title = 'Event Changed'; |
146 | $daoEvent->save(); |
147 | |
148 | // check if other events were affected |
149 | foreach ($generatedEntities as $entityID) { |
150 | $this->assertDBCompareValue('CRM_Event_DAO_Event', $entityID, 'title', 'id', 'Event Changed', 'Check if title was updated'); |
151 | } |
152 | } |
25b72113 |
153 | } |