Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_searchaccount.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 array|string
22  */
23  protected static function getCommonImportFile()
24  {
25  return array(
26  "PU_data_dcp_searchaccount.ods"
27  );
28  }
29  /**
30  * @dataProvider dataSearchByRole
31  */
32  public function testSearchByRole($roleFilter, $groupFilter, array $expectedAccounts)
33  {
34  $s = new \SearchAccount();
35  if ($roleFilter) $s->addRoleFilter($roleFilter);
36  if ($groupFilter) $s->addGroupFilter($groupFilter);
37  $s->setReturnType($s::returnAccount);
38  /**
39  * @var \AccountList $al
40  */
41  $al = $s->search();
42 
43  $expectedAccounts = array_map("mb_strtolower", $expectedAccounts);
44  $loginFounds = array();
45 
46  $lLogin = $this->getAccounlLogin($al);
47  /**
48  * @var \Account $account
49  */
50  foreach ($al as $account) {
51  $login = $account->login;
52  $this->assertTrue(in_array($login, $expectedAccounts) , sprintf("login <%s> must not be present : %s", $login, $lLogin));
53  $loginFounds[] = $login;
54  }
55 
56  foreach ($expectedAccounts as $expectLogin) {
57  $this->assertTrue(in_array($expectLogin, $loginFounds) , sprintf("login <%s> must be present", $expectLogin));
58  }
59  }
60 
61  private function getAccounlLogin(\AccountList $al)
62  {
63  $logins = array();
64  /**
65  * @var \Account $account
66  */
67  foreach ($al as $account) {
68  $logins[] = $account->login;
69  }
70  return implode(',', $logins);
71  }
72  /**
73  * @dataProvider dataSearchByRole
74  */
75  public function testSearchByRoleDocument($roleFilter, $groupFilter, array $expectedAccounts)
76  {
77  $s = new \SearchAccount();
78  if ($roleFilter) $s->addRoleFilter($roleFilter);
79  if ($groupFilter) $s->addGroupFilter($groupFilter);
80  $s->setReturnType($s::returnDocument);
81  /**
82  * @var \DocumentList $al
83  */
84  $al = $s->search();
85 
86  $expectedAccounts = array_map("mb_strtolower", $expectedAccounts);
87  $loginFounds = array();
88  /**
89  * @var \Doc $doc
90  */
91  foreach ($al as $doc) {
92  $login = '';
93  if ($doc->getAttribute("us_login")) $login = $doc->getRawValue("us_login");
94  elseif ($doc->getAttribute("role_login")) $login = $doc->getRawValue("role_login");
95  $this->assertTrue(in_array($login, $expectedAccounts) , sprintf("login <%s> #%s must not be present", $login, $doc->id));
96  $loginFounds[] = $login;
97  }
98 
99  foreach ($expectedAccounts as $expectLogin) {
100  $this->assertTrue(in_array($expectLogin, $loginFounds) , sprintf("login <%s> must be present", $expectLogin));
101  }
102  }
103  /**
104  * @dataProvider dataCountSearchByRole
105  */
106  public function testCountSearchByRole($slice, $start, $order, $roleFilter, array $expectedAccounts)
107  {
108  $s = new \SearchAccount();
109  $s->addRoleFilter($roleFilter);
110  $s->setSlice($slice);
111  $s->setStart($start);
112  $s->setOrder($order);
113  $s->setReturnType($s::returnAccount);
114  /**
115  * @var \AccountList $al
116  */
117  $al = $s->search();
118 
119  $expectedAccounts = array_map("mb_strtolower", $expectedAccounts);
120  /**
121  * @var \Account $account
122  */
123  $k = 0;
124  foreach ($al as $account) {
125  $login = $account->login;
126  $this->assertEquals($expectedAccounts[$k], $login, sprintf("%s login must not be present", $login));
127  $k++;
128  }
129  }
130  /**
131  * @dataProvider dataFilterSearch
132  */
133  public function testFilterSearch($filter, $filterArg, $accountType, array $expectedAccounts)
134  {
135  $s = new \SearchAccount();
136  $s->addFilter($filter, $filterArg);
137  if ($accountType) $s->setTypeFilter($accountType);
138  $s->setOrder("login");
139  $s->setReturnType($s::returnAccount);
140  /**
141  * @var \AccountList $al
142  */
143  $al = $s->search();
144 
145  $expectedAccounts = array_map("mb_strtolower", $expectedAccounts);
146  $ll = $this->getAccounlLogin($al);
147  /**
148  * @var \Account $account
149  */
150  $k = 0;
151  foreach ($al as $account) {
152  $login = $account->login;
153  $this->assertEquals($expectedAccounts[$k], $login, sprintf("%s login must not be present : found %s", $login, $ll));
154  $k++;
155  }
156  $this->assertEquals(count($expectedAccounts) , count($al) , sprintf("not same count expected %d : %s", count($expectedAccounts) , $ll));
157  }
158  /**
159  * @dataProvider dataFilterViewControl
160  */
161  public function testFilterViewControl($login, $filter, $filterArg, array $expectedAccounts)
162  {
163  $this->sudo($login);
164  $s = new \SearchAccount();
165  $s->addFilter($filter, $filterArg);
166  $s->setOrder("login");
167  $s->overrideViewControl(false);
168  $s->setReturnType($s::returnAccount);
169  /**
170  * @var \AccountList $al
171  */
172  $al = $s->search();
173 
174  $expectedAccounts = array_map("mb_strtolower", $expectedAccounts);
175  $ll = $this->getAccounlLogin($al);
176  /**
177  * @var \Account $account
178  */
179  $k = 0;
180  foreach ($al as $account) {
181  $login = $account->login;
182  $this->assertEquals($expectedAccounts[$k], $login, sprintf("%s login must not be present : found %s", $login, $ll));
183  $k++;
184  }
185 
186  $this->assertEquals(count($expectedAccounts) , count($al) , sprintf("not same count expected %d : %s", count($expectedAccounts) , $ll));
187  $this->exitSudo();
188  }
189  /**
190  * @dataProvider dataDocName2Login
191  */
192  public function testDocName2Login($docName, $login)
193  {
194  $this->assertEquals(mb_strtolower($login) , \SearchAccount::getLoginFromDocName($docName) , "logical name convert to login failed");
195  }
196  /**
197  * @dataProvider dataFilterByFamily
198  */
199  public function testFilterByFamily($family, $filter, $expectedCount)
200  {
201  $this->sudo("tstlogina1");
202  $s = new \SearchAccount();
203  $s->addFilter($filter);
204  $s->setOrder("login");
205  $s->overrideViewControl(false);
206  $s->setReturnType($s::returnAccount);
207  $s->filterFamily($family);
208  /**
209  * @var \AccountList $al
210  */
211  $al = $s->search();
212 
213  $ll = $this->getAccounlLogin($al);
214 
215  $this->assertEquals($expectedCount, count($al) , sprintf("not same count expected %d : %s", $expectedCount, $ll));
216  $this->exitSudo();
217  }
218  /**
219  * @dataProvider dataFilterByFamily
220  */
221  public function testFilterByFamilyNoView($family, $filter, $expectedCount)
222  {
223  $s = new \SearchAccount();
224  $s->addFilter($filter);
225  $s->setOrder("login");
226  $s->overrideViewControl(true);
227  $s->setReturnType($s::returnAccount);
228  $s->filterFamily($family);
229  /**
230  * @var \AccountList $al
231  */
232  $al = $s->search();
233 
234  $ll = $this->getAccounlLogin($al);
235 
236  $this->assertEquals($expectedCount, count($al) , sprintf("not same count expected %d : %s", $expectedCount, $ll));
237  }
238 
239  public function dataFilterByFamily()
240  {
241  return array(
242  array(
243  "family" => "TST_uSER",
244  "filter" => " login ~ '^tstloginu'",
245  "expect" => 7
246  ) ,
247  array(
248  "family" => "TST_OTHERuSER",
249  "filter" => " login ~ '^tstloginu'",
250  "expect" => 1
251  )
252  );
253  }
254  public function dataFilterViewControl()
255  {
256  return array(
257  array(
258  "login" => "tstLoginA1",
259  "filter" => "login ~ '%s'",
260  "arg" => '^tst.*1$',
261  array(
262  "tstlogina1",
263  "tstloginr1",
264  "tstloginu1",
265  "tstloginu11"
266  )
267  ) ,
268  array(
269  "login" => "tstLoginA2",
270  "filter" => "login ~ '%s'",
271  "arg" => '^tst.*1$',
272  array(
273  "tstlogina1",
274  "tstloging1",
275  "tstloginu1"
276  )
277  ) ,
278 
279  array(
280  "login" => "tstLoginU1",
281  "filter" => "login ~ '%s'",
282  "arg" => '^tst.*1$',
283  array()
284  )
285  );
286  }
287  public function dataFilterSearch()
288  {
289  return array(
290  array(
291  "filter" => "login = lower('%s')",
292  "arg" => 'tstLoginU1',
293  "type" => 0,
294  array(
295  "tstLoginU1"
296  )
297  ) ,
298  array(
299  "filter" => "login ~ '^tst.*1$'",
300  "arg" => '^tst.*1$',
301  "type" => \SearchAccount::userType,
302  array(
303  "tstLoginA1",
304  "tstLoginU1",
305  "tstLoginU11"
306  )
307  ) ,
308  array(
309  "filter" => "login ~ '%s'",
310  "arg" => '^tst.*1$',
311  "type" => \SearchAccount::groupType,
312  array(
313  "tstLoginG1"
314  )
315  ) ,
316  array(
317  "filter" => "login ~ '%s'",
318  "arg" => '^tst.*1$',
319  "type" => \SearchAccount::roleType,
320  array(
321  "tstLoginR1"
322  )
323  ) ,
324  array(
325  "filter" => "login ~ '%s'",
326  "arg" => '^tst.*1$',
328  array(
329  "tstLoginG1",
330  "tstLoginR1"
331  )
332  ) ,
333  array(
334  "filter" => "login ~ '%s'",
335  "arg" => '^tst.*1$',
337  array(
338  "tstLoginA1",
339  "tstLoginG1",
340  "tstLoginU1",
341  "tstLoginU11"
342  )
343  ) ,
344  array(
345  "filter" => "login ~ '%s'",
346  "arg" => '^tst.*1$',
348  array(
349  "tstLoginA1",
350  "tstLoginR1",
351  "tstLoginU1",
352  "tstLoginU11"
353  )
354  )
355  );
356  }
357 
358  public function dataDocName2Login()
359  {
360  return array(
361  array(
362  "TST_ROLE1",
363  "tstLoginR1"
364  ) ,
365  array(
366  "TST_GROUP1",
367  "tstLoginG1"
368  ) ,
369  array(
370  "TST_USER1",
371  "tstLoginU1"
372  )
373  );
374  }
375  public function dataCountSearchByRole()
376  {
377  return array(
378  array(
379  "slice" => "ALL",
380  "start" => 0,
381  "order" => "id",
382  "role" => "tstLoginR1",
383  array(
384  "tstLoginU1",
385  "tstLoginU2",
386  "tstLoginU3",
387  "tstLoginU4",
388  "tstLoginU5"
389  )
390  ) ,
391  array(
392  "slice" => "ALL",
393  "start" => 0,
394  "order" => "id desc",
395  "role" => "tstLoginR1",
396  array(
397  "tstLoginU5",
398  "tstLoginU4",
399  "tstLoginU3",
400  "tstLoginU2",
401  "tstLoginU1"
402  )
403  ) ,
404  array(
405  "slice" => "2",
406  "start" => 0,
407  "order" => "login",
408  "role" => "tstLoginR1",
409  array(
410  "tstLoginU1",
411  "tstLoginU2"
412  )
413  ) ,
414  array(
415  "slice" => 2,
416  "start" => 2,
417  "order" => "login",
418  "role" => "tstLoginR1",
419  array(
420  "tstLoginU3",
421  "tstLoginU4"
422  )
423  )
424  );
425  }
426 
427  public function dataSearchByRole()
428  {
429  return array(
430  array(
431  "role" => "tstLoginR1",
432  "group" => "",
433  array(
434  "tstLoginU1",
435  "tstLoginU2",
436  "tstLoginU3",
437  "tstLoginU4",
438  "tstLoginU5"
439  )
440  ) ,
441 
442  array(
443  "role" => "tstLoginR2",
444  "group" => "",
445  array(
446  "tstLoginU2",
447  "tstLoginU3",
448  "tstLoginU4",
449  "tstLoginU6"
450  )
451  ) ,
452 
453  array(
454  "role" => "tstLoginR3",
455  "group" => "",
456  array(
457  "tstLoginU3",
458  "tstLoginU4",
459  "tstLoginU7"
460  )
461  ) ,
462 
463  array(
464  "role" => "tstLoginR3 tstLoginR2",
465  "group" => "",
466  array(
467  "tstLoginU2",
468  "tstLoginU3",
469  "tstLoginU4",
470  "tstLoginU6",
471  "tstLoginU7"
472  )
473  ) ,
474 
475  array(
476  "role" => "tstLoginR3 tstLoginR1 tstLoginR2",
477  "group" => "",
478  array(
479  "tstLoginU1",
480  "tstLoginU2",
481  "tstLoginU3",
482  "tstLoginU4",
483  "tstLoginU5",
484  "tstLoginU6",
485  "tstLoginU7"
486  )
487  ) ,
488 
489  array(
490  "role" => "tstLoginR4",
491  "group" => "",
492  array(
493  "tstLoginG1",
494  "tstLoginU10",
495  "tstLoginU11",
496  "tstLoginU15",
497  "tstLoginU4"
498  )
499  ) ,
500  array(
501  "role" => "",
502  "group" => "tstLoginG1",
503  array(
504  "tstLoginU10",
505  "tstLoginU11",
506  "tstLoginU15"
507  )
508  ) ,
509 
510  array(
511  "role" => "",
512  "group" => "tstLoginG2",
513  array(
514  "tstLoginU12",
515  "tstLoginU13",
516  "tstLoginU15"
517  )
518  ) ,
519 
520  array(
521  "role" => "",
522  "group" => "tstLoginG3",
523  array(
524  "tstLoginU14",
525  "tstLoginU15"
526  )
527  ) ,
528 
529  array(
530  "role" => "",
531  "group" => "tstLoginG3 tstLoginG2 tstLoginG1",
532  array(
533  "tstLoginU10",
534  "tstLoginU11",
535  "tstLoginU12",
536  "tstLoginU13",
537  "tstLoginU14",
538  "tstLoginU15"
539  )
540  ) ,
541 
542  array(
543  "role" => "tstLoginR3",
544  "group" => "tstLoginG3",
545  array(
546  "tstLoginU14",
547  "tstLoginU15",
548  "tstLoginU3",
549  "tstLoginU4",
550  "tstLoginU7"
551  )
552  )
553  );
554  }
555 }
static sudo($login)
if($famId) $s
$login
Definition: dav.php:40
$account
Definition: guest.php:36
static getLoginFromDocName($name)
← centre documentaire © anakeen