All Data Structures Functions Variables Pages
ZurmoPaginationHelperTest.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  ZurmoDatabaseCompatibilityUtil::dropStoredFunctionsAndProcedures();
43  SecurityTestHelper::createSuperAdmin();
44  UserTestHelper::createBasicUser('billy');
45  UserTestHelper::createBasicUser('sally');
46  }
47 
48  public function testZurmoPaginationHelper()
49  {
50  $pager = new ZurmoPaginationHelper();
51  $pager->setListPageSize(11);
52  $pager->setSubListPageSize(12);
53  $pager->setModalListPageSize(13);
54  $pager->setMassEditProgressPageSize(14);
55  $pager->setAutoCompleteListPageSize(15);
56  $pager->setImportPageSize(16);
57  $pager->setDashboardListPageSize(17);
58  $pager->setMassDeleteProgressPageSize(18);
59  $pager->setReportResultsListPageSize(19);
60  $pager->setReportResultsSubListPageSize(20);
61  $pager->setMassSubscribeProgressPageSize(21);
62  $pager->setKanbanBoardPageSize(22);
63  $pager->setTaskKanbanBoardPageSize(23);
64 
65  //Retrieve settings for different current users.
66  Yii::app()->user->userModel = User::getByUsername('super');
67  Yii::app()->user->clearStates();
68  $this->assertEquals(11, $pager->resolveActiveForCurrentUserByType('listPageSize'));
69  Yii::app()->user->userModel = User::getByUsername('billy');
70  Yii::app()->user->clearStates();
71  $this->assertEquals(11, $pager->resolveActiveForCurrentUserByType('listPageSize'));
72  $this->assertEquals(12, $pager->resolveActiveForCurrentUserByType('subListPageSize'));
73  $this->assertEquals(13, $pager->resolveActiveForCurrentUserByType('modalListPageSize'));
74  $this->assertEquals(14, $pager->resolveActiveForCurrentUserByType('massEditProgressPageSize'));
75  $this->assertEquals(15, $pager->resolveActiveForCurrentUserByType('autoCompleteListPageSize'));
76  $this->assertEquals(16, $pager->resolveActiveForCurrentUserByType('importPageSize'));
77  $this->assertEquals(17, $pager->resolveActiveForCurrentUserByType('dashboardListPageSize'));
78  $this->assertEquals(18, $pager->resolveActiveForCurrentUserByType('massDeleteProgressPageSize'));
79  $this->assertEquals(19, $pager->resolveActiveForCurrentUserByType('reportResultsListPageSize'));
80  $this->assertEquals(20, $pager->resolveActiveForCurrentUserByType('reportResultsSubListPageSize'));
81  $this->assertEquals(21, $pager->resolveActiveForCurrentUserByType('massSubscribeProgressPageSize'));
82  $this->assertEquals(22, $pager->resolveActiveForCurrentUserByType('kanbanBoardPageSize'));
83  $this->assertEquals(23, $pager->resolveActiveForCurrentUserByType('taskKanbanBoardPageSize'));
84 
85  //Retrieve settings for different specific users
86  $sally = User::getByUsername('sally');
87  $billy = User::getByUsername('billy');
88  $super = User::getByUsername('super');
89  Yii::app()->user->userModel = $sally;
90  Yii::app()->user->clearStates();
91  $this->assertEquals(11, $pager->getByUserAndType($super, 'listPageSize'));
92  $this->assertEquals(11, $pager->getByUserAndType($billy, 'listPageSize'));
93  $this->assertEquals(12, $pager->getByUserAndType($super, 'subListPageSize'));
94  $this->assertEquals(12, $pager->getByUserAndType($billy, 'subListPageSize'));
95  $this->assertEquals(13, $pager->getByUserAndType($super, 'modalListPageSize'));
96  $this->assertEquals(13, $pager->getByUserAndType($billy, 'modalListPageSize'));
97  $this->assertEquals(14, $pager->getByUserAndType($super, 'massEditProgressPageSize'));
98  $this->assertEquals(14, $pager->getByUserAndType($billy, 'massEditProgressPageSize'));
99  $this->assertEquals(15, $pager->getByUserAndType($super, 'autoCompleteListPageSize'));
100  $this->assertEquals(15, $pager->getByUserAndType($billy, 'autoCompleteListPageSize'));
101  $this->assertEquals(16, $pager->getByUserAndType($super, 'importPageSize'));
102  $this->assertEquals(16, $pager->getByUserAndType($billy, 'importPageSize'));
103  $this->assertEquals(17, $pager->getByUserAndType($super, 'dashboardListPageSize'));
104  $this->assertEquals(17, $pager->getByUserAndType($billy, 'dashboardListPageSize'));
105  $this->assertEquals(18, $pager->getByUserAndType($super, 'massDeleteProgressPageSize'));
106  $this->assertEquals(18, $pager->getByUserAndType($billy, 'massDeleteProgressPageSize'));
107  $this->assertEquals(19, $pager->getByUserAndType($super, 'reportResultsListPageSize'));
108  $this->assertEquals(19, $pager->getByUserAndType($billy, 'reportResultsListPageSize'));
109  $this->assertEquals(20, $pager->getByUserAndType($super, 'reportResultsSubListPageSize'));
110  $this->assertEquals(20, $pager->getByUserAndType($billy, 'reportResultsSubListPageSize'));
111  $this->assertEquals(21, $pager->getByUserAndType($super, 'massSubscribeProgressPageSize'));
112  $this->assertEquals(21, $pager->getByUserAndType($billy, 'massSubscribeProgressPageSize'));
113  $this->assertEquals(22, $pager->getByUserAndType($super, 'kanbanBoardPageSize'));
114  $this->assertEquals(22, $pager->getByUserAndType($billy, 'kanbanBoardPageSize'));
115  $this->assertEquals(23, $pager->getByUserAndType($super, 'taskKanbanBoardPageSize'));
116  $this->assertEquals(23, $pager->getByUserAndType($billy, 'taskKanbanBoardPageSize'));
117 
118  $pager->setByUserAndType($billy, 'listPageSize', 88);
119  $pager->setByUserAndType($billy, 'subListPageSize', 89);
120  $pager->setByUserAndType($billy, 'modalListPageSize', 90);
121  $pager->setByUserAndType($billy, 'massEditProgressPageSize', 91);
122  $pager->setByUserAndType($billy, 'autoCompleteListPageSize', 92);
123  $pager->setByUserAndType($billy, 'importPageSize', 93);
124  $pager->setByUserAndType($billy, 'dashboardListPageSize', 94);
125  $pager->setByUserAndType($billy, 'massDeleteProgressPageSize', 95);
126  $pager->setByUserAndType($billy, 'reportResultsListPageSize', 96);
127  $pager->setByUserAndType($billy, 'reportResultsSubListPageSize', 97);
128  $pager->setByUserAndType($billy, 'massSubscribeProgressPageSize', 98);
129  $pager->setByUserAndType($billy, 'kanbanBoardPageSize', 99);
130  $pager->setByUserAndType($billy, 'taskKanbanBoardPageSize', 100);
131 
132  $this->assertEquals(88, $pager->getByUserAndType($billy, 'listPageSize'));
133  $this->assertEquals(89, $pager->getByUserAndType($billy, 'subListPageSize'));
134  $this->assertEquals(90, $pager->getByUserAndType($billy, 'modalListPageSize'));
135  $this->assertEquals(91, $pager->getByUserAndType($billy, 'massEditProgressPageSize'));
136  $this->assertEquals(92, $pager->getByUserAndType($billy, 'autoCompleteListPageSize'));
137  $this->assertEquals(93, $pager->getByUserAndType($billy, 'importPageSize'));
138  $this->assertEquals(94, $pager->getByUserAndType($billy, 'dashboardListPageSize'));
139  $this->assertEquals(95, $pager->getByUserAndType($billy, 'massDeleteProgressPageSize'));
140  $this->assertEquals(96, $pager->getByUserAndType($billy, 'reportResultsListPageSize'));
141  $this->assertEquals(97, $pager->getByUserAndType($billy, 'reportResultsSubListPageSize'));
142  $this->assertEquals(98, $pager->getByUserAndType($billy, 'massSubscribeProgressPageSize'));
143  $this->assertEquals(99, $pager->getByUserAndType($billy, 'kanbanBoardPageSize'));
144  $this->assertEquals(100, $pager->getByUserAndType($billy, 'taskKanbanBoardPageSize'));
145  }
146 
147  public function testSetGetGlobalValueByType()
148  {
149  $pager = new ZurmoPaginationHelper();
150  $pager->setListPageSize(11);
151  $pager->setSubListPageSize(12);
152  $pager->setModalListPageSize(13);
153  $pager->setMassEditProgressPageSize(14);
154  $pager->setAutoCompleteListPageSize(15);
155  $pager->setImportPageSize(16);
156  $pager->setDashboardListPageSize(17);
157  $pager->setMassDeleteProgressPageSize(18);
158  $pager->setReportResultsListPageSize(19);
159  $pager->setReportResultsSubListPageSize(20);
160  $pager->setMassSubscribeProgressPageSize(21);
161  $pager->setKanbanBoardPageSize(22);
162  $pager->setTaskKanbanBoardPageSize(23);
163  $this->assertEquals (11, $pager->getGlobalValueByType('listPageSize'));
164  $this->assertEquals (12, $pager->getGlobalValueByType('subListPageSize'));
165  $this->assertEquals (13, $pager->getGlobalValueByType('modalListPageSize'));
166  $this->assertEquals (14, $pager->getGlobalValueByType('massEditProgressPageSize'));
167  $this->assertEquals (15, $pager->getGlobalValueByType('autoCompleteListPageSize'));
168  $this->assertEquals (16, $pager->getGlobalValueByType('importPageSize'));
169  $this->assertEquals (17, $pager->getGlobalValueByType('dashboardListPageSize'));
170  $this->assertEquals (18, $pager->getGlobalValueByType('massDeleteProgressPageSize'));
171  $this->assertEquals (19, $pager->getGlobalValueByType('reportResultsListPageSize'));
172  $this->assertEquals (20, $pager->getGlobalValueByType('reportResultsSubListPageSize'));
173  $this->assertEquals (21, $pager->getGlobalValueByType('massSubscribeProgressPageSize'));
174  $this->assertEquals (22, $pager->getGlobalValueByType('kanbanBoardPageSize'));
175  $this->assertEquals (23, $pager->getGlobalValueByType('taskKanbanBoardPageSize'));
176  $pager->setGlobalValueByType('listPageSize', 88);
177  $pager->setGlobalValueByType('subListPageSize', 89);
178  $pager->setGlobalValueByType('modalListPageSize', 90);
179  $pager->setGlobalValueByType('massEditProgressPageSize', 91);
180  $pager->setGlobalValueByType('autoCompleteListPageSize', 92);
181  $pager->setGlobalValueByType('importPageSize', 93);
182  $pager->setGlobalValueByType('dashboardListPageSize', 94);
183  $pager->setGlobalValueByType('massDeleteProgressPageSize', 95);
184  $pager->setGlobalValueByType('reportResultsListPageSize', 96);
185  $pager->setGlobalValueByType('reportResultsSubListPageSize', 97);
186  $pager->setGlobalValueByType('massSubscribeProgressPageSize', 98);
187  $pager->setGlobalValueByType('kanbanBoardPageSize', 99);
188  $pager->setGlobalValueByType('taskKanbanBoardPageSize', 100);
189  $this->assertEquals (88, $pager->getGlobalValueByType('listPageSize'));
190  $this->assertEquals (89, $pager->getGlobalValueByType('subListPageSize'));
191  $this->assertEquals (90, $pager->getGlobalValueByType('modalListPageSize'));
192  $this->assertEquals (91, $pager->getGlobalValueByType('massEditProgressPageSize'));
193  $this->assertEquals (92, $pager->getGlobalValueByType('autoCompleteListPageSize'));
194  $this->assertEquals (93, $pager->getGlobalValueByType('importPageSize'));
195  $this->assertEquals (94, $pager->getGlobalValueByType('dashboardListPageSize'));
196  $this->assertEquals (95, $pager->getGlobalValueByType('massDeleteProgressPageSize'));
197  $this->assertEquals (96, $pager->getGlobalValueByType('reportResultsListPageSize'));
198  $this->assertEquals (97, $pager->getGlobalValueByType('reportResultsSubListPageSize'));
199  $this->assertEquals (98, $pager->getGlobalValueByType('massSubscribeProgressPageSize'));
200  $this->assertEquals (99, $pager->getGlobalValueByType('kanbanBoardPageSize'));
201  $this->assertEquals (100, $pager->getGlobalValueByType('taskKanbanBoardPageSize'));
202  }
203 
204  public function testSetForCurrentUserByType()
205  {
206  $sally = User::getByUsername('sally');
207  Yii::app()->user->userModel = $sally;
208  $pager = new ZurmoPaginationHelper();
209  $pager->setForCurrentUserByType('subListPageSize', 44);
210  Yii::app()->user->getState('subListPageSizeZurmoModule', 44);
211  $this->assertEquals(44, $pager->getByUserAndType($sally, 'subListPageSize'));
212  }
213  }
214 ?>
static getByUsername($username)
Definition: User.php:49
Generated on Tue Feb 25 2020 07:10:37