]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/OutboundEmail/Bug23140Test.php
Release 6.2.3
[Github/sugarcrm.git] / tests / include / OutboundEmail / Bug23140Test.php
1 <?php 
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 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/OutboundEmail/OutboundEmail.php');
39
40 /**
41  * @ticket 23140
42  */
43 class Bug23140Test extends Sugar_PHPUnit_Framework_TestCase
44 {
45         var $outbound_id = null;
46         var $_user = null;
47         var $ob = null;
48         var $userOverideAccont = null;
49         
50         public function setUp()
51     {
52         global $current_user, $currentModule ;
53                 $this->_user = SugarTestUserUtilities::createAnonymousUser();
54                 $current_user = $this->_user;
55         }
56
57     public function tearDown()
58     {
59         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
60         //unset($GLOBALS['current_user']);
61         
62         if ($this->ob != null)
63             $GLOBALS['db']->query("DELETE FROM outbound_email WHERE id= '{$this->ob->id}'");
64         if ($this->userOverideAccont != null)
65             $GLOBALS['db']->query("DELETE FROM outbound_email WHERE id= '{$this->userOverideAccont->id}'");
66     }
67     
68     function testSystemAccountMailSettingsChangedUserAccessToUsername()
69     {
70         //User not alloweed to access system email username/password
71         $GLOBALS['db']->query("INSERT INTO config (category,name,value) VALUES ('notify','allow_default_outbound','2') ");
72         
73         $newSystemPort = 864;
74         $newSystemServer = "system.imap.com";
75         $newSystemUsername = "system_user_name";
76         $newSystemPassword = "SYSTEM_PASSWORD";
77         
78         $userID = create_guid();
79         $ob = new OutboundEmail();
80         $ob->id = $userID;
81         $ob->new_with_id = TRUE;
82         $ob->name = 'Sugar Test';
83         $ob->type = 'system-override';
84         $ob->user_id = $this->_user->id;
85         $ob->mail_sendtype = "SMTP";
86         $ob->mail_smtpuser = "Test User";
87         $ob->mail_smtppass = "User Pass";
88         $ob->save();
89         $this->ob = $ob;
90         
91         
92         $system = $ob->getSystemMailerSettings();
93         $system->new_with_id = FALSE;
94         $system->mail_smtpport = $newSystemPort;
95         $system->mail_smtpserver = $newSystemServer;
96         $system->mail_smtpuser = $newSystemUsername;
97         $system->mail_smtppass = $newSystemPassword;
98         
99         $system->saveSystem();
100         
101         $obRetrieved = new OutboundEmail();
102         $obRetrieved->retrieve($userID);
103         
104         $this->assertEquals($newSystemPort, $obRetrieved->mail_smtpport, "Could not update users system-override accounts after system save.");
105         $this->assertEquals($newSystemServer, $obRetrieved->mail_smtpserver, "Could not update users system-override accounts after system save.");
106         $this->assertEquals($newSystemUsername, $obRetrieved->mail_smtpuser, "Could not update users system-override accounts after system save.");
107         $this->assertEquals($newSystemPassword, $obRetrieved->mail_smtppass, "Could not update users system-override accounts after system save.");
108         
109     }
110     
111     
112     function testSystemAccountMailSettingsChangedNoUserAccessToUsername()
113     {
114         //User not alloweed to access system email username/password
115         $GLOBALS['db']->query("DELETE FROM config WHERE category='notify' AND name='allow_default_outbound' ");
116         
117         $newSystemPort = 864;
118         $newSystemServer = "system.imap.com";
119         
120         $userID = create_guid();
121         $ob = new OutboundEmail();
122         $ob->id = $userID;
123         $ob->new_with_id = TRUE;
124         $ob->name = 'Sugar Test';
125         $ob->type = 'system-override';
126         $ob->user_id = $this->_user->id;
127         $ob->mail_sendtype = "SMTP";
128         $ob->mail_smtpuser = "Test User";
129         $ob->mail_smtppass = "User Pass";
130         $ob->save();
131         $this->ob = $ob;
132         
133         
134         $system = $ob->getSystemMailerSettings();
135         $system->new_with_id = FALSE;
136         $system->mail_smtpport = $newSystemPort;
137         $system->mail_smtpserver = $newSystemServer;
138         $system->saveSystem();
139         
140         $obRetrieved = new OutboundEmail();
141         $obRetrieved->retrieve($userID);
142         
143         $this->assertEquals($newSystemPort, $obRetrieved->mail_smtpport, "Could not update users system-override accounts after system save.");
144         $this->assertEquals($newSystemServer, $obRetrieved->mail_smtpserver, "Could not update users system-override accounts after system save.");
145         $this->assertEquals("Test User", $obRetrieved->mail_smtpuser, "Could not update users system-override accounts after system save.");
146         $this->assertEquals("User Pass", $obRetrieved->mail_smtppass, "Could not update users system-override accounts after system save.");
147     }
148     
149     
150     function testUserMailForSystemOverrideRetrieval()
151     {
152         $ob = new OutboundEmail();
153         $ob->name = 'Sugar Test';
154         $ob->type = 'system-override';
155         $ob->user_id = $this->_user->id;
156         $ob->mail_sendtype = "SMTP";
157         $ob->mail_smtpuser = "Test User";
158         $ob->save();
159         $this->ob = $ob;
160         
161         $retrievedOb = $ob->getUsersMailerForSystemOverride($this->_user->id);
162         $this->assertEquals($ob->name, $retrievedOb->name, "Could not retrieve users system override outbound email account");
163         $this->assertEquals($ob->type, $retrievedOb->type, "Could not retrieve users system override outbound email account");
164         $this->assertEquals($ob->user_id, $retrievedOb->user_id, "Could not retrieve users system override outbound email account");
165         $this->assertEquals($ob->mail_sendtype, $retrievedOb->mail_sendtype, "Could not retrieve users system override outbound email account");
166         $this->assertEquals("Test User", $retrievedOb->mail_smtpuser, "Could not retrieve users system override outbound email account");
167     }
168     
169     function testDuplicateSystemAccountForUser()
170     {
171         $oe = new OutboundEmail();
172         $userOverideAccont = $oe->createUserSystemOverrideAccount($this->_user->id, "TEST USER NAME", "TEST PASSWORD");
173         $this->userOverideAccont = $userOverideAccont;
174         $retrievedOb = $oe->getUsersMailerForSystemOverride($this->_user->id);
175         
176         $this->assertEquals("TEST USER NAME", $retrievedOb->mail_smtpuser, "Could not duplicate systems outbound account for user");
177         $this->assertEquals($this->_user->id, $retrievedOb->user_id, "Could not duplicate systems outbound account for user");
178         $this->assertEquals("TEST PASSWORD", $retrievedOb->mail_smtppass, "Could not duplicate systems outbound account for user");
179         $this->assertEquals('system-override', $userOverideAccont->type, "Could not duplicate systems outbound account for user");
180     }
181     
182     function testIsUserAlloweedAccessToSystemOutboundEmail()
183     {
184         $oe = new OutboundEmail();
185         $GLOBALS['db']->query("DELETE FROM config WHERE category='notify' AND name='allow_default_outbound' ");
186         $emptyTest = $oe->isAllowUserAccessToSystemDefaultOutbound();
187         $this->assertFalse($emptyTest, "User alloweed access to system outbound email account error");
188         
189         $GLOBALS['db']->query("INSERT INTO config (category,name,value) VALUES ('notify','allow_default_outbound','2') ");
190         $allowTest = $oe->isAllowUserAccessToSystemDefaultOutbound();
191         $this->assertTrue($allowTest, "User alloweed access to system outbound email account error");
192         
193         $GLOBALS['db']->query("DELETE FROM config WHERE category='notify' AND name='allow_default_outbound' ");
194         $emptyTest = $oe->isAllowUserAccessToSystemDefaultOutbound();
195         $this->assertFalse($emptyTest, "User alloweed access to system outbound email account error");
196            
197     }
198     
199     
200     function testIsUserAuthRequiredForOverrideAccount()
201     {
202         $oe = new OutboundEmail();
203         
204         $GLOBALS['db']->query("DELETE FROM config WHERE category='notify' AND name='allow_default_outbound' ");
205         $system = $oe->getSystemMailerSettings();
206         
207         //System does not require auth, no user overide account.
208         $system->mail_smtpauth_req = 0;
209         $system->save(FALSE);
210         
211         $notRequired = $oe->doesUserOverrideAccountRequireCredentials($this->_user->id);
212         $this->assertFalse($notRequired, "Test failed for determining if user auth required.");
213         
214         //System does require auth, no user overide account.
215         $system->mail_smtpauth_req = 1;
216         $system->save(FALSE);
217         $notRequired = $oe->doesUserOverrideAccountRequireCredentials($this->_user->id);
218         $this->assertTrue($notRequired, "Test failed for determining if user auth required.");
219         
220         //System requires auth and users alloweed to use sys defaults.
221         $GLOBALS['db']->query("INSERT INTO config (category,name,value) VALUES ('notify','allow_default_outbound','2') ");
222         $notRequired = $oe->doesUserOverrideAccountRequireCredentials($this->_user->id);
223         $this->assertFalse($notRequired, "Test failed for determining if user auth required.");
224         
225         
226         //System requires auth but user details are empty and users are not alloweed to use system details..
227         $GLOBALS['db']->query("DELETE FROM config WHERE category='notify' AND name='allow_default_outbound' ");
228         $userOverideAccont = $oe->createUserSystemOverrideAccount($this->_user->id, "", "");
229         $this->userOverideAccont = $userOverideAccont;
230         $notRequired = $oe->doesUserOverrideAccountRequireCredentials($this->_user->id);
231         $this->assertTrue($notRequired, "Test failed for determining if user auth required.");
232         
233         //User has provided all credentials.
234         $this->userOverideAccont->mail_smtpuser = "TEST USER NAME";
235         $this->userOverideAccont->mail_smtppass = "TEST PASSWORD";
236         $this->userOverideAccont->new_with_id = FALSE;
237         $this->userOverideAccont->save();
238         $notRequired = $oe->doesUserOverrideAccountRequireCredentials($this->_user->id);
239         $this->assertFalse($notRequired, "Test failed for determining if user auth required.");
240         
241     }
242     
243 }
244 ?>