Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
UserDefaultPermissionWalkthroughTest.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  $testGroup1 = new Group();
44  $testGroup1->name = 'testGroup1';
45  $saved = $testGroup1->save();
46  assert('$saved'); // Not Coding Standard
47  $testGroup2 = new Group();
48  $testGroup2->name = 'testGroup2';
49  $saved = $testGroup2->save();
50  assert('$saved'); // Not Coding Standard
51  }
52 
53  public function testUserCanSaveDefaultPermissions()
54  {
55  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
56  $group = Group::getByName('testGroup2');
57 
58  // set permission setting to 'everyone' and permission group settings to 'testGroup2'
59  $this->setGetArray(array('id' => $super->id));
60  $postData = array('defaultPermissionSetting' => UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE,
61  'defaultPermissionGroupSetting' => $group->id);
62  $this->setPostArray(array('UserConfigurationForm' => $postData));
63  $this->runControllerWithRedirectExceptionAndGetContent('users/default/configurationEdit',
64  Yii::app()->createUrl('users/default/details', array('id' => $super->id)));
66  UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE);
67  $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($super, 'defaultPermissionGroupSetting',
68  false));
69 
70  // set permission setting to 'users and group', set permission group settings to 'testGroup2'
71  $this->resetGetArray();
72  $this->resetPostArray();
73  $this->setGetArray(array('id' => $super->id));
74  $postData = array('defaultPermissionSetting' => UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP,
75  'defaultPermissionGroupSetting' => $group->id);
76  $this->setPostArray(array('UserConfigurationForm' => $postData));
77  //Make sure the redirect is to the details view and not the list view.
78  $this->runControllerWithRedirectExceptionAndGetContent('users/default/configurationEdit',
79  Yii::app()->createUrl('users/default/details', array('id' => $super->id)));
81  UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP);
82  $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetValue($super, 'defaultPermissionGroupSetting',
83  false), $group->id);
84  }
85 
90  {
91  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
92  $group = Group::getByName('testGroup2');
93  $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/create');
94  // test that 'Owner and users in' radio button is checked with testGroup2 selected
95  $this->assertEquals(preg_match('%<input id="Account_explicitReadWriteModelPermissions_type_1" value="2"'.
96  ' checked="checked" type="radio" name="Account\[explicitReadWriteModelPermissions\]\[type\]" />%',
97  $content), 1);
98  $this->assertEquals(preg_match('%<option value="' . $group->id .
99  '" selected="selected">' . $group->name . '</option>%', $content), 1);
100  }
101 
106  {
107  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
108  $testGroup1 = Group::getByName('testGroup1');
109  $testGroup2 = Group::getByName('testGroup2');
110  AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
111  $superAccountId = self::getModelIdByModelNameAndName ('Account', 'superAccount');
112  $this->setGetArray(array('id' => $superAccountId));
113  $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/edit');
114  // test that 'Owner and users in' radio button is not checked.
115  $this->assertEquals(preg_match('%<input id="Account_explicitReadWriteModelPermissions_type_1" value="2" '.
116  'checked="checked" type="radio" name="Account\[explicitReadWriteModelPermissions\]\[type\]" />%',
117  $content), 0);
118  // test that 'Owner' radio button is checked, which is default for AccountTestHelper
119  $this->assertEquals(preg_match('%<input id="Account_explicitReadWriteModelPermissions_type_0" value="" '.
120  'checked="checked" type="radio" name="Account\[explicitReadWriteModelPermissions\]\[type\]" />%',
121  $content), 1);
122  // test that no dropdown item is selected
123  $this->assertEquals(preg_match('%<option value="(\d+)" selected="selected">(.*)</option>%', $content), 0); // Not Coding Standard
124  }
125 
126  public function testGlobalDefaultsLoadedOnCreateInAbsenceOfUserDefaultPermissions()
127  {
128  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
129  UserConfigurationFormAdapter::setValue($super, null, 'defaultPermissionSetting', false);
131  $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/create');
132  // test that 'everyone' radio button is checked
133  $this->assertEquals(preg_match('%<input id="Account_explicitReadWriteModelPermissions_type_2" value="1" '.
134  'checked="checked" type="radio" name="Account\[explicitReadWriteModelPermissions\]\[type\]" />%',
135  $content), 1);
136  // test that no downdown item is selected
137  $this->assertEquals(preg_match('%<option value="(\d+)" selected="selected">(.*)</option>%', $content), 0); // Not Coding Standard
138  }
139  }
140 ?>
static resolveAndGetDefaultPermissionSetting(User $user)
static setDefaultPermissionGroupSetting(User $user, $value, $defaultPermissionSetting)
runControllerWithRedirectExceptionAndGetContent($route, $compareUrl=null, $compareUrlContains=false)
Definition: Group.php:37
static getByName($name)
Definition: Group.php:57
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static resolveAndGetValue(User $user, $key, $returnBoolean=true)
Generated on Thu Jul 9 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.