Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ConversationsMashableInboxRulesTest.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 $rules;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  SecurityTestHelper::createSuperAdmin();
45  Yii::app()->user->userModel = User::getByUsername('super');
47  $steven = UserTestHelper::createBasicUser('steven');
48  //Give user access, create, delete for conversation rights.
49  $steven->setRight('ConversationsModule', ConversationsModule::RIGHT_ACCESS_CONVERSATIONS);
50  $steven->setRight('ConversationsModule', ConversationsModule::RIGHT_CREATE_CONVERSATIONS);
51  $steven->setRight('ConversationsModule', ConversationsModule::RIGHT_DELETE_CONVERSATIONS);
52  $steven->save();
53  }
54 
55  public function setUp()
56  {
57  parent::setUp();
58  $this->rules = new ConversationMashableInboxRules();
59  }
60 
61  public function testListActionRenderListViewsForConversation()
62  {
63  $this->setGetArray(array('modelClassName' => 'Conversation'));
64  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
65  $steven = User::getByUsername('steven');
66  $this->createAndSaveNewConversationForUser($super, $steven);
67  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
68  $this->assertContains($this->rules->getListViewClassName(), $content);
69  $this->assertContains('list-view-markRead', $content);
70  $this->assertContains('list-view-markUnread', $content);
71  $this->assertContains('list-view-closeSelected', $content);
72  }
73 
74  public function testReadUnread()
75  {
76  $super = User::getByUsername('super');
77  $steven = User::getByUsername('steven');
78  Yii::app()->user->userModel = $super;
79  $createdConversation = $this->createAndSaveNewConversationForUser($super, $steven);
80  $this->assertTrue((bool)$createdConversation->ownerHasReadLatest);
81  $this->assertTrue((bool)$this->rules->hasCurrentUserReadLatest($createdConversation->id));
82  $this->rules->resolveMarkUnread($createdConversation->id);
83  $savedConversation = Conversation::getById($createdConversation->id);
84  $this->assertFalse((bool)$savedConversation->ownerHasReadLatest);
85  $this->assertFalse((bool)$this->rules->hasCurrentUserReadLatest($createdConversation->id));
86  $this->rules->resolveMarkRead($createdConversation->id);
87  $savedConversation = Conversation::getById($createdConversation->id);
88  $this->assertTrue((bool)$savedConversation->ownerHasReadLatest);
89  $this->assertTrue((bool)$this->rules->hasCurrentUserReadLatest($createdConversation->id));
90  }
91 
92  public function testResolveCloseSelected()
93  {
94  $super = User::getByUsername('super');
95  $steven = User::getByUsername('steven');
96  Yii::app()->user->userModel = $super;
97  $createdConversation = $this->createAndSaveNewConversationForUser($super, $steven);
98  $this->rules->resolveCloseSelected($createdConversation->id);
99  $conversation = Conversation::getById($createdConversation->id);
100  $this->assertTrue((bool)$conversation->isClosed);
101  }
102 
103  protected function createAndSaveNewConversationForUser(User $owner, User $participant)
104  {
105  foreach (Conversation::getAll() as $conversation)
106  {
107  $conversation->delete();
108  }
109  $conversation = new Conversation();
110  $conversation->owner = $owner;
111  $conversation->subject = 'My test conversation subject';
112  $conversation->description = 'My test conversation description';
113  $conversationParticipant = new ConversationParticipant();
114  $conversationParticipant->person = $participant;
115  $conversation->conversationParticipants->add($conversationParticipant);
116  $this->assertTrue($conversation->save());
117  return $conversation;
118  }
119 
120  protected function resolveControlerActionListAndGetContent($filteredBy, $optionForModel)
121  {
122  $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
123  $this->setGetArray(
124  array(
125  'modelClassName' => 'Conversation',
126  'ajax' => 'list-view',
127  'MashableInboxForm' => array(
128  'filteredBy' => $filteredBy,
129  'optionForModel' => $optionForModel
130  )
131  )
132  );
133  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
134  return $content;
135  }
136 
137  public function testFilters()
138  {
139  $steven = User::getByUsername('steven');
140  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
141  $conversation = $this->createAndSaveNewConversationForUser($super, $steven);
142  $content = $this->resolveControlerActionListAndGetContent(
143  MashableInboxForm::FILTERED_BY_ALL,
144  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CREATED);
145  $this->assertContains($conversation->subject, $content);
146  $this->assertContains('1 result(s)', $content);
147  $content = $this->resolveControlerActionListAndGetContent(
148  MashableInboxForm::FILTERED_BY_UNREAD,
149  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CREATED);
150  $this->assertNotContains($conversation->subject, $content);
151  $this->assertNotContains('result(s)', $content);
152  $content = $this->resolveControlerActionListAndGetContent(
153  MashableInboxForm::FILTERED_BY_ALL,
154  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_PARTICIPANT);
155  $this->assertContains($conversation->subject, $content);
156  $this->assertContains('1 result(s)', $content);
157  $content = $this->resolveControlerActionListAndGetContent(
158  MashableInboxForm::FILTERED_BY_UNREAD,
159  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_PARTICIPANT);
160  $this->assertNotContains($conversation->subject, $content);
161  $this->assertNotContains('result(s)', $content);
162  $content = $this->resolveControlerActionListAndGetContent(
163  MashableInboxForm::FILTERED_BY_ALL,
164  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CLOSED);
165  $this->assertNotContains($conversation->subject, $content);
166  $this->assertNotContains('result(s)', $content);
167  $content = $this->resolveControlerActionListAndGetContent(
168  MashableInboxForm::FILTERED_BY_UNREAD,
169  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CLOSED);
170  $this->assertNotContains($conversation->subject, $content);
171  $this->assertNotContains('result(s)', $content);
172 
173  //Testing with closed conversation
174  $conversation->isClosed = true;
175  $conversation->save();
176  $content = $this->resolveControlerActionListAndGetContent(
177  MashableInboxForm::FILTERED_BY_ALL,
178  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CREATED);
179  $this->assertNotContains($conversation->subject, $content);
180  $this->assertNotContains('result(s)', $content);
181  $content = $this->resolveControlerActionListAndGetContent(
182  MashableInboxForm::FILTERED_BY_UNREAD,
183  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CREATED);
184  $this->assertNotContains($conversation->subject, $content);
185  $this->assertNotContains('result(s)', $content);
186  $content = $this->resolveControlerActionListAndGetContent(
187  MashableInboxForm::FILTERED_BY_ALL,
188  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_PARTICIPANT);
189  $this->assertNotContains($conversation->subject, $content);
190  $this->assertNotContains('result(s)', $content);
191  $content = $this->resolveControlerActionListAndGetContent(
192  MashableInboxForm::FILTERED_BY_UNREAD,
193  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_PARTICIPANT);
194  $this->assertNotContains($conversation->subject, $content);
195  $this->assertNotContains('result(s)', $content);
196  $content = $this->resolveControlerActionListAndGetContent(
197  MashableInboxForm::FILTERED_BY_ALL,
198  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CLOSED);
199  $this->assertContains($conversation->subject, $content);
200  $this->assertContains('1 result(s)', $content);
201  $content = $this->resolveControlerActionListAndGetContent(
202  MashableInboxForm::FILTERED_BY_UNREAD,
203  ConversationsSearchDataProviderMetadataAdapter::LIST_TYPE_CLOSED);
204  $this->assertNotContains($conversation->subject, $content);
205  $this->assertNotContains('result(s)', $content);
206  }
207 
208  public function testSearch()
209  {
210  $super = User::getByUsername('super');
211  $steven = User::getByUsername('steven');
212  Yii::app()->user->userModel = $super;
213  $createdConversation = $this->createAndSaveNewConversationForUser($super, $steven);
214  $metadataForSearch = $this->rules->getSearchAttributeData();
215  $dataProvider = new RedBeanModelDataProvider('Conversation', null, false, $metadataForSearch);
216  $data = $dataProvider->getData();
217  $this->assertEquals(1, count($data));
218  $metadataForSearch = $this->rules->getSearchAttributeData("sub");
219  $dataProvider = new RedBeanModelDataProvider('Conversation', null, false, $metadataForSearch);
220  $data = $dataProvider->getData();
221  $this->assertEquals(1, count($data));
222  $metadataForSearch = $this->rules->getSearchAttributeData("description");
223  $dataProvider = new RedBeanModelDataProvider('Conversation', null, false, $metadataForSearch);
224  $data = $dataProvider->getData();
225  $this->assertEquals(0, count($data));
226  }
227  }
228 ?>
static rebuild($overwriteExistingTables=true, $forcePhp=false, $messageStreamer=null)
static getByUsername($username)
Definition: User.php:49
Definition: User.php:37
static getById($id, $modelClassName=null)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Sat Jul 4 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.