]> git.agnieray.net Git - galette.git/blob - tests/Galette/Middleware/tests/unit/CheckAcls.php
Switch to PSR12, phpcbf fix
[galette.git] / tests / Galette / Middleware / tests / unit / CheckAcls.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * CheckAcls tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2016 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Core
28 * @package GaletteTests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2020 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 2020-05-10
36 */
37
38 namespace Galette\Middleware\test\units;
39
40 use atoum;
41
42 /**
43 * CheckAcls tests class
44 *
45 * @category Core
46 * @name CheckAcls
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2020 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
52 * @since 2020-05-10
53 */
54 class CheckAcls extends atoum
55 {
56 private $container;
57
58 /**
59 * Set up tests
60 *
61 * @param stgring $testMethod Method tested
62 *
63 * @return void
64 */
65 public function beforeTestMethod($testMethod)
66 {
67 $app = new \Slim\App();
68 require GALETTE_ROOT . 'includes/core_acls.php';
69 $container = $app->getContainer();
70 //$this->acls = $core_acls;
71 $container['acls'] = $core_acls;
72 $container['view'] = new \stdClass();
73 $container['flash'] = new \stdClass();
74 $this->container = $container;
75 }
76
77 /**
78 * ACL provider
79 *
80 * @return array
81 */
82 protected function aclsProvider()
83 {
84 return [
85 ['doPreferences', 'admin'],
86 ['doPreferencesSthing', 'admin'],
87 ['removeSthing', 'staff'],
88 ['doremoveSthing', 'staff'],
89 ['anyDynamicField', 'admin'],
90 //existing routes as of Galette 0.9.4dev before regexp are supported
91 ['preferences', 'admin'],
92 ['store-preferences', 'admin'],
93 ['testEmail', 'admin'],
94 ['dashboard', 'member'],
95 ['sysinfos', 'staff'],
96 ['charts', 'staff'],
97 ['plugins', 'admin'],
98 ['pluginInitDb', 'admin'],
99 ['pluginsActivation', 'admin'],
100 ['history', 'staff'],
101 ['history_filter', 'staff'],
102 ['flushHistory', 'staff'],
103 ['doFlushHistory', 'staff'],
104 ['members', 'groupmanager'],
105 ['filter-memberslist', 'groupmanager'],
106 ['advanced-search', 'groupmanager'],
107 ['batch-memberslist', 'groupmanager'],
108 ['mailing', 'staff'],
109 ['doMailing', 'staff'],
110 ['mailingPreview', 'staff'],
111 ['previewAttachment', 'staff'],
112 ['mailingRecipients', 'staff'],
113 ['csv-memberslist', 'staff'],
114 ['groups', 'groupmanager'],
115 ['me', 'member'],
116 ['member', 'member'],
117 ['pdf-members-cards', 'member'],
118 ['pdf-members-labels', 'groupmanager'],
119 ['mailings', 'staff'],
120 ['mailings_filter', 'staff'],
121 ['removeMailing', 'staff'],
122 ['doRemoveMailing', 'staff'],
123 ['contributions', 'member'],
124 ['transactions', 'staff'],
125 ['payments_filter', 'member'],
126 ['editmember', 'member'],
127 ['impersonate', 'superadmin'],
128 ['unimpersonate', 'member'],
129 ['reminders', 'staff'],
130 ['doReminders', 'staff'],
131 ['reminders-filter', 'staff'],
132 ['export', 'staff'],
133 ['doExport', 'staff'],
134 ['removeCsv', 'staff'],
135 ['doRemoveCsv', 'staff'],
136 ['getCsv', 'staff'],
137 ['import', 'staff'],
138 ['doImport', 'staff'],
139 ['importModel', 'staff'],
140 ['getImportModel', 'staff'],
141 ['storeImportModel', 'staff'],
142 ['uploadImportFile', 'staff'],
143 ['pdfModels', 'staff'],
144 ['titles', 'staff'],
145 ['removeTitle', 'staff'],
146 ['doRemoveTitle', 'staff'],
147 ['editTitle', 'staff'],
148 ['texts', 'staff'],
149 ['changeText', 'staff'],
150 ['transaction', 'staff'],
151 ['doAddTransaction', 'staff'],
152 ['doEditTransaction', 'staff'],
153 ['addContribution', 'staff'],
154 ['doAddContribution', 'staff'],
155 ['editContribution', 'staff'],
156 ['doEditContribution', 'staff'],
157 ['contributionDates', 'staff'],
158 ['contributionMembers', 'staff'],
159 ['attendance_sheet_details', 'groupmanager'],
160 ['attendance_sheet', 'groupmanager'],
161 ['entitleds', 'staff'],
162 ['editEntitled', 'staff'],
163 ['removeEntitled', 'staff'],
164 ['doRemoveEntitled', 'staff'],
165 ['dynamicTranslations', 'staff'],
166 ['editDynamicTranslation', 'staff'],
167 ['printContribution', 'member'],
168 ['attach_contribution', 'staff'],
169 ['detach_contribution', 'staff'],
170 ['removeContribution', 'staff'],
171 ['removeContributions', 'staff'],
172 ['pdf_groups', 'groupmanager'],
173 ['ajax_group', 'groupmanager'],
174 ['ajax_groups', 'groupmanager'],
175 ['ajax_groupname_unique', 'groupmanager'],
176 ['ajax_groups_reorder', 'staff'],
177 ['add_group', 'staff'],
178 ['removeGroup', 'staff'],
179 ['doRemoveGroup', 'staff'],
180 ['doEditGroup', 'groupmanager'],
181 ['adhesionForm', 'member'],
182 ['removeMember', 'staff'],
183 ['removeMembers', 'staff'],
184 ['doRemoveMember', 'staff'],
185 ['doRemoveContribution', 'staff'],
186 ['configureCoreFields', 'admin'],
187 ['configureDynamicFields', 'admin'],
188 ['storeCoreFieldsConfig', 'admin'],
189 ['addDynamicField', 'admin'],
190 ['editDynamicField', 'admin'],
191 ['doAddDynamicField', 'admin'],
192 ['doEditDynamicField', 'admin'],
193 ['moveDynamicField', 'admin'],
194 ['removeDynamicField', 'admin'],
195 ['doRemoveDynamicField', 'admin'],
196 ['photoDnd', 'staff'],
197 ['ajaxMembers', 'groupmanager'],
198 ['ajaxGroupMembers', 'staff'],
199 ['getDynamicFile', 'member'],
200 ['fakeData', 'superadmin'],
201 ['doFakeData', 'superadmin'],
202 ['adminTools', 'superadmin'],
203 ['doAdminTools', 'superadmin'],
204 ['telemetryInfos', 'admin'],
205 ['telemetrySend', 'admin'],
206 ['setRegistered', 'admin'],
207 ['masschangeMembers', 'groupmanager'],
208 ['massstoremembers', 'groupmanager'],
209 ['masschangeMembersReview', 'groupmanager'],
210 ['duplicateMember', 'staff'],
211 ['paymentTypes', 'staff'],
212 ['removePaymentType', 'staff'],
213 ['doRemovePaymentType', 'staff'],
214 ['editPaymentType', 'staff'],
215 ['searches', 'member'],
216 ['removeSearch', 'member'],
217 ['removeSearches', 'member'],
218 ['doRemoveSearch', 'member'],
219 ['loadSearch', 'member']
220 ];
221 }
222
223 /**
224 * Test new PasswordImage generation
225 *
226 * @dataProvider aclsProvider
227 *
228 * @param string $name Route name
229 * @param string $expected Expected ACL
230 *
231 * @return void
232 */
233 public function testGetAclFor($name, $expected)
234 {
235 $this
236 ->given($check = $this->newTestedInstance($this->container))
237 ->if($acl_name = $this->testedInstance->getAclFor($name))
238 ->then
239 ->string($acl_name)->isIdenticalTo(
240 $expected,
241 sprintf(
242 '%1$s should be accesible to %2$s but is to %3$s',
243 $name,
244 $expected,
245 $acl_name
246 )
247 );
248 }
249 }