12 require_once
'PU_testcase_dcp_commonfamily.php';
18 return "PU_data_dcp_group.ods";
27 public function testDeleteGroupWithUser(
$login, array $groupLoginsToCreate, array $groupLoginsToDelete, array $groupLoginsResult)
31 $this->assertTrue(is_object(
$user) ,
"cannot create user");
34 $err.=
$user->setValue(
"us_passwd1", $password);
35 $err.=
$user->setValue(
"us_passwd2", $password);
36 $this->assertEmpty(
$err, sprintf(
"cannot set iuser %s",
$err));
39 $this->assertEmpty(
$err, sprintf(
"cannot store iuser %s",
$err));
43 foreach ($groupLoginsToCreate as $gLogin) {
48 $this->assertTrue(is_object($group) ,
"cannot create group");
49 $err = $group->setValue(
"us_login", $gLogin);
50 $this->assertEmpty(
$err, sprintf(
"cannot set igroup %s",
$err));
52 $err = $group->store();
53 $this->assertEmpty(
$err, sprintf(
"cannot store igroup %s",
$err));
54 $group->insertDocument(
$user->initid);
55 $newGids[] = $group->getRawValue(
"us_whatid");
56 $groups[$gLogin] = $group;
58 $u = new \Account(
"",
$user->getRawValue(
"us_whatid"));
59 $this->assertTrue($u->isAffected() , sprintf(
"cannot find %s account",
$user->getRawValue(
"us_whatid")));
60 $gids = $u->getGroupsId();
62 $this->assertEmpty(array_diff($newGids, $gids) ,
"groups are not in new user");
64 foreach ($groupLoginsToDelete as $gLogin) {
65 $err = $groups[$gLogin]->Delete();
66 $this->assertEmpty(
$err, sprintf(
"error when delete group : %s",
$err));
69 $userGroups = $u->getUserParents();
71 foreach ($userGroups as $uGroup) {
72 if (($uGroup[
"login"] !=
"all") && ($uGroup[
"accounttype"] !=
'R')) {
73 $this->assertTrue(in_array($uGroup[
"login"], $groupLoginsResult) , sprintf(
"login %s not in %s", $uGroup[
"login"], implode(
',', $groupLoginsResult)));
83 $group = $this->testCreateGroup(
$login);
84 $err = $group->Delete();
85 $this->assertEmpty(
$err, sprintf(
"cannot delete igroup %s",
$err));
92 public function testCreateGroup(
$login)
98 $this->assertTrue(is_object(
$doc) ,
"cannot create group");
100 $this->assertEmpty(
$err, sprintf(
"cannot set igroup %s",
$err));
103 $this->assertEmpty(
$err, sprintf(
"cannot store igroup %s",
$err));
106 $this->assertTrue($u->setLoginName(
$login) ,
"system group not found");
107 $this->assertEquals(
$login, $u->login);
108 $this->assertEquals(
$doc->id, $u->fid,
"mismatch document igroup reference");
109 $this->assertEquals(
$doc->getRawValue(
"us_whatid") , $u->id,
"mismatch system igroup reference");
119 public function testInsertInGroup($userLogin, array $groupLogins)
123 $this->assertTrue(is_object(
$user) ,
"cannot create user");
124 $err =
$user->setValue(
"us_login", $userLogin);
125 $password =
'secret';
126 $err.=
$user->setValue(
"us_passwd1", $password);
127 $err.=
$user->setValue(
"us_passwd2", $password);
128 $this->assertEmpty(
$err, sprintf(
"cannot set iuser %s",
$err));
131 $this->assertEmpty(
$err, sprintf(
"cannot store iuser %s",
$err));
134 foreach ($groupLogins as $gLogin) {
139 $this->assertTrue(is_object($group) ,
"cannot create group");
140 $err = $group->setValue(
"us_login", $gLogin);
141 $this->assertEmpty(
$err, sprintf(
"cannot set igroup %s",
$err));
143 $err = $group->store();
144 $this->assertEmpty(
$err, sprintf(
"cannot store igroup %s",
$err));
145 $group->insertDocument(
$user->initid);
146 $newGids[] = $group->getRawValue(
"us_whatid");
148 $u = new \Account(
"",
$user->getRawValue(
"us_whatid"));
149 $this->assertTrue($u->isAffected());
150 $gids = $u->getGroupsId();
152 $this->assertEmpty(array_diff($newGids, $gids) ,
"groups are not in new user");
162 $this->assertTrue(is_object(
$doc) ,
"cannot create group");
164 $this->assertEmpty(
$err, sprintf(
"cannot set igroup %s",
$err));
167 $this->assertNotEmpty(
$err, sprintf(
"must be impossible to store igroup"));
170 $this->assertTrue($u->setLoginName(
$login) ,
"system group not found");
171 $this->assertEquals(
$login, $u->login);
179 public function test_userInsertDocument($userId, $groupId, $insertUserId)
185 if (!
$user->isAlive()) {
186 $this->markTestIncomplete(sprintf(
"User with id '%s' is not alive.", $userId));
188 $userWhatId =
$user->getRawValue(
'us_whatid');
194 if (!$group->isAlive()) {
195 $this->markTestIncomplete(sprintf(
"Group with id '%s' is not alive.", $groupId));
197 $groupWhatId = $group->getRawValue(
'us_whatid');
203 if (!$insertUser->isAlive()) {
204 $this->markTestIncomplete(sprintf(
"User with id '%s' is not alive.", $insertUserId));
206 $insertUserWhatId = $insertUser->getRawValue(
'us_whatid');
211 $this->
sudo(
$user->getRawValue(
'us_login'));
215 $group->insertDocument($insertUserId);
219 $groupsIdList = $insertUserAccount->getGroupsId();
220 $this->assertTrue(in_array($groupWhatId, $groupsIdList) , sprintf(
"User with id '%d' has not group with id '%d' as parent.", $insertUserWhatId, $groupWhatId));
224 $fld = $group->getContent();
226 foreach ($fld as &
$doc) {
227 if ($doc[
'id'] == $insertUser->id) {
233 $this->assertTrue($found, sprintf(
"Group with '%d' does not contain inserted user with id '%d'.", $group->id, $insertUser->id));
data_userInsertDocument()
testNotCreateGroup($login)
datagroupWithUserDelete()
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
new_Doc($dbaccess, $id= '', $latest=false)
static getCommonImportFile()
if($file) if($subject==""&&$file) if($subject=="") $err