Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_groupaccount.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 require_once 'PU_testcase_dcp_commonfamily.php';
13 
15 {
16  protected static function getCommonImportFile()
17  {
18  return array(
19  'PU_data_dcp_groupaccount.ods'
20  );
21  }
22  /**
23  * @dataProvider dataClearGroup
24  * @param $groupId
25  * @param $expectedContents
26  */
27  public function testClearGroup($groupId, $expectedContents)
28  {
29  /**
30  * @var \Dcp\Core\GroupAccount $group
31  */
32  $group = new_Doc('', $groupId, true);
33  $this->assertTrue($group->isAlive() , sprintf("Could not get group with id '%s'.", $groupId));
34  $err = $group->Clear();
35  $this->assertEmpty($err, sprintf("Clear() on group with id '%s' returned unexpected error message: %s", $groupId, $err));
36  foreach ($expectedContents as $expectedContent) {
37  $subjectId = $expectedContent['subject'];
38  $subject = new_Doc('', $subjectId, true);
39  $this->assertTrue($subject->isAlive() , sprintf("Expected subject with id '%s' not found.", $subjectId));
40  $check = $expectedContent['check'];
41  $argv = isset($expectedContent['argv']) ? $expectedContent['argv'] : null;
42  switch ($check) {
43  case 'is-empty':
44  /**
45  * @var \Dcp\Core\GroupAccount $subject
46  */
47  $this->assertTrue(is_a($subject, '\Dcp\Core\GroupAccount') , sprintf("Subject with id '%s' is not of expected class '\\Dcp\\Core\\GroupAccount'.", $subjectId));
48  $content = $subject->getContent(false);
49  $this->assertCount(0, $content, sprintf("Unexpected content's count (%s) for subject with id '%s'.", count($content) , $subjectId));
50  break;
51 
52  case 'has-no-parent':
53  /**
54  * @var \Dcp\Core\UserAccount $subject
55  */
56  $this->assertTrue(is_a($subject, 'Dcp\Core\UserAccount') , sprintf("Subject with id '%s' is not of expected class 'Dcp\\Core\\UserAccount'.", $subjectId));
57  $parents = $subject->getAllUserGroups();
58  $this->assertCount(0, $parents, sprintf("Unexpected parent's count (%s) for subject with id '%s'.", count($parents) , $subjectId));
59  break;
60 
61  case 'has-not-parent':
62  /**
63  * @var \Dcp\Core\UserAccount $subject
64  */
65  $this->assertTrue(is_a($subject, 'Dcp\Core\UserAccount') , sprintf("Subject with id '%s' is not of expected class 'Dcp\\Core\\UserAccount'.", $subjectId));
66  $parents = $subject->getAllUserGroups();
67  $hasNotParent = true;
68  foreach ($parents as $sysId => $docId) {
69  $group = new_Doc('', $docId, true);
70  if (!$group->isAlive()) {
71  continue;
72  }
73  if ($group->name == $argv) {
74  $hasNotParent = false;
75  }
76  }
77  $this->assertTrue($hasNotParent, sprintf("User with id '%s' has unexpected parent '%s'.", $subjectId, $argv));
78  break;
79  }
80  }
81  }
82 
83  public function dataClearGroup()
84  {
85  return array(
86  array(
87  'G_FOO',
88  array(
89  array(
90  'subject' => 'G_FOO',
91  'check' => 'is-empty',
92  ) ,
93  array(
94  'subject' => 'U_FOO',
95  'check' => 'has-no-parents'
96  ) ,
97  array(
98  'subject' => 'G_BAR',
99  'check' => 'has-no-parents'
100  ) ,
101  array(
102  'subject' => 'U_BAR',
103  'check' => 'has-not-parent',
104  'argv' => 'G_FOO'
105  )
106  )
107  )
108  );
109  }
110 }
$subject
new_Doc($dbaccess, $id= '', $latest=false)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen