All Data Structures Functions Variables Pages
ModulePermissionsEditAndDetailsViewUtilTest.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 function testResolveMetadataFromPermissionsData()
40  {
41  $data = array(
42  'AccountsModule' => array(
43  Permission::CHANGE_OWNER => array(
44  'explicit' => null,
45  'inherited' => null,
46  ),
47  Permission::CHANGE_PERMISSIONS => array(
48  'explicit' => null,
49  'inherited' => null,
50  ),
51  Permission::DELETE => array(
52  'explicit' => null,
53  'inherited' => null,
54  ),
55  Permission::READ => array(
56  'explicit' => null,
57  'inherited' => Permission::ALLOW,
58  ),
59  Permission::WRITE => array(
60  'explicit' => null,
61  'inherited' => Permission::DENY,
62  ),
63  ),
64  'ContactsModule' => array(
65  Permission::CHANGE_OWNER => array(
66  'explicit' => null,
67  'inherited' => null,
68  ),
69  Permission::CHANGE_PERMISSIONS => array(
70  'explicit' => null,
71  'inherited' => null,
72  ),
73  Permission::DELETE => array(
74  'explicit' => null,
75  'inherited' => null,
76  ),
77  Permission::READ => array(
78  'explicit' => null,
79  'inherited' => Permission::ALLOW,
80  ),
81  Permission::WRITE => array(
82  'explicit' => null,
83  'inherited' => Permission::DENY,
84  ),
85  ),
86  );
87  $this->assertTrue(in_array('AccountsModule', GroupModulePermissionsDataToEditViewAdapater::getAdministrableModuleClassNames()));
89  $this->assertNotEmpty($newData);
90  $this->assertEquals($data, $newData);
92  $newData,
94  $compareData = array(
95  'global' => array(
96  'toolbar' => array(
97  'elements' => array(
98  array('type' => 'CancelLink', 'renderType' => 'Edit'),
99  array('type' => 'SaveButton', 'renderType' => 'Edit'),
100  ),
101  ),
102  'panels' => array(
103  array(
104  'rows' => array(
105  array('title' => 'Accounts', 'cells' =>
106  array(
107  array(
108  'elements' => array(
109  array(
110  'attributeName' => 'AccountsModule__' . Permission::READ,
111  'type' => 'PermissionInheritedAllowStaticDropDown'),
112  ),
113  ),
114  array(
115  'elements' => array(
116  array(
117  'attributeName' => 'AccountsModule__' . Permission::WRITE,
118  'type' => 'PermissionInheritedDenyText'),
119  ),
120  ),
121  array(
122  'elements' => array(
123  array(
124  'attributeName' => 'AccountsModule__' . Permission::DELETE,
125  'type' => 'PermissionStaticDropDown'),
126  ),
127  ),
128  )
129  ),
130  array('title' => 'Contacts&#160;&#38;&#160;Leads', 'cells' =>
131  array(
132  array(
133  'elements' => array(
134  array(
135  'attributeName' => 'ContactsModule__' . Permission::READ,
136  'type' => 'PermissionInheritedAllowStaticDropDown'),
137  ),
138  ),
139  array(
140  'elements' => array(
141  array(
142  'attributeName' => 'ContactsModule__' . Permission::WRITE,
143  'type' => 'PermissionInheritedDenyText'),
144  ),
145  ),
146  array(
147  'elements' => array(
148  array(
149  'attributeName' => 'ContactsModule__' . Permission::DELETE,
150  'type' => 'PermissionStaticDropDown'),
151  ),
152  ),
153  )
154  ),
155  ),
156  ),
157  ),
158  ),
159  );
160  $this->assertSame($compareData, $metadata);
162  $newData,
164  $compareData = array(
165  'global' => array(
166  'toolbar' => array(
167  'elements' => array(
168  array('type' => 'CancelLink', 'renderType' => 'Edit'),
169  array('type' => 'SaveButton', 'renderType' => 'Edit'),
170  ),
171  ),
172  'panels' => array(
173  array(
174  'rows' => array(
175  array('title' => 'Accounts', 'cells' =>
176  array(
177  array(
178  'elements' => array(
179  array(
180  'attributeName' => 'AccountsModule__' . Permission::READ . '__actual',
181  'type' => 'PermissionActual'),
182  ),
183  ),
184  array(
185  'elements' => array(
186  array(
187  'attributeName' => 'AccountsModule__' . Permission::WRITE . '__actual',
188  'type' => 'PermissionActual'),
189  ),
190  ),
191  array(
192  'elements' => array(
193  array(
194  'attributeName' => 'AccountsModule__' . Permission::DELETE . '__actual',
195  'type' => 'PermissionActual'),
196  ),
197  ),
198  )
199  ),
200  array('title' => 'Contacts&#160;&#38;&#160;Leads', 'cells' =>
201  array(
202  array(
203  'elements' => array(
204  array(
205  'attributeName' => 'ContactsModule__' . Permission::READ . '__actual',
206  'type' => 'PermissionActual'),
207  ),
208  ),
209  array(
210  'elements' => array(
211  array(
212  'attributeName' => 'ContactsModule__' . Permission::WRITE . '__actual',
213  'type' => 'PermissionActual'),
214  ),
215  ),
216  array(
217  'elements' => array(
218  array(
219  'attributeName' => 'ContactsModule__' . Permission::DELETE . '__actual',
220  'type' => 'PermissionActual'),
221  ),
222  ),
223  )
224  ),
225  ),
226  ),
227  ),
228  ),
229  );
230  $this->assertSame($compareData, $metadata);
231  }
232 
233  public function testResolveWritePermissionsFromArray()
234  {
235  $fakePost = array(
236  'LeadsModule__' . Permission::READ => Permission::ALLOW,
237  'LeadsModule__' . Permission::WRITE => Permission::ALLOW,
238  'AccountsModule__' . Permission::READ => '',
239  'OpportunitiesModule__' . Permission::DELETE => Permission::DENY,
240  );
242  $compareData = array(
243  'LeadsModule__' . Permission::READ => Permission::ALLOW,
244  'LeadsModule__' . Permission::WRITE => Permission::ALLOW,
245  'LeadsModule__' . Permission::CHANGE_PERMISSIONS => Permission::ALLOW,
246  'LeadsModule__' . Permission::CHANGE_OWNER => Permission::ALLOW,
247  'AccountsModule__' . Permission::READ => '',
248  'OpportunitiesModule__' . Permission::DELETE => Permission::DENY,
249  );
250  $this->assertEquals($compareData, $readyToSetPostData);
251  }
252 
253  public function testMatchingGetPermissionsForView()
254  {
257  $this->assertEquals(count($permissionsNames), count($permissions));
258  $this->assertEquals(3, count($permissionsNames));
259  }
260  }
261 ?>
static getMetadata()
static resolveMetadataFromData($data, $metadata)
Generated on Fri Feb 21 2020 07:10:37