Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_role.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 namespace Dcp\Pu;
8 /**
9  * @author Anakeen
10  * @package Dcp\Pu
11  */
12 
13 require_once 'PU_testcase_dcp_commonfamily.php';
14 
16 {
17  protected static $outputDir;
18  /**
19  * import TST_FAMSETVALUE family
20  * @static
21  * @return string
22  */
23  protected static function getCommonImportFile()
24  {
25  return array(
26  "PU_data_dcp_role_family.ods"
27  );
28  }
29  /**
30  * @dataProvider dataRoleByGroup
31  */
32  public function testRoleByGroup(array $addTo, array $expectedRoles)
33  {
34  $u = new \User(self::$dbaccess, "");
35  $u->login = "tst_jd1";
36  $u->password_new = 'a';
37  $err = $u->add();
38  $this->assertEmpty($err, "cannot create user");
39  $du = new_doc(self::$dbaccess, $u->fid);
40  $this->assertTrue($du->isAlive() , "cannot create user document");
41 
42  foreach ($addTo as $aGroupName) {
43  /**
44  * @var \_IGROUP $dg
45  */
46  $dg = new_doc(self::$dbaccess, $aGroupName);
47  $err = $dg->insertDocument($du->id);
48  $this->assertEmpty($err, "cannot add user to $aGroupName");
49  }
50  $u->setLoginName("tst_jd1");
51  $uRoles = $u->getAllRoles();
52  $uRoleLogins = array();
53  foreach ($uRoles as $aRole) {
54  $uRoleLogins[] = $aRole["login"];
55  }
56 
57  foreach ($expectedRoles as $roleLogin) {
58  $this->assertTrue(in_array($roleLogin, $uRoleLogins) , sprintf("role %s must be present", $roleLogin));
59  }
60  foreach ($uRoleLogins as $roleLogin) {
61  $this->assertTrue(in_array($roleLogin, $expectedRoles) , sprintf("role %s must not be present", $roleLogin));
62  }
63  }
64  /**
65  * test from import
66  * @dataProvider dataDirectRole
67  */
68  public function testDirectRole($login, array $expectedRoles)
69  {
70  $u = new \User(self::$dbaccess);
71  $u->setLoginName($login);
72  $this->assertTrue($u->isAffected() , "cannot find $login user");
73  $uRoleIds = $u->getRoles();
74  simpleQuery(self::$dbaccess, sprintf("select login from users where id in (%s)", implode(',', $uRoleIds)) , $uRoleLogins, true);
75 
76  foreach ($expectedRoles as $roleLogin) {
77  $this->assertTrue(in_array($roleLogin, $uRoleLogins) , sprintf("role %s must be present", $roleLogin));
78  }
79  foreach ($uRoleLogins as $roleLogin) {
80  $this->assertTrue(in_array($roleLogin, $expectedRoles) , sprintf("role %s must not be present", $roleLogin));
81  }
82  }
83  /**
84  * test from import
85  * @dataProvider dataRoleMail
86  */
87  public function testRoleMail($roleLogin, $expectRawMail, $expectCompleteMail)
88  {
89  $r = new \User(self::$dbaccess);
90  $r->setLoginName($roleLogin);
91  $this->assertTrue($r->isAffected() , "cannot find $roleLogin role");
92 
93  $rawMail = $r->getMail(true);
94  $completeMail = $r->getMail(false);
95  $this->assertEquals($expectRawMail, $rawMail, "role raw mail test");
96  $this->assertEquals($expectCompleteMail, $completeMail, "role complete mail test");
97  /**
98  * @var \_ROLE $dr
99  */
100  $dr = new_doc(self::$dbaccess, $r->fid);
101  $this->assertTrue($dr->isAlive() , "cannot find $roleLogin document role");
102 
103  $rawMail = $dr->getMail(true);
104  $completeMail = $dr->getMail(false);
105  $this->assertEquals($expectRawMail, $rawMail, "document role raw mail test");
106  $this->assertEquals($expectCompleteMail, $completeMail, "document role complete mail test");
107  }
108  /**
109  * @dataProvider dataAccessByRole
110  */
111  public function testAccessByRole($docid, $login, array $expectedAccesses)
112  {
113  $this->sudo($login);
114  $d = new_doc(self::$dbaccess, $docid);
115  $this->assertTrue($d->isAlive() , "document $docid not found");
116 
117  foreach ($expectedAccesses as $aName => $aAccess) {
118  $err = $d->control($aName);
119  $this->assertEquals($aAccess, ($err == "") , "error in access $aName : $err");
120  }
121  }
122 
123  public function dataAccessByRole()
124  {
125  return array(
126  array(
127  "docName" => "TST_BASERED1",
128  "login" => "ublue",
129  "access" => array(
130  "view" => true,
131  "edit" => true,
132  "delete" => false
133  )
134  ) ,
135  array(
136  "docName" => "TST_BASERED1",
137  "login" => "ugreen",
138  "access" => array(
139  "view" => false,
140  "edit" => false,
141  "delete" => false
142  )
143  ) ,
144 
145  array(
146  "docName" => "TST_BASERED2",
147  "login" => "ublue",
148  "access" => array(
149  "view" => true,
150  "edit" => true,
151  "delete" => false
152  )
153  ) ,
154  array(
155  "docName" => "TST_BASERED2",
156  "login" => "ugreen",
157  "access" => array(
158  "view" => false,
159  "edit" => false,
160  "delete" => false
161  )
162  ) ,
163  array(
164  "docName" => "TST_BASEBLUE1",
165  "login" => "ublue",
166  "access" => array(
167  "view" => true,
168  "edit" => true,
169  "delete" => false
170  )
171  ) ,
172  array(
173  "docName" => "TST_BASEBLUE1",
174  "login" => "ugreen",
175  "access" => array(
176  "view" => false,
177  "edit" => false,
178  "delete" => false
179  )
180  ) ,
181 
182  array(
183  "docName" => "TST_BASEBLUE2",
184  "login" => "ublue",
185  "access" => array(
186  "view" => true,
187  "edit" => true,
188  "delete" => false
189  )
190  ) ,
191  array(
192  "docName" => "TST_BASEBLUE2",
193  "login" => "ugreen",
194  "access" => array(
195  "view" => true,
196  "edit" => true,
197  "delete" => false
198  )
199  ) ,
200  array(
201  "docName" => "TST_BASEYELLOW1",
202  "login" => "ublue",
203  "access" => array(
204  "view" => false,
205  "edit" => false,
206  "delete" => false
207  )
208  ) ,
209  array(
210  "docName" => "TST_BASEYELLOW1",
211  "login" => "ugreen",
212  "access" => array(
213  "view" => false,
214  "edit" => false,
215  "delete" => false
216  )
217  ) ,
218 
219  array(
220  "docName" => "TST_BASEYELLOW2",
221  "login" => "ublue",
222  "access" => array(
223  "view" => false,
224  "edit" => false,
225  "delete" => false
226  )
227  ) ,
228  array(
229  "docName" => "TST_BASEYELLOW2",
230  "login" => "ugreen",
231  "access" => array(
232  "view" => true,
233  "edit" => true,
234  "delete" => false
235  )
236  ) ,
237  array(
238  "docName" => "TST_BASEYELLOW2",
239  "login" => "uryellow",
240  "access" => array(
241  "view" => true,
242  "edit" => true,
243  "delete" => false
244  )
245  ) ,
246  array(
247  "docName" => "TST_BASEYELLOW2",
248  "login" => "urgreen",
249  "access" => array(
250  "view" => true,
251  "edit" => true,
252  "delete" => false
253  )
254  ) ,
255  array(
256  "docName" => "TST_BASEYELLOW2",
257  "login" => "uggreen",
258  "access" => array(
259  "view" => true,
260  "edit" => true,
261  "delete" => false
262  )
263  ) ,
264 
265  array(
266  "docName" => "TST_BASEGREEN",
267  "login" => "ublue",
268  "access" => array(
269  "view" => true,
270  "edit" => false,
271  "delete" => false
272  )
273  ) ,
274  array(
275  "docName" => "TST_BASEGREEN",
276  "login" => "ugreen",
277  "access" => array(
278  "view" => true,
279  "edit" => true,
280  "delete" => false
281  )
282  ) ,
283  array(
284  "docName" => "TST_BASEGREEN",
285  "login" => "uryellow",
286  "access" => array(
287  "view" => true,
288  "edit" => false,
289  "delete" => false
290  )
291  ) ,
292  array(
293  "docName" => "TST_BASEGREEN",
294  "login" => "urgreen",
295  "access" => array(
296  "view" => true,
297  "edit" => false,
298  "delete" => false
299  )
300  ) ,
301  array(
302  "docName" => "TST_BASEGREEN",
303  "login" => "uggreen",
304  "access" => array(
305  "view" => true,
306  "edit" => true,
307  "delete" => false
308  )
309  )
310  );
311  }
312 
313  public function dataRoleMail()
314  {
315  return array(
316  array(
317  "login" => "rblue",
318  "rawMail" => "blue@anakeen.com, green@anakeen.com, green@group.org, green@role.org",
319  "completeMail" => '"John Bleu" <blue@anakeen.com>, "Jane Vert" <green@anakeen.com>, "John Vert" <green@group.org>, "John Blue-Yellow" <green@role.org>'
320  ) ,
321  array(
322  "login" => "rred",
323  "rawMail" => "blue@anakeen.com",
324  "completeMail" => '"John Bleu" <blue@anakeen.com>'
325  ) ,
326  array(
327  "login" => "ryellow",
328  "rawMail" => "green@anakeen.com, green@group.org, green@role.org, yellow@role.org",
329  "completeMail" => '"Jane Vert" <green@anakeen.com>, "John Vert" <green@group.org>, "John Blue-Yellow" <green@role.org>, "Jane Jaune" <yellow@role.org>'
330  )
331  );
332  }
333 
334  public function dataDirectRole()
335  {
336  return array(
337  array(
338  "login" => "ublue",
339  "expectRoles" => array(
340  "rblue"
341  )
342  ) ,
343  array(
344  "login" => "ugreen",
345  "expectRoles" => array(
346  "ryellow",
347  "rblue"
348  )
349  )
350  );
351  }
352 
353  public function dataRoleByGroup()
354  {
355  return array(
356  array(
357  "addTo" => array(
358  "TST_GRPRED"
359  ) ,
360  "expectRoles" => array(
361  "rred"
362  )
363  ) ,
364  array(
365  "addTo" => array(
366  "TST_GRPGREEN"
367  ) ,
368  "expectRoles" => array(
369  "rblue",
370  "ryellow"
371  )
372  ) ,
373  array(
374  "addTo" => array(
375  "TST_GRPYELLOW"
376  ) ,
377  "expectRoles" => array(
378  "rred",
379  "ryellow"
380  )
381  ) ,
382  array(
383  "addTo" => array(
384  "TST_GRPBLUE"
385  ) ,
386  "expectRoles" => array(
387  "rred",
388  "rblue"
389  )
390  ) ,
391  array(
392  "addTo" => array(
393  "TST_GRPBLUE",
394  "TST_GRPRED"
395  ) ,
396  "expectRoles" => array(
397  "rred",
398  "rblue"
399  )
400  ) ,
401  array(
402  "addTo" => array(
403  "TST_GRPBLUE",
404  "TST_GRPGREEN"
405  ) ,
406  "expectRoles" => array(
407  "rred",
408  "ryellow",
409  "rblue"
410  )
411  ) ,
412  array(
413  "addTo" => array(
414  "TST_GRPBLUE",
415  "TST_GRPGREEN",
416  "TST_GRPYELLOW"
417  ) ,
418  "expectRoles" => array(
419  "rred",
420  "ryellow",
421  "rblue"
422  )
423  ) ,
424  array(
425  "addTo" => array() ,
426  "expectRoles" => array()
427  )
428  );
429  }
430 }
static sudo($login)
testDirectRole($login, array $expectedRoles)
$d
Definition: dav.php:77
static getCommonImportFile()
$docid
Definition: cleanFamily.php:13
$login
Definition: dav.php:40
testAccessByRole($docid, $login, array $expectedAccesses)
$dbaccess
Definition: checkVault.php:17
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen