All Data Structures Functions Variables Pages
ConversationsUtilTest.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 testMarkUserHasReadLatest()
55  {
56  $super = User::getByUsername('super');
57  $steven = UserTestHelper::createBasicUser('steven');
58 
59  $conversation = new Conversation();
60  $conversation->owner = $super;
61  $conversation->subject = 'My test subject';
62  $conversation->description = 'My test description';
63  $this->assertTrue($conversation->save());
64  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
65  makeBySecurableItem($conversation);
66  $postData = array();
67  $postData['itemIds'] = $steven->getClassId('Item');
69  $conversation, $postData, $explicitReadWriteModelPermissions);
70  $this->assertTrue($conversation->save());
72  resolveExplicitReadWriteModelPermissions($conversation, $explicitReadWriteModelPermissions);
73  $this->assertTrue($success);
74 
75  $id = $conversation->id;
76  $conversation->forget();
77  unset($conversation);
78 
79  $conversation = Conversation::getById($id);
80  $this->assertEquals(1, $conversation->ownerHasReadLatest);
81  $this->assertEquals(0, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
82 
83  //After running for super, nothing will change.
84  ConversationsUtil::markUserHasReadLatest($conversation, $super);
85  $id = $conversation->id;
86  $conversation->forget();
87  unset($conversation);
88  $conversation = Conversation::getById($id);
89  $this->assertEquals(1, $conversation->ownerHasReadLatest);
90  $this->assertEquals(0, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
91 
92  //After running for steven, it will show read for him.
93  ConversationsUtil::markUserHasReadLatest($conversation, $steven);
94  $id = $conversation->id;
95  $conversation->forget();
96  unset($conversation);
97  $conversation = Conversation::getById($id);
98  $this->assertEquals(1, $conversation->ownerHasReadLatest);
99  $this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
100 
101  $conversation->ownerHasReadLatest = false;
102  $this->assertTrue($conversation->save());
103  $id = $conversation->id;
104  $conversation->forget();
105  unset($conversation);
106  $conversation = Conversation::getById($id);
107  $this->assertEquals(0, $conversation->ownerHasReadLatest);
108  $this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
109 
110  //Now try for Steven, nothing changes
111  ConversationsUtil::markUserHasReadLatest($conversation, $steven);
112  $id = $conversation->id;
113  $conversation->forget();
114  unset($conversation);
115  $conversation = Conversation::getById($id);
116  $this->assertEquals(0, $conversation->ownerHasReadLatest);
117  $this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
118 
119  //Now try for super, should change
120  ConversationsUtil::markUserHasReadLatest($conversation, $super);
121  $id = $conversation->id;
122  $conversation->forget();
123  unset($conversation);
124  $conversation = Conversation::getById($id);
125  $this->assertEquals(1, $conversation->ownerHasReadLatest);
126  $this->assertEquals(1, $conversation->conversationParticipants->offsetGet(0)->hasReadLatest);
127  }
128 
129  public function testResolvePeopleOnConversation()
130  {
131  $super = Yii::app()->user->userModel;
132  $jack = UserTestHelper::createBasicUser('jack');
133  $steven = User::getByUsername('steven');
134  $conversation = new Conversation();
135  $conversation->owner = Yii::app()->user->userModel;
136  $conversation->subject = 'Test People On Conversation';
137  $conversation->description = 'This is a test conversation';
138  $people = ConversationsUtil::
139  resolvePeopleOnConversation($conversation);
140  $this->assertEquals(1, count($people));
141  $conversationParticipant = new ConversationParticipant();
142  $conversationParticipant->person = $jack;
143  $conversation->conversationParticipants->add($conversationParticipant);
144  $people = ConversationsUtil::
145  resolvePeopleOnConversation($conversation);
146  $this->assertEquals(2, count($people));
147  $conversationParticipant = new ConversationParticipant();
148  $conversationParticipant->person = $steven;
149  $conversation->conversationParticipants->add($conversationParticipant);
150  $people = ConversationsUtil::
151  resolvePeopleOnConversation($conversation);
152  $this->assertEquals(3, count($people));
153  $this->assertTrue($conversation->save());
154  }
155 
160  {
161  $super = Yii::app()->user->userModel;
162  $jack = User::getByUsername('jack');
163  $steven = User::getByUsername('steven');
164  $conversation = new Conversation();
165  $conversation->owner = Yii::app()->user->userModel;
166  $conversation->subject = 'Test People To Send Notification';
167  $conversation->description = 'This is a test conversation';
168  $peopleToSendNotification = ConversationsUtil::
170  $this->assertEquals(0, count($peopleToSendNotification));
171  $conversationParticipant = new ConversationParticipant();
172  $conversationParticipant->person = $jack;
173  $conversation->conversationParticipants->add($conversationParticipant);
174  $peopleToSendNotification = ConversationsUtil::
176  $this->assertEquals(1, count($peopleToSendNotification));
177  $this->assertEquals($jack, $peopleToSendNotification[0]);
178  }
179  }
180 ?>
static makeBySecurableItem(SecurableItem $securableItem)
static markUserHasReadLatest(Conversation $conversation, User $user, $hasReadLatest=true)
static getByUsername($username)
Definition: User.php:49
static resolveExplicitReadWriteModelPermissions(SecurableItem $securableItem, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions, $validate=false)
static resolvePeopleOnConversation(Conversation $conversation)
static resolveConversationHasManyParticipantsFromPost(Conversation $conversation, $postData, $explicitReadWriteModelPermissions)
static resolvePeopleToSendNotificationToOnNewComment(Conversation $conversation, User $user)
static getById($id, $modelClassName=null)
Generated on Tue Apr 7 2020 07:10:41