Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_TestDocument.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * @author Anakeen
9  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
10  * @package FDL
11  */
12 
13 require_once './PU_Framework_TestDocument.php';
14 
16 {
17  /**
18  * @dataProvider provider
19  */
20  public function testAlive($a)
21  {
22  $d = new_doc($this->dbaccess, $a);
23  $this->assertTrue($d->isAlive() , sprintf("document %d not alive", $a));
24  return $d;
25  }
26  /**
27  * @dataProvider provider
28  * @---depends testAlive
29  */
30  public function testLock($a)
31  {
32 
33  $d = new_doc($this->dbaccess, $a, true);
34  if ($d->isAlive()) {
35  if ($d->canLock()) {
36  $d->lock();
37  $slock = $this->_DBGetValue(sprintf("select locked from docread where id=%d", $d->id));
38  $slock = intval($slock);
39  $this->assertEquals($d->userid, $slock, sprintf("document %d not locked", $a));
40  } else {
41  $this->markTestIncomplete(sprintf(_('Document %d is locked.') , $a));
42  }
43  } else {
44  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
45  }
46  }
47  /**
48  * @dataProvider provider
49  * @---depends testAlive
50  */
51  public function testunLock($a)
52  {
53 
54  $d = new_doc($this->dbaccess, $a, true);
55  if ($d->isAlive()) {
56  if ($d->canUnLock()) {
57  $d->unlock();
58  $slock = $this->_DBGetValue(sprintf("select locked from docread where id=%d", $d->id));
59  $slock = intval($slock);
60  $this->assertEquals(0, $slock, sprintf("document %d still locked", $a));
61  } else {
62  $this->markTestIncomplete(sprintf(_('Document %d is locked.') , $a));
63  }
64  } else {
65  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
66  }
67  }
68  /**
69  * @dataProvider provider
70  * @---depends testAlive
71  */
72  public function testautoLock($a)
73  {
74 
75  $d = new_doc($this->dbaccess, $a, true);
76  if ($d->isAlive()) {
77  if ($d->canLock()) {
78  $d->lock(true);
79 
80  $slock = $this->_DBGetValue(sprintf("select locked from docread where id=%d", $d->id));
81  $slock = intval($slock);
82  if ($d->userid == 1) $this->markTestIncomplete(sprintf(_('Admin cannot auto lock.')));
83  else $this->assertEquals(-($d->userid) , ($slock) , sprintf("document %d not locked", $a));
84  } else {
85  $this->markTestIncomplete(sprintf(_('Document %d is locked.') , $a));
86  }
87  } else {
88  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
89  }
90  }
91  /**
92  * @dataProvider folderProvider
93  * @---depends testAlive
94  */
95  public function testSetbadesc($a)
96  {
97  $d = new_doc($this->dbaccess, $a, true);
98  if ($d->isAlive()) {
99  $val = "testing " . time();
100  $err = $d->setValue("ba_desc", $val);
101  $this->assertEquals("", $err, sprintf("cannot object update", $a));
102  $this->assertEquals($val, $d->getValue("ba_desc") , sprintf("document not updated", $a));
103  $err = $d->modify();
104  $this->assertEquals("", $err, sprintf("cannot database update", $a));
105 
106  $sval = $this->_DBGetValue(sprintf("select ba_desc from doc2 where id=%d", $d->id));
107  $this->assertEquals($val, $sval, sprintf("document %d not locked", $a));
108  } else {
109  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
110  }
111  }
112  /**
113  * @dataProvider searchProvider
114  * @---depends testAlive
115  */
116  public function testnotSetbadesc($a)
117  {
118  $d = new_doc($this->dbaccess, $a, true);
119  if ($d->isAlive()) {
120  $val = "testing " . time();
121  $err = $d->setValue("ba_desc", $val);
122  $this->assertFalse($err == "", sprintf(_("cannot object update %s") , $a));
123  } else {
124  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
125  }
126  }
127  /**
128  * insert $b in $a
129  * @dataProvider twoFolderProvider
130  * @---depends testAlive
131  */
132  public function testAddFile($a, $b)
133  {
134  $da = new_doc($this->dbaccess, $a, true);
135  $db = new_doc($this->dbaccess, $b, true);
136  if ($da->isAlive() && $db->isAlive()) {
137 
138  $err = $da->addFile($db->initid);
139  if ($err == "") {
140  $this->assertEquals("", $err, sprintf(_("error ::addFile %s %s") , $a, $err));
141  $sval = $this->_DBGetValue(sprintf("select childid from fld where dirid=%d and childid=%d", $da->initid, $db->initid));
142 
143  $this->assertEquals($db->initid, $sval, sprintf("not inserted %s", $a));
144  } else {
145  $this->markTestIncomplete(sprintf(_('Cannot insert : %s.') , $err));
146  }
147  } else {
148  $this->markTestIncomplete(sprintf(_('Document %d not alive.') , $a));
149  }
150  }
151  /**
152  * move $c from $a to $b
153  * @dataProvider threeFolderProvider
154  * @---depends testAlive
155  */
156  public function testMoveDocument($a, $b, $c)
157  {
158  $da = new_doc($this->dbaccess, $a, true);
159  $db = new_doc($this->dbaccess, $b, true);
160  $dc = new_doc($this->dbaccess, $c, true);
161  if ($da->isAlive() && $db->isAlive() && $dc->isAlive()) {
162  $sval = $this->_DBGetValue(sprintf("select childid from fld where dirid=%d and childid=%d", $da->initid, $dc->initid));
163  //$err=simpleQuery($this->dbaccess,sprintf("select childid from fld where dirid=%d and childid=%d",$da->initid,$dc->initid),$sval,true,true);
164  //$this->assertEquals("",$err,sprintf("database select error",$a));
165  if ($dc->initid != $sval) {
166  $this->markTestSkipped(sprintf(_("not present %s in %s") , $c, $a));
167  }
168  $this->assertEquals($dc->initid, $sval, sprintf("not present %s in %s", $c, $a));
169  $err = $da->moveDocument($dc->initid, $db->initid);
170  if ($err == "") {
171  $this->assertEquals("", $err, sprintf(_("error ::moveDocument %s %s") , $a, $err));
172  $sval = $this->_DBGetValue(sprintf("select childid from fld where dirid=%d and childid=%d", $da->initid, $dc->initid));
173  $this->assertFalse($sval, sprintf("not unlinked %s", $a));
174  $sval = $this->_DBGetValue(sprintf("select childid from fld where dirid=%d and childid=%d", $db->initid, $dc->initid));
175  $this->assertEquals($dc->initid, $sval, sprintf("not inserted %s", $a));
176  $sval = $this->_DBGetValue(sprintf("select prelid from docread where initid=%d and locked != -1", $dc->initid));
177  $this->assertEquals($db->initid, $sval, sprintf("primary relation not updated %s", $c));
178  } else {
179  $this->markTestIncomplete(sprintf(_('Cannot move : %s.') , $err));
180  }
181  } else {
182  $this->markTestIncomplete(sprintf(_('One of these documents %s not alive.') , $a . "," . $b . ',' . $c));
183  }
184  }
185 
186  public function provider()
187  {
188  return array(
189  array(
190  9
191  ) ,
192  array(
193  10
194  ) ,
195  array(
196  11
197  ) ,
198  array(
199  12
200  )
201  );
202  }
203  public function folderProvider()
204  {
205  return array(
206  array(
207  9
208  ) ,
209  array(
210  10
211  )
212  );
213  }
214  public function searchProvider()
215  {
216  return array(
217  array(
218  11
219  ) ,
220  array(
221  12
222  ) ,
223  array(
224  13
225  )
226  );
227  }
228 
229  public function twoFolderProvider()
230  {
231  return array(
232  array(
233  9,
234  10
235  ) ,
236  array(
237  10,
238  11
239  )
240  );
241  }
242  public function threeFolderProvider()
243  {
244  return array(
245  array(
246  9,
247  10,
248  11
249  ) ,
250  array(
251  9,
252  10,
253  12
254  ) ,
255  array(
256  9,
257  10,
258  13
259  )
260  );
261  }
262 }
263 ?>
← centre documentaire © anakeen - published under CC License - Dynacase