Test Failed
Push — CI ( 0f01dd...c95a04 )
by Adam
55:13
created

InboundEmailTest   D

Complexity

Total Complexity 197

Size/Duplication

Total Lines 2925
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 7

Importance

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