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
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.
12 * Copyright (C) 2004-2013 SugarCRM Inc. All rights reserved.
13 ********************************************************************************/
16 require_once("modules/InboundEmail/InboundEmail.php");
20 * Inbound Email to Case creation does not automatically link up to the Account
22 * @author bsitnikovski@sugarcrm.com
25 class Bug58055Test extends Sugar_PHPUnit_Framework_TestCase
32 public function setUp()
34 SugarTestHelper::setUp("beanFiles");
35 SugarTestHelper::setUp("beanList");
36 SugarTestHelper::setUp("app_list_strings");
37 SugarTestHelper::setUp("app_strings");
39 SugarTestHelper::setUp("current_user");
41 $this->account = SugarTestAccountUtilities::createAccount();
42 $this->account->name = "Boro SugarTest 58055";
43 $this->account->save();
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();
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;
62 public function tearDown()
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();
72 private function getCase()
74 // Cache intentionally bypassed
75 $case = BeanFactory::newBean("Cases");
76 $case->retrieve($this->ie->parent_id);
78 $this->assertTrue($case->load_relationship("accounts"));
80 $this->assertTrue($case->load_relationship("contacts"));
85 public function testContactWithAccountLink()
87 // link contact to accounts
88 $this->assertTrue($this->contact->load_relationship("accounts"));
89 $this->contact->accounts->add($this->account->id);
91 $this->ie->handleCreateCase($this->ie, $GLOBALS["current_user"]->id);
93 $case = $this->getCase();
95 $this->assertContains($this->account->id, $case->accounts->get());
96 $this->assertContains($this->contact->id, $case->contacts->get());
99 public function testContactWithoutAccountLink()
101 $this->ie->handleCreateCase($this->ie, $GLOBALS["current_user"]->id);
102 $case = $this->getCase();
104 $this->assertNotContains($this->account->id, $case->accounts->get());
105 $this->assertContains($this->contact->id, $case->contacts->get());
108 public function testContactAccountEmail()
110 // set same e-mail address
111 $this->account->email1 = $this->contact->email1;
112 $this->account->save();
114 $this->ie->handleCreateCase($this->ie, $GLOBALS["current_user"]->id);
116 $case = $this->getCase();
118 $this->assertContains($this->account->id, $case->accounts->get());
119 $this->assertContains($this->contact->id, $case->contacts->get());