]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/InboundEmail/Bug58055Test.php
Release 6.5.15
[Github/sugarcrm.git] / tests / modules / InboundEmail / Bug58055Test.php
1 <?php
2 /*********************************************************************************
3  * By installing or using this file, you are confirming on behalf of the entity
4  * subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
5  * the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
6  * http://www.sugarcrm.com/master-subscription-agreement
7  *
8  * If Company is not bound by the MSA, then by installing or using this file
9  * you are agreeing unconditionally that Company will be bound by the MSA and
10  * certifying that you have authority to bind Company accordingly.
11  *
12  * Copyright (C) 2004-2013 SugarCRM Inc.  All rights reserved.
13  ********************************************************************************/
14
15
16 require_once("modules/InboundEmail/InboundEmail.php");
17
18 /**
19  * Bug #58055
20  * Inbound Email to Case creation does not automatically link up to the Account
21  *
22  * @author bsitnikovski@sugarcrm.com
23  * @ticket 58055
24  */
25 class Bug58055Test extends Sugar_PHPUnit_Framework_TestCase
26 {
27
28     private $ie;
29     private $account;
30     private $contact;
31
32     public function setUp()
33     {
34         SugarTestHelper::setUp("beanFiles");
35         SugarTestHelper::setUp("beanList");
36         SugarTestHelper::setUp("app_list_strings");
37         SugarTestHelper::setUp("app_strings");
38
39         SugarTestHelper::setUp("current_user");
40
41         $this->account = SugarTestAccountUtilities::createAccount();
42         $this->account->name = "Boro SugarTest 58055";
43         $this->account->save();
44
45         $this->contact = SugarTestContactUtilities::createContact();
46         $this->contact->first_name = "Boro";
47         $this->contact->last_name = "SugarTest 58055";
48         $this->contact->email1 = "bsitnikovskiBug58055Test@sugarcrm.com";
49         $this->contact->save();
50
51         $this->ie = new InboundEmail();
52         $this->ie->name = $this->ie->casename = "[CASE:58055] Bug58055 Test";
53         $this->ie->description = "This is a test for Bug58055";
54         $this->ie->mailbox_type = "createcase";
55         $this->ie->groupfolder_id = "non-empty";
56         $this->ie->from_addr = $this->contact->email1;
57
58
59         $this->ie->save();
60     }
61
62     public function tearDown()
63     {
64         $GLOBALS["db"]->query("DELETE FROM inbound_email WHERE id = '{$this->ie->id}'");
65         $GLOBALS["db"]->query("DELETE FROM cases WHERE name = '{$this->ie->casename}'");
66         SugarTestAccountUtilities::removeAllCreatedAccounts();
67         SugarTestContactUtilities::removeCreatedContactsEmailAddresses();
68         SugarTestContactUtilities::removeAllCreatedContacts();
69         SugarTestHelper::tearDown();
70     }
71
72     private function getCase()
73     {
74         // Cache intentionally bypassed
75         $case = BeanFactory::newBean("Cases");
76         $case->retrieve($this->ie->parent_id);
77
78         $this->assertTrue($case->load_relationship("accounts"));
79
80         $this->assertTrue($case->load_relationship("contacts"));
81
82         return $case;
83     }
84
85     public function testContactWithAccountLink()
86     {
87         // link contact to accounts
88         $this->assertTrue($this->contact->load_relationship("accounts"));
89         $this->contact->accounts->add($this->account->id);
90
91         $this->ie->handleCreateCase($this->ie, $GLOBALS["current_user"]->id);
92
93         $case = $this->getCase();
94
95         $this->assertContains($this->account->id, $case->accounts->get());
96         $this->assertContains($this->contact->id, $case->contacts->get());
97     }
98
99     public function testContactWithoutAccountLink()
100     {
101         $this->ie->handleCreateCase($this->ie, $GLOBALS["current_user"]->id);
102         $case = $this->getCase();
103
104         $this->assertNotContains($this->account->id, $case->accounts->get());
105         $this->assertContains($this->contact->id, $case->contacts->get());
106     }
107
108     public function testContactAccountEmail()
109     {
110         // set same e-mail address
111         $this->account->email1 = $this->contact->email1;
112         $this->account->save();
113
114         $this->ie->handleCreateCase($this->ie, $GLOBALS["current_user"]->id);
115
116         $case = $this->getCase();
117
118         $this->assertContains($this->account->id, $case->accounts->get());
119         $this->assertContains($this->contact->id, $case->contacts->get());
120     }
121 }