]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SugarEmailAddress/SugarEmailAddressAddChangeTest.php
Release 6.5.8
[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-2012 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         $this->email = SugarTestSugarEmailAddressUtilities::createEmailAddress($this->old_email);
63         $this->old_uuid = SugarTestSugarEmailAddressUtilities::fetchEmailIdByAddress($this->old_email);
64     }
65
66     protected function tearDown()
67     {
68         SugarTestSugarEmailAddressUtilities::removeCreatedContactAndRelationships();
69         SugarTestSugarEmailAddressUtilities::removeAllCreatedEmailAddresses();
70     }
71
72     /**
73      * @group bug57426
74      */
75     public function testEmailAddressesBrandNew()
76     {
77         $new_address = 'test_george@sugar.example.com';
78
79         // now change the email, keeping track of bean UUIDs
80         $old_uuid = $this->old_uuid;
81         $uuid = $this->email->AddUpdateEmailAddress($new_address);
82
83         $this->assertNotNull($uuid, 'Failed to enter the new email in the database!');
84         $this->assertNotNull($old_uuid, 'Not seeing the old email in the database!');
85         $this->assertNotEquals($uuid, $old_uuid, 'Same Email Address Bean used for different Email Addresses!');
86
87         $new_sea = $this->readSugarEmailAddress($uuid);
88         $old_sea = $this->readSugarEmailAddress($old_uuid);
89         $this->assertNotNull($new_sea, 'New Email Address not saved in database!');
90         $this->assertEquals($this->old_email, $old_sea->email_address, 'Old Email Address was improperly Changed');
91         $this->assertEquals($new_address, $new_sea->email_address, 'New Email Address was improperly saved!');
92
93     }
94
95     public function testEmailAddressesNoChange()
96     {
97         $uuid = $this->email->AddUpdateEmailAddress($this->old_email);
98
99         $this->assertNotNull($uuid, 'Where did my email address go?');
100         $this->assertEquals($this->old_uuid,$uuid, 'We are using a different bean for the same email address!');
101
102         $sea = $this->readSugarEmailAddress($uuid);
103         $this->assertNotNull($sea, 'We lost our Email Address row!');
104         $this->assertEquals($this->old_email, $sea->email_address, 'Our Email Address Improperly Changed!');
105     }
106
107     public function testEmailAddressesChangeCaps()
108     {
109         $new_address = 'TEST@SUGAR.example.COM';
110         // change the email with caps
111         $old_uuid = $this->old_uuid;
112         $uuid = $this->email->AddUpdateEmailAddress($new_address);
113
114         $this->assertNotNull($uuid, 'Failed to enter the new email in the database!');
115         $this->assertNotNull($old_uuid, 'Not seeing the old email in the database!');
116         $this->assertEquals($uuid, $old_uuid, 'Different Email Address Bean used for same Email Address!');
117
118         $new_sea = $this->readSugarEmailAddress($uuid);
119         $this->assertNotNull($new_sea, 'Email Address not found in DB!');
120         $this->assertEquals($new_address, $new_sea->email_address, 'Email Address in DB was not updated.');
121     }
122
123     public function testEmailSimulatedInvalidFlagWorkflow()
124     {
125
126         $workflow_email = 'testworkflow@sugar.example.com';
127         $new_email = 'afreshnewemail@sugar.example.com';
128
129         // simulate a before workflow: invalid is set to true
130         $email_old_invalid = SugarTestSugarEmailAddressUtilities::createEmailAddress($workflow_email,'',array('invalid' => true));
131         $old_uuid = SugarTestSugarEmailAddressUtilities::fetchEmailIdByAddress($workflow_email);
132         $contact = SugarTestSugarEmailAddressUtilities::getContact();
133
134         $email_old_invalid->stash($contact->id, $contact->module_dir);
135         $email_old_invalid->AddUpdateEmailAddress($workflow_email,0); // 'workflow'
136
137         $uuid = $email_old_invalid->AddUpdateEmailAddress($new_email,1,0,$old_uuid); // workflow is processed
138
139         $this->assertNotNull($old_uuid, 'where is the old email address?');
140         $this->assertNotNull($uuid, 'where is our new email address?');
141         $this->assertNotEquals($old_uuid, $uuid, 'we used the same Email Address Bean for different Email Addresses!');
142
143         // need a way to see our new work
144         $fresh_sea = $this->readSugarEmailAddress($uuid);
145
146         $this->assertNotNull($fresh_sea, 'Email Address not found in DB!');
147         $this->assertEquals($new_email, $fresh_sea->email_address, 'Email Address in DB is not the same as expected.');
148         $this->assertNotEquals(1, intval($fresh_sea->invalid_email), 'Workflow changes to Email not protected');
149     }
150 }