Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_getenum.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  public static function getCommonImportFile()
18  {
19  setLanguage("fr_FR");
20  return "PU_data_dcp_enumfamily1.ods";
21  }
22  /**
23  * @dataProvider dataGetEnum
24  */
25  public function testExecuteGetEnum($famid, $attrid, array $expectedKeys, array $expectedLabel)
26  {
27  $fam = new_doc(self::$dbaccess, $famid);
28  $this->assertTrue($fam->isAlive() , sprintf("family %s not found", $famid));
29  /**
30  * @var \NormalAttribute $oa
31  */
32  $oa = $fam->getAttribute($attrid);
33  $this->assertNotEmpty($oa, sprintf("attribute %s not found", $attrid));
34 
35  $enum = $oa->getEnum();
36  $keys = array_keys($enum);
37  $labels = array_values($enum);
38 
39  $this->assertEquals($expectedKeys, $keys, "enum keys mismatch");
40  $this->assertEquals($expectedLabel, $labels, "enum label mismatch");
41  }
42  /**
43  * @dataProvider dataGetLabelOfEnum
44  */
45  public function testGetLabelOfEnum($famid, $attrid, array $expectedKeysLabel)
46  {
47  $fam = new_doc(self::$dbaccess, $famid);
48  $this->assertTrue($fam->isAlive() , sprintf("family %s not found", $famid));
49  /**
50  * @var \NormalAttribute $oa
51  */
52  $oa = $fam->getAttribute($attrid);
53  $this->assertNotEmpty($oa, sprintf("attribute %s not found", $attrid));
54 
55  $enum = $oa->getEnum();
56  foreach ($expectedKeysLabel as $key => $label) {
57 
58  $this->assertEquals($label, $oa->getEnumLabel($key) , sprintf("enum single label mismatch: key %s\n%s", $key, print_r($enum, true)));
59  }
60  }
61  /**
62  * @dataProvider dataGetEnumLabel
63  */
64  public function testGetEnumLabel($famid, $attrid, array $expectedKeys, array $expectedLabel)
65  {
66  $a = _("TST_ENUMFAM1#tst_enuma#a");
67  $a = _("TST_ENUMFAM1#tst_enum2#0");
68  $fam = new_doc(self::$dbaccess, $famid);
69  $this->assertTrue($fam->isAlive() , sprintf("family %s not found", $famid));
70  /**
71  * @var \NormalAttribute $oa
72  */
73  $oa = $fam->getAttribute($attrid);
74  $this->assertNotEmpty($oa, sprintf("attribute %s not found", $attrid));
75 
76  $enum = $oa->getEnumLabel();
77  $keys = array_keys($enum);
78  $labels = array_values($enum);
79 
80  $this->assertEquals($expectedKeys, $keys, "enum keys mismatch");
81  $this->assertEquals($expectedLabel, $labels, "enum label mismatch");
82  }
83  /**
84  * @dataProvider dataInheritedGetEnum
85  *
86  * @param $familyIdList
87  * @param $attrId
88  * @param $expectedEnum
89  */
90  public function testInheritedGetEnum($familyIdList, $attrId, $expectedEnum)
91  {
92  /**
93  * @var \DocFam $fam
94  * @var \NormalAttribute $attr
95  */
96  foreach ($familyIdList as $familyId) {
97  $fam = new_doc(self::$dbaccess, $familyId);
98  $attr = $fam->getAttribute($attrId);
99  $enum = $attr->getEnum();
100  $this->assertTrue(is_array($enum) , sprintf("getEnum() on '%s' from '%s' is not an array (found type '%s').", $attrId, $fam->name, gettype($enum)));
101  $this->assertTrue(count($expectedEnum) === count($enum) , sprintf("Count mismatch for getEnum() on '%s' from '%s': found '%d' while expecting '%d'.", $attrId, $fam->name, count($enum) , count($expectedEnum)));
102  $diff = array_diff_key($expectedEnum, $enum);
103  $this->assertTrue(count($diff) === 0, sprintf("getEnum() on '%s' from '%s' returned unexpected keys.", $attrId, $fam->name));
104  }
105  }
106  /**
107  * @dataProvider dataInheritedAddEnum
108  *
109  * @param $addEnums
110  * @param $expectedEnums
111  */
112  public function testInheritedAddEnum($addEnums, $expectedEnums)
113  {
114  /**
115  * @var \DocFam $fam
116  * @var \NormalAttribute $attr
117  */
118  foreach ($addEnums as $familyId => $attrs) {
119  $fam = new_doc(self::$dbaccess, $familyId);
120  foreach ($attrs as $attrId => $enums) {
121  $attr = $fam->getAttribute($attrId);
122  foreach ($enums as $enumKey => $enumValue) {
123  $err = $attr->addEnum(self::$dbaccess, $enumKey, $enumValue);
124  $this->assertEmpty($err, sprintf("addEnum() returned unexpected error: %s", $err));
125  }
126  }
127  }
128  foreach ($expectedEnums as $familyId => $attrs) {
129  $fam = new_doc(self::$dbaccess, $familyId);
130  foreach ($attrs as $attrId => $expectedEnum) {
131  $attr = $fam->getAttribute($attrId);
132  $enum = $attr->getEnum();
133  $this->assertTrue(is_array($enum) , sprintf("getEnum() on '%s' from '%s' is not an array (found type '%s').", $attrId, $fam->name, gettype($enum)));
134  $this->assertTrue(count($expectedEnum) === count($enum) , sprintf("Count mismatch for getEnum() on '%s' from '%s': found '%d' while expecting '%d'.", $attrId, $fam->name, count($enum) , count($expectedEnum)));
135  $diff = array_diff_key($expectedEnum, $enum);
136  $this->assertTrue(count($diff) === 0, sprintf("getEnum() on '%s' from '%s' returned unexpected keys.", $attrId, $fam->name));
137  }
138  }
139  }
140  public function dataGetEnum()
141  {
142  return array(
143  array(
144 
145  'family' => 'TST_ENUMFAM1',
146  'attrid' => 'TST_ENUM1',
147  'keys' => array(
148  "0",
149  "1",
150  "2"
151  ) ,
152  'labels' => array(
153  "Zéro",
154  "Un",
155  "Deux"
156  )
157  ) ,
158  array(
159  'family' => 'TST_ENUMFAM1',
160  'attrid' => 'TST_ENUMA',
161  'keys' => array(
162  "a",
163  "b",
164  "c"
165  ) ,
166  'labels' => array(
167  "Lettre A", // translated A in i18n catalog
168  "B",
169  "C"
170  )
171  ) ,
172  array(
173  'family' => 'TST_ENUMFAM1',
174  'attrid' => 'TST_ENUM2',
175  'keys' => array(
176  "0",
177  "0.01",
178  "0.02",
179  "1",
180  "1.11",
181  "1.12"
182  ) ,
183  'labels' => array(
184  "Zéfiro",
185  "ZéroUn",
186  "ZéroDeux",
187  "Un",
188  "UnUn",
189  "UnDeux"
190  )
191  ) ,
192  array(
193  'family' => 'TST_ENUMFAM1',
194  'attrid' => 'TST_ENUMAUTO2',
195  'keys' => array(
196  "0",
197  "0.01",
198  "0.02",
199  "1",
200  "1.11",
201  "1.12"
202  ) ,
203  'labels' => array(
204  "Zéfiro",
205  "ZéroUn",
206  "ZéroDeux",
207  "Un",
208  "UnUn",
209  "UnDeux"
210  )
211  ),
212  array(
213 
214  'family' => 'TST_ENUMFAM1',
215  'attrid' => 'TST_ENUMNA',
216  'keys' => array(
217  "a",
218  "a.ab",
219  "a.ac",
220  "b",
221  "b.ba",
222  "b.bc"
223  ) ,
224  'labels' => array(
225  "A",
226  "AB",
227  "AC",
228  "B",
229  "BAB",
230  "BBC"
231  )
232  ),
233  array(
234 
235  'family' => 'TST_ENUMFAM1',
236  'attrid' => 'TST_ENUMNUMERIC',
237  'keys' => array(
238  "0\\.1",
239  "1\\.2",
240  "3\\.14"
241  ) ,
242  'labels' => array(
243  "Zéro virgule un",
244  "Un point 2",
245  "Pi"
246  )
247  )
248  );
249  }
250  public function dataGetEnumLabel()
251  {
252  return array(
253  array(
254 
255  'family' => 'TST_ENUMFAM1',
256  'attrid' => 'TST_ENUM1',
257  'keys' => array(
258  "0",
259  "1",
260  "2"
261  ) ,
262  'labels' => array(
263  "Zéro",
264  "Un",
265  "Deux"
266  )
267  ) ,
268  array(
269  'family' => 'TST_ENUMFAM1',
270  'attrid' => 'TST_ENUMA',
271  'keys' => array(
272  "a",
273  "b",
274  "c"
275  ) ,
276  'labels' => array(
277  "Lettre A", // translated A in i18n catalog
278  "B",
279  "C"
280  )
281  ) ,
282  array(
283  'family' => 'TST_ENUMFAM1',
284  'attrid' => 'TST_ENUM2',
285  'keys' => array(
286  "0",
287  "01",
288  "02",
289  "1",
290  "11",
291  "12"
292  ) ,
293  'labels' => array(
294  "Zéfiro",
295  "Zéfiro/ZéroUn",
296  "Zéfiro/ZéroDeux",
297  "Un",
298  "Un/UnUn",
299  "Un/UnDeux"
300  )
301  ) ,
302  array(
303  'family' => 'TST_ENUMFAM1',
304  'attrid' => 'TST_ENUMAUTO2',
305  'keys' => array(
306  "0",
307  "01",
308  "02",
309  "1",
310  "11",
311  "12"
312  ) ,
313  'labels' => array(
314  "Zéfiro",
315  "Zéfiro/ZéroUn",
316  "Zéfiro/ZéroDeux",
317  "Un",
318  "Un/UnUn",
319  "Un/UnDeux"
320  )
321  ),
322  array(
323  'family' => 'TST_ENUMFAM1',
324  'attrid' => 'TST_ENUMNUMERIC',
325  'keys' => array(
326  "0.1",
327  "1.2",
328  "3.14"
329  ) ,
330  'labels' => array(
331  "Zéro virgule un",
332  "Un point 2",
333  "Pi"
334  )
335  )
336  );
337  }
338  public function dataGetLabelOfEnum()
339  {
340  return array(
341  array(
342 
343  'family' => 'TST_ENUMFAM1',
344  'attrid' => 'TST_ENUM1',
345  'keysLabel' => array(
346  "0" => "Zéro",
347  "1" => "Un",
348  "2" => "Deux"
349  )
350  ) ,
351 
352  array(
353  'family' => 'TST_ENUMFAM1',
354  'attrid' => 'TST_ENUM2',
355  'keysLabel' => array(
356  "0" => "Zéfiro",
357  "01" => "Zéfiro/ZéroUn",
358  "02" => "Zéfiro/ZéroDeux",
359  "1" => "Un",
360  "11" => "Un/UnUn",
361  "12" => "Un/UnDeux"
362  )
363  ),
364 
365  array(
366  'family' => 'TST_ENUMFAM1',
367  'attrid' => 'TST_ENUMNUMERIC',
368  'keysLabel' => array(
369  "0.1" => "Zéro virgule un",
370  "1.2" => "Un point 2",
371  "3.14" => "Pi",
372  )
373  )
374  );
375  }
376  public function dataInheritedGetEnum()
377  {
378  return array(
379  array(
380  'families' => array(
381  'TST_INHERIT_GETENUM_A1',
382  'TST_INHERIT_GETENUM_B1',
383  'TST_INHERIT_GETENUM_C1'
384  ) ,
385  'attrid' => 'TST_ENUM1',
386  'expectedEnum' => array(
387  'ZERO' => 'Zéro',
388  'ONE' => 'Un',
389  'TWO' => 'Deux'
390  )
391  ) ,
392  array(
393  'families' => array(
394  'TST_INHERIT_GETENUM_A2',
395  'TST_INHERIT_GETENUM_B2',
396  'TST_INHERIT_GETENUM_C2',
397  'TST_INHERIT_GETENUM_D2'
398  ) ,
399  'attrid' => 'TST_ENUM1',
400  'expectedEnum' => array(
401  'ZERO' => 'Zéro',
402  'ONE' => 'Un',
403  'TWO' => 'Deux'
404  )
405  ) ,
406  array(
407  'families' => array(
408  'TST_INHERIT_GETENUM_A3',
409  'TST_INHERIT_GETENUM_B3',
410  'TST_INHERIT_GETENUM_C3',
411  'TST_INHERIT_GETENUM_D3'
412  ) ,
413  'attrid' => 'TST_ENUM1',
414  'expectedEnum' => array(
415  'ZERO' => 'Zéro',
416  'ONE' => 'Un',
417  'TWO' => 'Deux'
418  )
419  )
420  );
421  }
422  public function dataInheritedAddEnum()
423  {
424  return array(
425  array(
426  'addEnums' => array(
427  'TST_INHERIT_ADDENUM_B1' => array(
428  'TST_ENUM1' => array(
429  'THREE' => 'Trois'
430  )
431  ) ,
432  'TST_INHERIT_ADDENUM_C1' => array(
433  'TST_ENUM1' => array(
434  'FOUR' => 'Quatre'
435  )
436  ) ,
437  'TST_INHERIT_ADDENUM_D1' => array(
438  'TST_ENUM1' => array(
439  'FIVE' => 'Cinq'
440  )
441  ) ,
442  ) ,
443  'expectedEnums' => array(
444  'TST_INHERIT_ADDENUM_B1' => array(
445  'TST_ENUM1' => array(
446  'ZERO' => 'Zéro',
447  'ONE' => 'Un',
448  'TWO' => 'Two',
449  'THREE' => 'Trois',
450  'FOUR' => 'Quatre',
451  'FIVE' => 'Cinq'
452  )
453  ) ,
454  'TST_INHERIT_ADDENUM_C1' => array(
455  'TST_ENUM1' => array(
456  'ZERO' => 'Zéro',
457  'ONE' => 'Un',
458  'TWO' => 'Two',
459  'THREE' => 'Trois',
460  'FOUR' => 'Quatre',
461  'FIVE' => 'Cinq'
462  )
463  ) ,
464  'TST_INHERIT_ADDENUM_D1' => array(
465  'TST_ENUM1' => array(
466  'ZERO' => 'Zéro',
467  'ONE' => 'Un',
468  'TWO' => 'Two',
469  'THREE' => 'Trois',
470  'FOUR' => 'Quatre',
471  'FIVE' => 'Cinq'
472  )
473  ) ,
474  )
475  ) ,
476  array(
477  'addEnums' => array(
478  'TST_INHERIT_ADDENUM_B2' => array(
479  'TST_ENUM1' => array(
480  'THREE' => 'Trois'
481  )
482  ) ,
483  'TST_INHERIT_ADDENUM_C2' => array(
484  'TST_ENUM1' => array(
485  'FOUR' => 'Quatre'
486  )
487  ) ,
488  'TST_INHERIT_ADDENUM_D2' => array(
489  'TST_ENUM1' => array(
490  'FIVE' => 'Cinq'
491  )
492  ) ,
493  ) ,
494  'expectedEnums' => array(
495  'TST_INHERIT_ADDENUM_B2' => array(
496  'TST_ENUM1' => array(
497  'ZERO' => 'Zéro',
498  'ONE' => 'Un',
499  'TWO' => 'Two',
500  'THREE' => 'Trois',
501  'FOUR' => 'Quatre',
502  'FIVE' => 'Cinq'
503  )
504  ) ,
505  'TST_INHERIT_ADDENUM_C2' => array(
506  'TST_ENUM1' => array(
507  'ZERO' => 'Zéro',
508  'ONE' => 'Un',
509  'TWO' => 'Two',
510  'THREE' => 'Trois',
511  'FOUR' => 'Quatre',
512  'FIVE' => 'Cinq'
513  )
514  ) ,
515  'TST_INHERIT_ADDENUM_D2' => array(
516  'TST_ENUM1' => array(
517  'ZERO' => 'Zéro',
518  'ONE' => 'Un',
519  'TWO' => 'Two',
520  'THREE' => 'Trois',
521  'FOUR' => 'Quatre',
522  'FIVE' => 'Cinq'
523  )
524  ) ,
525  )
526  )
527  );
528  }
529 }
530 ?>
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
setLanguage($lang)
Definition: Lib.Common.php:886
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen