Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MissionsMashableInboxRulesTest.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  $steven->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS);
49  $steven->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS);
50  $steven->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS);
51  $steven->save();
52  $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
53  $everyoneGroup->save();
54  }
55 
56  public function setUp()
57  {
58  parent::setUp();
59  $this->rules = new MissionMashableInboxRules();
60  }
61 
62  public function testListActionRenderListViewsForMission()
63  {
64  $this->setGetArray(array('modelClassName' => 'Mission'));
65  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
66  $this->deleteAllMissions();
67  $this->createAndSaveNewMissionForUser($super);
68  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
69  $this->assertContains($this->rules->getListViewClassName(), $content);
70  $this->assertContains('list-view-markRead', $content);
71  $this->assertContains('list-view-markUnread', $content);
72  }
73 
74  public function testReadUnread()
75  {
76  $super = User::getByUsername('super');
77  Yii::app()->user->userModel = $super;
78  $this->deleteAllMissions();
79  $createdMission = $this->createAndSaveNewMissionForUser($super);
80  $this->assertTrue($this->rules->hasCurrentUserReadLatest($createdMission->id));
81  $this->rules->resolveMarkUnread($createdMission->id);
82  $savedMission = Mission::getById($createdMission->id);
83  $this->assertFalse($this->rules->hasCurrentUserReadLatest($createdMission->id));
84  $this->rules->resolveMarkRead($createdMission->id);
85  $savedMission = Mission::getById($createdMission->id);
86  $this->assertTrue($this->rules->hasCurrentUserReadLatest($createdMission->id));
87  }
88 
89  protected function deleteAllMissions()
90  {
91  foreach (Mission::getAll() as $mission)
92  {
93  $mission->delete();
94  }
95  }
96 
97  protected function createAndSaveNewMissionForUser(User $owner, $status = Mission::STATUS_AVAILABLE)
98  {
99  $mission = new Mission();
100  $mission->owner = $owner;
101  $mission->description = 'My test mission description with status: ' . $status;
102  $mission->status = $status;
103  $this->assertTrue($mission->save());
104  return $mission;
105  }
106 
107  protected function resolveControlerActionListAndGetContent($filteredBy, $optionForModel)
108  {
109  $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
110  $this->setGetArray(
111  array(
112  'modelClassName' => 'Mission',
113  'ajax' => 'list-view',
114  'MashableInboxForm' => array(
115  'filteredBy' => $filteredBy,
116  'optionForModel' => $optionForModel
117  )
118  )
119  );
120  $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list');
121  return $content;
122  }
123 
124  public function testFilters()
125  {
126  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
127  $this->deleteAllMissions();
128  $mission = $this->createAndSaveNewMissionForUser($super);
129  $content = $this->resolveControlerActionListAndGetContent(
130  MashableInboxForm::FILTERED_BY_ALL,
131  MissionsListConfigurationForm::LIST_TYPE_CREATED);
132  $this->assertContains($mission->description, $content);
133  $this->assertContains('1 result(s)', $content);
134  $content = $this->resolveControlerActionListAndGetContent(
135  MashableInboxForm::FILTERED_BY_UNREAD,
136  MissionsListConfigurationForm::LIST_TYPE_CREATED);
137  $this->assertNotContains($mission->description, $content);
138  $this->assertNotContains('result(s)', $content);
139  $content = $this->resolveControlerActionListAndGetContent(
140  MashableInboxForm::FILTERED_BY_ALL,
141  MissionsListConfigurationForm::LIST_TYPE_AVAILABLE);
142  $this->assertNotContains($mission->description, $content);
143  $this->assertNotContains('result(s)', $content);
144  $content = $this->resolveControlerActionListAndGetContent(
145  MashableInboxForm::FILTERED_BY_UNREAD,
146  MissionsListConfigurationForm::LIST_TYPE_CREATED);
147  $this->assertNotContains($mission->description, $content);
148  $this->assertNotContains('result(s)', $content);
149  $content = $this->resolveControlerActionListAndGetContent(
150  MashableInboxForm::FILTERED_BY_ALL,
151  MissionsListConfigurationForm::LIST_TYPE_MINE_TAKEN_BUT_NOT_ACCEPTED);
152  $this->assertNotContains($mission->description, $content);
153  $this->assertNotContains('result(s)', $content);
154  $content = $this->resolveControlerActionListAndGetContent(
155  MashableInboxForm::FILTERED_BY_UNREAD,
156  MissionsListConfigurationForm::LIST_TYPE_CREATED);
157  $this->assertNotContains($mission->description, $content);
158  $this->assertNotContains('result(s)', $content);
159  }
160 
161  public function testSearch()
162  {
163  $super = User::getByUsername('super');
164  Yii::app()->user->userModel = $super;
165  $this->deleteAllMissions();
166  $this->createAndSaveNewMissionForUser($super);
167  $searchAttributeData = $this->rules->getSearchAttributeData();
168  $dataProvider = new RedBeanModelDataProvider('Mission', null, false, $searchAttributeData);
169  $data = $dataProvider->getData();
170  $this->assertEquals(1, count($data));
171  $metadataForSearch = $this->rules->getSearchAttributeData("mis");
172  $dataProvider = new RedBeanModelDataProvider('Mission', null, false, $metadataForSearch);
173  $data = $dataProvider->getData();
174  $this->assertEquals(1, count($data));
175  $metadataForSearch = $this->rules->getSearchAttributeData("subject");
176  $dataProvider = new RedBeanModelDataProvider('Mission', null, false, $metadataForSearch);
177  $data = $dataProvider->getData();
178  $this->assertEquals(0, count($data));
179  }
180  }
181 ?>
static rebuild($overwriteExistingTables=true, $forcePhp=false, $messageStreamer=null)
static getByUsername($username)
Definition: User.php:49
Definition: User.php:37
static getByName($name)
Definition: Group.php:57
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:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.