All Data Structures Functions Variables Pages
ConversationsUserWalkthroughTest.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 
42  {
43  public static function setUpBeforeClass()
44  {
45  parent::setUpBeforeClass();
46  SecurityTestHelper::createSuperAdmin();
47  $super = User::getByUsername('super');
48  Yii::app()->user->userModel = $super;
50 
51  //Setup test data owned by the super user.
52  AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
53 
54  //Create test users
55  $steven = UserTestHelper::createBasicUser('steven');
56  $steven->primaryEmail->emailAddress = 'steven@testzurmo.com';
57  $sally = UserTestHelper::createBasicUser('sally');
58  $sally->primaryEmail->emailAddress = 'sally@testzurmo.com';
59  $mary = UserTestHelper::createBasicUser('mary');
60  $mary->primaryEmail->emailAddress = 'mary@testzurmo.com';
61 
62  //give 3 users access, create, delete for conversation rights.
63  $steven->setRight('ConversationsModule', ConversationsModule::RIGHT_ACCESS_CONVERSATIONS);
64  $steven->setRight('ConversationsModule', ConversationsModule::RIGHT_CREATE_CONVERSATIONS);
65  $steven->setRight('ConversationsModule', ConversationsModule::RIGHT_DELETE_CONVERSATIONS);
66  $saved = $steven->save();
67  if (!$saved)
68  {
69  throw new NotSupportedException();
70  }
71  $sally->setRight('ConversationsModule', ConversationsModule::RIGHT_ACCESS_CONVERSATIONS);
72  $sally->setRight('ConversationsModule', ConversationsModule::RIGHT_CREATE_CONVERSATIONS);
73  $sally->setRight('ConversationsModule', ConversationsModule::RIGHT_DELETE_CONVERSATIONS);
74  $saved = $sally->save();
75  if (!$saved)
76  {
77  throw new NotSupportedException();
78  }
79  $mary->setRight('ConversationsModule', ConversationsModule::RIGHT_ACCESS_CONVERSATIONS);
80  $mary->setRight('ConversationsModule', ConversationsModule::RIGHT_CREATE_CONVERSATIONS);
81  $mary->setRight('ConversationsModule', ConversationsModule::RIGHT_DELETE_CONVERSATIONS);
82  $saved = $mary->save();
83  if (!$saved)
84  {
85  throw new NotSupportedException();
86  }
87  }
88 
89  public function testSuperUserAllSimpleControllerActions()
90  {
91  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
92 
93  //Test all default controller actions that do not require any POST/GET variables to be passed.
94  //This does not include portlet controller actions.
95  $this->runControllerWithNoExceptionsAndGetContent('conversations/default');
96  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/index');
97  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/list');
98  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/create');
99  }
100 
105  {
106  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
107  $mary = User::getByUsername('mary');
108  $accounts = Account::getByName('superAccount');
109  $superAccountId = $accounts[0]->id;
110 
111  //Confirm no email notifications are sitting in the queue
112  $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
113  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
114 
115  //Test creating conversation via POST, invite Mary
116  $conversations = Conversation::getAll();
117  $this->assertEquals(0, count($conversations));
118  $itemPostData = array('Account' => array('id' => $superAccountId));
119  $this->setPostArray(array('ConversationParticipantsForm' => array('itemIds' => $mary->getClassId('Item')),
120  'ConversationItemForm' => $itemPostData,
121  'Conversation' => array('subject' => 'TestSubject',
122  'description' => 'TestDescription')));
123  $this->runControllerWithRedirectExceptionAndGetContent('conversations/default/create');
124 
125  //Confirm conversation saved.
126  $conversations = Conversation::getAll();
127  $this->assertEquals(1, count($conversations));
128  //Confirm conversation is connected to the related account.
129  $this->assertEquals(1, $conversations[0]->conversationItems->count());
130  $this->assertEquals($accounts[0], $conversations[0]->conversationItems->offsetGet(0));
131 
132  //Confirm Mary is invited.
133  $this->assertEquals(1, $conversations[0]->conversationParticipants->count());
134  $this->assertEquals($mary, $conversations[0]->conversationParticipants->offsetGet(0)->person);
135  $this->assertEquals(0, $conversations[0]->conversationParticipants->offsetGet(0)->hasReadLatest);
136 
137  //Confirm Mary got the email invite and it was correctly setup with a valid conversation id
138  $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
139  $this->assertEquals(1, count($emailMessages));
140  $this->assertNotContains('conversations/default/details?id=' . $conversations[0]->id . '">',
141  $emailMessages[0]->content->textContent);
142 
143  //Confirm Mary is the only one with explicit permissions on the conversation
144  $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
145  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
146  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
147  makeBySecurableItem($conversations[0]);
148  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
149  $this->assertEquals(1, count($readWritePermitables));
150  $this->assertTrue(isset($readWritePermitables[$mary->getClassId('Permitable')]));
151  }
152 
157  {
158  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
159  $steven = User::getByUsername('steven');
160  $sally = User::getByUsername('sally');
161  $mary = User::getByUsername('mary');
162  $conversations = Conversation::getAll();
163  $this->assertEquals(1, count($conversations));
164  $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
165  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
166 
167  //Test inviting steven and sally (via detailview)
168  $this->setGetArray(array('id' => $conversations[0]->id));
169  $this->setPostArray(array('ConversationParticipantsForm' => array('itemIds' => $mary->getClassId('Item') . ',' . // Not Coding Standard
170  $steven->getClassId('Item') . ',' . // Not Coding Standard
171  $sally->getClassId('Item'))));
172  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/updateParticipants', true);
173  $this->assertEquals(3, Yii::app()->emailHelper->getQueuedCount());
174  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
175 
176  //should be 2 explicits read/write
177  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
178  makeBySecurableItem($conversations[0]);
179  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
180  $this->assertEquals(3, count($readWritePermitables));
181 
182  //Uninvite mary (via detailview)
183  $this->setGetArray(array('id' => $conversations[0]->id));
184  $this->setPostArray(array('ConversationParticipantsForm' => array('itemIds' => $steven->getClassId('Item') . ',' . // Not Coding Standard
185  $sally->getClassId('Item'))));
186  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/updateParticipants', true);
187  $this->assertEquals(3, Yii::app()->emailHelper->getQueuedCount());
188  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
189  //should be 2 explicits read/write
190  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
191  makeBySecurableItem($conversations[0]);
192  $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
193  $this->assertEquals(2, count($readWritePermitables));
194  }
195 
200  {
201  if (!SECURITY_OPTIMIZED) //bug prevents this from running correctly
202  {
203  return;
204  }
205  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
206  $steven = User::getByUsername('steven');
207  $sally = User::getByUsername('sally');
208  $mary = User::getByUsername('mary');
209  $conversations = Conversation::getAll();
210  $this->assertEquals(1, count($conversations));
211  $this->assertEquals(0, $conversations[0]->comments->count());
212  $this->assertEquals(3, Yii::app()->emailHelper->getQueuedCount());
213  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
214  $oldStamp = $conversations[0]->latestDateTime;
215 
216  //Validate comment
217  $this->setGetArray(array('relatedModelId' => $conversations[0]->id,
218  'relatedModelClassName' => 'Conversation',
219  'relatedModelRelationName' => 'comments',
220  'redirectUrl' => 'someRedirect'));
221  $this->setPostArray(array('ajax' => 'comment-inline-edit-form',
222  'Comment' => array('description' => 'a ValidComment Name')));
223 
224  $content = $this->runControllerWithExitExceptionAndGetContent('comments/default/inlineCreateSave');
225  $this->assertEquals('[]', $content);
226 
227  //Now save that comment.
228  $this->setGetArray(array('relatedModelId' => $conversations[0]->id,
229  'relatedModelClassName' => 'Conversation',
230  'relatedModelRelationName' => 'comments',
231  'redirectUrl' => 'someRedirect'));
232  $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name')));
233  $content = $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave');
234  $id = $conversations[0]->id;
235  $conversations[0]->forget();
236  $conversation = Conversation::getById($id);
237  $this->assertEquals(1, $conversation->comments->count());
238 
239  //should update latest activity stamp
240  $this->assertNotEquals($oldStamp, $conversations[0]->latestDateTime);
241  $newStamp = $conversations[0]->latestDateTime;
242  sleep(2); // Sleeps are bad in tests, but I need some time to pass
243  //Mary is not a participant, so she should not be able to add a comment
244  $mary = $this->logoutCurrentUserLoginNewUserAndGetByUsername('mary');
245  $this->setGetArray(array('relatedModelId' => $conversations[0]->id,
246  'relatedModelClassName' => 'Conversation',
247  'relatedModelRelationName' => 'comments',
248  'redirectUrl' => 'someRedirect'));
249  $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name 2')));
250  $content = $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('comments/default/inlineCreateSave');
251 
252  //Add mary as a participant.
253  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
254  $this->setGetArray(array('id' => $conversations[0]->id));
255  $this->setPostArray(array('ConversationParticipantsForm' => array('itemIds' => $mary->getClassId('Item'))));
256  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/updateParticipants', true);
257 
258  //Mary can add comment ok
259  $mary = $this->logoutCurrentUserLoginNewUserAndGetByUsername('mary');
260  $this->setGetArray(array('relatedModelId' => $conversations[0]->id,
261  'relatedModelClassName' => 'Conversation',
262  'relatedModelRelationName' => 'comments',
263  'redirectUrl' => 'someRedirect'));
264  $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name 2')));
265  $content = $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave');
266  $id = $conversations[0]->id;
267  $conversations[0]->forget();
268  $conversation = Conversation::getById($id);
269  $this->assertEquals(2, $conversation->comments->count());
270  $this->assertNotEquals($newStamp, $conversation->latestDateTime);
271 
272  //Remove mary as a participant. should get redirect content
273  $this->setGetArray(array('id' => $conversations[0]->id));
274  $this->setPostArray(array('ConversationParticipantsForm' => array('itemIds' => '')));
275  $content = $this->runControllerWithNoExceptionsAndGetContent('conversations/default/updateParticipants');
276  $this->assertEquals('redirectToList', $content);
277  }
278 
283  {
284  if (!SECURITY_OPTIMIZED) //bug prevents this from running correctly
285  {
286  return;
287  }
288  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
289  $mary = User::getByUsername('mary');
290  $conversations = Conversation::getAll();
291  $this->assertEquals(1, count($conversations));
292  $this->assertEquals(2, $conversations[0]->comments->count());
293 
294  //Add mary back as a participant.
295  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
296  $this->setGetArray(array('id' => $conversations[0]->id));
297  $this->setPostArray(array('ConversationParticipantsForm' => array('itemIds' => $mary->getClassId('Item'))));
298  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/updateParticipants', true);
299 
300  //new test - mary, as a participant can edit the conversation
301  $mary = $this->logoutCurrentUserLoginNewUserAndGetByUsername('mary');
302  $this->setGetArray(array('id' => $conversations[0]->id));
303  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/edit');
304 
305  //new test - mary can delete a comment she wrote
306  $maryCommentId = $conversations[0]->comments->offsetGet(1)->id;
307  $this->assertEquals($conversations[0]->comments->offsetGet(1)->createdByUser->id, $mary->id);
308  $superCommentId = $conversations[0]->comments->offsetGet(0)->id;
309  $this->assertEquals($conversations[0]->comments->offsetGet(0)->createdByUser->id, $super->id);
310  $this->setGetArray(array('relatedModelId' => $conversations[0]->id,
311  'relatedModelClassName' => 'Conversation',
312  'relatedModelRelationName' => 'comments',
313  'id' => $maryCommentId));
314  $this->runControllerWithNoExceptionsAndGetContent('comments/default/deleteViaAjax', true);
315  $conversationId = $conversations[0]->id;
316  $conversations[0]->forget();
317  $conversation = Conversation::getById($conversationId);
318  $this->assertEquals(1, $conversation->comments->count());
319 
320  //new test - mary cannot delete a comment she did not write.
321  $this->setGetArray(array('relatedModelId' => $conversations[0]->id,
322  'relatedModelClassName' => 'Conversation',
323  'relatedModelRelationName' => 'comments',
324  'id' => $superCommentId));
325  $this->runControllerShouldResultInAjaxAccessFailureAndGetContent('comments/default/deleteViaAjax');
326  $conversationId = $conversations[0]->id;
327  $conversations[0]->forget();
328  $conversation = Conversation::getById($conversationId);
329  $this->assertEquals(1, $conversation->comments->count());
330  $this->assertEquals(1, $conversation->comments->count());
331 
332  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
333  //new test , super can view and edit the conversation
334  $this->setGetArray(array('id' => $conversation->id));
335  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/details');
336  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/edit');
337 
338  //new test , super can delete the conversation
339  $this->setGetArray(array('id' => $conversation->id));
340  $this->runControllerWithRedirectExceptionAndGetContent('conversations/default/delete');
341 
342  $conversations = Conversation::getAll();
343  $this->assertEquals(0, count($conversations));
344  }
345 
350  {
351  if (!SECURITY_OPTIMIZED) //bug prevents this from running correctly
352  {
353  return;
354  }
355  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
356  $accounts = Account::getByName('superAccount');
357  $superAccountId = $accounts[0]->id;
358 
359  //Load Details view to generate the portlets.
360  $this->setGetArray(array('id' => $superAccountId));
361  $this->resetPostArray();
362  $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
363 
364  //Find the LatestActivity portlet.
365  $portletToUse = null;
366  $portlets = Portlet::getAll();
367  foreach ($portlets as $portlet)
368  {
369  if ($portlet->viewType == 'AccountLatestActivitiesForPortlet')
370  {
371  $portletToUse = $portlet;
372  break;
373  }
374  }
375  $this->assertNotNull($portletToUse);
376  $this->assertEquals('AccountLatestActivitiesForPortletView', get_class($portletToUse->getView()));
377 
378  //Load the portlet details for latest activity
379  $getData = array('id' => $superAccountId,
380  'portletId' => $portletToUse->id,
381  'uniqueLayoutId' => 'AccountDetailsAndRelationsView_2',
382  'LatestActivitiesConfigurationForm' => array(
383  'filteredByModelName' => 'all',
384  'rollup' => false
385  ));
386  $this->setGetArray($getData);
387  $this->resetPostArray();
388  $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
389 
390  //Now add roll up
391  $getData['LatestActivitiesConfigurationForm']['rollup'] = true;
392  $this->setGetArray($getData);
393  $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
394  //Now filter by conversation
395  $getData['LatestActivitiesConfigurationForm']['filteredByModelName'] = 'Conversation';
396  $this->setGetArray($getData);
397  $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
398 
399  //Now do the same thing with filtering but turn off rollup.
400  $getData['LatestActivitiesConfigurationForm']['rollup'] = true;
401  $getData['LatestActivitiesConfigurationForm']['filteredByModelName'] = 'Conversation';
402  $this->setGetArray($getData);
403  $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
404  }
405 
409  public function testListViewFiltering()
410  {
411  if (!SECURITY_OPTIMIZED) //bug prevents this from running correctly
412  {
413  return;
414  }
415  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
416  $content = $this->runControllerWithNoExceptionsAndGetContent('conversations/default/list');
417  $this->assertContains('Conversations', $content);
418  $this->setGetArray(array(
419  'type' => ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CREATED));
420  $content = $this->runControllerWithNoExceptionsAndGetContent('conversations/default/list');
421  $this->assertContains('Conversations', $content);
422  $this->setGetArray(array(
423  'type' => ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_PARTICIPANT));
424  $content = $this->runControllerWithNoExceptionsAndGetContent('conversations/default/list');
425  $this->assertContains('Conversations', $content);
426  $this->setGetArray(array(
427  'type' => ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CLOSED));
428  $content = $this->runControllerWithNoExceptionsAndGetContent('conversations/default/list');
429  $this->assertContains('Conversations', $content);
430  }
431 
435  public function testCreateFromModel()
436  {
437  if (!SECURITY_OPTIMIZED) //bug prevents this from running correctly
438  {
439  return;
440  }
441  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
442  $accounts = Account::getByName('superAccount');
443  $superAccountId = $accounts[0]->id;
444 
445  $conversations = Conversation::getAll();
446  $this->assertEquals(0, count($conversations));
447 
448  //First just go to the createFromRelation action. Make sure it comes up right
449  $this->setGetArray(array( 'relationAttributeName' => 'notUsed',
450  'relationModelClassName' => 'Account',
451  'relationModelId' => $superAccountId,
452  'relationModuleId' => 'accounts',
453  'redirectUrl' => 'someRedirection'));
454  $this->resetPostArray();
455  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/createFromRelation');
456 
457  //add related note for account using createFromRelation action
458  $conversationItemPostData = array('account' => array('id' => $accounts[0]->id));
459  $this->setGetArray(array( 'relationAttributeName' => 'notUsed',
460  'relationModelClassName' => 'Account',
461  'relationModelId' => $superAccountId,
462  'relationModuleId' => 'accounts',
463  'redirectUrl' => 'someRedirection'));
464  $this->setPostArray(array('ConversationItemForm' => $conversationItemPostData,
465  'Conversation' => array('subject' => 'Conversation Subject', 'description' => 'A description')));
466  $this->runControllerWithRedirectExceptionAndGetContent('conversations/default/createFromRelation');
467 
468  $conversations = Conversation::getAll();
469  $this->assertEquals(1, count($conversations));
470  $this->assertEquals(1, $conversations[0]->conversationItems->count());
471  $this->assertEquals($accounts[0]->getClassId('Item'), $conversations[0]->conversationItems->offsetGet(0)->getClassId('Item'));
472  }
473 
478  {
479  if (!SECURITY_OPTIMIZED) //bug prevents this from running correctly
480  {
481  return;
482  }
483  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
484  $conversations = Conversation::getAll();
485  $this->assertEquals(1, count($conversations));
486  $this->setGetArray(array('relatedModelId' => $conversations[0]->id, 'relatedModelClassName' => 'Conversation',
487  'relatedModelRelationName' => 'comments'));
488  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
489  $content = $this->runControllerWithNoExceptionsAndGetContent('comments/default/ajaxListForRelatedModel');
490  }
491 
495  public function testClosingConversations()
496  {
497  if (!SECURITY_OPTIMIZED) //bug prevents this from running correctly
498  {
499  return;
500  }
501  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
502  $conversation = new Conversation();
503  $conversation->owner = $super;
504  $conversation->subject = "Test closed";
505  $conversation->description = "This is just to make the isClosed column in conversations table";
506  $conversation->save();
507  $conversations = Conversation::getAll();
508  $this->assertEquals(2, count($conversations));
509  $this->assertEquals($super->id, $conversations[0]->owner->id);
510  //Conversation is opened
511  $this->assertEquals(0, $conversations[0]->resolveIsClosedForNull());
512  $this->setGetArray(array('id' => $conversations[0]->id));
513  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/changeIsClosed');
514  //Conversation is closed
515  $this->assertEquals(1, $conversations[0]->resolveIsClosedForNull());
516  $this->setGetArray(array('id' => $conversations[0]->id));
517  $this->runControllerWithNoExceptionsAndGetContent('conversations/default/changeIsClosed');
518  //Conversation is Re-opened
519  $this->assertEquals(0, $conversations[0]->resolveIsClosedForNull());
520  }
521 
525  public function testSendEmailInNewComment()
526  {
527  if (!SECURITY_OPTIMIZED) //bug prevents this from running correctly
528  {
529  return;
530  }
531  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
532  $steven = User::getByUsername('steven');
533  $sally = User::getByUsername('sally');
534  $mary = User::getByUsername('mary');
535  $conversations = Conversation::getAll();
536  $this->assertEquals(2, count($conversations));
537  $this->assertEquals(0, $conversations[0]->comments->count());
538  foreach (EmailMessage::getAll() as $emailMessage)
539  {
540  $emailMessage->delete();
541  }
542  $initialQueued = 0;
543  $conversation = $conversations[0];
544  $conversationParticipant = new ConversationParticipant();
545  $conversationParticipant->person = $steven;
546  $conversation->conversationParticipants->add($conversationParticipant);
547  $conversationParticipant = new ConversationParticipant();
548  $conversationParticipant->person = $sally;
549  $conversation->conversationParticipants->add($conversationParticipant);
550  $conversationParticipant = new ConversationParticipant();
551  $conversationParticipant->person = $mary;
552  $conversation->conversationParticipants->add($conversationParticipant);
553  $inboxAndEmailNotificationSettings = UserTestHelper::getDefaultNotificationSettingsValuesForTestUser();
554  $inboxAndEmailNotificationSettings['enableConversationCommentNotification'] = array(
555  'inbox' => false,
556  'email' => false
557  );
558  UserNotificationUtil::
559  setValue($mary, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false);
560  //Save a new comment
561  $this->setGetArray(array('relatedModelId' => $conversation->id,
562  'relatedModelClassName' => 'Conversation',
563  'relatedModelRelationName' => 'comments',
564  'redirectUrl' => 'someRedirect'));
565  $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name')));
566  $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave');
567  $this->assertEquals(1, $conversation->comments->count());
568  $this->assertEquals($initialQueued + 2, Yii::app()->emailHelper->getQueuedCount());
569  $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
570  $emailMessages = EmailMessage::getAll();
571  $emailMessage = $emailMessages[$initialQueued];
572  $this->assertEquals(1, count($emailMessage->recipients));
573  $emailMessage = $emailMessages[$initialQueued + 1];
574  $this->assertEquals(1, count($emailMessage->recipients));
575  $this->assertContains('conversation', $emailMessage->subject);
576  $this->assertContains(strval($conversation), $emailMessage->subject);
577  $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->htmlContent);
578  $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->textContent);
579  }
580  }
581 ?>
static makeBySecurableItem(SecurableItem $securableItem)
static getDefaultNotificationSettingsValuesForTestUser()
static rebuild($overwriteExistingTables=true, $forcePhp=false, $messageStreamer=null)
static getByUsername($username)
Definition: User.php:49
runControllerWithRedirectExceptionAndGetContent($route, $compareUrl=null, $compareUrlContains=false)
runControllerWithAccessDeniedSecurityExceptionAndGetContent($route)
static getById($id, $modelClassName=null)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Thu Jun 4 2020 07:10:30