2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once 'include/SugarEmailAddress/SugarEmailAddress.php';
40 class SugarEmailAddressAddChangeTest extends Sugar_PHPUnit_Framework_TestCase
44 protected $old_email = 'test@sugar.example.com';
48 * Fetch a SugarEmailAddress for retrieval/checking purposes
49 * @param $uuid - uuid (guid) of row to read in
50 * @return SugarEmailAddress
52 protected function readSugarEmailAddress($uuid)
54 $sea = new SugarEmailAddress();
55 $sea->disable_row_level_security = true; // SugarEmailAddress doesn't roll with security
56 $sea->retrieve($uuid);
60 protected function setUp()
62 SugarTestHelper::setUp('current_user');
63 $this->email = SugarTestSugarEmailAddressUtilities::createEmailAddress($this->old_email);
64 $this->old_uuid = SugarTestSugarEmailAddressUtilities::fetchEmailIdByAddress($this->old_email);
67 protected function tearDown()
69 SugarTestSugarEmailAddressUtilities::removeCreatedContactAndRelationships();
70 SugarTestSugarEmailAddressUtilities::removeAllCreatedEmailAddresses();
71 SugarTestHelper::tearDown();
77 public function testEmailAddressesBrandNew()
79 $new_address = 'test_george@sugar.example.com';
81 // now change the email, keeping track of bean UUIDs
82 $old_uuid = $this->old_uuid;
83 $uuid = $this->email->AddUpdateEmailAddress($new_address);
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!');
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!');
97 public function testEmailAddressesNoChange()
99 $uuid = $this->email->AddUpdateEmailAddress($this->old_email);
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!');
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!');
109 public function testEmailAddressesChangeCaps()
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);
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!');
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.');
125 public function testEmailSimulatedInvalidFlagWorkflow()
128 $workflow_email = 'testworkflow@sugar.example.com';
129 $new_email = 'afreshnewemail@sugar.example.com';
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();
136 $email_old_invalid->stash($contact->id, $contact->module_dir);
137 $email_old_invalid->AddUpdateEmailAddress($workflow_email,0); // 'workflow'
139 $uuid = $email_old_invalid->AddUpdateEmailAddress($new_email,1,0,$old_uuid); // workflow is processed
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!');
145 // need a way to see our new work
146 $fresh_sea = $this->readSugarEmailAddress($uuid);
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');