All Data Structures Functions Variables Pages
UserConfigurationFormAdapterTest.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  SecurityTestHelper::createSuperAdmin();
43  UserTestHelper::createBasicUser('billy');
44  UserTestHelper::createBasicUser('sally');
45  }
46 
47  public function testMakeFormAndSetConfigurationFromForm()
48  {
49  $billy = User::getByUsername('billy');
50  $sally = User::getByUsername('sally');
51  Yii::app()->pagination->setGlobalValueByType('listPageSize', 50);
52  Yii::app()->pagination->setGlobalValueByType('subListPageSize', 51);
53  Yii::app()->pagination->setGlobalValueByType('dashboardListPageSize', 52);
54 
55  //Confirm sally's configuration is the defaults.
57  $this->assertEquals(50, $form->listPageSize);
58  $this->assertEquals(51, $form->subListPageSize);
59  $this->assertEquals(52, $form->dashboardListPageSize);
60  $this->assertEquals('blue', Yii::app()->themeManager->resolveAndGetThemeColorValue($sally));
61  $this->assertEquals(null, Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($sally));
62  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideWelcomeView'));
63  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'enableDesktopNotifications'));
64  $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'defaultPermissionGroupSetting', false));
65  $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($sally), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE);
66  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideFromSelecting'));
67  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideFromLeaderboard'));
68 
69  $sally->hideFromLeaderboard = true;
70  $sally->hideFromSelecting = true;
71  $this->assertTrue($sally->save());
72 
73  unset($sally);
74  $sally = User::getByUsername('sally');
75  $this->assertTrue((bool)$sally->hideFromLeaderboard);
76  $this->assertTrue((bool)$sally->hideFromSelecting);
77 
78  //Confirm billy's configuration is the defaults.
80  $this->assertEquals(50, $form->listPageSize);
81  $this->assertEquals(51, $form->subListPageSize);
82  $this->assertEquals(52, $form->dashboardListPageSize);
83  $this->assertEquals('blue', Yii::app()->themeManager->resolveAndGetThemeColorValue($billy));
84  $this->assertEquals(null, Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($billy));
85  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'hideWelcomeView'));
86  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'enableDesktopNotifications'));
87  $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'defaultPermissionGroupSetting', false));
88  $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($billy), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE);
89  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideFromSelecting'));
90  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideFromLeaderboard'));
91 
92  //Now change configuration for Billy.
93  $form->listPageSize = 60;
94  $form->subListPageSize = 61;
95  $form->dashboardListPageSize = 62;
96  $form->themeColor = 'lime';
97  $form->backgroundTexture = 'paper';
98  $form->hideWelcomeView = true;
99  $form->enableDesktopNotifications = true;
100  $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP;
101  $form->defaultPermissionGroupSetting = 6;
102  $form->hideFromLeaderboard = true;
103  $form->hideFromSelecting = true;
104 
106  //Confirm billy's settings are changed correctly.
108  $this->assertEquals(60, $form->listPageSize);
109  $this->assertEquals(61, $form->subListPageSize);
110  $this->assertEquals(62, $form->dashboardListPageSize);
111  $this->assertEquals('lime', Yii::app()->themeManager->resolveAndGetThemeColorValue($billy));
112  $this->assertEquals('paper', Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($billy));
113  $this->assertTrue(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'hideWelcomeView'));
114  $this->assertTrue(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'enableDesktopNotifications'));
115  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideWelcomeView'));
116  $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'enableDesktopNotifications'));
118  UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP);
119  $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'defaultPermissionGroupSetting', false), 6);
121  UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE);
122  $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'defaultPermissionGroupSetting', false));
123  $this->assertTrue((bool)$billy->hideFromLeaderboard);
124  $this->assertTrue((bool)$billy->hideFromSelecting);
125  //Now set configuration settings for sally and confirm they are correct.
126  Yii::app()->user->userModel = $sally;
129  $this->assertEquals(60, $form->listPageSize);
130  $this->assertEquals(61, $form->subListPageSize);
131  $this->assertEquals(62, $form->dashboardListPageSize);
132  $this->assertEquals('lime', Yii::app()->themeManager->resolveAndGetThemeColorValue($sally));
133  $this->assertEquals('paper', Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($sally));
134  $this->assertTrue(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideWelcomeView'));
135  $this->assertTrue(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'enableDesktopNotifications'));
136  $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($sally), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP);
137  $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'defaultPermissionGroupSetting', false), 6);
138  $this->assertTrue((bool)$billy->hideFromLeaderboard);
139  $this->assertTrue((bool)$billy->hideFromSelecting);
140 
141  //Now test that setting defaultPermissionSetting to owner makes the group settings null
143  $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER;
144  $form->defaultPermissionGroupSetting = 4;
147  $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($billy), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER);
148  $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'defaultPermissionGroupSetting', false));
149  }
150 
151  public function testEditTabMenuOrderByMakeFormAndSetConfigurationFromForm()
152  {
153  $sally = User::getByUsername('sally');
155  $this->assertEquals(count($form->selectedVisibleAndOrderedTabMenuItems), count(MenuUtil::getVisibleAndOrderedTabMenuByUser($sally)));
156  $defaultOrderedTabMenuItems = $form->selectedVisibleAndOrderedTabMenuItems;
157  $customOrderedTabMenuItems = array_reverse($defaultOrderedTabMenuItems);
158  $form->selectedVisibleAndOrderedTabMenuItems = $customOrderedTabMenuItems;
161  $this->assertEquals($form->selectedVisibleAndOrderedTabMenuItems, $customOrderedTabMenuItems);
162 
163  $billy = User::getByUsername('billy');
165  $this->assertEquals($form->selectedVisibleAndOrderedTabMenuItems, $defaultOrderedTabMenuItems);
166  $form->selectedVisibleAndOrderedTabMenuItems = $customOrderedTabMenuItems;
169  $this->assertEquals($form->selectedVisibleAndOrderedTabMenuItems, $customOrderedTabMenuItems);
170  }
171 
172  public function testGetVisibleAndOrderedTabMenuItemsByUser()
173  {
174  $sally = User::getByUsername('sally');
175  $sally->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
176  $this->assertTrue($sally->save());
179  $this->assertEquals(3, count($customOrderedTabMenuItems));
180  $form->selectedVisibleAndOrderedTabMenuItems = $customOrderedTabMenuItems;
182  $sally->removeRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
183  $this->assertTrue($sally->save());
185  $this->assertEquals(2, count($customOrderedTabMenuItems));
186  }
187  }
188 ?>
static resolveAndGetDefaultPermissionSetting(User $user)
static getByUsername($username)
Definition: User.php:49
static setConfigurationFromForm(UserConfigurationForm $form, User $user)
static getVisibleAndOrderedTabMenuItemsByUser($user, $selected=false)
static getVisibleAndOrderedTabMenuByUser($user)
Definition: MenuUtil.php:160
static makeFormFromUserConfigurationByUser(User $user)
static setConfigurationFromFormForCurrentUser(UserConfigurationForm $form)
static resolveAndGetValue(User $user, $key, $returnBoolean=true)
Generated on Thu Jan 23 2020 07:10:22