Completed
Push — console-installer ( e2b50d...6ce748 )
by Adam
22:30
created

InboundEmailTest   D

Complexity

Total Complexity 197

Size/Duplication

Total Lines 2510
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 2510
rs 4.4102
c 0
b 0
f 0
wmc 197
lcom 3
cbo 7

162 Methods

Rating   Name   Duplication   Size   Complexity  
A testthis_callback() 0 6 1
B testInboundEmail() 0 32 1
A testsaveAndOthers() 0 60 1
A getSingularRelatedId() 0 16 1
A getCorrectMessageNoForPop3() 0 12 1
A retrieve() 0 11 1
A retrieveByGroupId() 0 12 2
A retrieveAllByGroupId() 0 12 2
A retrieveAllByGroupIdWithGroupAccounts() 0 12 2
A renameFolder() 0 14 2
A search() 0 12 1
A saveMailBoxFolders() 0 14 1
A saveMailBoxValueOfInboundEmail() 0 13 1
A mark_deleted() 0 9 1
A hardDelete() 0 9 1
A testcustomGetMessageText() 0 7 1
A testgetFormattedRawSource() 0 13 1
A testfilterMailBoxFromRaw() 0 18 1
A testconvertToUtf8() 0 6 1
A testgetFormattedHeaders() 0 13 1
A testsetAndgetCacheTimestamp() 0 13 1
B testsetCacheValue() 0 30 1
A testgetCacheValueForUIDs() 0 19 1
A testgetCacheValue() 0 19 1
A testvalidCacheExists() 0 13 1
A testdisplayFetchedSortedListXML() 0 12 1
A testgetCacheUnreadCount() 0 14 1
A testgetCacheCount() 0 14 1
A testgetCacheUnread() 0 14 1
A testmark_answered() 0 14 1
A testpop3_shiftCache() 0 14 1
A testgetUIDLForMessage() 0 14 1
A testgetMsgnoForMessageID() 0 14 1
A testpop3_getCacheUidls() 0 10 1
A testsetStatuses() 0 19 1
A testdeleteMessageFromCache() 0 19 1
A testemptyTrash() 0 11 1
A testdeleteCache() 0 11 1
A testdeletePop3Cache() 0 14 2
A testpop3_open() 0 10 1
A testpop3_cleanUp() 0 14 2
A testpop3_sendCommand() 0 10 1
A testgetPop3NewMessagesToDownload() 0 10 1
A testgetPop3NewMessagesToDownloadForCron() 0 10 1
A testpop3_getUIDL() 0 11 1
A testpop3_checkPartialEmail() 0 17 2
A testpop3_checkEmail() 0 17 2
B testgetMessagesInEmailCache() 0 25 3
A testcheckEmailOneMailbox() 0 9 1
A testcheckEmailOneMailboxPartial() 0 10 1
A testgetCachedIMAPSearch() 0 10 1
A testcheckEmailIMAPPartial() 0 10 1
A testcheckEmail2_meta() 0 11 1
A testgetMailboxProcessCount() 0 8 1
B testcheckEmail() 0 24 3
A testsyncEmail() 0 15 2
A testdeleteCachedMessages() 0 14 2
A testgetOverviewsFromCacheFile() 0 8 1
B testupdateOverviewCacheFile() 0 24 1
A testsetReadFlagOnFolderCache() 0 12 1
B testfetchCheckedEmails() 0 34 1
A testmarkEmails() 0 17 2
A testdeleteFolder() 0 10 1
A testsaveNewFolder() 0 8 1
A testgetImapMboxFromSugarProprietary() 0 16 1
A testrepairAccount() 0 10 1
A testgetTeamSetIdForTeams() 0 18 1
B testsavePersonalEmailAccountAndOthers() 0 31 1
A handleIsPersonal() 0 14 1
A getUserPersonalAccountCount() 0 14 1
A retrieveByGroupFolderId() 0 18 2
A getUserNameFromGroupId() 0 14 1
A deletePersonalEmailAccount() 0 12 1
A testgetFoldersListForMailBox() 0 7 1
A testfindOptimumSettings() 0 12 1
A testgetSessionConnectionString() 0 13 1
A testsetSessionConnectionString() 0 7 1
A testgetSessionInboundDelimiterString() 0 13 1
A testsetSessionInboundDelimiterString() 0 7 1
A testgetSessionInboundFoldersString() 0 13 1
A testsetSessionInboundFoldersString() 0 7 1
A testgroupUserDupeCheck() 0 19 1
A testgetGroupsWithSelectOptions() 0 20 1
B testhandleAutoresponse() 0 24 2
A testhandleCaseAssignment() 0 16 1
A testhandleMailboxType() 0 23 2
A testisMailBoxTypeCreateCase() 0 21 1
A testhandleCreateCase() 0 21 2
A testhandleLinking() 0 16 1
A testgetEncodingFromBreadCrumb() 0 20 1
A testgetCharsetFromBreadCrumb() 0 12 1
A testgetMessageTextFromSingleMimePart() 0 17 2
A testaddBreadCrumbOffset() 0 21 1
A testgetMessageText() 0 18 2
B testdecodeHeader() 0 24 1
A testhandleCharsetTranslation() 0 18 1
A testbuildBreadCrumbs() 0 18 2
A testbuildBreadCrumbsHTML() 0 18 2
A testconvertImapToSugarEmailAddress() 0 16 1
A testhandleEncodedFilename() 0 13 1
A testgetMimeType() 0 13 1
A testsaveAttachments() 0 18 2
A testgetNoteBeanForAttachment() 0 10 1
A testretrieveAttachmentNameFromStructure() 0 21 1
A testsaveAttachmentBinaries() 0 20 2
A testhandleTranserEncoding() 0 8 1
A testgetMessageId() 0 10 1
A testimportDupeCheck() 0 9 1
A testhandleMimeHeaderDecode() 0 8 1
A testgetUnixHeaderDate() 0 8 1
A testgetDuplicateEmailId() 0 18 2
A testimportOneEmail() 0 15 2
A testisUuencode() 0 8 1
A testhandleUUEncodedEmailBody() 0 10 1
A testhandleUUDecode() 0 19 1
A testcheckFilterDomain() 0 17 1
A testcheckOutOfOffice() 0 13 1
A testsetAndgetAutoreplyStatus() 0 19 1
A testsaveInboundEmailSystemSettings() 0 16 1
A testgetSystemSettingsForm() 0 9 1
A testgetCaseIdFromCaseNumber() 0 7 1
A testget_stored_options() 0 10 1
A testgetRelatedId() 0 18 1
A testgetNewMessageIds() 0 8 1
A testgetConnectString() 0 8 1
A testdisconnectMailserver() 0 12 2
A testconnectMailserver() 0 12 1
A testcheckImap() 0 12 2
A testget_summary_text() 0 11 1
A testcreate_export_query() 0 14 1
B testget_list_view_data() 0 24 1
A testfill_in_additional_list_fields() 0 13 1
A testfill_in_additional_detail_fields() 0 13 1
A testisAutoImport() 0 15 1
A testcleanOutCache() 0 12 2
A testcopyEmails() 0 14 2
A testmoveEmails() 0 12 1
A testgetTempFilename() 0 14 1
A testdeleteMessageOnMailServer() 0 8 1
A testdeleteMessageOnMailServerForPop3() 0 12 2
A testisPop3Protocol() 0 11 1
A testSetAndGetUsersDefaultOutboundServerId() 0 15 1
A testsetEmailForDisplay() 0 16 1
A testdisplayOneEmail() 0 21 1
A testcollapseLongMailingList() 0 12 1
B testsortFetchedOverview() 0 33 1
A testdisplayFolderContents() 0 12 1
A testcreateUserSubscriptionsForGroupAccount() 0 14 1
A testcreateAutoImportSugarFolder() 0 17 1
A testgetMailboxes() 0 15 1
A testgetMailBoxesForGroupAccount() 0 12 1
A testretrieveMailBoxFolders() 0 10 1
A testinsertMailBoxFolders() 0 14 2
A testretrieveDelimiter() 0 8 1
A testgenerateFlatArrayFromMultiDimArray() 0 12 1
A testgenerateMultiDimArrayFromFlatArray() 0 10 1
A testgenerateArrayData() 0 12 1
A testsortMailboxes() 0 10 1
A testgetServiceString() 0 10 1
A testgetNewEmailsForSyncedMailbox() 0 12 2
A testimportMessages() 0 14 2
A testOverview() 0 11 1

How to fix   Complexity   

Complex Class

