Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_document.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 some documents
19  * @static
20  * @return string
21  */
22  protected static function getCommonImportFile()
23  {
24  return array(
25  "PU_data_dcp_somebasicdoc.ods",
26  "PU_data_dcp_fileattr.ods"
27  );
28  }
29  /**
30  * @dataProvider provider
31  * @param string $a
32  * @return \Doc
33  */
34  public function testAlive($a)
35  {
36  $d = new_doc(self::$dbaccess, $a);
37  $this->assertTrue($d->isAlive() , sprintf("document %s not alive", $a));
38  return $d;
39  }
40  /**
41  * @dataProvider logicalName
42  * @depends testAlive
43  * @param string $file
44  * @param array $ln
45  */
46  public function testLogicalName($file, array $ln)
47  {
48  $this->importDocument($file);
49 
50  foreach ($ln as $n) {
51  $this->testAlive($n);
52  }
53  }
54  /**
55  * @dataProvider provider
56  * @depends testAlive
57  * @param string $a
58  */
59  public function testLock($a)
60  {
61 
62  $d = new_doc(self::$dbaccess, $a, true);
63  if ($d->isAlive()) {
64  if ($d->canLock()) {
65  $d->lock();
66  $slock = $this->_DBGetValue(sprintf("select locked from docread where id=%d", $d->id));
67  $slock = intval($slock);
68  $this->assertEquals($d->userid, $slock, sprintf("document %d not locked", $a));
69  } else {
70  $this->markTestIncomplete(sprintf(_('Document %d is locked.') , $a));
71  }
72  } else {
73  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
74  }
75  }
76  /**
77  * @dataProvider provider
78  * @depends testAlive
79  * @param string $a
80  */
81  public function testunLock($a)
82  {
83  $d = new_doc(self::$dbaccess, $a, true);
84  if ($d->isAlive()) {
85  if ($d->canUnLock()) {
86  $d->unlock();
87  $slock = $this->_DBGetValue(sprintf("select locked from docread where id=%d", $d->id));
88  $slock = intval($slock);
89  $this->assertEquals(0, $slock, sprintf("document %d still locked", $a));
90  } else {
91  $this->markTestIncomplete(sprintf(_('Document %d is locked.') , $a));
92  }
93  } else {
94  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
95  }
96  }
97  /**
98  * @dataProvider provider
99  * @depends testAlive
100  * @param string $a
101  */
102  public function testautoLock($a)
103  {
104 
105  $d = new_doc(self::$dbaccess, $a, true);
106  if ($d->isAlive()) {
107  if ($d->canLock()) {
108  $d->lock(true);
109 
110  $slock = $this->_DBGetValue(sprintf("select locked from docread where id=%d", $d->id));
111  $slock = intval($slock);
112  if ($d->userid == 1) {
113  //$this->markTestIncomplete(sprintf(_('Admin cannot auto lock.')));
114 
115  } else $this->assertEquals(-($d->userid) , ($slock) , sprintf("document %d not locked", $a));
116  } else {
117  $this->markTestIncomplete(sprintf(_('Document %d is locked.') , $a));
118  }
119  } else {
120  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
121  }
122  }
123  /**
124  * @dataProvider dataDelete
125  * @param string $name
126  * @param string $familyName
127  */
128  public function testDelete($name, $familyName)
129  {
130  if ($name) {
131  $d = new_doc(self::$dbaccess, $name, true);
132  if ($d->isAlive()) {
133  $this->markTestIncomplete(sprintf(_('Document %s exists.') , $name));
134  }
135  }
136  $nd = createDoc(self::$dbaccess, $familyName, false);
137  if (!$nd) {
138  $this->assertFalse($nd, sprintf("cannot create document BASE"));
139  }
140  $err = $nd->add();
141  $this->assertEmpty($err, sprintf("error when create document BASE : %s", $err));
142  $this->assertTrue(($nd->id > 0) , sprintf("no id when create document BASE"));
143  if ($name) {
144  $err = $nd->setLogicalName($name);
145  $this->assertEmpty($err, sprintf("cannot set name %s : %s", $name, $err));
146  }
147  $err = $nd->delete();
148  $this->assertEmpty($err, sprintf("error when delete document BASE : %s", $err));
149  $slock = $this->_DBGetValue(sprintf("select locked from docread where id=%d", $nd->id));
150  $this->assertEquals(-1, $slock, sprintf("document %s not locked fix", $name));
151  $sdoctype = $this->_DBGetValue(sprintf("select doctype from docread where id=%d", $nd->id));
152  $this->assertEquals('Z', $sdoctype, sprintf("document %s not deleted fix", $name));
153 
154  $err = $nd->undelete();
155  $this->assertEmpty($err, sprintf("error when undelete document BASE : %s", $err));
156  $slock = $this->_DBGetValue(sprintf("select locked from docread where id=%d", $nd->id));
157  $this->assertGreaterThan(-1, $slock, sprintf("document %s locked fix", $name));
158  $sdoctype = $this->_DBGetValue(sprintf("select doctype from docread where id=%d", $nd->id));
159  $this->assertNotEquals('Z', $sdoctype, sprintf("document %s not revived fix", $name));
160  $sname = $this->_DBGetValue(sprintf("select name from docread where id=%d", $nd->id));
161  $this->assertEquals($name, $sname, sprintf("document %s not restore its name fix", $name));
162  // Redelete
163  if ($name) {
164  $err = $nd->delete();
165  $this->assertEmpty($err, sprintf("error when delete document BASE(1) : %s", $err));
166 
167  $nd2 = createDoc(self::$dbaccess, $familyName, false);
168 
169  $err = $nd2->add();
170  $this->assertEmpty($err, sprintf("error when create document BASE(2) : %s", $err));
171  $err = $nd2->setLogicalName($name);
172  $this->assertEmpty($err, sprintf("cannot set name %s : %s", $name, $err));
173  $err = $nd->undelete();
174  $this->assertEmpty($err, sprintf("error when undelete document BASE(1) : %s", $err));
175  $sname = $this->_DBGetValue(sprintf("select name from docread where id=%d", $nd->id));
176  $this->assertEmpty($sname, sprintf("document %s name must be empty", $name));
177  }
178  }
179  /**
180  * @dataProvider dataDelete
181  * @param string $name
182  * @param string $familyName
183  */
184  public function testReallyDelete($name, $familyName)
185  {
186  if ($name) {
187  $d = new_doc(self::$dbaccess, $name, true);
188  if ($d->isAlive()) {
189  $this->markTestIncomplete(sprintf(_('Document %s exists.') , $name));
190  }
191  }
192  $nd = createDoc(self::$dbaccess, $familyName, false);
193  if (!$nd) $this->assertFalse($nd, sprintf("cannot create document BASE"));
194  $err = $nd->add();
195  $this->assertEmpty($err, sprintf("error when create document BASE : %s", $err));
196 
197  $this->assertTrue(($nd->id > 0) , sprintf("no id when create document BASE"));
198  if ($name) {
199  $err = $nd->setLogicalName($name);
200  $this->assertEmpty($err, sprintf("cannot set name %s : %s", $name, $err));
201  }
202  $err = $nd->delete(true);
203  $this->assertEmpty($err, sprintf("error when delete document BASE : %s", $err));
204 
205  $sid = $this->_DBGetValue(sprintf("select id from docread where id=%d", $nd->id));
206  $this->assertFalse($sid, sprintf("document %s not really deleted (docread)", $nd->id));
207  if ($name) {
208  $sid = $this->_DBGetValue(sprintf("select id from docname where name='%s'", $name));
209  $this->assertFalse($sid, sprintf("document %s not really deleted (docname)", $name));
210  }
211  $sid = $this->_DBGetValue(sprintf("select id from docfrom where id='%s'", $nd->id));
212  $this->assertFalse($sid, sprintf("document %s not really deleted (docfrom)", $nd->id));
213 
214  $err = $nd->undelete();
215  $this->assertNotEmpty($err, sprintf("error when undelete document BASE : %s", $err));
216  }
217  /**
218  * @dataProvider dataStoreFile
219  * @param string $docId
220  * @param string $attrName
221  * @param string $filePathName
222  * @param string $fileName
223  * @param int $index
224  */
225  public function testStoreFile($docId, $attrName, $filePathName, $fileName, $index = - 1)
226  {
227  $doc = new_doc(self::$dbaccess, $docId);
228  $this->assertTrue($doc->isAlive() , sprintf("could not get document with id '%s'", $docId));
229 
230  $err = $doc->setFile($attrName, $filePathName, $fileName, $index);
231  $this->assertEmpty($err, sprintf("storeFile(%s, %s, %s, %s) returned with error: %s", $attrName, $filePathName, $fileName, $index, $err));
232 
233  $value = $doc->getMultipleRawValues($attrName, '', $index);
234  $this->assertNotEmpty($value, sprintf("value of '%s' at index %s should not be empty", $attrName, $index));
235  }
236  /**
237  * @dataProvider dataSaveFile
238  * @param string $docId
239  * @param string $attrName
240  * @param string $filePathName
241  * @param string $fileName
242  * @param int $index
243  */
244  public function testSaveFile($docId, $attrName, $filePathName, $fileName = '', $index = - 1)
245  {
246  /**
247  * @var \resource $fd
248  */
249  $fd = @fopen($filePathName, 'r');
250  $this->assertFalse(($fd === false) , sprintf("error openging file '%s': %s", $filePathName, isset($php_errormsg) ? $php_errormsg : ''));
251 
252  $doc = new_doc(self::$dbaccess, $docId);
253  $this->assertTrue($doc->isAlive() , sprintf("could not get document with id '%s'", $docId));
254 
255  $err = $doc->saveFile($attrName, $fd, $fileName, $index);
256  $this->assertEmpty($err, sprintf("saveFile(%s, %s, %s, %s) returned with error: %s", $attrName, $filePathName, $fileName, $index, $err));
257 
258  $value = $doc->getMultipleRawValues($attrName, '', $index);
259  $this->assertNotEmpty($value, sprintf("value of '%s' at index %s should not be empty", $attrName, $index));
260  }
261  /**
262  * @dataProvider dataSetFile
263  * @param string $docId
264  * @param string $attrName
265  * @param string $filePathName
266  * @param string $fileName
267  * @param int $index
268  */
269  public function testSetFile($docId, $attrName, $filePathName, $fileName, $index = - 1)
270  {
271  $doc = new_doc(self::$dbaccess, $docId);
272  $this->assertTrue($doc->isAlive() , sprintf("could not get document with id '%s'", $docId));
273 
274  $err = $doc->setFile($attrName, $filePathName, $fileName, $index);
275  $this->assertEmpty($err, sprintf("setFile(%s, %s, %s, %s) returned with error: %s", $attrName, $filePathName, $fileName, $index, $err));
276 
277  $value = $doc->getMultipleRawValues($attrName, '', $index);
278  $this->assertNotEmpty($value, sprintf("value of '%s' at index %s should not be empty", $attrName, $index));
279  }
280  /**
281  * @dataProvider dataVaultRegisterFile
282  * @param string $docId
283  * @param string $filename
284  * @param string $ftitle
285  * @param string $expectedFileName
286  * @param string $expectSuccess
287  */
288  public function testVaultRegisterFile($docId, $filename, $ftitle, $expectedFileName, $expectSuccess)
289  {
290  $doc = new_doc(self::$dbaccess, $docId);
291  $this->assertTrue($doc->isAlive() , sprintf("could not get document with id '%s'", $docId));
292 
293  $exception = '';
294  $vid = '';
295  /**
296  * @var \VaultFileInfo $info
297  */
298  $info = null;
299  try {
300  $vid = $doc->vaultRegisterFile($filename, $ftitle, $info);
301  }
302  catch(\Exception $e) {
303  $exception = $e->getMessage();
304  }
305  if ($expectSuccess) {
306  $this->assertEmpty($exception, sprintf("vaultRegisterFile thrown exception for file '%s': %s", $filename, $exception));
307  $ret = preg_match('/^.*|\d+|.*$/', $vid);
308  $this->assertTrue((($ret !== false) && ($ret > 0)) , sprintf("vaultRegisterFile returned a malformed VID '%s' for file '%s'", $vid, $filename));
309  $this->assertTrue(($expectedFileName == $info->name) , sprintf("Stored file name '%s' does not match expected file name '%s'.", $info->name, $expectedFileName));
310  } else {
311  $this->assertNotEmpty($exception, sprintf("vaultRegisterFile did not thrown expected exception for file '%s'", $filename));
312  }
313  }
314  public function provider()
315  {
316  return array(
317  array(
318  9
319  ) ,
320  array(
321  11
322  ) ,
323  array(
324  12
325  ) ,
326  array(
327  'TST_FOLDER1',
328  'TST_BASE1'
329  )
330  );
331  }
332  public function dataDelete()
333  {
334  return array(
335  array(
336  'TST_DELETE',
337  "BASE"
338  ) ,
339  array(
340  'TST_DELETE',
341  "DIR"
342  ) ,
343  array(
344  '',
345  "DIR"
346  )
347  );
348  }
349  public function logicalName()
350  {
351  return array(
352  array(
353  "PU_data_dcp_logicalname.xml",
354  array(
355  'TST_ONE',
356  'TST_TWO'
357  )
358  )
359  );
360  }
361  public function dataStoreFile()
362  {
363  return array(
364  array(
365  "TST_STOREFILE_1",
366  "tst_single_file",
367  "DCPTEST/Layout/tst_file.odt",
368  "tst_file_single_file.odt",
369  "-1"
370  ) ,
371  array(
372  "TST_STOREFILE_1",
373  "tst_array_file",
374  "DCPTEST/Layout/tst_file.odt",
375  "tst_file_array_file.odt",
376  "3"
377  ) ,
378  array(
379  "TST_STOREFILE_1",
380  "tst_multiple_file",
381  "DCPTEST/Layout/tst_file.odt",
382  "tst_file_multiple_file.odt",
383  "3"
384  )
385  );
386  }
387  public function dataSaveFile()
388  {
389  return array(
390  array(
391  "TST_SAVEFILE_1",
392  "tst_single_file",
393  "DCPTEST/Layout/tst_file.odt",
394  "tst_file_single_file.odt",
395  "-1"
396  ) ,
397  array(
398  "TST_SAVEFILE_1",
399  "tst_array_file",
400  "DCPTEST/Layout/tst_file.odt",
401  "tst_file_array_file.odt",
402  "3"
403  ) ,
404  array(
405  "TST_SAVEFILE_1",
406  "tst_multiple_file",
407  "DCPTEST/Layout/tst_file.odt",
408  "tst_file_multiple_file.odt",
409  "3"
410  )
411  );
412  }
413  public function dataSetFile()
414  {
415  return array(
416  array(
417  "TST_SETFILE_1",
418  "tst_single_file",
419  "DCPTEST/Layout/tst_file.odt",
420  "tst_file_single_file.odt",
421  "-1"
422  ) ,
423  array(
424  "TST_SETFILE_1",
425  "tst_array_file",
426  "DCPTEST/Layout/tst_file.odt",
427  "tst_file_array_file.odt",
428  "3"
429  ) ,
430  array(
431  "TST_STOREFILE_1",
432  "tst_multiple_file",
433  "DCPTEST/Layout/tst_file.odt",
434  "tst_file_multiple_file.odt",
435  "3"
436  )
437  );
438  }
439  public function dataVaultRegisterFile()
440  {
441  return array(
442  array(
443  "TST_VAULTREGISTERFILE_1",
444  "DCPTEST/Layout/tst_file.odt",
445  "",
446  "tst_file.odt",
447  true
448  ) ,
449  array(
450  "TST_VAULTREGISTERFILE_1",
451  "DCPTEST/Layout/tst_file.odt",
452  "a new name.odt",
453  "a new name.odt",
454  true
455  ) ,
456  array(
457  "TST_VAULTREGISTERFILE_1",
458  "DCPTEST/Layout/this_file_does_not_exists.odt",
459  "error",
460  "error",
461  false
462  )
463  );
464  }
465 }
466 ?>
testReallyDelete($name, $familyName)
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
testStoreFile($docId, $attrName, $filePathName, $fileName, $index=-1)
Exception class use exceptionCode to identifiy correctly exception.
Definition: exceptions.php:19
$ret
$filename
$file
static importDocument($file)
testSetFile($docId, $attrName, $filePathName, $fileName, $index=-1)
$d
Definition: dav.php:77
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
testLogicalName($file, array $ln)
$dbaccess
Definition: checkVault.php:17
$info
Definition: geticon.php:30
if($file) if($subject==""&&$file) if($subject=="") $err
testDelete($name, $familyName)
$value
← centre documentaire © anakeen