Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
EmailAccountTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo 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 ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo 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 Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified 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 Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  UserTestHelper::createBasicUser('billy');
44  }
45 
46  public function testResolveAndGetByUserAndName()
47  {
48  //Test a user that not have a Primary Email Address
49  $super = User::getByUsername('super');
50  Yii::app()->user->userModel = $super;
51  $emailAccount = EmailAccount::resolveAndGetByUserAndName($super);
52  $this->assertEquals('Default', $emailAccount->name);
53  $this->assertEquals($super, $emailAccount->user);
54  $this->assertEquals($super->getFullName(), $emailAccount->fromName);
55  $this->assertEquals($super->primaryEmail->emailAddress, $emailAccount->fromAddress);
56  $this->assertEquals(EmailMessageUtil::OUTBOUND_GLOBAL_SETTINGS, $emailAccount->useCustomOutboundSettings);
57  $this->assertEquals('smtp', $emailAccount->outboundType);
58  $emailAccountId = $emailAccount->id;
59  $emailAccount = EmailAccount::resolveAndGetByUserAndName($super);
60  $this->assertNotEquals($emailAccountId, $emailAccount->id);
61  $emailAccount->save();
62  $this->assertEquals($emailAccount->getError('fromAddress'), 'From Address cannot be blank.');
63  $emailAccount->fromAddress = 'super@zurmo.org';
64  $emailAccount->save();
65  $emailAccountId = $emailAccount->id;
66  $emailAccount = EmailAccount::resolveAndGetByUserAndName($super);
67  $this->assertEquals($emailAccountId, $emailAccount->id);
68  $this->assertEquals('Default', $emailAccount->name);
69  $this->assertEquals($super, $emailAccount->user);
70  $this->assertEquals($super->getFullName(), $emailAccount->fromName);
71  $this->assertEquals('super@zurmo.org', $emailAccount->fromAddress);
72  $this->assertEquals(EmailMessageUtil::OUTBOUND_GLOBAL_SETTINGS, $emailAccount->useCustomOutboundSettings);
73  $this->assertEquals('smtp', $emailAccount->outboundType);
74  }
75 
79  public function testGetByUserAndName()
80  {
81  $super = User::getByUsername('super');
82  Yii::app()->user->userModel = $super;
83  $emailAccount = EmailAccount::getByUserAndName($super);
84  $this->assertEquals('Default', $emailAccount->name);
85  $this->assertEquals($super, $emailAccount->user);
86  $this->assertEquals($super->getFullName(), $emailAccount->fromName);
87  $this->assertEquals('super@zurmo.org', $emailAccount->fromAddress);
88  $this->assertEquals(EmailMessageUtil::OUTBOUND_GLOBAL_SETTINGS, $emailAccount->useCustomOutboundSettings);
89  $this->assertEquals('smtp', $emailAccount->outboundType);
90  }
91 
92  public function testCrudForHasOneAndHasManyEmailAccountRelations()
93  {
94  $super = User::getByUsername('super');
95  Yii::app()->user->userModel = $super;
96  $emailAccount = EmailAccount::resolveAndGetByUserAndName($super);
97  $emailAccountId = $emailAccount->id;
98  $emailAccount->forgetAll();
99 
100  //Check read hasOne relation
101  $emailAccount = EmailAccount::getById($emailAccountId);
102  $user = $emailAccount->user;
103  $this->assertEquals($super->username, $user->username);
104 
105  //Check update hasOne relation
106  $user = User::getByUsername('billy');
107  $emailAccount->user = $user;
108  $this->assertTrue($emailAccount->save());
109  $emailAccount->forgetAll();
110  $emailAccount = EmailAccount::getById($emailAccountId);
111  $this->assertEquals('billy', $emailAccount->user->username);
112 
113  //Check delete hasOne relation
114  $emailAccount->user = null;
115  $this->assertTrue($emailAccount->save());
116  $emailAccount->forgetAll();
117  $emailAccount = EmailAccount::getById($emailAccountId);
118  $this->assertLessThan(0, $emailAccount->user->id);
119 
120  //Check create and read hasMany relation model
121  $emailMessage = EmailMessageTestHelper::
122  createDraftSystemEmail('first test email', $user);
123  $emailAccount->messages->add($emailMessage);
124  $this->assertTrue($emailAccount->save());
125  $emailAccount->forgetAll();
126  $emailAccount = EmailAccount::getById($emailAccountId);
127  $this->assertCount(1, $emailAccount->messages);
128  $this->assertEquals('first test email', $emailAccount->messages[0]->subject);
129 
130  //Check update hasMany relation
131  $emailMessage = $emailAccount->messages[0];
132  $emailMessage->subject = 'first test email modified';
133  $this->assertTrue($emailAccount->save());
134  $emailAccount->forgetAll();
135  $emailAccount = EmailAccount::getById($emailAccountId);
136  $this->assertCount(1, $emailAccount->messages);
137  $this->assertEquals($emailMessage->subject, $emailAccount->messages[0]->subject);
138 
139  //Check add and read another hasMany relation model
140  $emailMessage2 = EmailMessageTestHelper::
141  createDraftSystemEmail('second test email', $user);
142  $emailAccount->messages->add($emailMessage2);
143  $this->assertTrue($emailAccount->save());
144  $emailAccount->forgetAll();
145  $emailAccount = EmailAccount::getById($emailAccountId);
146  $this->assertCount(2, $emailAccount->messages);
147  $this->assertEquals($emailMessage2->subject, $emailAccount->messages[1]->subject);
148 
149  //Check delete hasMany relation first model
150  $emailAccount->messages->remove($emailMessage);
151  $this->assertTrue($emailAccount->save());
152  $emailAccount->forgetAll();
153  $emailAccount = EmailAccount::getById($emailAccountId);
154  $this->assertCount(1, $emailAccount->messages);
155  $this->assertEquals($emailMessage2->subject, $emailAccount->messages[0]->subject);
156 
157  //Check delete last hasMany relation model
158  $emailAccount->messages->remove($emailMessage2);
159  $this->assertTrue($emailAccount->save());
160  $emailAccount->forgetAll();
161  $emailAccount = EmailAccount::getById($emailAccountId);
162  $this->assertCount(0, $emailAccount->messages);
163  }
164  }
165 ?>
static resolveAndGetByUserAndName(User $user, $name=null, $decrypt=true)
static getByUsername($username)
Definition: User.php:49
static getByUserAndName(User $user, $name=null)
static getById($id, $modelClassName=null)
Generated on Thu Aug 6 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.