Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_profil.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_profil_family.ods",
27  "PU_data_dcp_profildata.ods"
28  );
29  }
30  /**
31  * @dataProvider dataProfilComputing
32  */
33  public function testProfilComputing($docName, $prfName, $login, $aclAttendees)
34  {
35 
36  $this->sudo($login);
37  $this->resetDocumentCache();
38  $df = \new_Doc(self::$dbaccess, $docName);
39  $this->assertTrue($df->isAlive() , "document $docName is not alive");
40  $df->setProfil($prfName);
41  foreach ($aclAttendees as $acl => $expect) {
42  $result = ($df->Control($acl) == "");
43  if ($expect) {
44  $this->assertTrue($result, "acl $acl is not granted");
45  } else {
46  $this->assertFalse($result, "acl $acl is granted");
47  }
48  }
49  }
50  /**
51  * @dataProvider dataProfilChange
52  * @depends testProfilComputing
53  */
54  public function testProfilDynamicChange($docName, $prfName, $login, $newPrfAcl, $aclAttendees)
55  {
56 
57  $df = \new_Doc(self::$dbaccess, $docName);
58  $this->assertTrue($df->isAlive() , "document $docName is not alive");
59  $df->setProfil($prfName);
60 
61  $this->importDocument($newPrfAcl);
62  $this->sudo($login);
63 
64  $this->resetDocumentCache();
65  $df = \new_Doc(self::$dbaccess, $docName);
66 
67  foreach ($aclAttendees as $acl => $expect) {
68  $result = ($df->Control($acl) == "");
69  if ($expect) {
70  $this->assertTrue($result, "acl $acl is not granted");
71  } else {
72  $this->assertFalse($result, "acl $acl is granted");
73  }
74  }
75  }
76  /**
77  * @dataProvider dataProfilChange
78  * @depends testProfilComputing
79  */
80  public function testSearchControlled($docName, $prfName, $login, $newPrfAcl, $aclAttendees)
81  {
82 
83  $df = \new_Doc(self::$dbaccess, $docName);
84  $this->assertTrue($df->isAlive() , "document $docName is not alive");
85  $df->setProfil($prfName);
86 
87  $this->importDocument($newPrfAcl);
88  $this->sudo($login);
89 
90  $this->resetDocumentCache();
91  $df = \new_Doc(self::$dbaccess, $docName);
92 
93  foreach ($aclAttendees as $acl => $expect) {
94  $result = ($df->Control($acl) == "");
95  if ($expect) {
96  $this->assertTrue($result, "acl $acl is not granted");
97  } else {
98  $this->assertFalse($result, "acl $acl is granted");
99  }
100  }
101  }
102  /**
103  * @dataProvider dataSearchDocument
104  * @depends testProfilComputing
105  */
106  public function testSearchView($profFile, $famName, $login, $expectNumber)
107  {
108 
109  $this->importDocument($profFile);
110  $this->sudo($login);
111 
112  $this->resetDocumentCache();
113  $s = new \SearchDoc(self::$dbaccess, $famName);
114  $s->search();
115 
116  $this->assertEquals($expectNumber, $s->count() , sprintf("query:%s: %s", print_r($s->getSearchInfo() , true) , print_r($this->getViews($famName) , true)));
117  }
118  /**
119  * @dataProvider dataProfilRecomputeProfiledDocuments
120  */
122  {
123  $profile = \new_Doc('', $data['profile']);
124  simpleQuery('', sprintf('DELETE FROM dochisto WHERE id = %d', $profile->initid));
125  $this->importCsvData($data['import']);
126  $this->resetDocumentCache();
127  $profile = \new_Doc('', $data['profile']);
128  $histo = $profile->getHisto();
129  $hasRecomputedProfileedDocuments = false;
130  foreach ($histo as $entry) {
131  if ($entry['code'] == 'RECOMPUTE_PROFILED_DOCUMENT') {
132  $hasRecomputedProfileedDocuments = true;
133  break;
134  }
135  }
136  $msg = sprintf("Import of profile '%s' has wrongfully %srecomputed profiled documents.", $data['profile'], $data['recomputed'] ? 'not ' : '');
137  $this->assertEquals($data['recomputed'], $hasRecomputedProfileedDocuments, $msg);
138  }
140  {
141  return array(
142  //
143  // -- Static profiles --
144  //
145  // Check that RESET always recomputes profiled documents
146  array(
147  array(
148  "import" => "PROFIL;TST_PRF_RESET;;RESET;view=TST_GRPALL;edit=TST_GRPSUBONE",
149  "profile" => "TST_PRF_RESET",
150  "recomputed" => true
151  )
152  ) ,
153  array(
154  array(
155  "import" => "PROFIL;TST_PRF_RESET;;RESET;view=TST_GRPALL;delete=TST_GRPSUBONE",
156  "profile" => "TST_PRF_RESET",
157  "recomputed" => true
158  )
159  ) ,
160  // Check that SET recomputes profiled documents only if changed
161  array(
162  array(
163  "import" => "PROFIL;TST_PRF_SET;;SET;view=TST_GRPALL;edit=TST_GRPSUBONE",
164  "profile" => "TST_PRF_SET",
165  "recomputed" => false
166  )
167  ) ,
168  array(
169  array(
170  "import" => "PROFIL;TST_PRF_SET;;SET;view=TST_GRPALL;delete=TST_GRPSUBONE",
171  "profile" => "TST_PRF_SET",
172  "recomputed" => true
173  )
174  ) ,
175  //
176  // -- Dynamic user profiles --
177  //
178  // Check that RESET always recomputes profiled documents
179  array(
180  array(
181  "import" => "PROFIL;TST_PRF_RESET_DYNUSER;;RESET;view=tst_user;edit=tst_user",
182  "profile" => "TST_PRF_RESET_DYNUSER",
183  "recomputed" => true
184  )
185  ) ,
186  array(
187  array(
188  "import" => "PROFIL;TST_PRF_RESET_DYNUSER;;RESET;view=tst_user;delete=tst_user",
189  "profile" => "TST_PRF_RESET_DYNUSER",
190  "recomputed" => true
191  )
192  ) ,
193  // Check that SET recomputes profiled documents only if changed
194  array(
195  array(
196  "import" => "PROFIL;TST_PRF_SET_DYNUSER;;SET;view=tst_user;edit=tst_user",
197  "profile" => "TST_PRF_SET_DYNUSER",
198  "recomputed" => false
199  )
200  ) ,
201  array(
202  array(
203  "import" => "PROFIL;TST_PRF_SET_DYNUSER;;SET;view=tst_user;delete=tst_user",
204  "profile" => "TST_PRF_SET_DYNUSER",
205  "recomputed" => true
206  )
207  )
208  );
209  }
210  private function getViews($famid)
211  {
213  simpleQuery(self::$dbaccess, "select id, name, profid, views from doc$famid", $r);
214  return $r;
215  }
216  public function dataSearchDocument()
217  {
218  return array(
219 
220  array(
221  "profil" => "PU_data_dcp_setprofildata.ods",
222  "famName" => "TST_PROFIL",
223  "admin",
224  7
225  ) ,
226  array(
227  "profil" => "PU_data_dcp_setprofildata.ods",
228  "famName" => "TST_PROFIL",
229  "john",
230  6
231  ) ,
232  array(
233  "profil" => "PU_data_dcp_setprofildata.ods",
234  "famName" => "TST_PROFIL",
235  "jane",
236  6
237  )
238  );
239  }
240  public function dataProfilChange()
241  {
242  return array(
243  array(
244  "TST_DOCPRFBASIC",
245  "TST_PRFJOHN",
246  "john",
247  "PU_data_dcp_profilJohn.ods",
248  array(
249  "view" => true,
250  "edit" => false,
251  "delete" => true
252  )
253  ) ,
254  array(
255  "TST_DOCPRFBASIC",
256  "TST_PRFJOHN_BIS",
257  "john",
258  "PU_data_dcp_profilJohn.ods",
259  array(
260  "view" => true,
261  "edit" => false,
262  "delete" => true
263  )
264  ) ,
265  array(
266  "TST_DOCPRFBASIC",
267  "TST_PRFJOHN",
268  "jane",
269  "PU_data_dcp_profilJohn.ods",
270  array(
271  "view" => true,
272  "edit" => false,
273  "delete" => false
274  )
275  ) ,
276  array(
277  "TST_DOCPRFBASIC",
278  "TST_PRFJOHN_BIS",
279  "jane",
280  "PU_data_dcp_profilJohn.ods",
281  array(
282  "view" => true,
283  "edit" => false,
284  "delete" => false
285  )
286  ) ,
287  array(
288  "TST_DOCPRFUSERJANE",
289  "TST_PRFDYNUSER",
290  "jane",
291  "PU_data_dcp_profilUser.ods",
292  array(
293  "view" => true,
294  "edit" => false,
295  "delete" => true
296  )
297  ) ,
298  array(
299  "TST_DOCPRFUSERJANE",
300  "TST_PRFDYNUSER",
301  "john",
302  "PU_data_dcp_profilUser.ods",
303  array(
304  "view" => false,
305  "edit" => false,
306  "delete" => false
307  )
308  ) ,
309  array(
310  "TST_DOCPRFUSERJOHN",
311  "TST_PRFDYNUSER",
312  "john",
313  "PU_data_dcp_profilUser.ods",
314  array(
315  "view" => true,
316  "edit" => false,
317  "delete" => true
318  )
319  ) ,
320  array(
321  "TST_DOCPRFUSERJOHN",
322  "TST_PRFDYNUSER",
323  "jane",
324  "PU_data_dcp_profilUser.ods",
325  array(
326  "view" => false,
327  "edit" => false,
328  "delete" => false
329  )
330  ) ,
331  array(
332  "TST_DOCPRFUSERJOHN",
333  "TST_PRFDYNUSER",
334  "john",
335  "PU_data_dcp_profilUserStatic.ods",
336  array(
337  "view" => true,
338  "edit" => false,
339  "delete" => false
340  )
341  ) ,
342  array(
343  "TST_DOCPRFUSERJOHN",
344  "TST_PRFDYNUSER",
345  "jane",
346  "PU_data_dcp_profilUserStatic.ods",
347  array(
348  "view" => true,
349  "edit" => false,
350  "delete" => false
351  )
352  )
353  );
354  }
355 
356  public function dataProfilComputing()
357  {
358  return array(
359  array(
360 
361  "TST_DOCPRFBASIC",
362  "TST_PRFJOHN",
363  "jane",
364  array(
365  "view" => true,
366  "edit" => false,
367  "delete" => false
368  )
369  ) ,
370  array(
371 
372  "TST_DOCPRFBASIC",
373  "TST_PRFJOHN_BIS",
374  "jane",
375  array(
376  "view" => true,
377  "edit" => false,
378  "delete" => false
379  )
380  ) ,
381 
382  array(
383 
384  "TST_DOCPRFBASIC",
385  "TST_PRFJOHN",
386  "john",
387  array(
388  "view" => true,
389  "edit" => true,
390  "delete" => false
391  )
392  ) ,
393  array(
394 
395  "TST_DOCPRFBASIC",
396  "TST_PRFJOHN_BIS",
397  "john",
398  array(
399  "view" => true,
400  "edit" => true,
401  "delete" => false
402  )
403  ) ,
404 
405  array(
406 
407  "TST_DOCPRFBASIC",
408  "TST_PRFJANE",
409  "john",
410  array(
411  "view" => true,
412  "edit" => false,
413  "delete" => false
414  )
415  ) ,
416  array(
417 
418  "TST_DOCPRFBASIC",
419  "TST_PRFJANE_ACCOUNT",
420  "john",
421  array(
422  "view" => true,
423  "edit" => false,
424  "delete" => false
425  )
426  ) ,
427  array(
428 
429  "TST_DOCPRFBASIC",
430  "TST_PRFJANE_DOCUMENT",
431  "john",
432  array(
433  "view" => true,
434  "edit" => false,
435  "delete" => false
436  )
437  ) ,
438  array(
439  "TST_DOCPRFBASIC",
440  "TST_PRFJANE_MIXED",
441  "john",
442  array(
443  "view" => true,
444  "edit" => false,
445  "delete" => false
446  )
447  ) ,
448  array(
449  "TST_DOCPRFBASIC",
450  "TST_PRFJANE_MIXEDNOTHING",
451  "john",
452  array(
453  "view" => true,
454  "edit" => false,
455  "delete" => false
456  )
457  ) ,
458  array(
459 
460  "TST_DOCPRFBASIC",
461  "TST_PRFJANE",
462  "jane",
463  array(
464  "view" => true,
465  "edit" => true,
466  "delete" => false
467  )
468  ) ,
469  array(
470  "TST_DOCPRFUSERJANE",
471  "TST_PRFDYNUSER",
472  "jane",
473  array(
474  "view" => true,
475  "edit" => true,
476  "delete" => false
477  )
478  ) ,
479  array(
480  "TST_DOCPRFUSERJANE",
481  "TST_PRFDYNUSER_ATTR",
482  "jane",
483  array(
484  "view" => true,
485  "edit" => true,
486  "delete" => false,
487  "send" => true
488  )
489  ) ,
490  array(
491  "TST_DOCPRFUSERJANE",
492  "TST_PRFDYNUSER_ACCOUNT",
493  "jane",
494  array(
495  "view" => true,
496  "edit" => true,
497  "delete" => false,
498  "send" => true,
499  "unlock" => false
500  )
501  ) ,
502  array(
503  "TST_DOCPRFUSERJANE",
504  "TST_PRFDYNUSER_ACCOUNT",
505  "john",
506  array(
507  "view" => false,
508  "edit" => true,
509  "delete" => false,
510  "send" => true,
511  "unlock" => true
512  )
513  ) ,
514  array(
515 
516  "TST_DOCPRFUSERJANE",
517  "TST_PRFDYNUSER",
518  "john",
519  array(
520  "view" => false,
521  "edit" => false,
522  "delete" => false
523  )
524  ) ,
525  array(
526 
527  "TST_DOCPRFUSERJOHN",
528  "TST_PRFDYNUSER",
529  "jane",
530  array(
531  "view" => false,
532  "edit" => false,
533  "delete" => false
534  )
535  ) ,
536  array(
537 
538  "TST_DOCPRFUSERJOHN",
539  "TST_PRFDYNUSER",
540  "john",
541  array(
542  "view" => true,
543  "edit" => true,
544  "delete" => false
545  )
546  ) ,
547  array(
548  "TST_DOCPRFUSERALL",
549  "TST_PRFDYNGROUP",
550  "jane",
551  array(
552  "view" => true,
553  "edit" => true,
554  "delete" => false
555  )
556  ) ,
557  array(
558  "TST_DOCPRFUSERALL",
559  "TST_PRFDYNGROUP",
560  "john",
561  array(
562  "view" => true,
563  "edit" => true,
564  "delete" => false
565  )
566  ) ,
567  array(
568  "TST_DOCPRFMGROUP",
569  "TST_PRFDYNMGROUP",
570  "jane",
571  array(
572  "view" => true,
573  "edit" => false,
574  "delete" => true
575  )
576  ) ,
577  array(
578  "TST_DOCPRFMGROUP",
579  "TST_PRFDYNMGROUP",
580  "john",
581  array(
582  "view" => true,
583  "edit" => false,
584  "delete" => true
585  )
586  ) ,
587  array(
588  "TST_DOCPRFMUSER",
589  "TST_PRFDYNMUSER",
590  "jane",
591  array(
592  "view" => true,
593  "edit" => true,
594  "delete" => false
595  )
596  ) ,
597  array(
598  "TST_DOCPRFMUSER",
599  "TST_PRFDYNMUSER",
600  "john",
601  array(
602  "view" => true,
603  "edit" => true,
604  "delete" => false
605  )
606  ) ,
607  array(
608  "TST_DOCPRFUSERS",
609  "TST_PRFDYNUSERS",
610  "jane",
611  array(
612  "view" => true,
613  "edit" => true,
614  "delete" => false
615  )
616  ) ,
617  array(
618  "TST_DOCPRFUSERS",
619  "TST_PRFDYNUSERS",
620  "john",
621  array(
622  "view" => true,
623  "edit" => true,
624  "delete" => false
625  )
626  )
627  );
628  }
629 }
static sudo($login)
testProfilComputing($docName, $prfName, $login, $aclAttendees)
testSearchControlled($docName, $prfName, $login, $newPrfAcl, $aclAttendees)
static importDocument($file)
if($famId) $s
testProfilDynamicChange($docName, $prfName, $login, $newPrfAcl, $aclAttendees)
$login
Definition: dav.php:40
getFamIdFromName($dbaccess, $name)
testProfilRecomputeProfiledDocuments($data)
new_Doc($dbaccess, $id= '', $latest=false)
testSearchView($profFile, $famName, $login, $expectNumber)
$dbaccess
Definition: checkVault.php:17
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
$data
← centre documentaire © anakeen