Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_getParam.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package Dcp\Pu
5 */
6 
7 namespace Dcp\Pu;
8 
9 require_once 'PU_testcase_dcp.php';
10 
12 {
13  /**
14  * @dataProvider dataGetCoreParamNonExisting
15  */
17  {
18  $value = getCoreParam($data['name'], $data['def']);
19 
20  $sameType = (gettype($value) == gettype($data['expected']));
21  $sameValue = ($value == $data['expected']);
22 
23  $this->assertTrue($sameType, sprintf("Result type mismatch: found type '%s' while expecting type '%s'.", gettype($value) , gettype($data['expected'])));
24  $this->assertTrue($sameValue, sprintf("Unexpected result: found '%s' while expecting '%s'.", $value, $data['expected']));
25  }
26  /**
27  * @dataProvider dataGetParamNonExisting
28  */
29  public function testGetParamNonExisting($data)
30  {
31  $value = getParam($data['name'], $data['def']);
32 
33  $sameType = (gettype($value) == gettype($data['expected']));
34  $sameValue = ($value == $data['expected']);
35 
36  $this->assertTrue($sameType, sprintf("Result type mismatch: found type '%s' while expecting type '%s'.", gettype($value) , gettype($data['expected'])));
37  $this->assertTrue($sameValue, sprintf("Unexpected result: found '%s' while expecting '%s'.", $value, $data['expected']));
38  }
39  /**
40  * @dataProvider dataGetCoreParamIsSet
41  */
42  public function testGetCoreParamIsSet($data)
43  {
44  $value = getCoreParam($data['name'], null);
45 
46  $this->assertTrue(($value !== null) , "Returned value is not set.");
47  }
48  /**
49  * @dataProvider dataGetCoreParamIsSet
50  */
51  public function testGetParamIsSet($data)
52  {
53  $value = getParam($data['name'], null);
54 
55  $this->assertTrue(($value !== null) , "Returned value is not set.");
56  }
57  /**
58  * @param $paramName
59  * @param $appName
60  * @param $expectedProps
61  * @dataProvider dataGetParamDef
62  */
63  public function testGetParamDef($paramName, $appName, $expectedProps)
64  {
65 
66  $appId = null;
67  if ($appName) {
68  simpleQuery(self::$dbaccess, sprintf("select id from application where name='%s'", pg_escape_string($appName)) , $appId, true, true);
69  }
70  $paramDef = \ParamDef::getParamDef($paramName, $appId);
71  if (empty($expectedProps)) {
72  $this->assertEmpty($paramDef, "parameter $paramName must not be found");
73  } else {
74  $this->assertNotEmpty($paramDef, "parameter $paramName must be found in app #$appId");
75  foreach ($expectedProps as $kProp => $vProp) {
76  $this->assertEquals($vProp, $paramDef->$kProp, "wrong property $kProp" . print_r($paramDef->getValues() , true));
77  }
78  }
79  }
80 
81  public function dataGetParamDef()
82  {
83  return array(
84  array(
85  'name' => 'CORE_NON_EXISTING_PARAM',
86  'app' => 'FDL',
87  'expected' => ''
88  ) ,
89  array(
90  'name' => 'AUTHENT_SHOW_LANG_SELECTION',
91  'app' => 'FDL',
92  'expected' => ''
93  ) ,
94  array(
95  'name' => 'AUTHENT_SHOW_LANG_SELECTION',
96  'app' => 'AUTHENT',
97  'expected' => array(
98  "name" => "AUTHENT_SHOW_LANG_SELECTION",
99  "isglob" => "N"
100  )
101  ) ,
102  array(
103  'name' => 'VERSION',
104  'app' => 'AUTHENT',
105  'expected' => array(
106  "name" => "VERSION",
107  "isglob" => "N"
108  )
109  ) ,
110  array(
111  'name' => 'CORE_CLIENT',
112  'app' => 'CORE',
113  'expected' => array(
114  "name" => "CORE_CLIENT",
115  "isglob" => "Y"
116  )
117  ) ,
118  array(
119  'name' => 'CORE_CLIENT',
120  'app' => '',
121  'expected' => array(
122  "name" => "CORE_CLIENT",
123  "isglob" => "Y"
124  )
125  ) ,
126  array(
127  'name' => 'CORE_CLIENT',
128  'app' => 'FDL',
129  'expected' => array(
130  "name" => "CORE_CLIENT",
131  "isglob" => "Y"
132  )
133  ) ,
134  array(
135  'name' => 'CORE_CLIENT',
136  'app' => 'FDL',
137  'expected' => array(
138  "name" => "CORE_CLIENT",
139  "isglob" => "Y"
140  )
141  ) ,
142  array(
143  'name' => 'SMTP_HOST',
144  'app' => '',
145  'expected' => array(
146  "name" => "SMTP_HOST",
147  "isglob" => "Y"
148  )
149  ) ,
150  array(
151  'name' => 'SMTP_HOST',
152  'app' => 'FDL',
153  'expected' => array(
154  "name" => "SMTP_HOST",
155  "isglob" => "Y"
156  )
157  ) ,
158  array(
159  'name' => 'SMTP_HOST',
160  'app' => 'APPMNG',
161  'expected' => array(
162  "name" => "SMTP_HOST",
163  "isglob" => "Y"
164  )
165  )
166  );
167  }
168 
169  public function dataGetCoreParamNonExisting()
170  {
171  return array(
172  array(
173  array(
174  'name' => 'CORE_NON_EXISTING_PARAM',
175  'def' => 'DOES_NOT_EXISTS',
176  'expected' => 'DOES_NOT_EXISTS'
177  )
178  )
179  );
180  }
181 
182  public function dataGetParamNonExisting()
183  {
184  return array(
185  array(
186  array(
187  'name' => 'CORE_NON_EXISTING_PARAM',
188  'def' => 'DOES_NOT_EXISTS',
189  'expected' => 'DOES_NOT_EXISTS'
190  )
191  )
192  );
193  }
194 
195  public function dataGetCoreParamIsSet()
196  {
197  return array(
198  array(
199  array(
200  'name' => 'CORE_CLIENT'
201  // CORE 'G'
202 
203  ) ,
204  array(
205  'name' => 'CORE_DB'
206  // CORE 'A'
207 
208  )
209  )
210  );
211  }
212 
213  public function dataGetParamIsSet()
214  {
215  return array(
216  array(
217  array(
218  'name' => 'CORE_CLIENT'
219  // CORE 'G'
220 
221  ) ,
222  array(
223  'name' => 'CORE_DB'
224  // CORE 'A'
225 
226  )
227  )
228  );
229  }
230 }
231 ?>
static getParamDef($name, $appid=null)
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
testGetParamDef($paramName, $appName, $expectedProps)
$dbaccess
Definition: checkVault.php:17
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
$value
getCoreParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:209
$data
← centre documentaire © anakeen