Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_applicationParameterManager.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.php';
14 require_once 'PU_testcase_dcp_application.php';
15 
17 {
18 
19  const appName = "DCPTEST2";
20 
21  /**
22  * Add conf
23  *
24  * @return array
25  */
26  public static function appConfig()
27  {
28  return array(
29  "appRoot" => join(DIRECTORY_SEPARATOR, array(
31  "DCPTEST",
32  "app"
33  )),
34  "appName" => "TST_PARAMETER_MANAGER"
35  );
36  }
37 
38  /**
39  * @param $parameters
40  * @return \Application
41  */
42  private function initTestApplication($parameters)
43  {
44  $appTest = new \Application(self::$dbaccess);
45  $appTest->name = self::appName;
46  $appTest->childof = 'TST_PARAMETER_MANAGER';
47  $err = $appTest->Add();
48 
49  $this->assertEmpty($err, "Cannot create application : $err");
50  $parent = null;
51  $appTest->set(self::appName, $parent);
52 
53  $this->assertTrue($appTest->isAffected(), sprintf("DCPTEST2 app not found"));
54 
55  $appTest->InitAllParam($parameters, $update = false);
56  $a = $this->getAction();
57  // add new parameters in current action
58  $a->parent->param->SetKey($appTest->id, $a->user->id);
59 
61  return $appTest;
62  }
63 
64  /**
65  * @dataProvider dataGetParam
66  */
67  public function testGetParam($parameters, array $expectedValues)
68  {
69 
70  $this->initTestApplication($parameters);
71 
72  foreach ($expectedValues as $k => $v) {
73  $this->assertEquals($v, \ApplicationParameterManager::getParameterValue(self::appName, $k), sprintf("wrong value for %s", $k));
74  }
75  }
76 
77  /**
78  * @dataProvider dataGetParam
79  */
80  public function testGetUnknownParam($parameters)
81  {
82 
83  $this->initTestApplication($parameters);
84 
85  $this->assertEquals(null, \ApplicationParameterManager::getParameterValue(self::appName, "UNKNOWN_OPTION_VALUE"));
86  }
87 
88  /**
89  * @dataProvider dataGetParam
90  * @expectedException Dcp\ApplicationParameterManager\Exception
91  */
92  public function testSetUnknownParam($parameters)
93  {
94 
95  $this->initTestApplication($parameters);
96 
97  \ApplicationParameterManager::setParameterValue(self::appName, "UNKNOWN_OPTION_VALUE", "25");
98  }
99 
100  /**
101  * @dataProvider dataGetParam
102  */
103  public function testGetScopedParam($parameters, array $expectedValues)
104  {
105 
106  $this->initTestApplication($parameters);
107 
108  foreach ($expectedValues as $k => $v) {
109  $this->assertEquals($v, \ApplicationParameterManager::getScopedParameterValue($k), sprintf("wrong value for %s", $k));
110  }
111  }
112 
113  /**
114  * @dataProvider dataGetGlobalParam
115  */
116  public function testGetGlobalParam($parameters, array $expectedValues)
117  {
118 
119  $this->initTestApplication($parameters);
120 
121  foreach ($expectedValues as $k => $v) {
122  $this->assertEquals($v, \ApplicationParameterManager::getCommonParameterValue(\ApplicationParameterManager::GLOBAL_PARAMETER, $k), sprintf("wrong value for %s", $k));
123  }
124  }
125 
126  /**
127  * @dataProvider dataSetApplicationParameter
128  */
129  public function testSetApplicationParameter($parameters, array $newValues, array $expectedValues)
130  {
131 
132  $this->initTestApplication($parameters);
133 
134  foreach ($newValues as $k => $v) {
136  }
137  foreach ($expectedValues as $k => $v) {
138  $this->assertEquals($v, \ApplicationParameterManager::getParameterValue(self::appName, $k), sprintf("wrong value for %s", $k));
139  }
140  }
141 
142  /**
143  * @dataProvider dataSetGlobalParameter
144  */
145  public function testSetGlobalParameter($parameters, array $newValues, array $expectedValues)
146  {
147 
148  $this->initTestApplication($parameters);
149 
150  foreach ($newValues as $k => $v) {
151 
153  }
154  foreach ($expectedValues as $k => $v) {
155  $this->assertEquals($v, \ApplicationParameterManager::getParameterValue(\ApplicationParameterManager::GLOBAL_PARAMETER, $k), sprintf("wrong value for %s", $k));
156  }
157  }
158 
159  /**
160  * @dataProvider dataSetUserApplicationParameter
161  */
162  public function testSetUserApplicationParameter($parameters, array $newValues, array $expectedValues)
163  {
164 
165  $this->initTestApplication($parameters);
166 
167  foreach ($newValues as $k => $v) {
169  }
170  foreach ($expectedValues as $k => $v) {
171  $this->assertEquals($v, \ApplicationParameterManager::getParameterValue(self::appName, $k), sprintf("wrong value for %s", $k));
172  }
173  }
174 
175  /**
176  * @dataProvider dataGetParameters
177  */
178  public function testGetParameters($parameters)
179  {
180 
181  $definedParametersKey = array_keys($parameters);
182 
183  $this->initTestApplication($parameters);
184  $applicationParameters = \ApplicationParameterManager::getParameters(self::appName);
185  $filterFunction = function ($value) use ($applicationParameters) {
186  foreach ($applicationParameters as $currentApplicationParameters) {
187  if ($currentApplicationParameters["name"] == $value) {
188  return false;
189  }
190  }
191  return true;
192  };
193  $definedParametersKey = array_filter($definedParametersKey, $filterFunction);
194  $this->assertEquals(count($definedParametersKey), 0);
195  }
196 
197  /**
198  * @dataProvider dataGetParameters
199  */
200  public function testGetParameter($parameters)
201  {
202  $this->initTestApplication($parameters);
203  $applicationParameter = \ApplicationParameterManager::getParameter(self::appName, "TST_GLOB1");
204 
205  $this->assertEquals("TST_GLOB1", $applicationParameter["name"]);
206  $this->assertEquals("Name of the glob", $applicationParameter["descr"]);
207  $this->assertEquals("Y", $applicationParameter["isglob"]);
208  $this->assertEquals("N", $applicationParameter["isuser"]);
209  }
210 
211 
212  public function dataUserSetGlobalParameter()
213  {
214  return array(
215  array(
216  "init" => array(
217  "VERSION" => "4.0.8",
218  "PARENT_USER_GLOBAL_PARAMETER_VALUE" => "128",
219  "TST_NAMEP1" => array(
220  "val" => "Test 2",
221  "descr" => "Name of test one",
222  "global" => "Y",
223  "user" => "Y"
224  ),
225  "TST_GLOB2" => array(
226  "val" => "Test global 2",
227  "descr" => "Name of the glob",
228  "global" => "Y",
229  "user" => "Y"
230  )
231  ),
232  "set" => array(
233  "TST_NAMEP1" => "Test 3",
234  "TST_GLOB2" => "Test G3",
235  ),
236  "expect" => array(
237  "TST_NAMEP1" => "Test 3",
238  "VERSION" => "4.0.8",
239  "TST_GLOB2" => "Test G3"
240  )
241  )
242  );
243  }
244 
246  {
247  return array(
248  array(
249  "init" => array(
250  "VERSION" => "0.3.2-2",
251  "PARENT_USER_GLOBAL_PARAMETER_VALUE" => "128",
252  "TST_NAMEP1" => array(
253  "val" => "Test 2",
254  "descr" => "Name of test one",
255  "global" => "N",
256  "user" => "Y"
257  ),
258  "TST_GLOB2" => array(
259  "val" => "Test global 2",
260  "descr" => "Name of the glob",
261  "global" => "Y",
262  "user" => "Y"
263  )
264  ),
265  "set" => array(
266  "PARENT_USER_PARAMETER" => "128,127",
267  "TST_NAMEP1" => "Test 3",
268  ),
269  "expect" => array(
270  "TST_NAMEP1" => "Test 3",
271  "PARENT_USER_PARAMETER" => "128,127",
272  "TST_GLOB2" => "Test global 2"
273  )
274  )
275  );
276  }
277 
278  public function dataSetGlobalParameter()
279  {
280  return array(
281  array(
282  "init" => array(
283  "VERSION" => "4.0.8",
284  "PARENT_GLOBAL_PARAMETER" => "128",
285  "TST_NAMEP1" => array(
286  "val" => "Test 2",
287  "descr" => "Name of test one",
288  "global" => "Y",
289  "user" => "N"
290  ),
291  "TST_GLOB2" => array(
292  "val" => "Test global 2",
293  "descr" => "Name of the glob",
294  "global" => "Y",
295  "user" => "N"
296  )
297  ),
298  "set" => array(
299  "TST_NAMEP1" => "Test 3",
300  "TST_GLOB2" => "Test G3",
301  ),
302  "expect" => array(
303  "TST_NAMEP1" => "Test 3",
304  "TST_GLOB2" => "Test G3"
305  )
306  )
307  );
308  }
309 
310  public function dataSetApplicationParameter()
311  {
312  return array(
313  array(
314  "init" => array(
315  "VERSION" => "0.3.2-2",
316  "PARENT_PARAMETER" => "128",
317  "TST_NAMEP1" => array(
318  "val" => "Test 2",
319  "descr" => "Name of test one",
320  "global" => "N",
321  "user" => "N"
322  ),
323  "TST_GLOB2" => array(
324  "val" => "Test global 2",
325  "descr" => "Name of the glob",
326  "global" => "Y",
327  "user" => "N"
328  )
329  ),
330  "set" => array(
331  "VERSION" => "4.0.7",
332  "PARENT_PARAMETER" => "128,127",
333  "TST_NAMEP1" => "Test 3",
334  ),
335  "expect" => array(
336  "TST_NAMEP1" => "Test 3",
337  "VERSION" => "4.0.7",
338  "PARENT_PARAMETER" => "128,127",
339  "TST_GLOB2" => "Test global 2"
340  )
341  )
342  );
343  }
344 
345  public function dataGetParam()
346  {
347  return array(
348  array(
349  array(
350  "VERSION" => "0.3.2-2",
351  "PARENT_PARAMETER" => "128",
352  "TST_NAMEP1" => array(
353  "val" => "Test 1",
354  "descr" => "Name of test one",
355  "global" => "N",
356  "user" => "N"
357  ),
358  "TST_GLOB1" => array(
359  "val" => "Test global 1",
360  "descr" => "Name of the glob",
361  "global" => "Y",
362  "user" => "N"
363  )
364  ),
365  array(
366  "TST_NAMEP1" => "Test 1",
367  "VERSION" => "0.3.2-2",
368  "PARENT_PARAMETER" => "128",
369  "TST_GLOB1" => "Test global 1"
370  )
371  )
372  );
373  }
374 
375  public function dataGetGlobalParam()
376  {
377  return array(
378  array(
379  array(
380  "VERSION" => "0.3.2-2",
381  "PARENT_PARAMETER" => "128",
382  "TST_NAMEP1" => array(
383  "val" => "Test 1",
384  "descr" => "Name of test one",
385  "global" => "N",
386  "user" => "N"
387  ),
388  "TST_GLOB1" => array(
389  "val" => "Test global 2",
390  "descr" => "Name of the glob",
391  "global" => "Y",
392  "user" => "N"
393  )
394  ),
395  array(
396  "TST_GLOB1" => "Test global 2"
397  )
398  )
399  );
400  }
401 
402  public function dataGetParameters()
403  {
404  return array(
405  array(
406  array(
407  "VERSION" => "0.3.2-2",
408  "PARENT_PARAMETER" => "128",
409  "TST_NAMEP1" => array(
410  "val" => "Test 1",
411  "descr" => "Name of test one",
412  "global" => "N",
413  "user" => "N"
414  ),
415  "TST_GLOB1" => array(
416  "val" => "Test global 2",
417  "descr" => "Name of the glob",
418  "global" => "Y",
419  "user" => "N"
420  )
421  )
422  )
423  );
424  }
425 }
426 
427 ?>
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
testSetUserApplicationParameter($parameters, array $newValues, array $expectedValues)
static getParameterValue($application, $parameterName)
static setParameterValue($application, $parameterName, $value)
testSetApplicationParameter($parameters, array $newValues, array $expectedValues)
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
testSetGlobalParameter($parameters, array $newValues, array $expectedValues)
$dbaccess
Definition: checkVault.php:17
static getCommonParameterValue($application, $parameterName)
if($file) if($subject==""&&$file) if($subject=="") $err
$value
static getParameter($application, $parameterName)
← centre documentaire © anakeen