1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class CampaignTest extends PHPUnit_Framework_TestCase { |
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
|
public function testCampaign() { |
8
|
|
|
|
9
|
|
|
//execute the contructor and check for the Object type and attributes |
10
|
|
|
$campaign = new Campaign(); |
11
|
|
|
$this->assertInstanceOf('Campaign',$campaign); |
12
|
|
|
$this->assertInstanceOf('SugarBean',$campaign); |
13
|
|
|
|
14
|
|
|
$this->assertAttributeEquals('Campaigns', 'module_dir', $campaign); |
15
|
|
|
$this->assertAttributeEquals('Campaign', 'object_name', $campaign); |
16
|
|
|
$this->assertAttributeEquals('campaigns', 'table_name', $campaign); |
17
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $campaign); |
18
|
|
|
$this->assertAttributeEquals(true, 'importable', $campaign); |
19
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testlist_view_parse_additional_sections() { |
23
|
|
|
|
24
|
|
|
error_reporting(E_ERROR | E_PARSE); |
25
|
|
|
|
26
|
|
|
$campaign = new Campaign(); |
27
|
|
|
|
28
|
|
|
//test with attributes preset and verify template variables are set accordingly |
29
|
|
|
$tpl = new Sugar_Smarty(); |
30
|
|
|
$campaign->list_view_parse_additional_sections($tpl); |
31
|
|
|
$this->assertEquals("" ,$tpl->_tpl_vars['ASSIGNED_USER_NAME']); |
32
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testget_summary_text() |
37
|
|
|
{ |
38
|
|
|
$campaign = new Campaign(); |
39
|
|
|
|
40
|
|
|
//test without setting name |
41
|
|
|
$this->assertEquals(Null,$campaign->get_summary_text()); |
42
|
|
|
|
43
|
|
|
//test with name set |
44
|
|
|
$campaign->name = "test"; |
45
|
|
|
$this->assertEquals('test',$campaign->get_summary_text()); |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testcreate_export_query() |
51
|
|
|
{ |
52
|
|
|
|
53
|
|
|
$campaign = new Campaign(); |
54
|
|
|
|
55
|
|
|
//test with empty string params |
56
|
|
|
$expected = "SELECT\n campaigns.*,\n users.user_name as assigned_user_name FROM campaigns LEFT JOIN users\n ON campaigns.assigned_user_id=users.id where campaigns.deleted=0 ORDER BY campaigns.name"; |
57
|
|
|
$actual = $campaign->create_export_query('',''); |
58
|
|
|
$this->assertSame($expected,$actual); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
//test with valid string params |
62
|
|
|
$expected = "SELECT\n campaigns.*,\n users.user_name as assigned_user_name FROM campaigns LEFT JOIN users\n ON campaigns.assigned_user_id=users.id where campaigns.name=\"\" AND campaigns.deleted=0 ORDER BY campaigns.id"; |
63
|
|
|
$actual = $campaign->create_export_query('campaigns.id','campaigns.name=""'); |
64
|
|
|
$this->assertSame($expected,$actual); |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testclear_campaign_prospect_list_relationship() |
70
|
|
|
{ |
71
|
|
|
$campaign = new Campaign(); |
72
|
|
|
|
73
|
|
|
//execute the method and test if it works and does not throws an exception. |
74
|
|
|
try { |
75
|
|
|
$campaign->clear_campaign_prospect_list_relationship(''); |
76
|
|
|
$campaign->clear_campaign_prospect_list_relationship('1'); |
77
|
|
|
$this->assertTrue(true); |
78
|
|
|
} |
79
|
|
|
catch (Exception $e) { |
80
|
|
|
$this->fail(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testmark_relationships_deleted() |
87
|
|
|
{ |
88
|
|
|
|
89
|
|
|
$campaign = new Campaign(); |
90
|
|
|
|
91
|
|
|
//execute the method and test if it works and does not throws an exception. |
92
|
|
|
try { |
93
|
|
|
$campaign->mark_relationships_deleted(''); |
94
|
|
|
$campaign->mark_relationships_deleted('1'); |
95
|
|
|
$this->assertTrue(true); |
96
|
|
|
} |
97
|
|
|
catch (Exception $e) { |
98
|
|
|
$this->fail(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testfill_in_additional_list_fields() |
105
|
|
|
{ |
106
|
|
|
|
107
|
|
|
$campaign = new Campaign(); |
108
|
|
|
|
109
|
|
|
//execute the method and test if it works and does not throws an exception. |
110
|
|
|
try { |
111
|
|
|
$campaign->fill_in_additional_list_fields(); |
112
|
|
|
$this->assertTrue(true); |
113
|
|
|
} |
114
|
|
|
catch (Exception $e) { |
115
|
|
|
$this->fail(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testfill_in_additional_detail_fields() |
122
|
|
|
{ |
123
|
|
|
|
124
|
|
|
$campaign = new Campaign(); |
125
|
|
|
|
126
|
|
|
//execute the method and test if it works and does not throws an exception. |
127
|
|
|
try { |
128
|
|
|
$campaign->fill_in_additional_detail_fields(); |
129
|
|
|
$this->assertTrue(true); |
130
|
|
|
} |
131
|
|
|
catch (Exception $e) { |
132
|
|
|
$this->fail(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testupdate_currency_id() |
140
|
|
|
{ |
141
|
|
|
$campaign = new Campaign(); |
142
|
|
|
|
143
|
|
|
//execute the method and test if it works and does not throws an exception. |
144
|
|
|
try { |
145
|
|
|
$campaign->update_currency_id('',''); |
146
|
|
|
$this->assertTrue(true); |
147
|
|
|
} |
148
|
|
|
catch (Exception $e) { |
149
|
|
|
$this->fail(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
public function testget_list_view_data() |
157
|
|
|
{ |
158
|
|
|
$campaign = new Campaign(); |
159
|
|
|
|
160
|
|
|
//execute the method and verify that it retunrs expected results |
161
|
|
|
|
162
|
|
|
$expected = array ( |
163
|
|
|
'DELETED' => 0, |
164
|
|
|
'TRACKER_COUNT' => '0', |
165
|
|
|
'REFER_URL' => 'http://', |
166
|
|
|
'IMPRESSIONS' => '0', |
167
|
|
|
'OPTIONAL_LINK' => 'display:none', |
168
|
|
|
'TRACK_CAMPAIGN_TITLE' => 'View Status', |
169
|
|
|
'TRACK_CAMPAIGN_IMAGE' => '~'.preg_quote('themes/SuiteR/images/view_status.gif?v=').'[\w-]+~', |
170
|
|
|
'LAUNCH_WIZARD_TITLE' => 'Launch Wizard', |
171
|
|
|
'LAUNCH_WIZARD_IMAGE' => '~'.preg_quote('themes/SuiteR/images/edit_wizard.gif?v=').'[\w-]+~', |
172
|
|
|
'TRACK_VIEW_ALT_TEXT' => 'View Status', |
173
|
|
|
'LAUNCH_WIZ_ALT_TEXT' => 'Launch Wizard', |
174
|
|
|
); |
175
|
|
|
|
176
|
|
|
$actual = $campaign->get_list_view_data(); |
177
|
|
|
foreach($expected as $expectedKey => $expectedVal){ |
178
|
|
|
if($expectedKey == 'LAUNCH_WIZARD_IMAGE' || $expectedKey == 'TRACK_CAMPAIGN_IMAGE'){ |
179
|
|
|
$this->assertRegExp($expected[$expectedKey],$actual[$expectedKey]); |
180
|
|
|
}else { |
181
|
|
|
$this->assertSame($expected[$expectedKey], $actual[$expectedKey]); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
public function testbuild_generic_where_clause() |
188
|
|
|
{ |
189
|
|
|
|
190
|
|
|
$campaign = new Campaign(); |
191
|
|
|
|
192
|
|
|
//test with blank parameter |
193
|
|
|
$expected = "campaigns.name like '%'"; |
194
|
|
|
$actual = $campaign->build_generic_where_clause (""); |
195
|
|
|
$this->assertSame($expected,$actual); |
196
|
|
|
|
197
|
|
|
//test with valid parameter |
198
|
|
|
$expected = "campaigns.name like '1%'"; |
199
|
|
|
$actual = $campaign->build_generic_where_clause (1); |
200
|
|
|
$this->assertSame($expected,$actual); |
201
|
|
|
|
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function testSaveAndMarkDeleted() |
205
|
|
|
{ |
206
|
|
|
|
207
|
|
|
$campaign = new Campaign(); |
208
|
|
|
$campaign->name = "test"; |
209
|
|
|
$campaign->amount = 100; |
210
|
|
|
|
211
|
|
|
|
212
|
|
|
$campaign->save(); |
213
|
|
|
|
214
|
|
|
//test for record ID to verify that record is saved |
215
|
|
|
$this->assertTrue(isset($campaign->id)); |
216
|
|
|
$this->assertEquals(36, strlen($campaign->id)); |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
//mark the record as deleted and verify that this record cannot be retrieved anymore. |
220
|
|
|
$campaign->mark_deleted($campaign->id); |
221
|
|
|
$result = $campaign->retrieve($campaign->id); |
222
|
|
|
$this->assertEquals(null,$result); |
223
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
public function testset_notification_body() |
228
|
|
|
{ |
229
|
|
|
$campaign = new Campaign(); |
230
|
|
|
|
231
|
|
|
//test with attributes preset and verify template variables are set accordingly |
232
|
|
|
$campaign->name = "test"; |
233
|
|
|
$campaign->budget = "1000"; |
234
|
|
|
$campaign->end_date = "10/01/2015"; |
235
|
|
|
$campaign->status = "Planned"; |
236
|
|
|
$campaign->content = "some text"; |
237
|
|
|
|
238
|
|
|
$result = $campaign->set_notification_body(new Sugar_Smarty(), $campaign); |
239
|
|
|
|
240
|
|
|
$this->assertEquals($campaign->name ,$result->_tpl_vars['CAMPAIGN_NAME']); |
241
|
|
|
$this->assertEquals($campaign->budget ,$result->_tpl_vars['CAMPAIGN_AMOUNT']); |
242
|
|
|
$this->assertEquals($campaign->end_date ,$result->_tpl_vars['CAMPAIGN_CLOSEDATE']); |
243
|
|
|
$this->assertEquals($campaign->status ,$result->_tpl_vars['CAMPAIGN_STATUS']); |
244
|
|
|
$this->assertEquals($campaign->content ,$result->_tpl_vars['CAMPAIGN_DESCRIPTION']); |
245
|
|
|
|
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function testtrack_log_leads() |
249
|
|
|
{ |
250
|
|
|
$campaign = new Campaign(); |
251
|
|
|
|
252
|
|
|
$expected = "SELECT campaign_log.* FROM campaign_log WHERE campaign_log.campaign_id = '' AND campaign_log.deleted=0 AND activity_type = 'lead' AND archived = 0 AND target_id IS NOT NULL "; |
253
|
|
|
$actual = $campaign->track_log_leads(); |
254
|
|
|
$this->assertSame($expected,$actual); |
255
|
|
|
|
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function testtrack_log_entries() |
259
|
|
|
{ |
260
|
|
|
$campaign = new Campaign(); |
261
|
|
|
|
262
|
|
|
//test without parameters |
263
|
|
|
$expected = "SELECT campaign_log.* FROM campaign_log WHERE campaign_log.campaign_id = '' AND campaign_log.deleted=0 AND activity_type='targeted' AND archived=0 "; |
264
|
|
|
$actual = $campaign->track_log_entries(); |
265
|
|
|
$this->assertSame($expected,$actual); |
266
|
|
|
|
267
|
|
|
//test with parameters |
268
|
|
|
$expected = "SELECT campaign_log.* FROM campaign_log WHERE campaign_log.campaign_id = '' AND campaign_log.deleted=0 AND activity_type='test1' AND archived=0 "; |
269
|
|
|
$actual = $campaign->track_log_entries(array('test1','test2')); |
270
|
|
|
$this->assertSame($expected,$actual); |
271
|
|
|
|
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
public function testget_queue_items() |
276
|
|
|
{ |
277
|
|
|
$campaign = new Campaign(); |
278
|
|
|
|
279
|
|
|
//without parameters |
280
|
|
|
$expected = "SELECT emailman.* ,\n campaigns.name as campaign_name,\n email_marketing.name as message_name,\n (CASE related_type\n WHEN 'Contacts' THEN LTRIM(RTRIM(CONCAT(IFNULL(contacts.first_name,''),' ',IFNULL(contacts.last_name,''))))\n WHEN 'Leads' THEN LTRIM(RTRIM(CONCAT(IFNULL(leads.first_name,''),' ',IFNULL(leads.last_name,''))))\n WHEN 'Accounts' THEN accounts.name\n WHEN 'Users' THEN LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,''))))\n WHEN 'Prospects' THEN LTRIM(RTRIM(CONCAT(IFNULL(prospects.first_name,''),' ',IFNULL(prospects.last_name,''))))\n END) recipient_name FROM emailman\n LEFT JOIN users ON users.id = emailman.related_id and emailman.related_type ='Users'\n LEFT JOIN contacts ON contacts.id = emailman.related_id and emailman.related_type ='Contacts'\n LEFT JOIN leads ON leads.id = emailman.related_id and emailman.related_type ='Leads'\n LEFT JOIN accounts ON accounts.id = emailman.related_id and emailman.related_type ='Accounts'\n LEFT JOIN prospects ON prospects.id = emailman.related_id and emailman.related_type ='Prospects'\n LEFT JOIN prospect_lists ON prospect_lists.id = emailman.list_id\n LEFT JOIN email_addr_bean_rel ON email_addr_bean_rel.bean_id = emailman.related_id and emailman.related_type = email_addr_bean_rel.bean_module and email_addr_bean_rel.primary_address = 1 and email_addr_bean_rel.deleted=0\n LEFT JOIN campaigns ON campaigns.id = emailman.campaign_id\n LEFT JOIN email_marketing ON email_marketing.id = emailman.marketing_id WHERE emailman.campaign_id = '' AND emailman.deleted=0 AND emailman.deleted=0"; |
281
|
|
|
$actual = $campaign->get_queue_items(); |
282
|
|
|
$this->assertSame($expected,$actual); |
283
|
|
|
|
284
|
|
|
//with parameters |
285
|
|
|
$expected = "SELECT emailman.* ,\n campaigns.name as campaign_name,\n email_marketing.name as message_name,\n (CASE related_type\n WHEN 'Contacts' THEN LTRIM(RTRIM(CONCAT(IFNULL(contacts.first_name,''),' ',IFNULL(contacts.last_name,''))))\n WHEN 'Leads' THEN LTRIM(RTRIM(CONCAT(IFNULL(leads.first_name,''),' ',IFNULL(leads.last_name,''))))\n WHEN 'Accounts' THEN accounts.name\n WHEN 'Users' THEN LTRIM(RTRIM(CONCAT(IFNULL(users.first_name,''),' ',IFNULL(users.last_name,''))))\n WHEN 'Prospects' THEN LTRIM(RTRIM(CONCAT(IFNULL(prospects.first_name,''),' ',IFNULL(prospects.last_name,''))))\n END) recipient_name FROM emailman\n LEFT JOIN users ON users.id = emailman.related_id and emailman.related_type ='Users'\n LEFT JOIN contacts ON contacts.id = emailman.related_id and emailman.related_type ='Contacts'\n LEFT JOIN leads ON leads.id = emailman.related_id and emailman.related_type ='Leads'\n LEFT JOIN accounts ON accounts.id = emailman.related_id and emailman.related_type ='Accounts'\n LEFT JOIN prospects ON prospects.id = emailman.related_id and emailman.related_type ='Prospects'\n LEFT JOIN prospect_lists ON prospect_lists.id = emailman.list_id\n LEFT JOIN email_addr_bean_rel ON email_addr_bean_rel.bean_id = emailman.related_id and emailman.related_type = email_addr_bean_rel.bean_module and email_addr_bean_rel.primary_address = 1 and email_addr_bean_rel.deleted=0\n LEFT JOIN campaigns ON campaigns.id = emailman.campaign_id\n LEFT JOIN email_marketing ON email_marketing.id = emailman.marketing_id INNER JOIN (select min(id) as id from emailman em GROUP BY users.id ) secondary\n on emailman.id = secondary.id WHERE emailman.campaign_id = '' AND emailman.deleted=0 AND marketing_id ='1' AND emailman.deleted=0"; |
286
|
|
|
$actual = $campaign->get_queue_items(array("EMAIL_MARKETING_ID_VALUE"=>1,"group_by"=>"users.id")); |
287
|
|
|
$this->assertSame($expected,$actual); |
288
|
|
|
|
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
public function testbean_implements() |
293
|
|
|
{ |
294
|
|
|
$campaign = new Campaign(); |
295
|
|
|
$this->assertEquals(false, $campaign->bean_implements('')); //test with blank value |
296
|
|
|
$this->assertEquals(false, $campaign->bean_implements('test')); //test with invalid value |
297
|
|
|
$this->assertEquals(true, $campaign->bean_implements('ACL')); //test with valid value |
298
|
|
|
|
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
|
302
|
|
|
|
303
|
|
|
public function testcreate_list_count_query() |
304
|
|
|
{ |
305
|
|
|
|
306
|
|
|
$campaign = new Campaign(); |
307
|
|
|
|
308
|
|
|
//test without parameters |
309
|
|
|
$expected = ""; |
310
|
|
|
$actual = $campaign->create_list_count_query(''); |
311
|
|
|
$this->assertSame($expected,$actual); |
312
|
|
|
|
313
|
|
|
//test with query parameters |
314
|
|
|
$expected = "SELECT count(*) c FROM campaigns"; |
315
|
|
|
$actual = $campaign->create_list_count_query('select * from campaigns'); |
316
|
|
|
$this->assertSame($expected,$actual); |
317
|
|
|
|
318
|
|
|
//test with distinct |
319
|
|
|
$expected = "SELECT count(DISTINCT campaigns.id) c FROM campaigns"; |
320
|
|
|
$actual = $campaign->create_list_count_query('SELECT distinct marketing_id FROM campaigns'); |
321
|
|
|
$this->assertSame($expected,$actual); |
322
|
|
|
|
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
|
326
|
|
|
public function testgetDeletedCampaignLogLeadsCount() |
327
|
|
|
{ |
328
|
|
|
$campaign = new Campaign(); |
329
|
|
|
$result = $campaign->getDeletedCampaignLogLeadsCount(); |
330
|
|
|
$this->assertEquals(0,$result); |
331
|
|
|
|
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
|
335
|
|
|
} |
336
|
|
|
?> |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.