Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_VaultDiskStorage.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  }
26  /**
27  * @dataProvider dataStore
28  */
29  public function testStore($data)
30  {
31  $id_file = null;
32 
33  $vds = new \VaultDiskStorage(self::$dbaccess);
34  $err = $vds->Store($data['infile'], $data['public_access'], $id_file);
35  if (!$data['expect:success']) {
36  $this->assertNotEmpty($err, sprintf("Store(%s) did not returned with an expected error.", $data['infile']));
37  return;
38  }
39  $this->assertEmpty($err, sprintf("Unexpected error in Store(%s): %s", $data['infile'], $err));
40  $this->assertNotNull($id_file, sprintf("Store(%s) returned a null id_file.", $data['infile']));
41  $this->assertTrue(is_numeric($id_file) , sprintf("Store(%s) did not returned a numeric id_file.", $data['infile']));
42  $this->assertTrue(($id_file > 0) , sprintf("Store(%s) did not returned an id_file > 0.", $data['infile']));
43  }
44  public function dataStore()
45  {
46  return array(
47  array(
48  array(
49  "infile" => "DCPTEST/Layout/tst_VaultDiskStorage.odt",
50  "public_access" => false,
51  "expect:success" => true
52  ) ,
53  array(
54  "infile" => "DCPTEST/Layout/tst_VaultDiskStorage_non_existing_file.odt",
55  "public_access" => false,
56  "expect:success" => false
57  )
58  )
59  );
60  }
61  /**
62  * @dataProvider dataShow
63  */
64  public function testShow($data)
65  {
66  $id_file = null;
67 
68  $vds = new \VaultdiskStorage(self::$dbaccess);
69  $err = $vds->Store($data['infile'], false, $id_file);
70  if ($err != '') {
71  $this->markTestIncomplete(sprintf("Store(%s) returned with error: %s", $data['infile'], $err));
72  }
73 
74  $vfi = null;
75  $vds = new \VaultDiskStorage(self::$dbaccess);
76  $err = $vds->show($id_file, $vfi);
77  $this->assertEmpty($err, sprintf("show(%s) returned with error: %s", $id_file, $err));
78  $this->assertTrue(is_object($vfi) , sprintf("show(%s) did not returned an object.", $id_file));
79  $this->assertTrue(is_a($vfi, '\VaultFileInfo') , sprintf("show(%s) dit not returned a VaultFileInfo object: class is %s", $id_file, get_class($vfi)));
80  }
81  public function dataShow()
82  {
83  return array(
84  array(
85  array(
86  "infile" => "DCPTEST/Layout/tst_VaultDiskStorage.odt"
87  )
88  )
89  );
90  }
91  /**
92  * @dataProvider dataGetPath
93  */
94  public function testGetPath($data)
95  {
96  $id_file = null;
97 
98  $vds = new \VaultDiskStorage(self::$dbaccess);
99  $err = $vds->Store($data['infile'], false, $id_file);
100  if ($err != '') {
101  $this->markTestIncomplete(sprintf("Store(%s) returned with error: %s", $data['infile'], $err));
102  }
103 
104  $vds = new \VaultDiskStorage(self::$dbaccess, $id_file);
105  $this->assertTrue($vds->isAffected() , sprintf("Could not get back id_file '%s' from previously stored file '%s'.", $id_file, $data['infile']));
106 
107  $path = $vds->getPath();
108  $this->assertNotEmpty($path, sprintf("getPath() on id_file '%s' returned an empty path.", $id_file));
109  $this->assertTrue(is_file($path) , sprintf("getPath() returned path '%s' for id_file '%s' is not a file.", $path, $id_file));
110  }
111  public function dataGetPath()
112  {
113  return array(
114  array(
115  array(
116  "infile" => "DCPTEST/Layout/tst_VaultDiskStorage.odt"
117  )
118  )
119  );
120  }
121  /**
122  * @dataProvider dataDestroy
123  */
124  public function testDestroy($data)
125  {
126  $id_file = null;
127 
128  $vds = new \VaultDiskStorage(self::$dbaccess);
129  $err = $vds->Store($data['infile'], false, $id_file);
130  if ($err != '') {
131  $this->markTestIncomplete(sprintf("Store(%s) returned with error: %s", $err));
132  }
133 
134  $vds = new \VaultDiskStorage(self::$dbaccess, $id_file);
135  if (!$vds->isAffected()) {
136  $this->markTestIncomplete(sprintf("Could not get back id_file '%s' from previously stored file '%s'.", $id_file, $data['infile']));
137  }
138 
139  $path = $vds->getPath();
140  if (!is_file($path)) {
141  $this->markTestIncomplete(sprintf("Invalid path '%s' for stored file '%s' with id_file '%s'.", $path, $data['infile'], $id_file));
142  }
143 
144  $err = $vds->Destroy($id_file);
145  $this->assertEmpty($err, sprintf("Destroy() returned with error: %s", $err));
146  $this->assertFalse(is_file($path) , sprintf("File '%s' from id_file %s is still present after Destroy().", $path, $id_file));
147 
148  $vds = new \VaultDiskStorage(self::$dbaccess, $id_file);
149  $this->assertFalse($vds->isAffected() , sprintf("id_file '%s' is still present in database after Destroy().", $id_file));
150  }
151  public function dataDestroy()
152  {
153  return array(
154  array(
155  array(
156  "infile" => "DCPTEST/Layout/tst_VaultDiskStorage.odt"
157  )
158  )
159  );
160  }
161 }
162 ?>
$path
Definition: dav.php:39
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
$data
← centre documentaire © anakeen