Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_docenum.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  const familyName = "TST_DOCENUM";
18  /**
19  * import TST_DOCENUM family
20  * @static
21  * @return string
22  */
23  protected static function getCommonImportFile()
24  {
25  return array(
26  "PU_data_dcp_docenum_family.ods"
27  );
28  }
29 
30  public static function tearDownAfterClass()
31  {
32  $langs = array(
33  "fr_FR",
34  "en_US"
35  );
36  foreach ($langs as $lang) {
37  $moFile = \DocEnum::getMoFilename(self::familyName, $lang);
38  unlink($moFile);
39  }
41  parent::tearDownAfterClass();
42  }
43  /**
44  * @dataProvider dataDocEnumAdd
45  */
46  public function testDocEnumAdd($attrid, $key, $label, $absOrder, $expectedOrder)
47  {
48  $s = new \EnumStructure();
49  $s->key = $key;
50  $s->label = $label;
51  $s->absoluteOrder = $absOrder;
52 
53  \DocEnum::addEnum(self::familyName, $attrid, $s);
54 
55  $this->verifyEnumProperties($attrid, $key, $label, $expectedOrder);
56  }
57  /**
58  * @dataProvider dataDocEnumMod
59  */
60  public function testDocEnumMod($attrid, $key, $label, $absOrder, $expectedOrder)
61  {
62  $s = new \EnumStructure();
63  $s->key = $key;
64  $s->label = $label;
65  $s->absoluteOrder = $absOrder;
66 
67  \DocEnum::modifyEnum(self::familyName, $attrid, $s);
68 
69  $this->verifyEnumProperties($attrid, $key, $label, $expectedOrder);
70  }
71  /**
72  * @dataProvider dataDocAddRelativeOrder
73  */
74  public function testDocEnumAddRelativeOrder($attrid, $key, $label, $relativeOrder, $expectedOrder)
75  {
76  $s = new \EnumStructure();
77  $s->key = $key;
78  $s->label = $label;
79  $s->orderBeforeThan = $relativeOrder;
80 
81  \DocEnum::addEnum(self::familyName, $attrid, $s);
82 
83  $this->verifyEnumProperties($attrid, $key, $label, $expectedOrder);
84  }
85  /**
86  * @dataProvider dataDocEnumDisabled
87  */
88  public function testDocEnumDisabled($attrid, array $disabledKeys, $expectedEnums)
89  {
90  $fam = new_doc(self::$dbaccess, self::familyName);
91 
92  foreach ($disabledKeys as $key) {
93  $oe = new \DocEnum("", array(
94  $fam->id,
95  $attrid,
96  $key
97  ));
98 
99  $this->assertTrue($oe->isAffected() , "enum $attrid : $key not found");
100  $s = new \EnumStructure();
101  $s->key = $oe->key;
102  $s->label = $oe->label;
103  $s->absoluteOrder = $oe->eorder;
104  $s->disabled = true;
105 
106  \DocEnum::modifyEnum(self::familyName, $attrid, $s);
107  }
108  /**
109  * @var \NormalAttribute $oa
110  */
111  $oa = $fam->getAttribute($attrid);
112  $oa->resetEnum();
113  $enums = $oa->getEnumLabel(null, false);
114  $enumKey = array_keys($enums);
115  $diff = array_diff($enumKey, $expectedEnums);
116 
117  $this->assertEmpty($diff, sprintf("getEnumLabel:: not expected visible \nExpect:\n %s,\nHas\n %s", print_r($expectedEnums, true) , print_r($enumKey, true)));
118 
119  $this->assertEquals(count($expectedEnums) , count($enumKey) , sprintf("getEnumLabel:: not expected enum count %s, %s", print_r($expectedEnums, true) , print_r($enums, true)));
120 
121  $oa->resetEnum();
122  $enums = $oa->getEnum(false);
123  $enums2 = $oa->getEnum(false);
124  $this->assertEquals($enums, $enums2, sprintf("getEnum::not same with cache %s, %s", print_r($enums, true) , print_r($enums2, true)));
125 
126  $enumKey = array_keys($enums);
127  $diff = array_diff($enumKey, $expectedEnums);
128 
129  $this->assertEmpty($diff, sprintf("getEnum:: not expected visible \nExpect:\n %s,\nHas\n %s", print_r($expectedEnums, true) , print_r($enumKey, true)));
130 
131  $this->assertEquals(count($expectedEnums) , count($enumKey) , sprintf("getEnum::not expected enum count %s, %s", print_r($expectedEnums, true) , print_r($enums, true)));
132  }
133  /**
134  * @dataProvider dataDocModRelativeOrder
135  */
136  public function testDocEnumModRelativeOrder($attrid, $key, $label, $relativeOrder, $expectedOrder)
137  {
138  $s = new \EnumStructure();
139  $s->key = $key;
140  $s->label = $label;
141  $s->orderBeforeThan = $relativeOrder;
142 
143  \DocEnum::modifyEnum(self::familyName, $attrid, $s);
144 
145  $this->verifyEnumProperties($attrid, $key, $label, $expectedOrder);
146  }
147  private function verifyEnumProperties($attrid, $key, $expectedLabel, $expectedOrder)
148  {
149  $f = new_Doc("", self::familyName);
150  /**
151  * @var \NormalAttribute $oa
152  */
153  $oa = $f->getAttribute($attrid);
154  $oa->resetEnum();
155  $elabel = $oa->getEnumLabel($key);
156  $this->assertTrue($elabel !== null, "Enum not inserted");
157  $this->assertEquals($expectedLabel, $elabel, "Enum not inserted");
158 
159  $de = new \DocEnum("", array(
160  $f->id,
161  $attrid,
162  $key
163  ));
164  $this->assertTrue($de->isAffected() , "Enum record not found");
165  $this->assertEquals($expectedOrder, $de->eorder, "Enum order not the good one");
166  }
167  /**
168  * @dataProvider dataDocEnumAddLocale
169  */
170  public function testDocEnumAddLocale($attrid, $key, $label, array $locale)
171  {
172  $s = new \EnumStructure();
173  $s->key = $key;
174  $s->label = $label;
175 
176  foreach ($locale as $lang => $localeLabel) {
177  $s->localeLabel[] = new \EnumLocale($lang, $localeLabel);
178  }
179 
180  \DocEnum::addEnum(self::familyName, $attrid, $s);
182 
183  $f = new_Doc("", self::familyName);
184  /**
185  * @var \NormalAttribute $oa
186  */
187  $oa = $f->getAttribute($attrid);
188  $oa->resetEnum();
189  $label = $oa->getEnumLabel($key);
190  $this->assertTrue($label !== null, "Enum not inserted");
191 
192  foreach ($locale as $lang => $localeLabel) {
194  $oa->resetEnum();
195  $eLabel = $oa->getEnumLabel($key);
196  $this->assertEquals($localeLabel, $eLabel, sprintf("not good %s mabel", $lang));
197  }
198  }
199 
200  public function dataDocEnumAdd()
201  {
202  return array(
203  array(
204  "attrid" => "tst_enum1",
205  "key" => 4,
206  "label" => "quatro",
207  "order" => 4,
208  "expectedOrder" => 4
209  ) ,
210  array(
211  "attrid" => "tst_enum1",
212  "key" => 5,
213  "label" => "cinqo",
214  "order" => 1,
215  "expectedOrder" => 1
216  ) ,
217  array(
218  "attrid" => "tst_enum1",
219  "key" => 50,
220  "label" => "mucho",
221  "order" => 50,
222  "expectedOrder" => 5
223  ) ,
224  array(
225  "attrid" => "tst_enum1",
226  "key" => 500,
227  "label" => "mucho mucho",
228  "order" => 0,
229  "expectedOrder" => 5
230  ) ,
231  array(
232  "attrid" => "tst_enum1",
233  "key" => 400,
234  "label" => "mucho mucho",
235  "order" => - 1,
236  "expectedOrder" => 5
237  )
238  );
239  }
240  public function dataDocEnumMod()
241  {
242  return array(
243  array(
244  "attrid" => "tst_enum1",
245  "key" => 1,
246  "label" => "one more",
247  "order" => 4,
248  "expectedOrder" => 3
249  ) ,
250  array(
251  "attrid" => "tst_enum1",
252  "key" => 1,
253  "label" => "one more",
254  "order" => 0,
255  "expectedOrder" => 4
256  )
257  );
258  }
259  public function dataDocAddRelativeOrder()
260  {
261  return array(
262  array(
263  "attrid" => "tst_enuma",
264  "key" => "a1",
265  "label" => "one more",
266  "before" => "b",
267  "expectedOrder" => 2
268  ) ,
269  array(
270  "attrid" => "tst_enuma",
271  "key" => "a0",
272  "label" => "one more",
273  "before" => "a",
274  "expectedOrder" => 1
275  ) ,
276  array(
277  "attrid" => "tst_enuma",
278  "key" => "a0",
279  "label" => "one more",
280  "before" => "d",
281  "expectedOrder" => 4
282  ) ,
283  array(
284  "attrid" => "tst_enuma",
285  "key" => "a0",
286  "label" => "one more",
287  "before" => "",
288  "expectedOrder" => 5
289  )
290  );
291  }
292  public function dataDocModRelativeOrder()
293  {
294  return array(
295  array(
296  "attrid" => "tst_enuma",
297  "key" => "b",
298  "label" => "one more",
299  "before" => "b",
300  "expectedOrder" => 2
301  ) ,
302  array(
303  "attrid" => "tst_enuma",
304  "key" => "d",
305  "label" => "one more",
306  "before" => "a",
307  "expectedOrder" => 1
308  ) ,
309  array(
310  "attrid" => "tst_enuma",
311  "key" => "a",
312  "label" => "one more",
313  "before" => "",
314  "expectedOrder" => 4
315  )
316  );
317  }
318 
319  public function dataDocEnumDisabled()
320  {
321  return array(
322  array(
323  "attrid" => "tst_enum1",
324  "disable" => array(
325  "1"
326  ) ,
327  "expect" => array(
328  " ",
329  "0",
330  "2"
331  )
332  ) ,
333  array(
334  "attrid" => "tst_enum1",
335  "disable" => array() ,
336  "expect" => array(
337  " ",
338  "0",
339  "1",
340  "2"
341  )
342  ) ,
343  array(
344  "attrid" => "tst_enum1",
345  "disable" => array(
346  " ",
347  "0",
348  "1",
349  "2"
350  ) ,
351  "expect" => array()
352  ) ,
353  array(
354  "attrid" => "tst_enum1",
355  "disable" => array(
356  " ",
357  "0",
358  "1"
359  ) ,
360  "expect" => array(
361  "2"
362  )
363  ) ,
364  array(
365  "attrid" => "tst_enuma",
366  "disable" => array(
367  "b",
368  "d"
369  ) ,
370  "expect" => array(
371  "a",
372  "c"
373  )
374  )
375  );
376  }
377  public function dataDocEnumAddLocale()
378  {
379  return array(
380  array(
381  "attrid" => "tst_enum1",
382  "key" => 4,
383  "label" => "quatro",
384  "locale" => array(
385  "en_US" => "four",
386  "fr_FR" => "quatre"
387  )
388  )
389  );
390  }
391 }
static reloadLocaleCache()
Definition: Lib.System.php:118
testDocEnumAddRelativeOrder($attrid, $key, $label, $relativeOrder, $expectedOrder)
static modifyEnum($famId, $attrid, EnumStructure $enumStruct)
$locale
static addEnum($famId, $attrid, EnumStructure $enumStruct)
if($famId) $s
$lang
Definition: lang.php:18
testDocEnumAdd($attrid, $key, $label, $absOrder, $expectedOrder)
testDocEnumMod($attrid, $key, $label, $absOrder, $expectedOrder)
setLanguage($lang)
Definition: Lib.Common.php:886
$oe
Definition: migrEnum.php:37
new_Doc($dbaccess, $id= '', $latest=false)
$dbaccess
Definition: checkVault.php:17
testDocEnumModRelativeOrder($attrid, $key, $label, $relativeOrder, $expectedOrder)
static getMoFilename($famId, $lang)
← centre documentaire © anakeen