Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_doccontrolsubstitute.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_substitute_family.ods"
27  );
28  }
29 
30  private function getSearchName(\SearchDoc & $s)
31  {
32  $names = array();
33  while ($doc = $s->getNextDoc()) {
34  $names[] = $doc->name;
35  }
36  return $names;
37  }
38  /**
39  * @dataProvider dataControlIncumbent
40  */
41  public function testControlIncumbent($login, array $incumbents, array $expectedDocNames)
42  {
43  $nu = new \Account();
44  $nu->setLoginName($login);
45 
46  foreach ($incumbents as $aIncumbent) {
47  $u = new \Account();
48  $u->setLoginName($aIncumbent);
49  if (!$u->isAffected()) $this->markTestIncomplete("cannot find $aIncumbent account");
50  $err = $u->setSubstitute($nu->id);
51  $this->assertEmpty($err, "substitute error: $err");
52  }
53 
54  $this->sudo($login);
55  $s = new \SearchDoc(self::$dbaccess, 'TST_SUBSTITUTE1');
56  $s->setObjectReturn();
57  $s->search();
58  $err = $s->getError();
59  $this->assertEmpty($err, "substitute search error: $err");
60 
61  $names = $this->getSearchName($s);
62 
63  $this->assertEquals(count($expectedDocNames) , $s->count() , sprintf("not expected items:\n\tfound : %s \n\texpect : %s", implode(',', $names) , implode(',', $expectedDocNames)));
64 
65  $this->assertEquals(count($expectedDocNames) , count(array_intersect($names, $expectedDocNames)) , sprintf("not expected items.\n\t found : %s\n\t expect : %s", implode(',', $names) , implode(',', $expectedDocNames)));
66  $this->exitSudo();
67  }
68  /**
69  * @dataProvider dataControlSubstitute
70  */
71  public function testControlSubstitute(array $substituts, array $expectedDocNamesByLogin)
72  {
73 
74  foreach ($substituts as $incumbent => $aSubstitute) {
75  $u = new \Account();
76  $u->setLoginName($incumbent);
77  if (!$u->isAffected()) $this->markTestIncomplete("cannot find $incumbent account");
78  $err = $u->setSubstitute($aSubstitute);
79  $this->assertEmpty($err, "substitute error : $err");
80  }
81  foreach ($expectedDocNamesByLogin as $login => $expectNames) {
82  $this->sudo($login);
83  $s = new \SearchDoc(self::$dbaccess, 'TST_SUBSTITUTE1');
84  $s->setObjectReturn();
85  $s->search();
86  $err = $s->getError();
87  $this->assertEmpty($err, "substitute search error");
88 
89  $names = $this->getSearchName($s);
90 
91  $this->assertEquals(count($expectNames) , $s->count() , sprintf("not expected items:\n\tfound : %s \n\texpect : %s", implode(',', $names) , implode(',', $expectNames)));
92 
93  $this->assertEquals(count($expectNames) , count(array_intersect($names, $expectNames)) , sprintf("not expected items.\n\t found : %s\n\t expect : %s", implode(',', $names) , implode(',', $expectNames)));
94  $this->exitSudo();
95  }
96  }
97  /**
98  * @dataProvider dataControlReSubstitute
99  */
100  public function testControlReSubstitute(array $previousSubstitues, array $substituts, array $expectedDocNamesByLogin)
101  {
102 
103  foreach ($previousSubstitues as $incumbent => $aSubstitute) {
104  $u = new \Account();
105  $u->setLoginName($incumbent);
106  if (!$u->isAffected()) $this->markTestIncomplete("cannot find $incumbent account");
107  $err = $u->setSubstitute($aSubstitute);
108  $this->assertEmpty($err, "substitute error : $err");
109  }
110  $this->testControlSubstitute($substituts, $expectedDocNamesByLogin);
111  }
112  /**
113  * @dataProvider dataControlStrict
114  */
115  public function testControlStrict($login, array $incumbents, array $expectedDocNames)
116  {
117  $nu = new \Account();
118  $nu->setLoginName($login);
119  foreach ($incumbents as $aIncumbent) {
120  $u = new \Account();
121  $u->setLoginName($aIncumbent);
122  if (!$u->isAffected()) $this->markTestIncomplete("cannot find $aIncumbent account");
123  $err = $u->setSubstitute($nu->id);
124  $this->assertEmpty($err, "substitute error : $err");
125  }
126  clearCacheDoc();
127  $this->sudo($login);
128  foreach ($expectedDocNames as $docName => $expectControl) {
129  $d = new_doc(self::$dbaccess, $docName);
130  $this->assertEquals($expectControl["normal"], $d->control('view', false) == "", sprintf("not correct normal control view for %s", $docName));
131 
132  $this->assertEquals($expectControl["strict"], $d->control('view', true) == "", sprintf("not correct strict control view for %s", $docName));
133  }
134  $this->exitSudo();
135  }
136 
137  public function dataControlReSubstitute()
138  {
139  return array(
140  array(
141 
142  "previousSubstitutes" => array(
143  "ured" => "ublue",
144  "ublue" => "ured"
145  ) ,
146  "substitutes" => array(
147  "ured" => "uyellow",
148  "ublue" => "uyellow"
149  ) ,
150  "expect" => array(
151  "ured" => array(
152  'TST_D1',
153  'TST_D2',
154  'TST_D6'
155  ) ,
156  "ublue" => array(
157  'TST_D2',
158  'TST_D3',
159  'TST_D4',
160  'TST_D7'
161  ) ,
162  "uyellow" => array(
163  'TST_D1',
164  'TST_D2',
165  'TST_D3',
166  'TST_D4',
167  'TST_D5',
168  'TST_D6',
169  'TST_D7',
170  'TST_D8'
171  )
172  )
173  )
174  );
175  }
176  public function dataControlSubstitute()
177  {
178  return array(
179  array(
180  "substitutes" => array(
181  "ured" => "uyellow",
182  "ublue" => "uyellow"
183  ) ,
184  "expect" => array(
185  "ured" => array(
186  'TST_D1',
187  'TST_D2',
188  'TST_D6'
189  ) ,
190  "ublue" => array(
191  'TST_D2',
192  'TST_D3',
193  'TST_D4',
194  'TST_D7'
195  ) ,
196  "uyellow" => array(
197  'TST_D1',
198  'TST_D2',
199  'TST_D3',
200  'TST_D4',
201  'TST_D5',
202  'TST_D6',
203  'TST_D7',
204  'TST_D8'
205  )
206  )
207  ) ,
208  array(
209  "substitutes" => array(
210  "ured" => "ublue",
211  "ublue" => "uyellow"
212  ) ,
213  "expect" => array(
214  "ured" => array(
215  'TST_D1',
216  'TST_D2',
217  'TST_D6'
218  ) ,
219  "ublue" => array(
220  'TST_D1',
221  'TST_D2',
222  'TST_D6',
223  'TST_D3',
224  'TST_D4',
225  'TST_D7'
226  ) ,
227  "uyellow" => array(
228  'TST_D2',
229  'TST_D3',
230  'TST_D4',
231  'TST_D5',
232  'TST_D7',
233  'TST_D8'
234  )
235  )
236  ) ,
237  array(
238  "substitutes" => array(
239  "ured" => "ublue",
240  "uyellow" => "ured"
241  ) ,
242  "expect" => array(
243  "ured" => array(
244  'TST_D1',
245  'TST_D2',
246  'TST_D5',
247  'TST_D8',
248  'TST_D6'
249  ) ,
250  "ublue" => array(
251  'TST_D2',
252  'TST_D3',
253  'TST_D4',
254  'TST_D7',
255  'TST_D1',
256  'TST_D6'
257  ) ,
258  "uyellow" => array(
259  'TST_D5',
260  'TST_D8'
261  )
262  )
263  )
264  );
265  }
266 
267  public function dataControlIncumbent()
268  {
269  return array(
270  array(
271  "login" => "ured",
272  "incumbent" => array() ,
273  "expect" => array(
274  'TST_D1',
275  'TST_D2',
276  'TST_D6'
277  )
278  ) ,
279  array(
280  "login" => "ublue",
281  "incumbent" => array() ,
282  "expect" => array(
283  'TST_D2',
284  'TST_D3',
285  'TST_D4',
286  'TST_D7'
287  )
288  ) ,
289  array(
290  "login" => "uyellow",
291  "incumbent" => array() ,
292  "expect" => array(
293  'TST_D5',
294  'TST_D8'
295  )
296  ) ,
297  array(
298  "login" => "uyellow",
299  "incumbent" => array(
300  "ured"
301  ) ,
302  "expect" => array(
303  'TST_D1',
304  'TST_D2',
305  'TST_D6',
306  'TST_D8',
307  'TST_D5'
308  )
309  ) ,
310  array(
311  "login" => "uyellow",
312  "incumbent" => array(
313  "ublue"
314  ) ,
315  "expect" => array(
316  'TST_D2',
317  'TST_D3',
318  'TST_D4',
319  'TST_D7',
320  'TST_D8',
321  'TST_D5'
322  )
323  ) ,
324  array(
325  "login" => "uyellow",
326  "incumbent" => array(
327  "ublue",
328  "ured"
329  ) ,
330  "expect" => array(
331  'TST_D1',
332  'TST_D2',
333  'TST_D3',
334  'TST_D4',
335  'TST_D6',
336  'TST_D7',
337  'TST_D8',
338  'TST_D5'
339  )
340  )
341  );
342  }
343 
344  public function dataControlStrict()
345  {
346  return array(
347  array(
348  "login" => "ured",
349  "incumbent" => array() ,
350  "expect" => array(
351  'TST_D1' => array(
352  "strict" => true,
353  "normal" => true
354  ) ,
355  'TST_D2' => array(
356  "strict" => true,
357  "normal" => true
358  ) ,
359  'TST_D3' => array(
360  "strict" => false,
361  "normal" => false
362  ) ,
363  'TST_D4' => array(
364  "strict" => false,
365  "normal" => false
366  ) ,
367  'TST_D5' => array(
368  "strict" => false,
369  "normal" => false
370  ) ,
371  'TST_D6' => array(
372  "strict" => true,
373  "normal" => true
374  ) ,
375  'TST_D7' => array(
376  "strict" => false,
377  "normal" => false
378  ) ,
379  'TST_D8' => array(
380  "strict" => false,
381  "normal" => false
382  ) ,
383  )
384  ) ,
385  array(
386  "login" => "uyellow",
387  "incumbent" => array(
388  "ured"
389  ) ,
390  "expect" => array(
391  'TST_D1' => array(
392  "strict" => false,
393  "normal" => true
394  ) ,
395  'TST_D2' => array(
396  "strict" => false,
397  "normal" => true
398  ) ,
399  'TST_D3' => array(
400  "strict" => false,
401  "normal" => false
402  ) ,
403  'TST_D4' => array(
404  "strict" => false,
405  "normal" => false
406  ) ,
407  'TST_D5' => array(
408  "strict" => true,
409  "normal" => true
410  ) ,
411  'TST_D6' => array(
412  "strict" => false,
413  "normal" => true
414  ) ,
415  'TST_D7' => array(
416  "strict" => false,
417  "normal" => false
418  ) ,
419  'TST_D8' => array(
420  "strict" => true,
421  "normal" => true
422  ) ,
423  )
424  )
425  );
426  }
427 }
static sudo($login)
testControlStrict($login, array $incumbents, array $expectedDocNames)
clearCacheDoc($id=0)
testControlSubstitute(array $substituts, array $expectedDocNamesByLogin)
if($famId) $s
$d
Definition: dav.php:77
setObjectReturn($returnobject=true)
testControlIncumbent($login, array $incumbents, array $expectedDocNames)
$login
Definition: dav.php:40
testControlReSubstitute(array $previousSubstitues, array $substituts, array $expectedDocNamesByLogin)
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen