Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_importAccounts.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  /**
18  * import TST_FAMSETVALUE family
19  * @static
20  * @return string
21  */
22  protected static function getCommonImportFile()
23  {
24  return "PU_data_dcp_accountFamilies.ods";
25  }
26  /**
27  * test import simple document
28  * @dataProvider dataGoodImportAccount
29  * @param $accountFile
30  * @param array $expects
31  */
32  public function testGoodImportAccount($accountFile, array $expects)
33  {
34  $err = '';
35 
36  try {
37  $import = new \Dcp\Core\ImportAccounts();
38 
39  $import->setFile(sprintf("%s/DCPTEST/Layout/%s", DEFAULT_PUBDIR, $accountFile));
40  $import->import();
41  }
42  catch(\Exception $e) {
43  $err = $e->getMessage();
44  }
45  $this->assertEmpty($err, "import error detected $err");
46  $testingAccount = new \Account();
47  foreach ($expects as $accountData) {
48  $login = $accountData["login"];
49  $testingAccount->setLoginName($login);
50 
51  $this->assertTrue($testingAccount->isAffected() , "Login $login not found");
52  foreach ($accountData["expectValues"] as $aid => $expVal) {
53 
54  $this->assertEquals($expVal, $testingAccount->$aid, "Search \"$aid\"." . print_r($testingAccount->getValues() , true));
55  }
56  if (isset($accountData["docName"])) {
57  $doc = new_doc("", $accountData["docName"]);
58  $this->assertTrue($doc->isAlive() , sprintf("Doc %s not found", $accountData["docName"]));
59  $this->assertEquals($doc->getRawValue("us_whatid") , $testingAccount->id, sprintf("Account \"%s\" is not linked: %s", $testingAccount->login, $accountData["docName"]));
60  } else {
61  $doc = new_doc("", $testingAccount->fid);
62  }
63 
64  if (isset($accountData["expectedDocValue"])) {
65  foreach ($accountData["expectedDocValue"] as $aid => $expVal) {
66  $this->assertEquals($expVal, $doc->getRawValue($aid) , sprintf("for %s (%s) : %s", $doc, $aid, print_r($doc->getValues() , true)));
67  }
68  }
69  if (isset($accountData["expectedRoles"])) {
70  $roles = $testingAccount->getAllRoles();
71  $this->assertEquals(count($accountData["expectedRoles"]) , count($roles) , sprintf("Role count fail %s : %s", $testingAccount->login, print_r($roles, true)));
72  foreach ($accountData["expectedRoles"] as $roleRef) {
73  $filteredRoles = array_filter($roles, function ($roleData) use ($roleRef)
74  {
75  return ($roleData["login"] === $roleRef);
76  });
77  $this->assertEquals(count($filteredRoles) , 1, sprintf("role %s not found : %s", $roleRef, $testingAccount->login, print_r($roles, true)));
78  }
79  }
80 
81  if (isset($accountData["expectedGroups"])) {
82  $groupIds = $testingAccount->getGroupsId();
83  $this->assertEquals(count($accountData["expectedGroups"]) , count($groupIds) , sprintf("Group count fail %s : %s", $testingAccount->login, print_r($groupIds, true)));
84  foreach ($accountData["expectedGroups"] as $groupRef) {
85  $filteredRoles = array_filter($groupIds, function ($groupId) use ($groupRef)
86  {
87  $a = new \Account();
88  $a->select($groupId);
89  return ($a->login === strtolower($groupRef));
90  });
91  $this->assertEquals(count($filteredRoles) , 1, sprintf("group %s not found : %s : %s", $groupRef, $testingAccount->login, print_r($groupIds, true)));
92  }
93  }
94 
95  if (isset($accountData["password"])) {
96  $this->assertTrue($testingAccount->checkpassword($accountData["password"]) , sprintf("password no match for %s : \"%s\"\n%s", $testingAccount->login, $testingAccount->password, print_r($testingAccount->getValues() , true)));
97  }
98  }
99  }
100  public function dataGoodImportAccount()
101  {
102  return array(
103  array(
104  "file" => "PU_data_dcp_accounts1.xml",
105  array(
106  // ============= ROLES ===========
107  array(
108  "login" => "fat capacity",
109  "expectValues" => array(
110  "lastname" => "Grosse capacité",
111  "mail" => "",
112  "password" => "-"
113  ) ,
114  "docName" => "TST_CAPACITY1",
115  "expectedRoles" => array() ,
116  "expectedGroups" => array()
117  ) ,
118  array(
119  "login" => "big capacity",
120  "expectValues" => array(
121  "lastname" => "Grande capacité",
122  "mail" => "",
123  "password" => "-"
124  ) ,
125  "docName" => "TST_CAPACITY2",
126  "expectedDocValue" => array(
127  "role_login" => "big capacity",
128  "role_name" => "Grande capacité",
129  "tst_addr" => "10 rue des agences"
130  ) ,
131  "expectedRoles" => array() ,
132  "expectedGroups" => array()
133  ) ,
134  array(
135  "login" => "supervisor",
136  "expectValues" => array(
137  "lastname" => "Surveillance galactique",
138  "mail" => "",
139  "password" => "-"
140  ) ,
141  "docName" => "TST_SUPERVISOR",
142  "expectedDocValue" => array(
143  "role_login" => "supervisor",
144  "role_name" => "Surveillance galactique"
145  ) ,
146  "expectedRoles" => array() ,
147  "expectedGroups" => array()
148  ) ,
149  // ============= GROUPS ===========
150  array(
151  "login" => "topsupervisor",
152  "expectValues" => array(
153  "lastname" => "Sécurité du toit",
154  "mail" => "",
155  "password" => "-"
156  ) ,
157  "docName" => "TST_GRP_ROOFSUPERVISOR",
158  "expectedDocValue" => array(
159  "us_login" => "topsupervisor",
160  "grp_name" => "Sécurité du toit"
161  ) ,
162  "expectedRoles" => array(
163  "supervisor"
164  ) ,
165  "expectedGroups" => array()
166  ) ,
167  array(
168  "login" => "levelsupervisor",
169  "expectValues" => array(
170  "lastname" => "Sécurité des niveaux",
171  "mail" => "",
172  "password" => "-"
173  ) ,
174  "docName" => "TST_GRP_LEVELSUPERVISOR",
175  "expectedDocValue" => array(
176  "us_login" => "levelsupervisor",
177  "grp_name" => "Sécurité des niveaux"
178  ) ,
179  "expectedRoles" => array(
180  "supervisor"
181  ) ,
182  "expectedGroups" => array(
183  "topsupervisor"
184  )
185  ) ,
186  array(
187  "login" => "undergroundsupervisor",
188  "expectValues" => array(
189  "lastname" => "Sécurité du sous-sol",
190  "mail" => "",
191  "password" => "-"
192  ) ,
193  "docName" => "TST_GRP_UNDERGROUNDSUPERVISOR",
194  "expectedDocValue" => array(
195  "us_login" => "undergroundsupervisor",
196  "grp_name" => "Sécurité du sous-sol"
197  ) ,
198  "expectedRoles" => array(
199  "supervisor"
200  ) ,
201  "expectedGroups" => array(
202  "topsupervisor"
203  )
204  ) ,
205  // ============= USERS ===========
206  array(
207  "login" => "chewie",
208  "expectValues" => array(
209  "lastname" => "Chewbacca",
210  "mail" => "chewie@starwars.com",
211  "status" => "A",
212  "password" => "-"
213  ) ,
214  "expectedRoles" => array() ,
215  "expectedGroups" => array()
216  ) ,
217 
218  array(
219  "login" => "luke",
220  "expectValues" => array(
221  "firstname" => "Luke",
222  "lastname" => "Skywalker",
223  "mail" => "luke@starwars.com",
224  "status" => "A"
225  ) ,
226  "docName" => "TST_AGENT_L",
227  "expectedDocValue" => array(
228  "tst_phone" => "63.76.89.33",
229  "tst_mat" => "3323",
230  "us_group" => "Sécurité des niveaux"
231  ) ,
232  "expectedRoles" => array(
233  "big capacity",
234  "supervisor"
235  ) ,
236  "expectedGroups" => array(
237  "LevelSupervisor"
238  ) ,
239  "password" => "May the force be with you"
240  ) ,
241 
242  array(
243  "login" => "leia",
244  "expectValues" => array(
245  "firstname" => "Leia",
246  "lastname" => "Skywalker",
247  "mail" => "leia@starwars.com",
248  "status" => "A"
249  ) ,
250  "docName" => "TST_AGENT_P",
251  "expectedDocValue" => array(
252  "tst_phone" => "63.76.89.34",
253  "tst_mat" => "3324",
254  "us_group" => "Sécurité des niveaux"
255  ) ,
256  "expectedRoles" => array(
257  "big capacity",
258  "supervisor"
259  ) ,
260  "expectedGroups" => array(
261  "LevelSupervisor"
262  ) ,
263  "password" => "May the force be with you"
264  ) ,
265 
266  array(
267  "login" => "solo",
268  "expectValues" => array(
269  "firstname" => "Han",
270  "lastname" => "Solo",
271  "mail" => "solo@starwars.com",
272  "status" => "D"
273  ) ,
274  "docName" => "TST_AGENT_H",
275  "expectedDocValue" => array(
276  "tst_phone" => "83.26.89.43",
277  "tst_mat" => "3524",
278  "us_group" => "Sécurité des niveaux\nSécurité du toit"
279  ) ,
280  "expectedRoles" => array(
281  "fat capacity",
282  "supervisor"
283  ) ,
284  "expectedGroups" => array(
285  "LevelSupervisor",
286  "TopSupervisor"
287  ) ,
288  "password" => "Falcon Millenium"
289  )
290  )
291  )
292  );
293  }
294 }
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
testGoodImportAccount($accountFile, array $expects)
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
$login
Definition: dav.php:40
if($file) if($subject==""&&$file) if($subject=="") $err
$import
← centre documentaire © anakeen