]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SugarEmailAddress/SugarEmailAddressAddChangeTest.php
Release 6.5.10
[Github/sugarcrm.git] / tests / include / SugarEmailAddress / SugarEmailAddressAddChangeTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38 require_once 'include/SugarEmailAddress/SugarEmailAddress.php';
39
40 class SugarEmailAddressAddChangeTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42
43     protected $email;
44     protected $old_email = 'test@sugar.example.com';
45     protected $old_uuid;
46
47     /**
48      * Fetch a SugarEmailAddress for retrieval/checking purposes
49      * @param $uuid - uuid (guid) of row to read in
50      * @return SugarEmailAddress
51      */
52     protected function readSugarEmailAddress($uuid)
53     {
54         $sea = new SugarEmailAddress();
55         $sea->disable_row_level_security = true; // SugarEmailAddress doesn't roll with security
56         $sea->retrieve($uuid);
57         return $sea;
58     }
59
60     protected function setUp()
61     {
62         SugarTestHelper::setUp('current_user');
63         $this->email = SugarTestSugarEmailAddressUtilities::createEmailAddress($this->old_email);
64         $this->old_uuid = SugarTestSugarEmailAddressUtilities::fetchEmailIdByAddress($this->old_email);
65     }
66
67     protected function tearDown()
68     {
69         SugarTestSugarEmailAddressUtilities::removeCreatedContactAndRelationships();
70         SugarTestSugarEmailAddressUtilities::removeAllCreatedEmailAddresses();
71         SugarTestHelper::tearDown();
72     }
73
74     /**
75      * @group bug57426
76      */
77     public function testEmailAddressesBrandNew()
78     {
79         $new_address = 'test_george@sugar.example.com';
80
81         // now change the email, keeping track of bean UUIDs
82         $old_uuid = $this->old_uuid;
83         $uuid = $this->email->AddUpdateEmailAddress($new_address);
84
85         $this->assertNotNull($uuid, 'Failed to enter the new email in the database!');
86         $this->assertNotNull($old_uuid, 'Not seeing the old email in the database!');
87         $this->assertNotEquals($uuid, $old_uuid, 'Same Email Address Bean used for different Email Addresses!');
88
89         $new_sea = $this->readSugarEmailAddress($uuid);
90         $old_sea = $this->readSugarEmailAddress($old_uuid);
91         $this->assertNotNull($new_sea, 'New Email Address not saved in database!');
92         $this->assertEquals($this->old_email, $old_sea->email_address, 'Old Email Address was improperly Changed');
93         $this->assertEquals($new_address, $new_sea->email_address, 'New Email Address was improperly saved!');
94
95     }
96
97     public function testEmailAddressesNoChange()
98     {
99         $uuid = $this->email->AddUpdateEmailAddress($this->old_email);
100
101         $this->assertNotNull($uuid, 'Where did my email address go?');
102         $this->assertEquals($this->old_uuid,$uuid, 'We are using a different bean for the same email address!');
103
104         $sea = $this->readSugarEmailAddress($uuid);
105         $this->assertNotNull($sea, 'We lost our Email Address row!');
106         $this->assertEquals($this->old_email, $sea->email_address, 'Our Email Address Improperly Changed!');
107     }
108
109     public function testEmailAddressesChangeCaps()
110     {
111         $new_address = 'TEST@SUGAR.example.COM';
112         // change the email with caps
113         $old_uuid = $this->old_uuid;
114         $uuid = $this->email->AddUpdateEmailAddress($new_address);
115
116         $this->assertNotNull($uuid, 'Failed to enter the new email in the database!');
117         $this->assertNotNull($old_uuid, 'Not seeing the old email in the database!');
118         $this->assertEquals($uuid, $old_uuid, 'Different Email Address Bean used for same Email Address!');
119
120         $new_sea = $this->readSugarEmailAddress($uuid);
121         $this->assertNotNull($new_sea, 'Email Address not found in DB!');
122         $this->assertEquals($new_address, $new_sea->email_address, 'Email Address in DB was not updated.');
123     }
124
125     public function testEmailSimulatedInvalidFlagWorkflow()
126     {
127
128         $workflow_email = 'testworkflow@sugar.example.com';
129         $new_email = 'afreshnewemail@sugar.example.com';
130
131         // simulate a before workflow: invalid is set to true
132         $email_old_invalid = SugarTestSugarEmailAddressUtilities::createEmailAddress($workflow_email,'',array('invalid' => true));
133         $old_uuid = SugarTestSugarEmailAddressUtilities::fetchEmailIdByAddress($workflow_email);
134         $contact = SugarTestSugarEmailAddressUtilities::getContact();
135
136         $email_old_invalid->stash($contact->id, $contact->module_dir);
137         $email_old_invalid->AddUpdateEmailAddress($workflow_email,0); // 'workflow'
138
139         $uuid = $email_old_invalid->AddUpdateEmailAddress($new_email,1,0,$old_uuid); // workflow is processed
140
141         $this->assertNotNull($old_uuid, 'where is the old email address?');
142         $this->assertNotNull($uuid, 'where is our new email address?');
143         $this->assertNotEquals($old_uuid, $uuid, 'we used the same Email Address Bean for different Email Addresses!');
144
145         // need a way to see our new work
146         $fresh_sea = $this->readSugarEmailAddress($uuid);
147
148         $this->assertNotNull($fresh_sea, 'Email Address not found in DB!');
149         $this->assertEquals($new_email, $fresh_sea->email_address, 'Email Address in DB is not the same as expected.');
150         $this->assertNotEquals(1, intval($fresh_sea->invalid_email), 'Workflow changes to Email not protected');
151     }
152 }