Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ConversationParticipantsUtilTest.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  $super = User::getByUsername('super');
44  Yii::app()->user->userModel = $super;
45  AccountTestHelper::createAccountByNameForOwner('anAccount', $super);
46  }
47 
48  public function setUp()
49  {
50  parent::setUp();
51  Yii::app()->user->userModel = User::getByUsername('super');
52  }
53 
54  public function testIsUserAParticipant()
55  {
56  $steven = UserTestHelper::createBasicUser('steven');
57  $conversation = new Conversation();
58  $conversation->owner = Yii::app()->user->userModel;
59  $conversation->subject = 'My test subject2';
60  $conversation->description = 'My test description2';
61  $this->assertTrue($conversation->save());
62  $this->assertFalse(ConversationParticipantsUtil::isUserAParticipant($conversation, $steven));
63 
64  $conversationParticipant = new ConversationParticipant();
65  $conversationParticipant->person = $steven;
66  $conversation->conversationParticipants->add($conversationParticipant);
67  $this->assertTrue($conversation->save());
68  $this->assertTrue(ConversationParticipantsUtil::isUserAParticipant($conversation, $steven));
69  }
70 
71  public function testResolveConversationHasManyParticipantsFromPost()
72  {
73  $super = Yii::app()->user->userModel;
74  $mary = UserTestHelper::createBasicUser('mary');
75  $steven = User::getByUsername('steven');
76  $conversation = new Conversation();
77  $conversation->owner = Yii::app()->user->userModel;
78  $conversation->subject = 'My test subject2';
79  $conversation->description = 'My test description2';
80  $this->assertTrue($conversation->save());
81 
82  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
83  makeBySecurableItem($conversation);
84  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
85  $this->assertEquals(0, count($readWritePermitables));
86 
87  //test no existing participants. Do not add owner of conversation
88  $postData = array();
89  $postData['itemIds'] = $super->getClassId('Item');
91  $conversation, $postData, $explicitReadWriteModelPermissions);
92  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
93  $this->assertEquals(0, count($readWritePermitables));
94  $this->assertEquals(0, $conversation->conversationParticipants->count());
95 
96  //test adding 2 more participants
97  $postData = array();
98  $postData['itemIds'] = $super->getClassId('Item'). ',' . $steven->getClassId('Item') . ',' . $mary->getClassId('Item'); // Not Coding Standard
100  $conversation, $postData, $explicitReadWriteModelPermissions);
101  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
102  $this->assertEquals(2, count($readWritePermitables));
103  $this->assertEquals(2, $conversation->conversationParticipants->count());
104 
105  $this->assertTrue($conversation->save());
107  resolveExplicitReadWriteModelPermissions($conversation, $explicitReadWriteModelPermissions);
108  $this->assertTrue($success);
109 
110  //Just making sure the readWrite count is still 2
111  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
112  makeBySecurableItem($conversation);
113  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
114  $this->assertEquals(2, count($readWritePermitables));
115 
116  //test removing a participant (remove steven)
117  $postData = array();
118  $postData['itemIds'] = $super->getClassId('Item') . ',' . $mary->getClassId('Item'); // Not Coding Standard
120  $conversation, $postData, $explicitReadWriteModelPermissions);
121  $this->assertTrue($conversation->save());
123  resolveExplicitReadWriteModelPermissions($conversation, $explicitReadWriteModelPermissions);
124  $this->assertTrue($success);
125 
126  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
127  makeBySecurableItem($conversation);
128  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
129  $this->assertEquals(1, count($readWritePermitables));
130  $this->assertEquals(1, $conversation->conversationParticipants->count());
131  $this->assertEquals($mary, $conversation->conversationParticipants[0]->person);
132 
133  //test removing all participants.
134  $postData = array();
135  $postData['itemIds'] = '';
137  $conversation, $postData, $explicitReadWriteModelPermissions);
138  $this->assertTrue($conversation->save());
140  resolveExplicitReadWriteModelPermissions($conversation, $explicitReadWriteModelPermissions);
141  $this->assertTrue($success);
142  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
143  makeBySecurableItem($conversation);
144  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
145  $this->assertEquals(0, count($readWritePermitables));
146  $this->assertEquals(0, $conversation->conversationParticipants->count());
147  }
148 
153  {
154  $super = Yii::app()->user->userModel;
155  $jack = UserTestHelper::createBasicUser('jack');
156  $steven = User::getByUsername('steven');
157  $conversation = new Conversation();
158  $conversation->owner = Yii::app()->user->userModel;
159  $conversation->subject = 'Test Resolve Conversation Participants';
160  $conversation->description = 'This is for testing conversation participants.';
161  $this->assertTrue($conversation->save());
162  $participants = ConversationParticipantsUtil::
163  getConversationParticipants($conversation);
164  $this->assertEquals(0, count($participants));
165  $conversationParticipant = new ConversationParticipant();
166  $conversationParticipant->person = $jack;
167  $conversation->conversationParticipants->add($conversationParticipant);
168  $this->assertEquals(0, count($participants));
169  $participants = ConversationParticipantsUtil::
170  getConversationParticipants($conversation);
171  $this->assertEquals(1, count($participants));
172  $conversationParticipant = new ConversationParticipant();
173  $conversationParticipant->person = $steven;
174  $conversation->conversationParticipants->add($conversationParticipant);
175  $participants = ConversationParticipantsUtil::
176  getConversationParticipants($conversation);
177  $this->assertEquals(2, count($participants));
178  }
179 
184  {
185  $this->assertEquals(0, Notification::getCount());
186  $this->assertEquals(0, EmailMessage::getCount());
187  $super = Yii::app()->user->userModel;
188  $super->primaryEmail->emailAddress = 'super@zurmo.com';
189  NotificationTestHelper::setNotificationSettingsForUser($super, 'ConversationInvites');
190  $jack = User::getByUsername('jack');
191  $jack->primaryEmail->emailAddress = 'jack@zurmo.com';
192  NotificationTestHelper::setNotificationSettingsForUser($jack, 'ConversationInvites', true, false);
193  $steven = User::getByUsername('steven');
194  $steven->primaryEmail->emailAddress = 'steven@zurmo.com';
195  NotificationTestHelper::setNotificationSettingsForUser($steven, 'ConversationInvites', false, true);
196  $mary = User::getByUsername('mary');
197  $mary->primaryEmail->emailAddress = 'mary@zurmo.com';
198  NotificationTestHelper::setNotificationSettingsForUser($mary, 'ConversationInvites', false, false);
199  $conversation = new Conversation();
200  $conversation->owner = $super;
201  $conversation->subject = 'Test Resolve Conversation Participants';
202  $conversation->description = 'This is for testing conversation participants.';
203  $this->assertTrue($conversation->save());
205  $conversation,
206  array($super, $jack, $steven, $mary));
207  $this->assertEquals(2, Notification::getCount());
208  $notifications = Notification::getAll();
209  $this->assertContains('<h2 class="h2">Join the Conversation</h2>Clark Kent would like you to join a conversation <strong>"Test Resolve Conversation Participants"</strong><br/>',
210  $notifications[0]->notificationMessage->htmlContent);
211  $this->assertContains('Clark Kent would like you to join a conversation "Test Resolve Conversation Participants"',
212  $notifications[0]->notificationMessage->textContent);
213  $this->assertEquals(2, EmailMessage::getCount());
214  $emailMessages = EmailMessage::getAll();
215  $this->assertContains('<h2 class="h2">Join the Conversation</h2>Clark Kent would like you to join a conversation <strong>"Test Resolve Conversation Participants"</strong><br/>',
216  $emailMessages[0]->content->htmlContent);
217  $this->assertContains('Powered By <a href="http://www.zurmo.com">Zurmo</a>', $emailMessages[0]->content->htmlContent);
218  $this->assertContains('Clark Kent would like you to join a conversation "Test Resolve Conversation Participants"',
219  $emailMessages[0]->content->textContent);
220  $this->assertContains('Manage your email preferences', $emailMessages[0]->content->textContent);
221  $this->assertEquals('You have been invited to participate in a conversation',
222  $emailMessages[0]->subject);
223  }
224  }
225 ?>
static makeBySecurableItem(SecurableItem $securableItem)
static getByUsername($username)
Definition: User.php:49
static resolveExplicitReadWriteModelPermissions(SecurableItem $securableItem, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions, $validate=false)
static getConversationParticipants(Conversation $conversation)
static resolveConversationHasManyParticipantsFromPost(Conversation $conversation, $postData, $explicitReadWriteModelPermissions)
static isUserAParticipant(Conversation $model, User $user)
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
static resolveEmailInvitesByPeople($conversation, $people)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Wed Nov 25 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.