Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_importfamily.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_document.php';
10 
12 {
13  protected static $outputDir;
14  /**
15  * @dataProvider dataBadFamilyFiles
16  */
17  public function testErrorImportFamily($familyFile, $expectedErrors)
18  {
19  $err = '';
20  try {
21  $this->importDocument($familyFile);
22  }
23  catch(\Exception $e) {
24  $err = $e->getMessage();
25  }
26  $this->assertNotEmpty($err, "no import error detected");
27  if (!is_array($expectedErrors)) $expectedErrors = array(
28  $expectedErrors
29  );
30 
31  foreach ($expectedErrors as $expectedError) {
32  $this->assertContains($expectedError, $err, sprintf("not the correct error reporting : %s", $err));
33  }
34  }
35  /**
36  * test sql view create
37  * @dataProvider dataGoodFamilyFiles
38  */
39  public function testSqlViewFamily($familyFile, $familyName)
40  {
41  $err = '';
42  try {
43  $this->importDocument($familyFile);
44  }
45  catch(\Exception $e) {
46  $err = $e->getMessage();
47  }
48  $this->assertEmpty($err, "import error detected $err");
49  $doc = createDoc("", $familyName);
50  $this->assertTrue(is_object($doc));
51  $err = $doc->store();
52  $this->assertEmpty($err, "cannot create good doc");
53  $id = $this->_DBGetValue(sprintf("select id from family.%s limit 1", strtolower($familyName)));
54 
55  $this->assertGreaterThan(1000, $id, "not found by view");
56  }
57  /**
58  * @dataProvider dataBadUpdateFamilyFiles
59  */
60  public function testBadUpdateFamily($installFamilyFile, $updateFamilyFile, $expectedError)
61  {
62  //print "log:".ini_get("error_log").".\n";
63  $this->importDocument($installFamilyFile);
64  $err = '';
65  try {
66  $this->importDocument($updateFamilyFile);
67  }
68  catch(\Exception $e) {
69  $err = $e->getMessage();
70  }
71  $this->assertNotEmpty($err, "no update error detected");
72  $this->assertContains($expectedError, $err, sprintf("not the correct error reporting : %s", $err));
73  }
74 
75  public function dataBadUpdateFamilyFiles()
76  {
77  return array(
78  // test attribute too long
79  array(
80  "PU_data_dcp_initfamily1.ods",
81  "PU_data_dcp_updatefamily1.ods",
82  "TST_TITLE"
83  ) ,
84  array(
85  "PU_data_dcp_initfamily2.ods",
86  "PU_data_dcp_updatefamily2.ods",
87  "TST_TITLE"
88  )
89  );
90  }
91 
92  public function dataBadFamilyFiles()
93  {
94  return array(
95  // type modattr
96  array(
97  "PU_data_dcp_badmodattr1.ods",
98  array(
99  "ATTR0604",
100  "TST_BADMODFAM_2",
101  "attr_int",
102  '"int"',
103  "TST_BADMODFAM_3",
104  "attr_date",
105  '"date"'
106  )
107  ) ,
108  // enum redfinition
109  array(
110  "PU_data_dcp_badmodattr2.ods",
111  array(
112  "ATTR0606",
113  "attr_enum_a",
114  "TST_BADMODFAM_4"
115  )
116  ) ,
117  // undefined modattr
118  array(
119  "PU_data_dcp_badmodattr3.ods",
120  array(
121  "ATTR0605",
122  "attr_undefined"
123  )
124  ) ,
125  // test attribute too long
126  array(
127  "PU_data_dcp_badattr1.ods",
128  array(
129  "ATTR0100",
130  "aaaaaa",
131  "ATTR0102",
132  "tst number",
133  "ATTR0101",
134  "select",
135  "ATTR0103",
136  "title",
137  "ATTR0200",
138  "tst_orphan",
139  "ATTR0201",
140  "tst_invstruct",
141  "not defined",
142  "ATTR0202",
143  "tst_same",
144  "ATTR0206",
145  "none_tab"
146  )
147  ) ,
148  // test method not found
149  array(
150  "PU_data_dcp_badattr2.ods",
151  array(
152  "Method.NotFound"
153  )
154  ) ,
155  // test order needed
156  array(
157  "PU_data_dcp_badattr3.ods",
158  array(
159  "ATTR0700",
160  "tst_noorder",
161  "ATTR0702",
162  "tst_errorder"
163  )
164  ) ,
165  // test type
166  array(
167  "PU_data_dcp_badattr4.ods",
168  array(
169  "ATTR0600",
170  "tst_typetest",
171  "ATTR0601",
172  "ATTR0602",
173  "tst_errtype",
174  "tst_notype"
175  )
176  ) ,
177  // test visibility
178  array(
179  "PU_data_dcp_badattr5.ods",
180  array(
181  "ATTR0800",
182  "tst_novis",
183  "ATTR0801",
184  "tst_errvis",
185  "ZS",
186  "ATTR0802",
187  "tst_noarray"
188  )
189  ) ,
190  // test isTitle isAbstract isNeeded
191  array(
192  "PU_data_dcp_badattr6.ods",
193  array(
194  "ATTR0500",
195  "tst_noabstract",
196  "ATTR0501",
197  "tst_t_abstract",
198  "ATTR0400",
199  "tst_notitle",
200  "ATTR0401",
201  "tst_t_title",
202  "ATTR0900",
203  "tst_two",
204  "ATTR0901",
205  "tst_noneed"
206  )
207  ) ,
208  // input help
209  array(
210  "PU_data_dcp_badattr7.ods",
211  array(
212  "ATTR1100",
213  "tstNoHelp.php",
214  "ATTR1101",
215  "ATTR1200",
216  "ATTR1201",
217  "tst_nphelp",
218  "noParenthesis",
219  "ATTR1202",
220  "ATTR1203",
221  "testNoExistsReally",
222  "ATTR1209",
223  "is_a",
224  "ATTR1210",
225  "addLogMsg"
226  )
227  ) ,
228  // options syntax
229  array(
230  "PU_data_dcp_badattr8.ods",
231  array(
232  "ATTR1500",
233  "optionerror",
234  "ATTR1501",
235  "wrong error"
236  )
237  ) ,
238  // options syntax
239  array(
240  "PU_data_dcp_badattr9.ods",
241  array(
242  "ATTR1250",
243  "tst_number1",
244  "ATTR1252",
245  "ATTR1251",
246  "tst_number2",
247  "bad Compute1",
248  "ATTR1400",
249  "tst_number3",
250  "ATTR1255",
251  "tst_number4"
252  )
253  ) ,
254  // method control in the end
255  array(
256  "PU_data_dcp_badattr10.ods",
257  array(
258  "ATTR1260",
259  "badCompute1",
260  "context : \"phpFunc\"",
261  "tst_number1",
262  "ATTR1261",
263  "tst_number2",
264  "goodCompute2",
265  "tst_number3",
266  "ATTR1401",
267  "tst_number4",
268  "ATTR1402",
269  "DFLT0004",
270  "context : \"Default value\"",
271  "DFLT0005",
272  "tst_notfound",
273  "badCall",
274  "ATTR1001",
275  "ATTR1002",
276  "goodCompute1",
277  "DFLT0006",
278  "notjson",
279  "INIT0005",
280  "tst_p2"
281  )
282  ) ,
283  // method control in the end
284  array(
285  "PU_data_dcp_badattr11.ods",
286  array(
287  "ATTR0203",
288  "tst_number2",
289  "ATTR0204",
290  "tst_number1",
291  "ATTR0205",
292  "tst_number4",
293  "ATTR0207",
294  "tst_frame2"
295  )
296  ) ,
297  // static enum
298  array(
299  "PU_data_dcp_badattr12.ods",
300  array(
301  "ATTR1270",
302  "tst_badeenum",
303  "tst_badnenum",
304  "ATTR1271",
305  "tst_badkenum",
306  "DFLT0001",
307  "tst syntax",
308  "DFLT0002",
309  "DFLT0003",
310  "ATTR1272",
311  "tst_bad_enum_empty_key"
312  )
313  ) ,
314  // format string
315  array(
316  "PU_data_dcp_badattr13.ods",
317  array(
318  "ATTR0603",
319  "tst_badformat2"
320  )
321  ) ,
322  // format string
323  array(
324  "PU_data_dcp_badattr14.ods",
325  array(
326  "ATTR1701"
327  )
328  ) ,
329  // PARAM frame errors
330  array(
331  "PU_data_dcp_badattr15.ods",
332  array(
333  "ATTR0208",
334  "tst_number2",
335  "ATTR0209",
336  "tst_number1",
337  "ATTR0210",
338  "tst_number4",
339  "tst_frame2",
340  "ATTR0903",
341  "tst_colneed"
342  )
343  ) ,
344  // PARAM phpfunc errors
345  array(
346  "PU_data_dcp_badattr16.ods",
347  array(
348  "ATTR0211",
349  "tst_docid"
350  )
351  ) ,
352  array(
353  "PU_data_dcp_badattr17.ods",
354  array(
355  "ATTR0212",
356  "tst_errorder",
357  "one"
358  )
359  ) ,
360  array(
361  "PU_data_dcp_badattr18.ods",
362  array(
363  "ATTR0213",
364  "tst_t3",
365  "tst_frame1",
366  "tst_frame2"
367  )
368  ),
369  array(
370  "PU_data_dcp_badattr19.ods",
371  array(
372  "ATTR0214",
373  "loop_a5"
374  )
375  )
376  );
377  }
378 
379  public function dataGoodFamilyFiles()
380  {
381  return array(
382  // test simple family
383  array(
384  "PU_data_dcp_goodfamily1.ods",
385  "TST_GOODFAMIMP1",
386  false
387  ) , // with method file
388  array(
389  "PU_data_dcp_goodfamily2.ods",
390  "TST_GOODFAMIMP2",
391  false
392  ) , // with class file
393  array(
394  "PU_data_dcp_goodfamily4.ods",
395  "TST_GOODFAMIMP4",
396  false
397  ) ,
398  // Family update with PARAM + INITIAL value
399  array(
400  "PU_data_dcp_goodfamily5.ods",
401  "TST_GOODFAMIMP5",
402  false
403  ) ,
404  // Family update with PARAM + INITIAL value
405  array(
406  "PU_data_dcp_goodfamily6.ods",
407  "TST_GOODFAMIMP6",
408  false
409  )
410  );
411  }
412 }
testSqlViewFamily($familyFile, $familyName)
static importDocument($file)
testErrorImportFamily($familyFile, $expectedErrors)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
testBadUpdateFamily($installFamilyFile, $updateFamilyFile, $expectedError)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen