Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_importDocuments.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  /**
18  * import TST_FAMSETVALUE family
19  * @static
20  * @return string
21  */
22  protected static function getCommonImportFile()
23  {
24  return "PU_data_dcp_goodfamilyfordoc.ods";
25  }
26  /**
27  * test import simple document
28  * @dataProvider dataGoodDocFiles
29  */
30  public function testGoodImportDocument($documentFile, array $expects)
31  {
32  $err = '';
33  $d = createDoc(self::$dbaccess, "TST_GOODFAMIMPDOC");
34  $this->assertTrue(is_object($d) , "cannot create TST_GOODFAMIMPDOC document");
35  try {
36  $this->importDocument($documentFile);
37  }
38  catch(\Exception $e) {
39  $err = $e->getMessage();
40  }
41  $this->assertEmpty($err, "import error detected $err");
42 
43  foreach ($expects as $docNames) {
44  $name = $docNames["docName"];
45  $t = getTDoc(self::$dbaccess, $name);
46  $this->assertArrayHasKey('id', $t, sprintf("cannot find %s document", $name));
47  foreach ($docNames["expectValue"] as $aid => $expVal) {
48  if ($expVal[0] === "*") {
49  $this->assertContains(substr($expVal, 1) , $t[$aid]);
50  } else {
51  $this->assertEquals($expVal, $t[$aid]);
52  }
53  }
54  }
55  }
56  /**
57  * @dataProvider dataBadDocFiles
58  * @---depends testGoodImportDocument
59  *
60  */
61  public function testErrorImportDocument($familyFile, array $expectedErrors)
62  {
63 
64  $err = '';
65  try {
66  $this->importDocument($familyFile);
67  }
68  catch(\Exception $e) {
69  $err = $e->getMessage();
70  }
71  $this->assertNotEmpty($err, "no import error detected");
72  if (!is_array($expectedErrors)) $expectedErrors = array(
73  $expectedErrors
74  );
75 
76  foreach ($expectedErrors as $expectedError) {
77  $this->assertContains($expectedError, $err, sprintf("not the correct error reporting : %s", $err));
78  }
79  }
80  /**
81  * @dataProvider dataReturnOfImportDocument
82  */
84  {
85  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
86 
87  $err = '';
88  $cr = array();
89  try {
90  $cr = $this->importDocument($data['file']);
91  }
92  catch(\Exception $e) {
93  $err = $e->getMessage();
94  }
95  $this->assertEmpty($err, sprintf("Import of '%s' returned with unexpected errors: %s", $data['file'], $err));
96 
97  foreach (array(
98  'specmsg'
99  ) as $prop) {
100  if (isset($data[$prop])) {
101  if (isset($data[$prop]['contains'])) {
102  foreach ($data[$prop]['contains'] as $string) {
103  $found = false;
104  foreach ($cr as $line) {
105  $msg = (isset($line[$prop]) ? $line[$prop] : '');
106  if (strpos($msg, $string) !== false) {
107  $found = true;
108  }
109  }
110  $this->assertTrue($found, sprintf("Expected string '%s' not found in '%s': %s", $string, $prop, var_export($cr, true)));
111  }
112  }
113  if (isset($data[$prop]['not:contains'])) {
114  foreach ($data[$prop]['not:contains'] as $string) {
115  $found = false;
116  foreach ($cr as $line) {
117  $msg = (isset($line[$prop]) ? $line[$prop] : '');
118  if (strpos($msg, $string) !== false) {
119  $found = true;
120  }
121  }
122  $this->assertFalse($found, sprintf("Non-expected string '%s' found in '%s': %s", $string, $prop, var_export($cr, true)));
123  }
124  }
125  }
126  }
127  }
128  public function dataGoodDocFiles()
129  {
130  return array(
131  array(
132  "file" => "PU_data_dcp_importdocgood1.ods",
133  array(
134  array(
135  "docName" => "TST_GOOD1",
136  "expectValue" => array(
137  "tst_title" => "Test1",
138  "tst_number" => "20"
139  )
140  ) ,
141  array(
142  "docName" => "TST_GOOD4",
143  "expectValue" => array(
144  "tst_title" => "Portez ce vieux whisky au juge blond qui fume sur son île intérieure, à côté de l'alcôve ovoïde, où les bûches se consument dans l'âtre, ce qui lui permet de penser à la cænogénèse de l'être dont il est question dans la cause ambiguë entendue à Moÿ, dans un capharnaüm qui, pense-t-il, diminue çà et là la qualité de son œuvre.",
145  "tst_number" => "-4"
146  )
147  )
148  )
149  ) ,
150  array(
151  "file" => "../PU_data_dcp_importdocgood2.zip",
152  array(
153  array(
154  "docName" => "TST_GOOD2",
155  "expectValue" => array(
156  "tst_title" => "Dès Noël où un zéphyr haï me vêt de glaçons würmiens je dîne d’exquis rôtis de bœuf au kir à l’aÿ d’âge mûr & cætera",
157  "tst_number" => "9878",
158  "tst_date" => "1987-12-02"
159  )
160  ) ,
161  array(
162  "docName" => "TST_GOOD3",
163  "expectValue" => array(
164  "tst_title" => "Zéphir",
165  "tst_number" => "987",
166  "tst_date" => "2015-10-02",
167  "tst_file" => "*Zéphir.txt"
168  )
169  ) ,
170  array(
171  "docName" => "TST_GOOD4",
172  "expectValue" => array(
173  "tst_title" => "<Foo'Bar\"Baz&Buz>",
174  "tst_number" => "987",
175  "tst_date" => "2015-10-02",
176  "tst_file" => "*|<Foo'Bar\"Baz&Buz>.txt"
177  )
178  )
179  )
180  )
181  );
182  }
183 
184  public function dataBadDocFiles()
185  {
186  return array(
187  array(
188  "file" => "PU_data_dcp_importdocbad1.ods",
189  "errors" => array(
190  "DOC0100",
191  "tst_number",
192  "DOC0002",
193  "NoFamily",
194  "DOC0003",
195  "Bad Family",
196  "DOC0004",
197  "DOC0005",
198  "UNKNOWFAMILY",
199  "DOC0006",
200  "NotFamily",
201  "Bad name",
202  "DOC0008",
203  "DIR",
204  "DOC0201",
205  "TST_BADINSERT",
206  "DOC0202",
207  "TST_UNKFOLDER"
208  ) ,
209  ) ,
210  array(
211  "file" => "PU_data_dcp_importdocbad2.ods",
212  "errors" => array(
213  "ORDR0001",
214  "ORDR0002",
215  "TST_FOLDER1",
216  "ORDR0003",
217  "ORDR0006",
218  "TST_FAMUNK",
219  "ORDR0100",
220  "tst_unknow"
221  )
222  ) ,
223  array(
224  "file" => "PU_data_dcp_importdocbad3.ods",
225  "errors" => array(
226  "KEYS0001",
227  "KEYS0002",
228  "TST_FOLDER1",
229  "KEYS0003",
230  "KEYS0006",
231  "TST_KEYFAMUNK",
232  "KEYS0100",
233  "tst_keyunknow",
234  "KEYS0101",
235  "KEYS0101",
236  "KEYS0102"
237  )
238  ) ,
239  array(
240  "PU_data_dcp_importdocbad5.ods",
241  array(
242  "Couldn't find end of Start Tag p",
243  "error parsing attribute name",
244  "Opening and ending tag mismatch: p and em"
245  )
246  )
247  );
248  }
249  public function dataReturnOfImportDocument()
250  {
251  return array(
252  array(
253  array(
254  "file" => "PU_data_dcp_importdocbad4.ods",
255  "specmsg" => array(
256  "contains" => array(
257  "Nom logique 'TST_GOODFAMIMPDOC_4' inconnu dans l'attribut 'tst_docid_1'",
258  "Nom logique 'TST_GOODFAMIMPDOC_4' inconnu dans l'attribut 'tst_docid_m'",
259  "Nom logique 'TST_GOODFAMIMPDOC_4' inconnu dans l'attribut 'tst_docid_x'"
260  ) ,
261  "not:contains" => array(
262  "Nom logique 'TST_GOODFAMIMPDOC_1' inconnu dans l'attribut 'tst_docid_",
263  "Nom logique 'TST_GOODFAMIMPDOC_3' inconnu dans l'attribut 'tst_docid_"
264  )
265  )
266  )
267  )
268  );
269  }
270 }
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
testGoodImportDocument($documentFile, array $expects)
static importDocument($file)
$d
Definition: dav.php:77
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
testErrorImportDocument($familyFile, array $expectedErrors)
requiresCoreParamEquals($paramName, $requiredValue, $markTestIncomplete=true)
$data
← centre documentaire © anakeen