Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_importXmlDocuments.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_FAMIMP1 family
19  * @static
20  * @return string
21  */
22  protected static function getCommonImportFile()
23  {
24  return "PU_data_dcp_importfamily1.ods";
25  }
26  /**
27  * count error from import report message
28  * @param $err
29  * @return int|void
30  */
31  private function countErrors($err)
32  {
33  if (!$err) return 0;
34  return count(explode("]\n[", $err));
35  }
36  /**
37  * @dataProvider dataDocumentFiles
38  * @param string $documentFile
39  * @param int $nbError
40  * @throws \Dcp\Db\Exception
41  */
42  public function testErrorImportDocument($documentFile, $nbError)
43  {
44  $err = '';
45  try {
46  $this->importDocument($documentFile);
47  }
48  catch(\Dcp\Exception $e) {
49  $err = $e->getMessage();
50  }
51  $this->assertNotEmpty($err);
52  $this->assertEquals($nbError, $this->countErrors($err) , sprintf('status error : "%s"', $err));
53 
54  $s = new \SearchDoc("", "TST_FAMIMP1");
55  $this->assertEquals(0, $s->onlyCount() , "document is created and must be not");
56  }
57  /**
58  * @dataProvider dataIuserFiles
59  * @param string $documentFile
60  */
61  public function testErrorImportIuser($documentFile)
62  {
63  $err = '';
64  try {
65  $this->importDocument($documentFile);
66  }
67  catch(\Dcp\Exception $e) {
68  $err = $e->getMessage();
69  }
70  $this->assertNotEmpty($err);
71  }
72  /**
73  * @dataProvider dataFolderImportDocument
74  * @param string $documentFile
75  * @param string $docName
76  * @param array $folderNames
77  */
78  public function testFolderImportDocument($documentFile, $docName, array $folderNames)
79  {
80  $err = '';
81  try {
82  $this->importDocument($documentFile);
83  }
84  catch(\Dcp\Exception $e) {
85  $err = $e->getMessage();
86  }
87  $this->assertEmpty($err, sprintf("Error : $err"));
88  $doc = new_doc("", $docName);
89  $this->assertTrue($doc->isAlive() , sprintf("cannot import %s document", $docName));
90  $folders = $doc->getParentFolderIds();
91  foreach ($folderNames as $folder) {
92  $fid = getIdFromName(self::$dbaccess, $folder);
93  $this->assertTrue(in_array($fid, $folders) , sprintf("folder %s not found in %s", $folder, print_r($folders, true)));
94  }
95  }
96  /**
97  * @dataProvider dataExtraImportDocument
98  * @param string $documentFile
99  * @param string $docName
100  * @param array $extraValues
101  */
102  public function testExtraImportDocument($documentFile, $docName, array $extraValues)
103  {
104  $err = '';
105  try {
106  $this->importDocument($documentFile);
107  }
108  catch(\Dcp\Exception $e) {
109  $err = $e->getMessage();
110  }
111  $this->assertEmpty($err, sprintf("Error : $err"));
112  $doc = new_doc("", $docName);
113  $this->assertTrue($doc->isAlive() , sprintf("cannot import %s document", $docName));
114  $tColK = $doc->getMultipleRawValues("tst_extrakey");
115  $tColv = $doc->getMultipleRawValues("tst_extraval");
116  $tExtra = array();
117  foreach ($tColK as $k => $v) {
118  $tExtra[$v] = $tColv[$k];
119  }
120  foreach ($extraValues as $expKey => $expVal) {
121 
122  $this->assertEquals($expVal, $tExtra[$expKey], sprintf("not correct extra : %s", print_r($tExtra, true)));
123  }
124  }
125 
126  public function dataDocumentFiles()
127  {
128  return array(
129  array(
130  "PU_data_dcp_importdoc1.xml",
131  1
132  ) ,
133  array(
134  "PU_data_dcp_importdoc2.xml",
135  1
136  ) ,
137  array(
138  "PU_data_dcp_importdoc3.xml",
139  2
140  ) ,
141  array(
142  "PU_data_dcp_importdoc4.xml",
143  1
144  )
145  );
146  }
147  public function dataIuserFiles()
148  {
149  return array(
150  array(
151  "PU_dcp_data_iuser.xml"
152  )
153  );
154  }
155 
156  public function dataExtraImportDocument()
157  {
158  return array(
159  array(
160  "PU_data_dcp_importdoc8.xml",
161  "TST_DOCIMP4",
162  array(
163  'state' => "test",
164  'title' => "Un",
165  "revision" => 2
166  )
167  )
168  );
169  }
170  public function dataFolderImportDocument()
171  {
172  return array(
173  array(
174  "PU_data_dcp_importdoc5.xml",
175  "TST_DOCIMP1",
176  array(
177  'TST_FOLDER1'
178  )
179  ) ,
180  array(
181  "PU_data_dcp_importdoc6.xml",
182  "TST_DOCIMP2",
183  array(
184  'TST_FOLDER1',
185  'TST_FOLDER2'
186  )
187  ) ,
188  array(
189  "PU_data_dcp_importdoc7.xml",
190  "TST_DOCIMP3",
191  array(
192  'TST_FOLDER1',
193  'TST_FOLDER2',
194  'TST_FOLDER3'
195  )
196  )
197  );
198  }
199 }
200 ?>
testExtraImportDocument($documentFile, $docName, array $extraValues)
static importDocument($file)
if($famId) $s
testErrorImportDocument($documentFile, $nbError)
testFolderImportDocument($documentFile, $docName, array $folderNames)
$dbaccess
Definition: checkVault.php:17
getIdFromName($dbaccess, $name)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen