]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Bug58863Test.php
Release 6.5.15
[Github/sugarcrm.git] / tests / include / Bug58863Test.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 /**
17  * Bug #58863
18  * associated emails showing in parent record
19  *
20  * @author mgusev@sugarcrm.com
21  * @ticked 58863
22  */
23 class Bug58863Test extends Sugar_PHPUnit_Framework_TestCase
24 {
25     /**
26      * @var Account
27      */
28     protected $account = null;
29
30     /**
31      * @var Contact
32      */
33     protected $contact = null;
34
35     /**
36      * @var Email
37      */
38     protected $email = null;
39
40     /**
41      * @var Opportunity
42      */
43     protected $opportunity = null;
44
45     /**
46      * @var SugarApplication
47      */
48     protected $application = null;
49
50     public function setUp()
51     {
52         SugarTestHelper::setUp('beanFiles');
53         SugarTestHelper::setUp('beanList');
54         SugarTestHelper::setUp('current_user');
55
56         $this->account = SugarTestAccountUtilities::createAccount();
57         $this->contact = SugarTestContactUtilities::createContact();
58         $this->email = SugarTestEmailUtilities::createEmail();
59         $this->opportunity = SugarTestOpportunityUtilities::createOpportunity('', $this->account);
60
61         $this->contact->account_id = $this->account->id;
62         $this->contact->save();
63
64         $this->opportunity->load_relationship('contacts');
65         $this->opportunity->contacts->add($this->contact);
66
67         $this->email->parent_id = $this->contact->id;
68         $this->email->parent_type = $this->contact->module_name;
69         $this->email->save();
70
71         if (isset($GLOBALS['app'])) {
72             $this->application = $GLOBALS['app'];
73         }
74         $GLOBALS['app'] = new SugarApplication();
75         $GLOBALS['app']->controller = new SugarController();
76     }
77
78     public function tearDown()
79     {
80         SugarTestHelper::tearDown();
81         SugarTestOpportunityUtilities::removeAllCreatedOpportunities();
82         SugarTestEmailUtilities::removeAllCreatedEmails();
83         SugarTestContactUtilities::removeAllCreatedContacts();
84         SugarTestAccountUtilities::removeAllCreatedAccounts();
85
86         $GLOBALS['app'] = $this->application;
87     }
88
89     /**
90      * Test asserts that contact's email is present for account and isn't present for opportunity
91      *
92      * @group 58863
93      * @return void
94      */
95     public function testGetEmailsByAssignOrLink()
96     {
97         /**
98          * @var DBManager $db
99          */
100         global $db;
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');
105
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');
110     }
111 }