Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MashableInboxUserWalkthroughTest.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  private $modelsWithMashableInboxInterface;
40 
41  public function setup()
42  {
43  parent::setUp();
44  SecurityTestHelper::createSuperAdmin();
45  $super = User::getByUsername('super');
46  Yii::app()->user->userModel = $super;
47  $this->modelsWithMashableInboxInterface =
48  array_keys(MashableUtil::getModelDataForCurrentUserByInterfaceName('MashableInboxInterface'));
49  }
50 
51  public function testListActionRenderListViewsForMashableInboxAndModels()
52  {
53  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
54  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default');
55  $this->assertContains('MashableInboxListView', $content);
56  $this->assertContains('list-view-markRead', $content);
57  $this->assertContains('list-view-markUnread', $content);
58  foreach ($this->modelsWithMashableInboxInterface as $modelClassName)
59  {
60  $this->setGetArray(array('modelClassName' => $modelClassName));
61  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
62  $mashableRules = MashableUtil::createMashableInboxRulesByModel($modelClassName);
63  if ($mashableRules->getZeroModelViewClassName() !== null)
64  {
65  $this->assertContains($mashableRules->getZeroModelViewClassName(), $content);
66  }
67  else
68  {
69  $this->assertContains($mashableRules->getListViewClassName(), $content);
70  $this->assertContains('list-view-markRead', $content);
71  $this->assertContains('list-view-markUnread', $content);
72  foreach (array_keys($mashableRules->getMassOptions()) as $massAction)
73  {
74  $this->assertContains('list-view-' . $massAction, $content);
75  }
76  }
77  }
78  }
79 
80  public function testMarkReadUnreadMassAction()
81  {
82  $super = User::getByUsername('super');
83  $conversation = new Conversation();
84  $conversation->owner = $super;
85  $conversation->subject = 'My test conversation subject';
86  $conversation->description = 'My test conversation description';
87  $this->assertTrue($conversation->save());
88  $conversationId = $conversation->id;
89  $mission = new Mission();
90  $mission->owner = $super;
91  $mission->description = 'My test mission description';
92  $mission->status = Mission::STATUS_AVAILABLE;
93  $this->assertTrue($mission->save());
94  $missionId = $mission->id;
95  $this->assertTrue((bool)ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
96  $this->assertTrue((bool)MissionsUtil::hasUserReadMissionLatest($mission, $super));
97 
98  //Mark conversation and mission as unread
99  $selectedIds = get_class($conversation) . '_' . $conversationId;
100  $selectedIds .= ',' . get_class($mission) . '_' . $missionId; // Not Coding Standard
101  $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
102  $this->setGetArray(
103  array(
104  'ajax' => 'list-view',
105  'MashableInboxForm' => array(
106  'massAction' => 'markUnread',
107  'selectedIds' => $selectedIds,
108  )
109  )
110  );
111  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
112  $conversation = Conversation::getById($conversationId);
113  $this->assertFalse((bool)ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
114  $mission = Mission::getById($missionId);
115  $this->assertFalse((bool)MissionsUtil::hasUserReadMissionLatest($mission, $super));
116 
117  //Mark conversation and mission as read
118  $this->setGetArray(
119  array(
120  'ajax' => 'list-view',
121  'MashableInboxForm' => array(
122  'massAction' => 'markRead',
123  'selectedIds' => $selectedIds,
124  )
125  )
126  );
127  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
128  $conversation = Conversation::getById($conversationId);
129  $this->assertTrue((bool)ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
130  $mission = Mission::getById($missionId);
131  $this->assertTrue((bool)MissionsUtil::hasUserReadMissionLatest($mission, $super));
132 
133  //Mark conversation as unread
134  $selectedIds = get_class($conversation) . '_' . $conversationId;
135  $this->setGetArray(
136  array(
137  'ajax' => 'list-view',
138  'MashableInboxForm' => array(
139  'massAction' => 'markUnread',
140  'selectedIds' => $selectedIds,
141  )
142  )
143  );
144  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
145  $conversation = Conversation::getById($conversationId);
146  $this->assertFalse((bool)ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
147  $mission = Mission::getById($missionId);
148  $this->assertTrue((bool)MissionsUtil::hasUserReadMissionLatest($mission, $super));
149  }
150 
151  public function testMarkReadUnreadMassActionByModel()
152  {
153  $super = User::getByUsername('super');
154 
155  //Conversation model
156  $conversation = new Conversation();
157  $conversation->owner = $super;
158  $conversation->subject = 'My test conversation subject';
159  $conversation->description = 'My test conversation description';
160  $this->assertTrue($conversation->save());
161  $conversationId = $conversation->id;
162  $this->assertTrue((bool)ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
163 
164  //Mark conversation as unread
165  $selectedIds = $conversationId;
166  $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
167  $this->setGetArray(
168  array(
169  'ajax' => 'list-view',
170  'modelClassName' => 'Conversation',
171  'MashableInboxForm' => array(
172  'massAction' => 'markUnread',
173  'selectedIds' => $selectedIds,
174  )
175  )
176  );
177  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
178  $conversation = Conversation::getById($conversationId);
179  $this->assertFalse((bool)ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
180 
181  //Mark conversation as read
182  $this->setGetArray(
183  array(
184  'ajax' => 'list-view',
185  'modelClassName' => 'Conversation',
186  'MashableInboxForm' => array(
187  'massAction' => 'markRead',
188  'selectedIds' => $selectedIds,
189  )
190  )
191  );
192  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
193  $conversation = Conversation::getById($conversationId);
194  $this->assertTrue((bool)ConversationsUtil::hasUserReadConversationLatest($conversation, $super));
195 
196  //Mission model
197  $mission = new Mission();
198  $mission->owner = $super;
199  $mission->description = 'My test mission description';
200  $mission->status = Mission::STATUS_AVAILABLE;
201  $this->assertTrue($mission->save());
202  $missionId = $mission->id;
203  $this->assertTrue((bool)MissionsUtil::hasUserReadMissionLatest($mission, $super));
204 
205  //Mark mission as unread
206  $selectedIds = $missionId;
207  $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
208  $this->setGetArray(
209  array(
210  'ajax' => 'list-view',
211  'modelClassName' => 'Mission',
212  'MashableInboxForm' => array(
213  'massAction' => 'markUnread',
214  'selectedIds' => $selectedIds,
215  )
216  )
217  );
218  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
219  $mission = Mission::getById($missionId);
220  $this->assertFalse((bool)MissionsUtil::hasUserReadMissionLatest($mission, $super));
221 
222  //Mark mission as read
223  $this->setGetArray(
224  array(
225  'ajax' => 'list-view',
226  'modelClassName' => 'Mission',
227  'MashableInboxForm' => array(
228  'massAction' => 'markRead',
229  'selectedIds' => $selectedIds,
230  )
231  )
232  );
233  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
234  $mission = Mission::getById($missionId);
235  $this->assertTrue((bool)MissionsUtil::hasUserReadMissionLatest($mission, $super));
236  }
237 
238  public function testModuleSecurityAccess()
239  {
240  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
241  $nobody = UserTestHelper::createBasicUser('nobody');
242  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
243  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default');
244  foreach ($this->modelsWithMashableInboxInterface as $modelClassName)
245  {
246  $this->setGetArray(array('modelClassName' => $modelClassName));
247  $moduleClassName = $modelClassName::getModuleClassName();
248  if (is_subclass_of($moduleClassName, 'SecurableModule'))
249  {
250  $this->runControllerShouldResultInAccessFailureAndGetContent('mashableInbox/default/list');
251  }
252  else
253  {
254  $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
255  }
256  $mashableRules = MashableUtil::createMashableInboxRulesByModel($modelClassName);
257  }
258  }
259 
260  public function testSaveStickyOption()
261  {
262  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
263  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
264  $this->assertContains('value="all" checked="checked"', $content);
265  $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
266  $this->setGetArray(
267  array(
268  'ajax' => 'list-view',
269  'MashableInboxForm' => array(
270  'filteredBy' => 'unread',
271  )
272  )
273  );
274  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
275  $this->resetGetArray();
276  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
277  $this->assertContains('value="unread" checked="checked"', $content);
278  }
279  }
280 ?>
static getByUsername($username)
Definition: User.php:49
static getModelDataForCurrentUserByInterfaceName($interfaceClassName, $includeHavingRelatedItems=true)
static hasUserReadMissionLatest(Mission $mission, User $user)
static createMashableInboxRulesByModel($modelClassName)
static getById($id, $modelClassName=null)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static hasUserReadConversationLatest(Conversation $conversation, User $user)
Generated on Sat Jul 4 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.