Complex classes like InboundEmailTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use InboundEmailTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
4
class InboundEmailTest extends PHPUnit_Framework_TestCase
5
{
6
    public function testthis_callback()
7
    {
8
9
        //$result = this_callback("%test%");
10
        //var_dump($result);
11
    }
12
13
    public function testInboundEmail()
14
    {
15
16
        //execute the contructor and check for the Object type and  attributes
17
        $inboundEmail = new InboundEmail();
18
19
        $this->assertInstanceOf('InboundEmail', $inboundEmail);
20
        $this->assertInstanceOf('SugarBean', $inboundEmail);
21
22
        $this->assertAttributeEquals('InboundEmail', 'module_dir', $inboundEmail);
23
        $this->assertAttributeEquals('InboundEmail', 'object_name', $inboundEmail);
24
        $this->assertAttributeEquals('inbound_email', 'table_name', $inboundEmail);
25
26
        $this->assertAttributeEquals(true, 'new_schema', $inboundEmail);
27
        $this->assertAttributeEquals(true, 'process_save_dates', $inboundEmail);
28
29
        $this->assertAttributeEquals('defaultIEAccount', 'keyForUsersDefaultIEAccount', $inboundEmail);
30
        $this->assertAttributeEquals(10, 'defaultEmailNumAutoreplies24Hours', $inboundEmail);
31
        $this->assertAttributeEquals(10, 'maxEmailNumAutoreplies24Hours', $inboundEmail);
32
33
        $this->assertAttributeEquals('InboundEmail.cache.php', 'InboundEmailCacheFile', $inboundEmail);
34
35
        $this->assertAttributeEquals('date', 'defaultSort', $inboundEmail);
36
        $this->assertAttributeEquals('DESC', 'defaultDirection', $inboundEmail);
37
        $this->assertAttributeEquals('F', 'iconFlagged', $inboundEmail);
38
        $this->assertAttributeEquals('D', 'iconDraft', $inboundEmail);
39
        $this->assertAttributeEquals('A', 'iconAnswered', $inboundEmail);
40
        $this->assertAttributeEquals('del', 'iconDeleted', $inboundEmail);
41
        $this->assertAttributeEquals(false, 'isAutoImport', $inboundEmail);
42
43
        $this->assertAttributeEquals(0, 'attachmentCount', $inboundEmail);
44
    }
45
46
    public function testsaveAndOthers()
47
    {
48
        error_reporting(E_ERROR | E_PARSE);
49
50
        //unset and reconnect Db to resolve mysqli fetch exeception
51
        global $db;
52
        unset($db->database);
53
        $db->checkConnection();
54
55
        $inboundEmail = new InboundEmail();
56
57
        $inboundEmail->name = 'test';
58
        $inboundEmail->group_id = 1;
59
        $inboundEmail->status = 'Active';
60
        $inboundEmail->email_user = 'testuser';
61
        $inboundEmail->email_password = 'testpass';
62
        $inboundEmail->mailbox = 'mailbox1,mailbox2,mailbox3';
63
64
        $inboundEmail->save();
65
66
        //test for record ID to verify that record is saved
67
        $this->assertTrue(isset($inboundEmail->id));
68
        $this->assertEquals(36, strlen($inboundEmail->id));
69
70
        //test getCorrectMessageNoForPop3 method
71
        $this->getCorrectMessageNoForPop3($inboundEmail->id);
72
73
        //test retrieve method
74
        $this->retrieve($inboundEmail->id);
75
76
        //test retrieveByGroupId method
77
        $this->retrieveByGroupId($inboundEmail->group_id);
78
79
        //test retrieveAllByGroupId method
80
        $this->retrieveAllByGroupId($inboundEmail->group_id);
81
82
        //test retrieveAllByGroupIdWithGroupAccounts method
83
        $this->retrieveAllByGroupIdWithGroupAccounts($inboundEmail->group_id);
84
85
        //test getSingularRelatedId method
86
        $this->getSingularRelatedId();
87
88
        //test renameFolder method
89
        $this->renameFolder($inboundEmail->id);
90
91
        //test search method
92
        $this->search($inboundEmail->id);
93
94
        //test saveMailBoxFolders method
95
        $this->saveMailBoxFolders($inboundEmail->id);
96
97
        //test saveMailBoxValueOfInboundEmail method
98
        $this->saveMailBoxValueOfInboundEmail($inboundEmail->id);
99
100
        //test mark_deleted method
101
        $this->mark_deleted($inboundEmail->id);
102
103
        //test hardDelete method
104
        $this->hardDelete($inboundEmail->id);
105
    }
106
107
    public function getSingularRelatedId()
108
    {
109
110
        //unset and reconnect Db to resolve mysqli fetch exeception
111
        global $db;
112
        unset($db->database);
113
        $db->checkConnection();
114
115
        $inboundEmail = new InboundEmail();
116
117
        $result = $inboundEmail->getSingularRelatedId('test', 'inbound_email');
118
        $this->assertEquals(false, $result);
119
120
        $result = $inboundEmail->getSingularRelatedId('invalid test', 'inbound_email');
121
        $this->assertEquals(null, $result);
122
    }
123
124
    public function getCorrectMessageNoForPop3($id)
125
    {
126
        $inboundEmail = new InboundEmail();
127
128
        $inboundEmail->retrieve($id);
129
130
        $result = $inboundEmail->getCorrectMessageNoForPop3('100');
131
        $this->assertEquals(-1, $result);
132
133
        $result = $inboundEmail->getCorrectMessageNoForPop3('1');
134
        $this->assertEquals(-1, $result);
135
    }
136
137
    public function retrieve($id)
138
    {
139
        $inboundEmail = new InboundEmail();
140
141
        $inboundEmail->retrieve($id);
142
143
        $this->assertEquals('test', $inboundEmail->name);
144
        $this->assertEquals('Active', $inboundEmail->status);
145
        $this->assertEquals('testuser', $inboundEmail->email_user);
146
        $this->assertEquals('testpass', $inboundEmail->email_password);
147
    }
148
149
    public function retrieveByGroupId($group_id)
150
    {
151
        $inboundEmail = new InboundEmail();
152
153
        $result = $inboundEmail->retrieveByGroupId($group_id);
154
155
        $this->assertTrue(is_array($result));
156
157
        foreach ($result as $ie) {
158
            $this->assertInstanceOf('InboundEmail', $ie);
159
        }
160
    }
161
162
    public function retrieveAllByGroupId($group_id)
163
    {
164
        $inboundEmail = new InboundEmail();
165
166
        $result = $inboundEmail->retrieveAllByGroupId($group_id);
167
168
        $this->assertTrue(is_array($result));
169
170
        foreach ($result as $ie) {
171
            $this->assertInstanceOf('InboundEmail', $ie);
172
        }
173
    }
174
175
    public function retrieveAllByGroupIdWithGroupAccounts($group_id)
176
    {
177
        $inboundEmail = new InboundEmail();
178
179
        $result = $inboundEmail->retrieveAllByGroupIdWithGroupAccounts($group_id);
180
181
        $this->assertTrue(is_array($result));
182
183
        foreach ($result as $ie) {
184
            $this->assertInstanceOf('InboundEmail', $ie);
185
        }
186
    }
187
188
    public function renameFolder($id)
189
    {
190
        $inboundEmail = new InboundEmail();
191
192
        $inboundEmail->retrieve($id);
193
194
        //execute the method and test if it works and does not throws an exception.
195
        try {
196
            $inboundEmail->renameFolder('mailbox1', 'new_mailbox');
197
            $this->assertTrue(true);
198
        } catch (Exception $e) {
199
            $this->fail();
200
        }
201
    }
202
203
    public function search($id)
204
    {
205
        $inboundEmail = new InboundEmail();
206
207
        $inboundEmail->retrieve($id);
208
209
        $result = $inboundEmail->search($id);
210
211
        $this->assertTrue(is_array($result));
212
        $this->assertEquals('Search Results', $result['mbox']);
213
        $this->assertEquals($id, $result['ieId']);
214
    }
215
216
    public function saveMailBoxFolders($id)
217
    {
218
        $inboundEmail = new InboundEmail();
219
220
        $inboundEmail->retrieve($id);
221
222
        //execute he method and verify attributes
223
        $inboundEmail->saveMailBoxFolders('INBOX,TRASH');
224
        $this->assertEquals(array('INBOX', 'TRASH'), $inboundEmail->mailboxarray);
225
226
        //retrieve it back and verify the updates
227
        $inboundEmail->retrieve($id);
228
        $this->assertEquals('INBOX,TRASH', $inboundEmail->mailbox);
229
    }
230
231
    public function saveMailBoxValueOfInboundEmail($id)
232
    {
233
        $this->markTestSkipped('saveMailBoxValueOfInboundEmail skipped - method looks suspect. Should likely be removed.');
234
        $inboundEmail = new InboundEmail();
235
236
        $inboundEmail->email_user = 'TEST';
237
238
        $inboundEmail->saveMailBoxValueOfInboundEmail();
239
240
        //retrieve it back and verify the updates
241
        $inboundEmail->retrieve($id);
242
        $this->assertEquals('TEST', $inboundEmail->mailbox);
243
    }
244
245
    public function mark_deleted($id)
246
    {
247
        $inboundEmail = new InboundEmail();
248
249
        $inboundEmail->mark_deleted($id);
250
251
        $result = $inboundEmail->retrieve($id);
252
        $this->assertEquals(null, $result);
253
    }
254
255
    public function hardDelete($id)
256
    {
257
        $inboundEmail = new InboundEmail();
258
259
        $inboundEmail->hardDelete($id);
260
261
        $result = $inboundEmail->retrieve($id);
262
        $this->assertEquals(null, $result);
263
    }
264
265
    public function testcustomGetMessageText()
266
    {
267
        $inboundEmail = new InboundEmail();
268
269
        $result = $inboundEmail->customGetMessageText('some message');
270
        $this->assertEquals('some message', $result);
271
    }
272
273
    public function testgetFormattedRawSource()
274
    {
275
        $inboundEmail = new InboundEmail();
276
277
        //test without ID
278
        $result = $inboundEmail->getFormattedRawSource('1');
279
        $this->assertEquals('This information is not available', $result);
280
281
        //test with ID
282
        $inboundEmail->id = 1;
283
        $result = $inboundEmail->getFormattedRawSource('1');
284
        $this->assertEquals('', $result);
285
    }
286
287
    public function testfilterMailBoxFromRaw()
288
    {
289
290
        //unset and reconnect Db to resolve mysqli fetch exeception
291
        global $db;
292
        unset($db->database);
293
        $db->checkConnection();
294
295
        $inboundEmail = new InboundEmail();
296
297
        //test with array having common element
298
        $result = $inboundEmail->filterMailBoxFromRaw(array('mailbox1', 'mailbox2', 'mailbox3'), array('mailbox1'));
299
        $this->assertSame(array('mailbox1'), $result);
300
301
        //test with array having nothing common
302
        $result = $inboundEmail->filterMailBoxFromRaw(array('mailbox1', 'mailbox2'), array('mailbox4'));
303
        $this->assertSame(array(), $result);
304
    }
305
306
    public function testconvertToUtf8()
307
    {
308
        $inboundEmail = new InboundEmail();
309
        $result = $inboundEmail->convertToUtf8('some text with non UTF8 chars');
310
        $this->assertSame('some text with non UTF8 chars', $result);
311
    }
312
313
    public function testgetFormattedHeaders()
314
    {
315
        $inboundEmail = new InboundEmail();
316
317
        //test for default/imap
318
        $result = $inboundEmail->getFormattedHeaders(1);
319
        $this->assertSame("<table cellspacing='0' cellpadding='2' border='0' width='100%'></table>", $result);
320
321
        //test for pop3
322
        $inboundEmail->protocol = 'pop3';
323
        $result = $inboundEmail->getFormattedHeaders(1);
324
        $this->assertSame("<table cellspacing='0' cellpadding='2' border='0' width='100%'></table>", $result);
325
    }
326
327
    public function testsetAndgetCacheTimestamp()
328
    {
329
        $inboundEmail = new InboundEmail();
330
331
        $inboundEmail->id = 1;
332
333
        //test setCacheTimestamp method
334
        $inboundEmail->setCacheTimestamp('INBOX');
335
336
        //test getCacheTimestamp method
337
        $result = $inboundEmail->getCacheTimestamp('INBOX');
338
        $this->assertGreaterThan(0, strlen($result));
339
    }
340
341
    public function testsetCacheValue()
342
    {
343
        $inboundEmail = new InboundEmail();
344
345
        $inboundEmail->id = 1;
346
347
        $inserts = array();
348
349
        $overview = new Overview();
350
        $overview->imap_uid = 1;
351
        $overview->subject = 'subject';
352
        $overview->from = 'from';
353
        $overview->fromaddr = '[email protected]';
354
        $overview->to = 'to';
355
        $overview->toaddr = '[email protected]';
356
        $overview->size = 0;
357
        $overview->message_id = 1;
358
359
        $inserts[] = $overview;
360
361
        //execute the method to populate email cache
362
        $inboundEmail->setCacheValue('INBOX', $inserts);
363
        $inboundEmail->setCacheValue('INBOX.Trash', $inserts);
364
365
        //retrieve back to verify the records created
366
        $result = $inboundEmail->getCacheValue('INBOX');
367
368
        $this->assertGreaterThan(0, count($result['retArr'][0]));
369
        $this->assertEquals(1, $result['retArr'][0]->message_id);
370
    }
371
372
    public function testgetCacheValueForUIDs()
373
    {
374
        $inboundEmail = new InboundEmail();
375
376
        //test wih default protocol
377
        $result = $inboundEmail->getCacheValueForUIDs('INBOX', array(1, 2, 3, 4, 5));
378
379
        $this->assertTrue(is_array($result));
380
        $this->assertTrue(is_array($result['uids']));
381
        $this->assertTrue(is_array($result['retArr']));
382
383
        //test wih pop3 protocol
384
        $inboundEmail->protocol = 'pop3';
385
        $result = $inboundEmail->getCacheValueForUIDs('INBOX', array(1, 2, 3, 4, 5));
386
387
        $this->assertTrue(is_array($result));
388
        $this->assertTrue(is_array($result['uids']));
389
        $this->assertTrue(is_array($result['retArr']));
390
    }
391
392
    public function testgetCacheValue()
393
    {
394
        $inboundEmail = new InboundEmail();
395
396
        //test wih default protocol
397
        $result = $inboundEmail->getCacheValue('INBOX');
398
399
        $this->assertTrue(is_array($result));
400
        $this->assertTrue(is_array($result['uids']));
401
        $this->assertTrue(is_array($result['retArr']));
402
403
        //test wih pop3 protocol
404
        $inboundEmail->protocol = 'pop3';
405
        $result = $inboundEmail->getCacheValue('INBOX');
406
407
        $this->assertTrue(is_array($result));
408
        $this->assertTrue(is_array($result['uids']));
409
        $this->assertTrue(is_array($result['retArr']));
410
    }
411
412
    public function testvalidCacheExists()
413
    {
414
        $inboundEmail = new InboundEmail();
415
416
        //test without a valid id
417
        $result = $inboundEmail->validCacheExists('');
418
        $this->assertEquals(false, $result);
419
420
        //test with a valid id set
421
        $inboundEmail->id = 1;
422
        $result = $inboundEmail->validCacheExists('');
423
        $this->assertEquals(true, $result);
424
    }
425
426
    public function testdisplayFetchedSortedListXML()
427
    {
428
        $inboundEmail = new InboundEmail();
429
430
        //get the cache values array first
431
        $inboundEmail->id = 1;
432
        $ret = $inboundEmail->getCacheValue('INBOX');
433
434
        //use the cache values array as parameter and verify that it returns an array
435
        $result = $inboundEmail->displayFetchedSortedListXML($ret, 'INBOX');
436
        $this->assertTrue(is_array($result));
437
    }
438
439
    public function testgetCacheUnreadCount()
440
    {
441
        $inboundEmail = new InboundEmail();
442
443
        $inboundEmail->id = 1;
444
445
        //test with invalid mailbox
446
        $result = $inboundEmail->getCacheUnreadCount('OUTBOX');
447
        $this->assertEquals(0, $result);
448
449
        //test with valid mailbox
450
        $result = $inboundEmail->getCacheUnreadCount('INBOX');
451
        $this->assertGreaterThanOrEqual(1, $result);
452
    }
453
454
    public function testgetCacheCount()
455
    {
456
        $inboundEmail = new InboundEmail();
457
458
        $inboundEmail->id = 1;
459
460
        //test with invalid mailbox
461
        $result = $inboundEmail->getCacheCount('OUTBOX');
462
        $this->assertEquals(0, $result);
463
464
        //test with valid mailbox
465
        $result = $inboundEmail->getCacheCount('INBOX');
466
        $this->assertGreaterThanOrEqual(1, $result);
467
    }
468
469
    public function testgetCacheUnread()
470
    {
471
        $inboundEmail = new InboundEmail();
472
473
        $inboundEmail->id = 1;
474
475
        //test with invalid mailbox
476
        $result = $inboundEmail->getCacheUnread('OUTBOX');
477
        $this->assertEquals(0, $result);
478
479
        //test with valid mailbox
480
        $result = $inboundEmail->getCacheUnread('INBOX');
481
        $this->assertGreaterThanOrEqual(1, $result);
482
    }
483
484
    public function testmark_answered()
485
    {
486
        $inboundEmail = new InboundEmail();
487
488
        $inboundEmail->id = 1;
489
490
        //execute the method to populate answered field
491
        $inboundEmail->mark_answered(1, 'pop3');
492
493
        //retrieve back to verify the records updated
494
        $result = $inboundEmail->getCacheValue('INBOX');
495
496
        $this->assertEquals(1, $result['retArr'][0]->answered);
497
    }
498
499
    public function testpop3_shiftCache()
500
    {
501
        $inboundEmail = new InboundEmail();
502
503
        $inboundEmail->id = 1;
504
505
        $result = $inboundEmail->pop3_shiftCache(array('1' => '1'), array('1'));
506
507
        //retrieve back to verify the records updated
508
        $result = $inboundEmail->getCacheValue('INBOX');
509
510
        $this->assertEquals(1, $result['retArr'][0]->imap_uid);
511
        $this->assertEquals(1, $result['retArr'][0]->msgno);
512
    }
513
514
    public function testgetUIDLForMessage()
515
    {
516
        $inboundEmail = new InboundEmail();
517
518
        $inboundEmail->id = 1;
519
520
        //test with invalid msgNo
521
        $result = $inboundEmail->getUIDLForMessage('2');
522
        $this->assertEquals('', $result);
523
524
        //test with valid msgNo
525
        $result = $inboundEmail->getUIDLForMessage('1');
526
        $this->assertEquals('1', $result);
527
    }
528
529
    public function testgetMsgnoForMessageID()
530
    {
531
        $inboundEmail = new InboundEmail();
532
533
        $inboundEmail->id = 1;
534
535
        //test with invalid msgNo
536
        $result = $inboundEmail->getMsgnoForMessageID('2');
537
        $this->assertEquals('', $result);
538
539
        //test with valid msgNo but most probably it will never work because of wrong column name in return statement
540
        $result = $inboundEmail->getMsgnoForMessageID('1');
541
        $this->assertEquals('', $result);
542
    }
543
544
    public function testpop3_getCacheUidls()
545
    {
546
        $inboundEmail = new InboundEmail();
547
548
        $inboundEmail->id = 1;
549
550
        $result = $inboundEmail->pop3_getCacheUidls();
551
552
        $this->assertEquals(array('1' => '1'), $result);
553
    }
554
555
    /**
556
     * @todo: NEEDS REVISION
557
     */
558
    public function testsetStatuses()
559
    {
560
        /*
561
        $inboundEmail = new InboundEmail();
562
563
        $inboundEmail->id = 1;
564
        $inboundEmail->mailbox = 'INBOX';
565
566
        //execute the method
567
        $inboundEmail->setStatuses('1', 'message_id', '123');
568
569
        //retrieve back to verify the records created
570
        $result = $inboundEmail->getCacheValueForUIDs('INBOX', array(1));
571
572
        $this->assertTrue(is_array($result));
573
        $this->assertEquals('123', $result['retArr'][0]->message_id);
574
        */
575
        $this->markTestIncomplete("Different results for php5 and php7");
576
    }
577
578
    /**
579
     * @todo: NEEDS REVISION
580
     */
581
    public function testdeleteMessageFromCache()
582
    {
583
        /*
584
        $inboundEmail = new InboundEmail();
585
586
        $inboundEmail->id = 1;
587
        $inboundEmail->mailbox = 'INBOX';
588
        $inboundEmail->protocol = 'pop3';
589
590
        $inboundEmail->deleteMessageFromCache('123');
591
592
        //retrieve back to verify the records deleted
593
        $result = $inboundEmail->getCacheValueForUIDs('INBOX', array(1));
594
595
        $this->assertTrue(is_array($result));
596
        $this->assertEquals(0, count($result['retArr']));
597
        */
598
        $this->markTestIncomplete("Unable to test until testsetStatuses is re-enabled");
599
    }
600
601
    public function testemptyTrash()
602
    {
603
        $inboundEmail = new InboundEmail();
604
605
        $inboundEmail->id = 1;
606
607
        $inboundEmail->emptyTrash();
608
609
        $result = $inboundEmail->getCacheValue('INBOX.Trash');
610
        $this->assertEquals(0, count($result['retArr']));
611
    }
612
613
    public function testdeleteCache()
614
    {
615
        $inboundEmail = new InboundEmail();
616
617
        $inboundEmail->id = 1;
618
619
        $inboundEmail->deleteCache();
620
621
        $result = $inboundEmail->getCacheValue('INBOX');
622
        $this->assertEquals(0, count($result['retArr']));
623
    }
624
625
    public function testdeletePop3Cache()
626
    {
627
        $inboundEmail = new InboundEmail();
628
629
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
630
631
        //execute the method and test if it works and does not throws an exception.
632
        try {
633
            $inboundEmail->deletePop3Cache();
634
            $this->assertTrue(true);
635
        } catch (Exception $e) {
636
            $this->fail();
637
        }
638
    }
639
640
    public function testpop3_open()
641
    {
642
        $inboundEmail = new InboundEmail();
643
644
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
645
646
        $result = $inboundEmail->pop3_open();
647
648
        $this->assertEquals(false, $result);
649
    }
650
651
    public function testpop3_cleanUp()
652
    {
653
        $inboundEmail = new InboundEmail();
654
655
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
656
657
        //execute the method and test if it works and does not throws an exception.
658
        try {
659
            $inboundEmail->pop3_cleanUp();
660
            $this->assertTrue(true);
661
        } catch (Exception $e) {
662
            $this->fail();
663
        }
664
    }
665
666
    public function testpop3_sendCommand()
667
    {
668
        $inboundEmail = new InboundEmail();
669
670
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
671
672
        $result = $inboundEmail->pop3_sendCommand('get');
673
674
        $this->assertEquals('', $result);
675
    }
676
677
    public function testgetPop3NewMessagesToDownload()
678
    {
679
        $inboundEmail = new InboundEmail();
680
681
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
682
683
        $result = $inboundEmail->getPop3NewMessagesToDownload();
684
685
        $this->assertTrue(is_array($result));
686
    }
687
688
    public function testgetPop3NewMessagesToDownloadForCron()
689
    {
690
        $inboundEmail = new InboundEmail();
691
692
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
693
694
        $result = $inboundEmail->getPop3NewMessagesToDownloadForCron();
695
696
        $this->assertTrue(is_array($result));
697
    }
698
699
    public function testpop3_getUIDL()
700
    {
701
        $inboundEmail = new InboundEmail();
702
703
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
704
        $inboundEmail->protocol = 'pop3';
705
706
        $result = $inboundEmail->getPop3NewMessagesToDownloadForCron();
707
708
        $this->assertTrue(is_array($result));
709
    }
710
711
    public function testpop3_checkPartialEmail()
712
    {
713
        $inboundEmail = new InboundEmail();
714
715
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
716
        $inboundEmail->protocol = 'pop3';
717
718
        //execute the method and test if it works and does not throws an exception.
719
        try {
720
            $result = $inboundEmail->pop3_checkPartialEmail();
721
            $this->assertEquals('could not open socket connection to POP3 server', $result);
722
723
            $this->assertTrue(true);
724
        } catch (Exception $e) {
725
            $this->fail();
726
        }
727
    }
728
729
    public function testpop3_checkEmail()
730
    {
731
        $inboundEmail = new InboundEmail();
732
733
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
734
        $inboundEmail->protocol = 'pop3';
735
736
        //execute the method and test if it works and does not throws an exception.
737
        try {
738
            $result = $inboundEmail->pop3_checkEmail();
739
            $this->assertEquals(false, $result);
740
741
            $this->assertTrue(true);
742
        } catch (Exception $e) {
743
            $this->fail();
744
        }
745
    }
746
747
    public function testgetMessagesInEmailCache()
748
    {
749
        $inboundEmail = new InboundEmail();
750
751
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
752
753
        //test for IMAP
754
        //execute the method and test if it works and does not throws an exception.
755
        try {
756
            $result = $inboundEmail->getMessagesInEmailCache(0, 1);
757
            $this->assertTrue(true);
758
        } catch (Exception $e) {
759
            $this->fail();
760
        }
761
762
        //test for pop3
763
        $inboundEmail->protocol = 'pop3';
764
        //execute the method and test if it works and does not throws an exception.
765
        try {
766
            $result = $inboundEmail->getMessagesInEmailCache(1, 0);
767
            $this->assertTrue(true);
768
        } catch (Exception $e) {
769
            $this->fail();
770
        }
771
    }
772
773
    public function testcheckEmailOneMailbox()
774
    {
775
        $inboundEmail = new InboundEmail();
776
777
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
778
779
        $result = $inboundEmail->checkEmailOneMailbox('INBOX');
780
        $this->assertEquals(1, $result);
781
    }
782
783
    public function testcheckEmailOneMailboxPartial()
784
    {
785
        $inboundEmail = new InboundEmail();
786
787
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
788
789
        $result = $inboundEmail->checkEmailOneMailboxPartial('INBOX');
790
791
        $this->assertEquals(array('status' => 'done'), $result);
792
    }
793
794
    public function testgetCachedIMAPSearch()
795
    {
796
        $inboundEmail = new InboundEmail();
797
798
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
799
800
        $result = $inboundEmail->getCachedIMAPSearch('test');
801
802
        $this->assertTrue(is_array($result));
803
    }
804
805
    public function testcheckEmailIMAPPartial()
806
    {
807
        $inboundEmail = new InboundEmail();
808
809
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
810
811
        $result = $inboundEmail->checkEmailIMAPPartial();
812
813
        $this->assertTrue(is_array($result));
814
    }
815
816
    public function testcheckEmail2_meta()
817
    {
818
        $inboundEmail = new InboundEmail();
819
820
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
821
822
        $result = $inboundEmail->checkEmail2_meta();
823
824
        $this->assertTrue(is_array($result));
825
        $this->assertEquals(array('mailboxes' => array('INBOX' => 0), 'processCount' => 0), $result);
826
    }
827
828
    public function testgetMailboxProcessCount()
829
    {
830
        $inboundEmail = new InboundEmail();
831
832
        $result = $inboundEmail->getMailboxProcessCount('INBOX');
833
834
        $this->assertEquals(0, $result);
835
    }
836
837
    public function testcheckEmail()
838
    {
839
        $inboundEmail = new InboundEmail();
840
841
        //test for IMAP
842
        //execute the method and test if it works and does not throws an exception.
843
        try {
844
            $inboundEmail->checkEmail('INBOX');
845
            $this->assertTrue(true);
846
        } catch (Exception $e) {
847
            $this->fail();
848
        }
849
850
        //test for pop3
851
        $inboundEmail->protocol = 'pop3';
852
853
        //execute the method and test if it works and does not throws an exception.
854
        try {
855
            $inboundEmail->checkEmail('INBOX');
856
            $this->assertTrue(true);
857
        } catch (Exception $e) {
858
            $this->fail();
859
        }
860
    }
861
862
    public function testsyncEmail()
863
    {
864
        global $current_user;
865
        $current_user = new User('1');
866
867
        $inboundEmail = new InboundEmail();
868
869
        //execute the method and test if it works and does not throws an exception.
870
        try {
871
            $inboundEmail->syncEmail();
872
            $this->assertTrue(true);
873
        } catch (Exception $e) {
874
            $this->fail();
875
        }
876
    }
877
878
    public function testdeleteCachedMessages()
879
    {
880
        $inboundEmail = new InboundEmail();
881
882
        $inboundEmail->id = 1;
883
884
        //execute the method and test if it works and does not throws an exception.
885
        try {
886
            $inboundEmail->deleteCachedMessages('1,2', 'test');
887
            $this->assertTrue(true);
888
        } catch (Exception $e) {
889
            $this->fail();
890
        }
891
    }
892
893
    public function testgetOverviewsFromCacheFile()
894
    {
895
        $inboundEmail = new InboundEmail();
896
897
        $result = $inboundEmail->getOverviewsFromCacheFile('1,2', 'INBOX');
898
899
        $this->assertTrue(is_array($result));
900
    }
901
902
    /**
903
     * @todo: NEEDS REVISION
904
     */
905
    public function testupdateOverviewCacheFile()
906
    {
907
        /*
908
        $inboundEmail = new InboundEmail();
909
910
        $inboundEmail->id = 1;
911
        $inboundEmail->mailbox = 'INBOX';
912
913
        $overview = new Overview();
914
        $overview->subject = 'subject 1';
915
        $overview->size = '10001';
916
        $overview->uid = '1';
917
918
        $overviews = array($overview);
919
920
        $inboundEmail->updateOverviewCacheFile($overviews);
921
922
        //retrieve back to verify the records created
923
        $result = $inboundEmail->getCacheValue('INBOX');
924
        $this->assertGreaterThan(0, count($result['retArr'][0]));
925
        $this->assertEquals('subject 1', $result['retArr'][0]->subject);
926
        */
927
        $this->markTestIncomplete("Different results for php5 and php7");
928
    }
929
930
    public function testsetReadFlagOnFolderCache()
931
    {
932
        $inboundEmail = new InboundEmail();
933
934
        $inboundEmail->id = 1;
935
936
        $inboundEmail->setReadFlagOnFolderCache('INBOX', '1');
937
938
        //retrieve back to verify the records updated
939
        $result = $inboundEmail->getCacheValue('INBOX');
940
        $this->assertEquals(0, $result['retArr'][0]->seen);
941
    }
942
943
    public function testfetchCheckedEmails()
944
    {
945
946
        //unset and reconnect Db to resolve mysqli fetch exeception
947
        global $db;
948
        unset($db->database);
949
        $db->checkConnection();
950
951
        $inboundEmail = new InboundEmail();
952
953
        $inboundEmail->id = 1;
954
        $inboundEmail->mailbox = 'INBOX';
955
956
        //test with size over 1000 and no imap_uid
957
        $overview1 = new Overview();
958
        $overview1->subject = 'subject 1';
959
        $overview1->size = '10001';
960
961
        $fetchedOverviews = array($overview1);
962
        $result = $inboundEmail->fetchCheckedEmails($fetchedOverviews);
963
964
        $this->assertEquals(false, $result);
965
966
        //test with size less than 1000 and imap_uid set
967
        $overview2 = new Overview();
968
        $overview2->subject = 'subject 2';
969
        $overview2->size = '100';
970
        //$overview2->imap_uid = 1; //dies if imap_uid is set
971
972
        $fetchedOverviews = array($overview2);
973
        $result = $inboundEmail->fetchCheckedEmails($fetchedOverviews);
974
975
        $this->assertEquals(true, $result);
976
    }
977
978
    public function testmarkEmails()
979
    {
980
        $inboundEmail = new InboundEmail();
981
982
        //execute the method and test if it works and does not throws an exception.
983
        try {
984
            $inboundEmail->markEmails('1', 'unread');
985
            $inboundEmail->markEmails('1', 'read');
986
            $inboundEmail->markEmails('1', 'flagged');
987
            $inboundEmail->markEmails('1', 'unflagged');
988
            $inboundEmail->markEmails('1', 'answered');
989
990
            $this->assertTrue(true);
991
        } catch (Exception $e) {
992
            $this->fail();
993
        }
994
    }
995
996
    public function testdeleteFolder()
997
    {
998
        $inboundEmail = new InboundEmail();
999
1000
        $inboundEmail->mailbox = 'INBOX,OUTBOX';
1001
1002
        $result = $inboundEmail->deleteFolder('INBOX');
1003
1004
        $this->assertTrue(is_array($result));
1005
    }
1006
1007
    public function testsaveNewFolder()
1008
    {
1009
        $inboundEmail = new InboundEmail();
1010
1011
        $result = $inboundEmail->saveNewFolder('TEST', 'INBOX');
1012
1013
        $this->assertEquals(false, $result);
1014
    }
1015
1016
    public function testgetImapMboxFromSugarProprietary()
1017
    {
1018
        $inboundEmail = new InboundEmail();
1019
1020
        //test with invalid format string
1021
        $result = $inboundEmail->getImapMboxFromSugarProprietary('INBOX.TRASH');
1022
        $this->assertEquals('', $result);
1023
1024
        //test with valid format but shorter string
1025
        $result = $inboundEmail->getImapMboxFromSugarProprietary('INBOX::TRASH');
1026
        $this->assertEquals('', $result);
1027
1028
        //test with valid format longer string
1029
        $result = $inboundEmail->getImapMboxFromSugarProprietary('INBOX::TRASH::TEST');
1030
        $this->assertEquals('TEST', $result);
1031
    }
1032
1033
    public function testrepairAccount()
1034
    {
1035
        $inboundEmail = new InboundEmail();
1036
1037
        $inboundEmail->email_password = 'test_pass';
1038
1039
        $result = $inboundEmail->repairAccount();
1040
1041
        $this->assertEquals(false, $result);
1042
    }
1043
1044
    public function testgetTeamSetIdForTeams()
1045
    {
1046
1047
        //unset and reconnect Db to resolve mysqli fetch exeception
1048
        global $db;
1049
        unset($db->database);
1050
        $db->checkConnection();
1051
1052
        $inboundEmail = new InboundEmail();
1053
1054
        //$result = $inboundEmail->getTeamSetIdForTeams("1");
1055
1056
        //test for record ID to verify that record is saved
1057
        //$this->assertTrue(isset($result));
1058
        //$this->assertEquals(36, strlen($result));
1059
1060
        $this->markTestIncomplete("Fatal error: Class 'Team' not found");
1061
    }
1062
1063
    public function testsavePersonalEmailAccountAndOthers()
1064
    {
1065
        $inboundEmail = new InboundEmail();
1066
1067
        $_REQUEST['ie_name'] = 'test';
1068
        $_REQUEST['ie_status'] = 'Active';
1069
        $_REQUEST['server_url'] = '';
1070
        $_REQUEST['email_user'] = 'test';
1071
        $_REQUEST['email_password'] = 'test_pass';
1072
        $_REQUEST['mailbox'] = 'INBOX';
1073
1074
        $result = $inboundEmail->savePersonalEmailAccount(1, 'admin', true);
1075
1076
        $this->assertTrue(isset($inboundEmail->id));
1077
        $this->assertEquals(36, strlen($inboundEmail->id));
1078
1079
        //test handleIsPersonal method
1080
        $this->handleIsPersonal($inboundEmail->id);
1081
1082
        //test getUserPersonalAccountCount method
1083
        $this->getUserPersonalAccountCount();
1084
1085
        //test retrieveByGroupFolderId method
1086
        $this->retrieveByGroupFolderId();
1087
1088
        //test getUserNameFromGroupId method
1089
        $this->getUserNameFromGroupId($inboundEmail->id);
1090
1091
        //test deletePersonalEmailAccount method
1092
        $this->deletePersonalEmailAccount($inboundEmail->id);
1093
    }
1094
1095
    public function handleIsPersonal($id)
1096
    {
1097
        $inboundEmail = new InboundEmail();
1098
1099
        //test with a invalid group_id
1100
        $inboundEmail->group_id = 2;
1101
        $result = $inboundEmail->handleIsPersonal();
1102
        $this->assertEquals(false, $result);
1103
1104
        //test with a valid group_id
1105
        $inboundEmail->retrieve($id);
1106
        $result = $inboundEmail->handleIsPersonal();
1107
        $this->assertEquals(true, $result);
1108
    }
1109
1110
    public function getUserPersonalAccountCount()
1111
    {
1112
        $inboundEmail = new InboundEmail();
1113
1114
        //test with invalid user id
1115
        $user = new User();
1116
        $result = $inboundEmail->getUserPersonalAccountCount($user);
1117
        $this->assertEquals(0, $result);
1118
1119
        //test with valid user id
1120
        $user->id = 1;
1121
        $result = $inboundEmail->getUserPersonalAccountCount($user);
1122
        $this->assertGreaterThan(0, $result);
1123
    }
1124
1125
    public function retrieveByGroupFolderId()
1126
    {
1127
        $inboundEmail = new InboundEmail();
1128
1129
        //test with invalid groupfolder id
1130
        $result = $inboundEmail->retrieveByGroupFolderId('1');
1131
1132
        $this->assertTrue(is_array($result));
1133
        $this->assertEquals(0, count($result));
1134
1135
        //test with valid groupfolder id
1136
        $result = $inboundEmail->retrieveByGroupFolderId('');
1137
1138
        $this->assertTrue(is_array($result));
1139
        foreach ($result as $ie) {
1140
            $this->assertInstanceOf('InboundEmail', $ie);
1141
        }
1142
    }
1143
1144
    public function getUserNameFromGroupId($id)
1145
    {
1146
        $inboundEmail = new InboundEmail();
1147
1148
        //test with a invalid group_id
1149
        $inboundEmail->group_id = 2;
1150
        $result = $inboundEmail->getUserNameFromGroupId();
1151
        $this->assertEquals('', $result);
1152
1153
        //test with a valid group_id
1154
        $inboundEmail->retrieve($id);
1155
        $result = $inboundEmail->getUserNameFromGroupId();
1156
        $this->assertEquals('admin', $result);
1157
    }
1158
1159
    public function deletePersonalEmailAccount($id)
1160
    {
1161
        $inboundEmail = new InboundEmail();
1162
1163
        //test with invalid username
1164
        $result = $inboundEmail->deletePersonalEmailAccount($id, 'test');
1165
        $this->assertEquals(false, $result);
1166
1167
        //test with valid username
1168
        $result = $inboundEmail->deletePersonalEmailAccount($id, 'admin');
1169
        $this->assertEquals(true, $result);
1170
    }
1171
1172
    public function testgetFoldersListForMailBox()
1173
    {
1174
        $inboundEmail = new InboundEmail();
1175
1176
        $result = $inboundEmail->getFoldersListForMailBox();
1177
        $this->assertTrue(is_array($result));
1178
    }
1179
1180
    public function testfindOptimumSettings()
1181
    {
1182
        $inboundEmail = new InboundEmail();
1183
1184
        //test with different parameters, it will always return false because we do not have a mail server to connect.
1185
1186
        $this->assertEquals(false, $inboundEmail->findOptimumSettings());
1187
1188
        $this->assertEquals(false, $inboundEmail->findOptimumSettings(true));
1189
1190
        $this->assertEquals(false, $inboundEmail->findOptimumSettings(false, 'test', 'test', '', '', 'INBOX'));
1191
    }
1192
1193
    public function testgetSessionConnectionString()
1194
    {
1195
        $inboundEmail = new InboundEmail();
1196
1197
        //test without setting session key
1198
        $result = $inboundEmail->getSessionConnectionString('mail.google.com', 'test', 22, 'IMAP');
1199
        $this->assertEquals('', $result);
1200
1201
        //test with session key set
1202
        $_SESSION['mail.google.comtest22IMAP'] = 'test connection string';
1203
        $result = $inboundEmail->getSessionConnectionString('mail.google.com', 'test', 22, 'IMAP');
1204
        $this->assertEquals('test connection string', $result);
1205
    }
1206
1207
    public function testsetSessionConnectionString()
1208
    {
1209
        $inboundEmail = new InboundEmail();
1210
1211
        $result = $inboundEmail->setSessionConnectionString('mail.google.com', 'test', 22, 'IMAP', 'test connection');
1212
        $this->assertEquals('test connection', $_SESSION['mail.google.comtest22IMAP']);
1213
    }
1214
1215
    public function testgetSessionInboundDelimiterString()
1216
    {
1217
        $inboundEmail = new InboundEmail();
1218
1219
        //test without setting session key
1220
        $result = $inboundEmail->getSessionInboundDelimiterString('mail.google.com', 'test', 22, 'IMAP');
1221
        $this->assertEquals('', $result);
1222
1223
        //test with session key set
1224
        $_SESSION['mail.google.comtest22IMAPdelimiter'] = 'delimit string';
1225
        $result = $inboundEmail->getSessionInboundDelimiterString('mail.google.com', 'test', 22, 'IMAP');
1226
        $this->assertEquals('delimit string', $result);
1227
    }
1228
1229
    public function testsetSessionInboundDelimiterString()
1230
    {
1231
        $inboundEmail = new InboundEmail();
1232
1233
        $result = $inboundEmail->setSessionInboundDelimiterString('mail.google.com', 'test', 22, 'IMAP', 'test string');
1234
        $this->assertEquals('test string', $_SESSION['mail.google.comtest22IMAPdelimiter']);
1235
    }
1236
1237
    public function testgetSessionInboundFoldersString()
1238
    {
1239
        $inboundEmail = new InboundEmail();
1240
1241
        //test without setting session key
1242
        $result = $inboundEmail->getSessionInboundFoldersString('mail.google.com', 'test', 22, 'IMAP');
1243
        $this->assertEquals('', $result);
1244
1245
        //test with session key set
1246
        $_SESSION['mail.google.comtest22IMAPfoldersList'] = 'foldersList string';
1247
        $result = $inboundEmail->getSessionInboundFoldersString('mail.google.com', 'test', 22, 'IMAP');
1248
        $this->assertEquals('foldersList string', $result);
1249
    }
1250
1251
    public function testsetSessionInboundFoldersString()
1252
    {
1253
        $inboundEmail = new InboundEmail();
1254
1255
        $result = $inboundEmail->setSessionInboundFoldersString('mail.google.com', 'test', 22, 'IMAP', 'foldersList string');
1256
        $this->assertEquals('foldersList string', $_SESSION['mail.google.comtest22IMAPfoldersList']);
1257
    }
1258
1259
    public function testgroupUserDupeCheck()
1260
    {
1261
1262
        //unset and reconnect Db to resolve mysqli fetch exeception
1263
        global $db;
1264
        unset($db->database);
1265
        $db->checkConnection();
1266
1267
        $inboundEmail = new InboundEmail();
1268
1269
        //test without name i-e user_name in query
1270
        $result = $inboundEmail->groupUserDupeCheck();
1271
        $this->assertEquals(false, $result);
1272
1273
        //test with name i-e user_name in query
1274
        $inboundEmail->name = 'admin';
1275
        $result = $inboundEmail->groupUserDupeCheck();
1276
        $this->assertEquals(false, $result);
1277
    }
1278
1279
    public function testgetGroupsWithSelectOptions()
1280
    {
1281
1282
        //unset and reconnect Db to resolve mysqli fetch exeception
1283
        global $db;
1284
        unset($db->database);
1285
        $db->checkConnection();
1286
1287
        $inboundEmail = new InboundEmail();
1288
1289
        $inboundEmail->group_id = 1;
1290
1291
        $result = $inboundEmail->getGroupsWithSelectOptions();
1292
        $this->assertEquals('', $result);
1293
1294
        $expected = "\n<OPTION value='0'>1</OPTION>\n<OPTION selected value='1'>2</OPTION>\n<OPTION value='2'>3</OPTION>";
1295
        $result = $inboundEmail->getGroupsWithSelectOptions(array(1, 2, 3));
1296
        $this->assertEquals($expected, $result);
1297
        //var_dump($result);
1298
    }
1299
1300
    public function testhandleAutoresponse()
1301
    {
1302
1303
        //unset and reconnect Db to resolve mysqli fetch exeception
1304
        global $db;
1305
        unset($db->database);
1306
        $db->checkConnection();
1307
1308
        $inboundEmail = new InboundEmail();
1309
1310
        $inboundEmail->template_id = 1;
1311
        $email = new Email();
1312
        $email->name = 'test';
1313
1314
        $contactAddr = '[email protected]';
1315
1316
        //execute the method and test if it works and does not throws an exception.
1317
        try {
1318
            $result = $inboundEmail->handleAutoresponse($email, $contactAddr);
1319
            $this->assertTrue(true);
1320
        } catch (Exception $e) {
1321
            $this->fail();
1322
        }
1323
    }
1324
1325
    public function testhandleCaseAssignment()
1326
    {
1327
1328
        //unset and reconnect Db to resolve mysqli fetch exeception
1329
        global $db;
1330
        unset($db->database);
1331
        $db->checkConnection();
1332
1333
        $inboundEmail = new InboundEmail();
1334
1335
        $email = new Email();
1336
        $email->name = 'test';
1337
1338
        $result = $inboundEmail->handleCaseAssignment($email);
1339
        $this->assertEquals(false, $result);
1340
    }
1341
1342
    public function testhandleMailboxType()
1343
    {
1344
1345
        //unset and reconnect Db to resolve mysqli fetch exeception
1346
        global $db;
1347
        unset($db->database);
1348
        $db->checkConnection();
1349
1350
        $inboundEmail = new InboundEmail();
1351
1352
        $email = new Email();
1353
        $email->name = 'test';
1354
1355
        $inboundEmail->mailbox_type = 'support';
1356
1357
        //execute the method and test if it works and does not throws an exception.
1358
        try {
1359
            $inboundEmail->handleMailboxType($email, $header);
1360
            $this->assertTrue(true);
1361
        } catch (Exception $e) {
1362
            $this->fail();
1363
        }
1364
    }
1365
1366
    public function testisMailBoxTypeCreateCase()
1367
    {
1368
1369
        //unset and reconnect Db to resolve mysqli fetch exeception
1370
        global $db;
1371
        unset($db->database);
1372
        $db->checkConnection();
1373
1374
        $inboundEmail = new InboundEmail();
1375
1376
        //test without setting attributes
1377
        $result = $inboundEmail->isMailBoxTypeCreateCase();
1378
        $this->assertEquals(false, $result);
1379
1380
        //test with attributes set
1381
        $inboundEmail->mailbox_type = 'createcase';
1382
        $inboundEmail->groupfolder_id = 1;
1383
1384
        $result = $inboundEmail->isMailBoxTypeCreateCase();
1385
        $this->assertEquals(true, $result);
1386
    }
1387
1388
    public function testhandleCreateCase()
1389
    {
1390
1391
        //unset and reconnect Db to resolve mysqli fetch exeception
1392
        global $db;
1393
        unset($db->database);
1394
        $db->checkConnection();
1395
1396
        $inboundEmail = new InboundEmail();
1397
1398
        $email = new Email();
1399
        $email->name = 'test';
1400
1401
        //execute the method and test if it works and does not throws an exception.
1402
        try {
1403
            $inboundEmail->handleCreateCase($email, 1);
1404
            $this->assertTrue(true);
1405
        } catch (Exception $e) {
1406
            $this->fail();
1407
        }
1408
    }
1409
1410
    public function testhandleLinking()
1411
    {
1412
1413
        //unset and reconnect Db to resolve mysqli fetch exeception
1414
        global $db;
1415
        unset($db->database);
1416
        $db->checkConnection();
1417
1418
        $inboundEmail = new InboundEmail();
1419
1420
        $email = new Email();
1421
        $email->from_addr = '[email protected]';
1422
1423
        $result = $inboundEmail->handleLinking($email);
1424
        $this->assertEquals($email->from_addr, $result);
1425
    }
1426
1427
    public function testgetEncodingFromBreadCrumb()
1428
    {
1429
1430
        //unset and reconnect Db to resolve mysqli fetch exeception
1431
        global $db;
1432
        unset($db->database);
1433
        $db->checkConnection();
1434
1435
        $inboundEmail = new InboundEmail();
1436
1437
        $parts = array(
1438
                    (Object) array('encoding' => 'utf-8', 'parts' => array((Object) array('encoding' => 'utf-8', 'parts' => array((Object) array('encoding' => 'utf-8', 'parts' => 'dummy parts 2'))))),
1439
                );
1440
1441
        //$result = $inboundEmail->getEncodingFromBreadCrumb("1.2.3", $parts);
1442
1443
        //$this->assertEqilas('utf-8', $result);
1444
1445
        $this->markTestIncomplete('errors in method');
1446
    }
1447
1448
    public function testgetCharsetFromBreadCrumb()
1449
    {
1450
        $inboundEmail = new InboundEmail();
1451
1452
        $parts = array(
1453
                (Object) array('ifparameters' => 1, 'attribute' => 'charset', 'value' => 'test', 'parts' => array((Object) array('ifparameters' => 1, 'attribute' => 'charset', 'value' => 'test', 'parts' => array((Object) array('ifparameters' => 1, 'attribute' => 'charset', 'value' => 'test', 'parts' => 'dummy parts 2'))))),
1454
        );
1455
1456
        $result = $inboundEmail->getCharsetFromBreadCrumb('1.2.3', $parts);
1457
1458
        $this->assertEquals('default', $result);
1459
    }
1460
1461
    public function testgetMessageTextFromSingleMimePart()
1462
    {
1463
        //unset and reconnect Db to resolve mysqli fetch exeception
1464
        global $db;
1465
        unset($db->database);
1466
        $db->checkConnection();
1467
1468
        $inboundEmail = new InboundEmail();
1469
1470
        //execute the method and test if it works and does not throws an exception.
1471
        try {
1472
            $result = $inboundEmail->getMessageTextFromSingleMimePart(1, 1, $structure);
1473
            $this->assertTrue(true);
1474
        } catch (Exception $e) {
1475
            $this->fail();
1476
        }
1477
    }
1478
1479
    public function testaddBreadCrumbOffset()
1480
    {
1481
        //unset and reconnect Db to resolve mysqli fetch exeception
1482
        global $db;
1483
        unset($db->database);
1484
        $db->checkConnection();
1485
1486
        $inboundEmail = new InboundEmail();
1487
1488
        //test with empty offset string
1489
        $result = $inboundEmail->addBreadCrumbOffset('1.1.1', '');
1490
        $this->assertEquals('1.1.1', $result);
1491
1492
        //test with empty bread crumb string
1493
        $result = $inboundEmail->addBreadCrumbOffset('', '1.1.1');
1494
        $this->assertEquals('1.1.1', $result);
1495
1496
        //test with shorter bread crumb string
1497
        $result = $inboundEmail->addBreadCrumbOffset('1.1.1', '2.2.2.2');
1498
        $this->assertEquals('3.3.3.2', $result);
1499
    }
1500
1501
    public function testgetMessageText()
1502
    {
1503
1504
        //unset and reconnect Db to resolve mysqli fetch exeception
1505
        global $db;
1506
        unset($db->database);
1507
        $db->checkConnection();
1508
1509
        $inboundEmail = new InboundEmail();
1510
1511
        //execute the method and test if it works and does not throws an exception.
1512
        try {
1513
            $result = $inboundEmail->getMessageText(1, 'PLAIN', $structure, $fullHeader);
1514
            $this->assertTrue(true);
1515
        } catch (Exception $e) {
1516
            $this->fail();
1517
        }
1518
    }
1519
1520
    public function testdecodeHeader()
1521
    {
1522
1523
        //unset and reconnect Db to resolve mysqli fetch exeception
1524
        global $db;
1525
        unset($db->database);
1526
        $db->checkConnection();
1527
1528
        $inboundEmail = new InboundEmail();
1529
1530
        $expected = array(
1531
                          'From' => 'Media Temple user ([email protected])',
1532
                          'Subject' => 'article: How to Trace a Email',
1533
                          'Date' => 'January 25, 2011 3:30:58 PM PDT',
1534
                          'To' => '[email protected]',
1535
                          'Return-Path' => '<[email protected]>',
1536
                          'Envelope-To' => '[email protected]',
1537
                          'Delivery-Date' => 'Tue, 25 Jan 2011 15:31:01 -0700',
1538
                        );
1539
        $header = "From: Media Temple user ([email protected])\r\nSubject: article: How to Trace a Email\r\nDate: January 25, 2011 3:30:58 PM PDT\r\nTo: [email protected]\r\nReturn-Path: <[email protected]>\r\nEnvelope-To: [email protected]\r\nDelivery-Date: Tue, 25 Jan 2011 15:31:01 -0700";
1540
1541
        $result = $inboundEmail->decodeHeader($header);
1542
        $this->assertEquals($expected, $result);
1543
    }
1544
1545
    public function testhandleCharsetTranslation()
1546
    {
1547
1548
        //unset and reconnect Db to resolve mysqli fetch exeception
1549
        global $db;
1550
        unset($db->database);
1551
        $db->checkConnection();
1552
1553
        $inboundEmail = new InboundEmail();
1554
1555
        //test with default
1556
        $result = $inboundEmail->handleCharsetTranslation('sample text', 'default');
1557
        $this->assertEquals('sample text', $result);
1558
1559
        //test with ISO-8859-8
1560
        $result = $inboundEmail->handleCharsetTranslation('sample text', 'ISO-8859-8');
1561
        $this->assertEquals('sample text', $result);
1562
    }
1563
1564
    public function testbuildBreadCrumbs()
1565
    {
1566
1567
        //unset and reconnect Db to resolve mysqli fetch exeception
1568
        global $db;
1569
        unset($db->database);
1570
        $db->checkConnection();
1571
1572
        $inboundEmail = new InboundEmail();
1573
1574
        //execute the method and test if it works and does not throws an exception.
1575
        try {
1576
            $result = $inboundEmail->buildBreadCrumbs(array(), 'ALTERNATIVE', '1');
1577
            $this->assertTrue(true);
1578
        } catch (Exception $e) {
1579
            $this->fail();
1580
        }
1581
    }
1582
1583
    public function testbuildBreadCrumbsHTML()
1584
    {
1585
1586
        //unset and reconnect Db to resolve mysqli fetch exeception
1587
        global $db;
1588
        unset($db->database);
1589
        $db->checkConnection();
1590
1591
        $inboundEmail = new InboundEmail();
1592
1593
        //execute the method and test if it works and does not throws an exception.
1594
        try {
1595
            $inboundEmail->buildBreadCrumbsHTML(array());
1596
            $this->assertTrue(true);
1597
        } catch (Exception $e) {
1598
            $this->fail();
1599
        }
1600
    }
1601
1602
    public function testconvertImapToSugarEmailAddress()
1603
    {
1604
1605
        //unset and reconnect Db to resolve mysqli fetch exeception
1606
        global $db;
1607
        unset($db->database);
1608
        $db->checkConnection();
1609
1610
        $inboundEmail = new InboundEmail();
1611
1612
        $inboundEmail->mailbox = 'INBOX';
1613
        $inboundEmail->host = 'mail.google.com';
1614
1615
        $result = $inboundEmail->convertImapToSugarEmailAddress(array($inboundEmail));
1616
        $this->assertEquals('[email protected]', $result);
1617
    }
1618
1619
    public function testhandleEncodedFilename()
1620
    {
1621
1622
        //unset and reconnect Db to resolve mysqli fetch exeception
1623
        global $db;
1624
        unset($db->database);
1625
        $db->checkConnection();
1626
1627
        $inboundEmail = new InboundEmail();
1628
1629
        $result = $inboundEmail->handleEncodedFilename('attachment1.pdf');
1630
        $this->assertEquals('attachment1.pdf', $result);
1631
    }
1632
1633
    public function testgetMimeType()
1634
    {
1635
        //unset and reconnect Db to resolve mysqli fetch exeception
1636
        global $db;
1637
        unset($db->database);
1638
        $db->checkConnection();
1639
1640
        $inboundEmail = new InboundEmail();
1641
1642
        $this->assertEquals('text/plain', $inboundEmail->getMimeType(0, 'plain'));
1643
        $this->assertEquals('multipart/binary', $inboundEmail->getMimeType(1, 'binary'));
1644
        $this->assertEquals('other/subtype', $inboundEmail->getMimeType('test', 'subtype'));
1645
    }
1646
1647
    public function testsaveAttachments()
1648
    {
1649
1650
        //unset and reconnect Db to resolve mysqli fetch exeception
1651
        global $db;
1652
        unset($db->database);
1653
        $db->checkConnection();
1654
1655
        $inboundEmail = new InboundEmail();
1656
1657
        //execute the method and test if it works and does not throws an exception.
1658
        try {
1659
            $inboundEmail->saveAttachments('1', array(), '1', '0', true);
1660
            $this->assertTrue(true);
1661
        } catch (Exception $e) {
1662
            $this->fail();
1663
        }
1664
    }
1665
1666
    public function testgetNoteBeanForAttachment()
1667
    {
1668
        $inboundEmail = new InboundEmail();
1669
1670
        $result = $inboundEmail->getNoteBeanForAttachment('1');
1671
1672
        $this->assertInstanceOf('Note', $result);
1673
        $this->assertAttributeEquals('1', 'parent_id', $result);
1674
        $this->assertAttributeEquals('Emails', 'parent_type', $result);
1675
    }
1676
1677
    public function testretrieveAttachmentNameFromStructure()
1678
    {
1679
        $inboundEmail = new InboundEmail();
1680
1681
        //test with filename attribute
1682
        $part = (Object) array('dparameters' => array((Object) array('attribute' => 'filename', 'value' => 'test1.txt'), (Object) array('attribute' => 'filename', 'value' => 'test2.txt')),
1683
                                'parameters' => array((Object) array('attribute' => 'name', 'value' => 'test1'), (Object) array('attribute' => 'name', 'value' => 'test2')),
1684
                                );
1685
1686
        $result = $inboundEmail->retrieveAttachmentNameFromStructure($part);
1687
        $this->assertEquals('test1.txt', $result);
1688
1689
        //test with no filename attribute
1690
        $part = (Object) array('dparameters' => array((Object) array('attribute' => 'name', 'value' => 'test1.txt')),
1691
                                'parameters' => array((Object) array('attribute' => 'name', 'value' => 'test1'), (Object) array('attribute' => 'name', 'value' => 'test2')),
1692
1693
                                );
1694
1695
        $result = $inboundEmail->retrieveAttachmentNameFromStructure($part);
1696
        $this->assertEquals('test1', $result);
1697
    }
1698
1699
    public function testsaveAttachmentBinaries()
1700
    {
1701
1702
        //unset and reconnect Db to resolve mysqli fetch exeception
1703
        global $db;
1704
        unset($db->database);
1705
        $db->checkConnection();
1706
1707
        $inboundEmail = new InboundEmail();
1708
1709
        $part = (Object) array('disposition' => 'multipart', 'subtype' => 10);
1710
1711
        //execute the method and test if it works and does not throws an exception.
1712
        try {
1713
            $inboundEmail->saveAttachmentBinaries(new Note(), '1', '1.1', $part, 1);
1714
            $this->assertTrue(true);
1715
        } catch (Exception $e) {
1716
            $this->fail();
1717
        }
1718
    }
1719
1720
    public function testhandleTranserEncoding()
1721
    {
1722
        $inboundEmail = new InboundEmail();
1723
1724
        $this->assertEquals('test', $inboundEmail->handleTranserEncoding('test'));
1725
        $this->assertEquals('test', $inboundEmail->handleTranserEncoding('dGVzdA==', 3));
1726
        $this->assertEquals('test', $inboundEmail->handleTranserEncoding('test', 4));
1727
    }
1728
1729
    public function testgetMessageId()
1730
    {
1731
        $inboundEmail = new InboundEmail();
1732
1733
        $header = "From: Media Temple user ([email protected])\r\nSubject: article: How to Trace a Email\r\nDate: January 25, 2011 3:30:58 PM PDT\r\nTo: [email protected]\r\nReturn-Path: <[email protected]>\r\nEnvelope-To: [email protected]\r\nDelivery-Date: Tue, 25 Jan 2011 15:31:01 -0700";
1734
1735
        $result = $inboundEmail->getMessageId($header);
1736
1737
        $this->assertEquals('21c65f7db176f0bd93768214b00ae397', $result);
1738
    }
1739
1740
    public function testimportDupeCheck()
1741
    {
1742
        $inboundEmail = new InboundEmail();
1743
1744
        $textHeader = "From: Media Temple user ([email protected])\r\nSubject: article: How to Trace a Email\r\nDate: January 25, 2011 3:30:58 PM PDT\r\nTo: [email protected]\r\nReturn-Path: <[email protected]>\r\nEnvelope-To: [email protected]\r\nDelivery-Date: Tue, 25 Jan 2011 15:31:01 -0700";
1745
1746
        $result = $inboundEmail->importDupeCheck('1', $textHeader, $textHeader);
1747
        $this->assertEquals(true, $result);
1748
    }
1749
1750
    public function testhandleMimeHeaderDecode()
1751
    {
1752
        $inboundEmail = new InboundEmail();
1753
1754
        $result = $inboundEmail->handleMimeHeaderDecode('Subject: article: How to Trace a Email');
1755
1756
        $this->assertEquals('Subject: article: How to Trace a Email', $result);
1757
    }
1758
1759
    public function testgetUnixHeaderDate()
1760
    {
1761
        $inboundEmail = new InboundEmail();
1762
1763
        $result = $inboundEmail->handleMimeHeaderDecode('Date: January 25, 2011 3:30:58 PM PDT');
1764
1765
        $this->assertEquals('Date: January 25, 2011 3:30:58 PM PDT', $result);
1766
    }
1767
1768
    public function testgetDuplicateEmailId()
1769
    {
1770
1771
        //unset and reconnect Db to resolve mysqli fetch exeception
1772
        global $db;
1773
        unset($db->database);
1774
        $db->checkConnection();
1775
1776
        $inboundEmail = new InboundEmail();
1777
1778
        //execute the method and test if it works and does not throws an exception.
1779
        try {
1780
            $result = $inboundEmail->getDuplicateEmailId('1', '1');
1781
            $this->assertTrue(true);
1782
        } catch (Exception $e) {
1783
            $this->fail();
1784
        }
1785
    }
1786
1787
    public function testimportOneEmail()
1788
    {
1789
        $inboundEmail = new InboundEmail();
1790
1791
        $inboundEmail->mailbox = 'INBOX';
1792
        $inboundEmail->id = 1;
1793
1794
        //execute the method and test if it works and does not throws an exception.
1795
        try {
1796
            $result = $inboundEmail->importOneEmail('1', '1');
1797
            $this->assertEquals(false, $result);
1798
        } catch (Exception $e) {
1799
            $this->fail();
1800
        }
1801
    }
1802
1803
    public function testisUuencode()
1804
    {
1805
        $inboundEmail = new InboundEmail();
1806
1807
        $this->assertEquals(false, $inboundEmail->isUuencode('test'));
1808
1809
        $this->assertEquals(false, $inboundEmail->isUuencode("begin 0744 odt_uuencoding_file.dat\r+=&5S=\"!S=')I;F<`\r`\rend"));
1810
    }
1811
1812
    public function testhandleUUEncodedEmailBody()
1813
    {
1814
        $inboundEmail = new InboundEmail();
1815
1816
        $raw = 'Message Body: This is a KnowledgeBase article that provides information on how to find email headers and use the data to trace a email.';
1817
1818
        $result = $inboundEmail->handleUUEncodedEmailBody($raw, 1);
1819
1820
        $this->assertEquals("\n".$raw, $result);
1821
    }
1822
1823
    public function testhandleUUDecode()
1824
    {
1825
1826
        /*
1827
        //unset and reconnect Db to resolve mysqli fetch exeception
1828
        global $db;
1829
        unset ($db->database);
1830
        $db->checkConnection();
1831
1832
1833
        $inboundEmail = new InboundEmail();
1834
1835
        $raw = "\nMessage Body: This is a KnowledgeBase article that provides information on how to find email headers and use the data to trace a email.";
1836
1837
        $inboundEmail->handleUUDecode("1", "handleUUDecode_test", $raw);
1838
1839
        */
1840
        $this->markTestIncomplete('Uncaught require_once(include/PHP_Compat/convert_uudecode.php)');
1841
    }
1842
1843
    public function testcheckFilterDomain()
1844
    {
1845
1846
        //unset and reconnect Db to resolve mysqli fetch exeception
1847
        global $db;
1848
        unset($db->database);
1849
        $db->checkConnection();
1850
1851
        $inboundEmail = new InboundEmail();
1852
1853
        $email = new Email();
1854
        $email->reply_to_email = '[email protected]';
1855
        $email->from_addr = '[email protected]';
1856
1857
        $result = $inboundEmail->checkFilterDomain($email);
1858
        $this->assertEquals(true, $result);
1859
    }
1860
1861
    public function testcheckOutOfOffice()
1862
    {
1863
1864
        //unset and reconnect Db to resolve mysqli fetch exeception
1865
        global $db;
1866
        unset($db->database);
1867
        $db->checkConnection();
1868
1869
        $inboundEmail = new InboundEmail();
1870
1871
        $this->assertEquals(false, $inboundEmail->checkOutOfOffice('currently Out of Office, will reply later'));
1872
        $this->assertEquals(true, $inboundEmail->checkOutOfOffice('test subject'));
1873
    }
1874
1875
    public function testsetAndgetAutoreplyStatus()
1876
    {
1877
1878
        //unset and reconnect Db to resolve mysqli fetch exeception
1879
        global $db;
1880
        unset($db->database);
1881
        $db->checkConnection();
1882
1883
        $inboundEmail = new InboundEmail();
1884
1885
        $inboundEmail->id = 1;
1886
1887
        //execute the setAutoreplyStatus method to set an auto reply status for email
1888
        $inboundEmail->setAutoreplyStatus('[email protected]');
1889
1890
        //test with and invalid email. it will return true as well because it's stil under max limit.
1891
        $result = $inboundEmail->getAutoreplyStatus('[email protected]');
1892
        $this->assertEquals(true, $result);
1893
    }
1894
1895
    public function testsaveInboundEmailSystemSettings()
1896
    {
1897
        global $sugar_config, $db;
1898
1899
        //unset and reconnect Db to resolve mysqli fetch exeception
1900
        unset($db->database);
1901
        $db->checkConnection();
1902
1903
        $inboundEmail = new InboundEmail();
1904
1905
        //execute the method to save the setting
1906
        $inboundEmail->saveInboundEmailSystemSettings('test', 'test_macro');
1907
1908
        //verify the key created
1909
        $this->assertEquals('test_macro', $sugar_config['inbound_email_test_subject_macro']);
1910
    }
1911
1912
    public function testgetSystemSettingsForm()
1913
    {
1914
        $inboundEmail = new InboundEmail();
1915
1916
        $expected = "			<form action=\"index.php\" method=\"post\" name=\"Macro\" id=\"form\">\n						<input type=\"hidden\" name=\"module\" value=\"InboundEmail\">\n						<input type=\"hidden\" name=\"action\" value=\"ListView\">\n						<input type=\"hidden\" name=\"save\" value=\"true\">\n\n			<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n				<tr>\n					<td>\n						<input 	title=\"Save\"\n								accessKey=\"a\"\n								class=\"button\"\n								onclick=\"this.form.return_module.value='InboundEmail'; this.form.return_action.value='ListView';\"\n								type=\"submit\" name=\"Edit\" value=\"  Save  \">\n					</td>\n				</tr>\n			</table>\n\n			<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"detail view\">\n				<tr>\n					<td valign=\"top\" width='10%' NOWRAP scope=\"row\">\n						<slot>\n							<b>:</b>\n						</slot>\n					</td>\n					<td valign=\"top\" width='20%'>\n						<slot>\n							<input name=\"inbound_email_case_macro\" type=\"text\" value=\"[CASE:%1]\">\n						</slot>\n					</td>\n					<td valign=\"top\" width='70%'>\n						<slot>\n							\n							<br />\n							<i></i>\n						</slot>\n					</td>\n				</tr>\n			</table>\n			</form>";
1917
        $result = $inboundEmail->getSystemSettingsForm();
1918
1919
        $this->assertSame($expected, $result);
1920
    }
1921
1922
    public function testgetCaseIdFromCaseNumber()
1923
    {
1924
        $inboundEmail = new InboundEmail();
1925
1926
        $result = $inboundEmail->getCaseIdFromCaseNumber('test', new aCase());
1927
        $this->assertEquals(false, $result);
1928
    }
1929
1930
    public function testget_stored_options()
1931
    {
1932
        $inboundEmail = new InboundEmail();
1933
1934
        $result = $inboundEmail->get_stored_options('test', '');
1935
        $this->assertEquals('', $result);
1936
1937
        $result = $inboundEmail->get_stored_options('test', 'default_option');
1938
        $this->assertEquals('default_option', $result);
1939
    }
1940
1941
    public function testgetRelatedId()
1942
    {
1943
1944
        //unset and reconnect Db to resolve mysqli fetch exeception
1945
        global $db;
1946
        unset($db->database);
1947
        $db->checkConnection();
1948
1949
        $inboundEmail = new InboundEmail();
1950
1951
        //test with Users module
1952
        $inboundEmail->getRelatedId('[email protected]', 'Users');
1953
        $this->assertEquals(false, $result);
1954
1955
        //test with Contacts module
1956
        $inboundEmail->getRelatedId('[email protected]', 'Contacts');
1957
        $this->assertEquals(false, $result);
1958
    }
1959
1960
    public function testgetNewMessageIds()
1961
    {
1962
        $inboundEmail = new InboundEmail();
1963
1964
        $result = $inboundEmail->getNewMessageIds();
1965
1966
        $this->assertEquals(null, $result);
1967
    }
1968
1969
    public function testgetConnectString()
1970
    {
1971
        $inboundEmail = new InboundEmail();
1972
1973
        $this->assertEquals('{:/service=}', $inboundEmail->getConnectString()); //test with default options
1974
        $this->assertEquals('{:/service=mail.google.com}INBOX', $inboundEmail->getConnectString('mail.google.com', 'INBOX'));//test with includeMbox true
1975
        $this->assertEquals('{:/service=mail.google.com}', $inboundEmail->getConnectString('mail.google.com', 'INBOX', false));//test with includeMbox false
1976
    }
1977
1978
    public function testdisconnectMailserver()
1979
    {
1980
        $inboundEmail = new InboundEmail();
1981
1982
        //execute the method and test if it works and does not throws an exception.
1983
        try {
1984
            $inboundEmail->disconnectMailserver();
1985
            $this->assertTrue(true);
1986
        } catch (Exception $e) {
1987
            $this->fail();
1988
        }
1989
    }
1990
1991
    public function testconnectMailserver()
1992
    {
1993
        $inboundEmail = new InboundEmail();
1994
1995
        //test with default parameters
1996
        $result = $inboundEmail->connectMailserver();
1997
        $this->assertEquals('false', $result);
1998
1999
        //test with test and force true
2000
        $result = $inboundEmail->connectMailserver(true, true);
2001
        $this->assertEquals("Can't open mailbox {:/service=}: invalid remote specification<p><p><p>", $result);
2002
    }
2003
2004
    public function testcheckImap()
2005
    {
2006
        $inboundEmail = new InboundEmail();
2007
2008
        //execute the method and test if it works and does not throws an exception.
2009
        try {
2010
            $inboundEmail->checkImap();
2011
            $this->assertTrue(true);
2012
        } catch (Exception $e) {
2013
            $this->fail();
2014
        }
2015
    }
2016
2017
    public function testget_summary_text()
2018
    {
2019
        $inboundEmail = new InboundEmail();
2020
2021
        //test without setting name
2022
        $this->assertEquals(null, $inboundEmail->get_summary_text());
2023
2024
        //test with name set
2025
        $inboundEmail->name = 'test';
2026
        $this->assertEquals('test', $inboundEmail->get_summary_text());
2027
    }
2028
2029
    public function testcreate_export_query()
2030
    {
2031
        $inboundEmail = new InboundEmail();
2032
2033
        //test with empty string params
2034
        $expected = " SELECT  inbound_email.*  , jt0.user_name created_by_name , jt0.created_by created_by_name_owner  , 'Users' created_by_name_mod FROM inbound_email   LEFT JOIN  users jt0 ON jt0.id=inbound_email.created_by AND jt0.deleted=0\n AND jt0.deleted=0 where inbound_email.deleted=0";
2035
        $actual = $inboundEmail->create_export_query('', '');
2036
        $this->assertSame($expected, $actual);
2037
2038
        //test with valid string params
2039
        $expected = " SELECT  inbound_email.*  , jt0.user_name created_by_name , jt0.created_by created_by_name_owner  , 'Users' created_by_name_mod FROM inbound_email   LEFT JOIN  users jt0 ON jt0.id=inbound_email.created_by AND jt0.deleted=0\n AND jt0.deleted=0 where (jt0.user_name=\"\") AND inbound_email.deleted=0 ORDER BY inbound_email.id";
2040
        $actual = $inboundEmail->create_export_query('id', 'jt0.user_name=""');
2041
        $this->assertSame($expected, $actual);
2042
    }
2043
2044
    public function testget_list_view_data()
2045
    {
2046
        $inboundEmail = new InboundEmail();
2047
2048
        $inboundEmail->mailbox_type = 'INBOX';
2049
        $inboundEmail->status = 'Active';
2050
2051
        $result = $inboundEmail->get_list_view_data();
2052
2053
        $expected = array(
2054
                        'DELETED' => '0',
2055
                        'STATUS' => null,
2056
                        'DELETE_SEEN' => '0',
2057
                        'MAILBOX_TYPE' => 'INBOX',
2058
                        'IS_PERSONAL' => '0',
2059
                        'MAILBOX_TYPE_NAME' => null,
2060
                        'GLOBAL_PERSONAL_STRING' => null,
2061
                    );
2062
2063
        $this->assertTrue(is_array($result));
2064
        $this->assertEquals($expected, $result);
2065
2066
        $result = $inboundEmail->get_list_view_data();
2067
    }
2068
2069
    public function testfill_in_additional_list_fields()
2070
    {
2071
        $inboundEmail = new InboundEmail();
2072
2073
        $inboundEmail->service = 'tls::ca::ssl::protocol';
2074
2075
        $result = $inboundEmail->fill_in_additional_list_fields();
2076
2077
        $this->assertEquals($inboundEmail->tls, 'tls');
2078
        $this->assertEquals($inboundEmail->ca, 'ca');
2079
        $this->assertEquals($inboundEmail->ssl, 'ssl');
2080
        $this->assertEquals($inboundEmail->protocol, 'protocol');
2081
    }
2082
2083
    public function testfill_in_additional_detail_fields()
2084
    {
2085
        $inboundEmail = new InboundEmail();
2086
2087
        $inboundEmail->service = 'tls::ca::ssl::protocol';
2088
2089
        $result = $inboundEmail->fill_in_additional_detail_fields();
2090
2091
        $this->assertEquals($inboundEmail->tls, 'tls');
2092
        $this->assertEquals($inboundEmail->ca, 'ca');
2093
        $this->assertEquals($inboundEmail->ssl, 'ssl');
2094
        $this->assertEquals($inboundEmail->protocol, 'protocol');
2095
    }
2096
2097
    public function testisAutoImport()
2098
    {
2099
        $inboundEmail = new InboundEmail();
2100
2101
        $user = new User();
2102
2103
        //test with invalid user
2104
        $result = $inboundEmail->isAutoImport($user);
2105
        $this->assertEquals(false, $result);
2106
2107
        //test with default user
2108
        $user->retrieve('1');
2109
        $result = $inboundEmail->isAutoImport($user);
2110
        $this->assertEquals(false, $result);
2111
    }
2112
2113
    public function testcleanOutCache()
2114
    {
2115
        $inboundEmail = new InboundEmail();
2116
2117
        //execute the method and test if it works and does not throws an exception.
2118
        try {
2119
            $inboundEmail->cleanOutCache();
2120
            $this->assertTrue(true);
2121
        } catch (Exception $e) {
2122
            $this->fail();
2123
        }
2124
    }
2125
2126
    public function testcopyEmails()
2127
    {
2128
        $inboundEmail = new InboundEmail();
2129
2130
        $inboundEmail->id = 1;
2131
2132
        //execute the method and test if it works and does not throws an exception.
2133
        try {
2134
            $result = $inboundEmail->copyEmails(1, 'INBOX', 1, 'TRASH', array(1));
2135
            $this->assertTrue(true);
2136
        } catch (Exception $e) {
2137
            $this->fail();
2138
        }
2139
    }
2140
2141
    public function testmoveEmails()
2142
    {
2143
        $inboundEmail = new InboundEmail();
2144
2145
        $inboundEmail->id = 1;
2146
2147
        $result = $inboundEmail->moveEmails(1, 'INBOX', 1, 'TRASH', array(1));
2148
        $this->assertEquals(false, $result);
2149
2150
        $result = $inboundEmail->moveEmails(1, 'INBOX', 2, 'TRASH', array(1));
2151
        $this->assertEquals(false, $result);
2152
    }
2153
2154
    public function testgetTempFilename()
2155
    {
2156
        $inboundEmail = new InboundEmail();
2157
2158
        $inboundEmail->compoundMessageId = 'cmid';
2159
2160
        //test with default false
2161
        $result = $inboundEmail->getTempFilename();
2162
        $this->assertEquals('cmid0', $result);
2163
2164
        //test with true
2165
        $result = $inboundEmail->getTempFilename(true);
2166
        $this->assertEquals('cmid', $result);
2167
    }
2168
2169
    public function testdeleteMessageOnMailServer()
2170
    {
2171
        $inboundEmail = new InboundEmail();
2172
2173
        $result = $inboundEmail->deleteMessageOnMailServer('1');
2174
2175
        $this->assertEquals(false, $result);
2176
    }
2177
2178
    public function testdeleteMessageOnMailServerForPop3()
2179
    {
2180
        $inboundEmail = new InboundEmail();
2181
2182
        //execute the method and test if it works and does not throws an exception.
2183
        try {
2184
            $inboundEmail->deleteMessageOnMailServerForPop3('1');
2185
            $this->assertTrue(true);
2186
        } catch (Exception $e) {
2187
            $this->fail();
2188
        }
2189
    }
2190
2191
    public function testisPop3Protocol()
2192
    {
2193
        $inboundEmail = new InboundEmail();
2194
2195
        //test without setting protocol
2196
        $this->assertEquals(false, $inboundEmail->isPop3Protocol());
2197
2198
        //test with pop3 protocol
2199
        $inboundEmail->protocol = 'pop3';
2200
        $this->assertEquals(true, $inboundEmail->isPop3Protocol());
2201
    }
2202
2203
    public function testSetAndGetUsersDefaultOutboundServerId()
2204
    {
2205
        $inboundEmail = new InboundEmail();
2206
2207
        $user = new User();
2208
        $user->retrieve(1);
2209
2210
        //set a Outbound Server Id
2211
        $inboundEmail->setUsersDefaultOutboundServerId($user, '123');
2212
2213
        //retrieve Outbound Server Id back and verify
2214
        $result = $inboundEmail->getUsersDefaultOutboundServerId($user);
2215
2216
        $this->assertEquals('123', $result);
2217
    }
2218
2219
    public function testsetEmailForDisplay()
2220
    {
2221
        $inboundEmail = new InboundEmail();
2222
2223
        $result = $inboundEmail->setEmailForDisplay('');
2224
        $this->assertEquals('NOOP', $result);
2225
2226
        //test with pop3 protocol and default parameters
2227
        $inboundEmail->protocol = 'pop3';
2228
        $result = $inboundEmail->setEmailForDisplay('1');
2229
        $this->assertEquals('error', $result);
2230
2231
        //test with pop3 protocol and all parameters true
2232
        $result = $inboundEmail->setEmailForDisplay('1', true, true, true);
2233
        $this->assertEquals('error', $result);
2234
    }
2235
2236
    public function testdisplayOneEmail()
2237
    {
2238
        $inboundEmail = new InboundEmail();
2239
2240
        $inboundEmail->id = 1;
2241
        $inboundEmail->mailbox = 'INBOX';
2242
        $inboundEmail->email = new Email();
2243
2244
        $inboundEmail->email->name = 'test';
2245
        $inboundEmail->email->from_addr_name = 'from';
2246
        $inboundEmail->email->to_addrs_names = 'to';
2247
        $inboundEmail->email->cc_addrs_names = 'cc';
2248
        $inboundEmail->email->reply_to_addr = 'reply';
2249
2250
        $expected = array(
2251
                          'meta' => array('type' => 'archived', 'uid' => 1, 'ieId' => 1, 'email' => array('name' => 'test', 'from_name' => '', 'from_addr' => 'from', 'date_start' => ' ', 'time_start' => '', 'message_id' => '', 'cc_addrs' => 'cc', 'attachments' => '', 'toaddrs' => 'to', 'description' => '', 'reply_to_addr' => 'reply'), 'mbox' => 'INBOX', 'cc' => '', 'is_sugarEmail' => false),
2252
                        );
2253
        $result = $inboundEmail->displayOneEmail(1, 'INBOX');
2254
2255
        $this->assertEquals($expected, $result);
2256
    }
2257
2258
    public function testcollapseLongMailingList()
2259
    {
2260
        $inboundEmail = new InboundEmail();
2261
2262
        $emails = '[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]';
2263
2264
        $expected = "<span onclick='javascript:SUGAR.email2.detailView.showFullEmailList(this);' style='cursor:pointer;'>[email protected], [email protected] [...4 More]</span><span onclick='javascript:SUGAR.email2.detailView.showCroppedEmailList(this)' style='cursor:pointer; display:none;'>[email protected], [email protected], [email protected], [email protected], [email protected], [email protected] [ less ]</span>";
2265
2266
        $actual = $inboundEmail->collapseLongMailingList($emails);
2267
2268
        $this->assertEquals($expected, $actual);
2269
    }
2270
2271
    public function testsortFetchedOverview()
2272
    {
2273
        $inboundEmail = new InboundEmail();
2274
2275
        $inboundEmail->id = 1;
2276
        $inboundEmail->mailbox = 'INBOX';
2277
2278
        $overview1 = new Overview();
2279
        $overview1->subject = 'subject 1';
2280
        $overview1->from = 'from 1';
2281
        $overview1->flagged = '1';
2282
        $overview1->answered = '1';
2283
        $overview1->date = '2016-01-01';
2284
2285
        $overview2 = new Overview();
2286
        $overview2->subject = 'subject 2';
2287
        $overview2->from = 'from 2';
2288
        $overview2->flagged = '2';
2289
        $overview2->answered = '2';
2290
        $overview2->date = '2016-01-02';
2291
2292
        $arr = array();
2293
        $arr[] = $overview1;
2294
        $arr[] = $overview2;
2295
2296
        //execute the method to sort the objects array descending and verify the order
2297
        $result = $inboundEmail->sortFetchedOverview($arr, 3, 'DESC');
2298
        $this->assertEquals('subject 2', $result['retArr'][0]->subject);
2299
2300
        //execute the method to sort the objects array ascending and verify the order
2301
        $result = $inboundEmail->sortFetchedOverview($arr, 3, 'ASC');
2302
        $this->assertEquals('subject 1', $result['retArr'][0]->subject);
2303
    }
2304
2305
    public function testdisplayFolderContents()
2306
    {
2307
        $inboundEmail = new InboundEmail();
2308
2309
        $expected = array('mbox' => 'INBOX', 'ieId' => 1, 'name' => 'test', 'fromCache' => 0, 'out' => array());
2310
        $inboundEmail->id = 1;
2311
        $inboundEmail->name = 'test';
2312
2313
        $result = $inboundEmail->displayFolderContents('INBOX', 'false', 1);
2314
2315
        $this->assertEquals($expected, $result);
2316
    }
2317
2318
    public function testcreateUserSubscriptionsForGroupAccount()
2319
    {
2320
2321
        //unset and reconnect Db to resolve mysqli fetch exeception
2322
        global $db;
2323
        unset($db->database);
2324
        $db->checkConnection();
2325
2326
        $inboundEmail = new InboundEmail();
2327
2328
        //$inboundEmail->createUserSubscriptionsForGroupAccount();
2329
2330
        $this->markTestIncomplete("Fatal error: Class 'Team' not found");
2331
    }
2332
2333
    public function testcreateAutoImportSugarFolder()
2334
    {
2335
        //unset and reconnect Db to resolve mysqli fetch exeception
2336
        global $db;
2337
        unset($db->database);
2338
        $db->checkConnection();
2339
2340
        $inboundEmail = new InboundEmail();
2341
2342
        $inboundEmail->name = 'test';
2343
2344
        $result = $inboundEmail->createAutoImportSugarFolder();
2345
2346
        //test for record ID to verify that record is saved
2347
        $this->assertTrue(isset($result));
2348
        $this->assertEquals(36, strlen($result));
2349
    }
2350
2351
    public function testgetMailboxes()
2352
    {
2353
        $inboundEmail = new InboundEmail();
2354
2355
        $inboundEmail->mailboxarray = array('INBOX.TRASH', 'OUTBOX.TRASH');
2356
        $expected = array('INBOX' => array('TRASH' => 'TRASH'), 'OUTBOX' => array('TRASH' => 'TRASH'));
2357
2358
        //test with justRaw default/false
2359
        $result = $inboundEmail->getMailboxes();
2360
        $this->assertEquals($expected, $result);
2361
2362
        //test with justRaw true
2363
        $result = $inboundEmail->getMailboxes(true);
2364
        $this->assertEquals($inboundEmail->mailboxarray, $result);
2365
    }
2366
2367
    public function testgetMailBoxesForGroupAccount()
2368
    {
2369
        $inboundEmail = new InboundEmail();
2370
2371
        $inboundEmail->mailbox = 1;
2372
        $inboundEmail->mailbox = 'INBOX.TRASH,OUTBOX.TRASH';
2373
        $expected = array('INBOX' => array('TRASH' => 'TRASH'), 'OUTBOX' => array('TRASH' => 'TRASH'));
2374
2375
        $result = $inboundEmail->getMailBoxesForGroupAccount();
2376
2377
        $this->assertEquals($expected, $result);
2378
    }
2379
2380
    public function testretrieveMailBoxFolders()
2381
    {
2382
        $inboundEmail = new InboundEmail();
2383
2384
        $inboundEmail->mailbox = 'INBOX,OUTBOX,TRASH';
2385
2386
        $inboundEmail->retrieveMailBoxFolders();
2387
2388
        $this->assertEquals(array('INBOX', 'OUTBOX', 'TRASH'), $inboundEmail->mailboxarray);
2389
    }
2390
2391
    public function testinsertMailBoxFolders()
2392
    {
2393
        $inboundEmail = new InboundEmail();
2394
2395
        $inboundEmail->id = '101';
2396
2397
        //execute the method and test if it works and does not throws an exception.
2398
        try {
2399
            $inboundEmail->insertMailBoxFolders(array('INBOX', 'OUTBOX'));
2400
            $this->assertTrue(true);
2401
        } catch (Exception $e) {
2402
            $this->fail();
2403
        }
2404
    }
2405
2406
    public function testretrieveDelimiter()
2407
    {
2408
        $inboundEmail = new InboundEmail();
2409
2410
        $result = $inboundEmail->retrieveDelimiter();
2411
2412
        $this->assertEquals('.', $result);
2413
    }
2414
2415
    public function testgenerateFlatArrayFromMultiDimArray()
2416
    {
2417
        $inboundEmail = new InboundEmail();
2418
2419
        $arraymbox = array('INBOX' => array('TRASH' => 'TRASH'), 'OUTBOX' => array('TRASH' => 'TRASH'));
2420
2421
        $expected = array('INBOX', 'INBOX.TRASH', 'OUTBOX', 'OUTBOX.TRASH');
2422
2423
        $result = $inboundEmail->generateFlatArrayFromMultiDimArray($arraymbox, '.');
2424
2425
        $this->assertEquals($expected, $result);
2426
    }
2427
2428
    public function testgenerateMultiDimArrayFromFlatArray()
2429
    {
2430
        $inboundEmail = new InboundEmail();
2431
2432
        $expected = array('INBOX' => array('TRASH' => 'TRASH'), 'OUTBOX' => array('TRASH' => 'TRASH'));
2433
2434
        $result = $inboundEmail->generateMultiDimArrayFromFlatArray(array('INBOX.TRASH', 'OUTBOX.TRASH'), '.');
2435
2436
        $this->assertEquals($expected, $result);
2437
    }
2438
2439
    public function testgenerateArrayData()
2440
    {
2441
        $inboundEmail = new InboundEmail();
2442
2443
        $result = array();
2444
        $arraymbox = array('INBOX' => array('TRASH' => 'TRASH'));
2445
        $expected = array('MAIN', 'MAIN.INBOX', 'MAIN.INBOX.TRASH');
2446
2447
        $inboundEmail->generateArrayData('MAIN', $arraymbox, $result, '.');
2448
2449
        $this->assertEquals($expected, $result);
2450
    }
2451
2452
    public function testsortMailboxes()
2453
    {
2454
        $inboundEmail = new InboundEmail();
2455
2456
        $result = $inboundEmail->sortMailboxes('INBOX.TRASH', array());
2457
2458
        $expected = array('INBOX' => array('TRASH' => 'TRASH'));
2459
2460
        $this->assertEquals($expected, $result);
2461
    }
2462
2463
    public function testgetServiceString()
2464
    {
2465
        $inboundEmail = new InboundEmail();
2466
2467
        $inboundEmail->service = 'tls::ca::ssl::protocol';
2468
2469
        $result = $inboundEmail->getServiceString();
2470
2471
        $this->assertEquals('/tls/ca/ssl/protocol', $result);
2472
    }
2473
2474
    public function testgetNewEmailsForSyncedMailbox()
2475
    {
2476
        $inboundEmail = new InboundEmail();
2477
2478
        //execute the method and test if it works and does not throws an exception.
2479
        try {
2480
            $inboundEmail->getNewEmailsForSyncedMailbox();
2481
            $this->assertTrue(true);
2482
        } catch (Exception $e) {
2483
            $this->fail();
2484
        }
2485
    }
2486
2487
    public function testimportMessages()
2488
    {
2489
        $inboundEmail = new InboundEmail();
2490
2491
        //execute the method and test if it works and does not throws an exception.
2492
        try {
2493
            $inboundEmail->protocol = 'pop3';
2494
            $inboundEmail->importMessages();
2495
2496
            $this->assertTrue(true);
2497
        } catch (Exception $e) {
2498
            $this->fail();
2499
        }
2500
    }
2501
2502
    public function testOverview()
2503
    {
2504
2505
        //execute the contructor and check for the Object type and  attributes
2506
        $overview = new Overview();
2507
2508
        $this->assertInstanceOf('Overview', $overview);
2509
2510
        $this->assertTrue(is_array($overview->fieldDefs));
2511
        $this->assertTrue(is_array($overview->indices));
2512
    }
2513
}
2514