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 ********************************************************************************/
18 * associated emails showing in parent record
20 * @author mgusev@sugarcrm.com
23 class Bug58863Test extends Sugar_PHPUnit_Framework_TestCase
28 protected $account = null;
33 protected $contact = null;
38 protected $email = null;
43 protected $opportunity = null;
46 * @var SugarApplication
48 protected $application = null;
50 public function setUp()
52 SugarTestHelper::setUp('beanFiles');
53 SugarTestHelper::setUp('beanList');
54 SugarTestHelper::setUp('current_user');
56 $this->account = SugarTestAccountUtilities::createAccount();
57 $this->contact = SugarTestContactUtilities::createContact();
58 $this->email = SugarTestEmailUtilities::createEmail();
59 $this->opportunity = SugarTestOpportunityUtilities::createOpportunity('', $this->account);
61 $this->contact->account_id = $this->account->id;
62 $this->contact->save();
64 $this->opportunity->load_relationship('contacts');
65 $this->opportunity->contacts->add($this->contact);
67 $this->email->parent_id = $this->contact->id;
68 $this->email->parent_type = $this->contact->module_name;
71 if (isset($GLOBALS['app'])) {
72 $this->application = $GLOBALS['app'];
74 $GLOBALS['app'] = new SugarApplication();
75 $GLOBALS['app']->controller = new SugarController();
78 public function tearDown()
80 SugarTestHelper::tearDown();
81 SugarTestOpportunityUtilities::removeAllCreatedOpportunities();
82 SugarTestEmailUtilities::removeAllCreatedEmails();
83 SugarTestContactUtilities::removeAllCreatedContacts();
84 SugarTestAccountUtilities::removeAllCreatedAccounts();
86 $GLOBALS['app'] = $this->application;
90 * Test asserts that contact's email is present for account and isn't present for opportunity
95 public function testGetEmailsByAssignOrLink()
101 $GLOBALS['app']->controller->bean = $this->account;
102 $query = get_emails_by_assign_or_link(array('import_function_file' => 'include/utils.php', 'link' => 'contacts'));
103 $email = $db->fetchByAssoc($db->query($query['select'] . $query['from'] . $query['join'] . $query['where']));
104 $this->assertEquals($this->email->id, $email['id'], 'Email should be present for Account');
106 $GLOBALS['app']->controller->bean = $this->opportunity;
107 $query = get_emails_by_assign_or_link(array('import_function_file' => 'include/utils.php', 'link' => 'contacts'));
108 $email = $db->fetchByAssoc($db->query($query['select'] . $query['from'] . $query['join'] . $query['where']));
109 $this->assertEmpty($email, 'Email should not be present for Opportunity');