Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_newdoc.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  private static $ids = array();
19 
20  public static function getCommonImportFile()
21  {
22  setLanguage("fr_FR");
23  return "PU_data_dcp_newdoc.ods";
24  }
25 
26  public static function setUpBeforeClass()
27  {
28  parent::setUpBeforeClass();
29  $d = createDoc(self::$dbaccess, \Dcp\Family\Base::familyName);
30  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x1-" . $d->revision);
31  $d->store();
32 
33  $d->setLogicalName("TST_X1");
34  self::$ids[$d->name][$d->revision] = array(
35  "id" => $d->id,
36  "title" => $d->getTitle()
37  );
38 
39  $d = createDoc(self::$dbaccess, \Dcp\Family\Base::familyName);
40  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x2-" . $d->revision);
41  $d->store();
42  $d->setLogicalName("TST_X2");
43  self::$ids[$d->name][$d->revision] = array(
44  "id" => $d->id,
45  "title" => $d->getTitle()
46  );
47  $d->revise();
48 
49  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x2-" . $d->revision);
50  $d->store();
51  self::$ids[$d->name][$d->revision] = array(
52  "id" => $d->id,
53  "title" => $d->getTitle()
54  );
55 
56  $d = createDoc(self::$dbaccess, \Dcp\Family\Base::familyName);
57  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x3-" . $d->revision);
58  $d->store();
59  $d->setLogicalName("TST_X3");
60  self::$ids[$d->name][$d->revision] = array(
61  "id" => $d->id,
62  "title" => $d->getTitle()
63  );
64 
65  $d->revise();
66  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x3-" . $d->revision);
67  $d->store();
68  self::$ids[$d->name][$d->revision] = array(
69  "id" => $d->id,
70  "title" => $d->getTitle()
71  );
72  $d->revise();
73  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x3-" . $d->revision);
74  self::$ids[$d->name][$d->revision] = array(
75  "id" => $d->id,
76  "title" => $d->getTitle()
77  );
78  $d->store();
79 
80  $d = createDoc(self::$dbaccess, \Dcp\Family\Base::familyName);
81  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x4-" . $d->revision);
82  $d->store();
83  $d->setLogicalName("TST_X4");
84  self::$ids[$d->name][$d->revision] = array(
85  "id" => $d->id,
86  "title" => $d->getTitle()
87  );
88  $d->revise();
89  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x4-" . $d->revision);
90  $d->store();
91  self::$ids[$d->name][$d->revision] = array(
92  "id" => $d->id,
93  "title" => $d->getTitle()
94  );
95  $d->revise();
96  $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x4-" . $d->revision);
97  self::$ids[$d->name][$d->revision] = array(
98  "id" => $d->id,
99  "title" => $d->getTitle()
100  );
101 
102  $d->store();
103  $d->locked = - 1;
104  $d->modify(); // close document
105  $dM = createDoc(self::$dbaccess, \Dcp\Family\Dir::familyName);
106  // need to change its family BASE to DIR
107  $dM->initid = $d->initid;
108  $dM->name = $d->name;
109  $dM->revision = $d->revision + 1;
110  $dM->setAttributeValue(\Dcp\AttributeIdentifiers\Dir::ba_title, "x4M-" . $dM->revision);
111  $dM->setAttributeValue(\Dcp\AttributeIdentifiers\Dir::fld_allbut, "1");
112  $dM->store();
113  self::$ids[$dM->name][$dM->revision] = array(
114  "id" => $dM->id,
115  "title" => $d->getTitle()
116  );
117  $dM->revise();
118  $dM->setAttributeValue(\Dcp\AttributeIdentifiers\Dir::ba_title, "x4M-" . $dM->revision);
119  $dM->setAttributeValue(\Dcp\AttributeIdentifiers\Dir::fld_allbut, "2");
120  $dM->store();
121  self::$ids[$dM->name][$dM->revision] = array(
122  "id" => $dM->id,
123  "title" => $dM->getTitle()
124  );
125  // Need to reset cause phpunit reset dbid when clone global objects
126  self::resetDocumentCache();
127  }
128  /**
129  * @dataProvider dataSimpleNewDoc
130  */
131  public function testSimpleNewDoc($docName, $expectedTitle)
132  {
133  $d = new_doc(self::$dbaccess, $docName);
134  $this->assertTrue($d->isAffected() , "document $docName not found");
135  $this->assertTrue($d->isAlive() , "document $docName not last revision\n" . print_r(self::$ids[$docName], true));
136  $this->assertEquals($expectedTitle, $d->getTitle() , "wrong title for $docName\n" . print_r(self::$ids[$docName], true));
137  // print_r("test".print_r(self::$ids[$docName], true) );
138 
139  }
140  /**
141  * @dataProvider dataSharedNewDoc
142  */
143  public function testSharedNewDoc($docName, $expectedTitle, $someValues)
144  {
145  $nd = createDoc(self::$dbaccess, "TST_ND");
146  $this->assertEquals("no", $nd->getrawValue("tst_shared"));
147  $nd->store();
148  $this->assertEquals("yes", $nd->getrawValue("tst_shared"));
149 
150  $d1 = new_doc(self::$dbaccess, $docName);
151  $this->assertEquals("yes", $d1->getrawValue("tst_shared"));
152  $this->assertTrue($d1->isAffected() , "document $docName not found");
153  $this->assertTrue($d1->isAlive() , "document $docName not last revision");
154  $this->assertEquals($expectedTitle, $d1->getTitle() , "wrong title for $docName");
155 
156  $d1->setAttributeValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title, $someValues[0]);
157  $d2 = new_doc(self::$dbaccess, $docName);
158  $this->assertEquals($someValues[0], $d2->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
159  $d2->setAttributeValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title, $someValues[1]);
160  $this->assertEquals($someValues[1], $d2->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
161 
162  $this->assertEquals("yes", $d2->getrawValue("tst_shared"));
163  $d2->revise();
164 
165  $this->assertEquals("yes", $d2->getrawValue("tst_shared"));
166  $d2->setAttributeValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title, $someValues[2]);
167  $d3 = new_doc(self::$dbaccess, $docName);
168  $this->assertEquals($someValues[2], $d3->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
169 
170  $d4 = new_doc(self::$dbaccess, $d3->initid, true);
171  $this->assertEquals($someValues[2], $d4->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
172 
173  $d5 = new_doc(self::$dbaccess, $d3->initid);
174  $this->assertEquals($someValues[1], $d5->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
175  $d5->setAttributeValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title, $someValues[3]);
176 
177  $d6 = new_doc(self::$dbaccess, $d3->initid);
178 
179  $this->assertEquals($someValues[3], $d6->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
180  $this->assertEquals($someValues[3], $d5->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
181  $this->assertEquals($someValues[2], $d4->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
182  $this->assertEquals($someValues[2], $d3->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
183  $this->assertEquals($someValues[2], $d2->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
184  $this->assertEquals($someValues[2], $d1->getRawValue(\Dcp\AttributeIdentifiers\Tst_nd::tst_title));
185  }
186  /**
187  * @dataProvider dataReviseNewDoc
188  */
189  public function testReviseNewDoc($docName, $revision, $expectedTitle)
190  {
191  $id = self::$ids[$docName][$revision]["id"];
192  $d = new_doc(self::$dbaccess, $id);
193  $this->assertTrue($d->isAffected() , "document $docName not found");
194  $this->assertEquals($d->id, $id, "document $docName (rev $revision) not match id");
195  $this->assertEquals($expectedTitle, $d->getTitle() , "wrong title for $docName");
196  }
197  /**
198  * @dataProvider dataLatestNewDoc
199  */
200  public function testLatestNewDoc($docName, $revision, $expectedTitle)
201  {
202  $id = self::$ids[$docName][$revision]["id"];
203  $d = new_doc(self::$dbaccess, $id, true);
204  $this->assertTrue($d->isAffected() , "document $docName not found");
205  $this->assertTrue($d->isAlive() , "document $docName #$id not last revision" . print_r(self::$ids[$docName], true));
206  $this->assertEquals($expectedTitle, $d->getTitle() , "wrong title for $docName");
207  }
208  /**
209  * @dataProvider dataSimplegetTDoc
210  */
211  public function testSimpleGetTDoc($docName, $expectedValues)
212  {
213  $d = getTDoc(self::$dbaccess, $docName);
214  foreach ($expectedValues as $attrid => $expectedValue) {
215  $this->assertTrue(isset($d[strtolower($attrid) ]) , sprintf("attribut %s not found", $attrid));
216  $this->assertEquals($expectedValue, $d[strtolower($attrid) ], sprintf("wrong value %s : %s", $attrid, print_r($d, true)));
217  }
218  $d = getLatestTDoc(self::$dbaccess, $d["initid"]);
219  foreach ($expectedValues as $attrid => $expectedValue) {
220  $this->assertTrue(isset($d[strtolower($attrid) ]) , sprintf("attribut for latest %s not found", $attrid));
221  $this->assertEquals($expectedValue, $d[strtolower($attrid) ], sprintf("wrong value for latest %s : %s", $attrid, print_r($d, true)));
222  }
223  }
224  /**
225  * @dataProvider dataGetLatestRevisionNumber
226  */
227  public function testGetLatestRevisionNumber($docName, $expectedValues)
228  {
229  $d = getTDoc(self::$dbaccess, $docName);
230  $this->assertEquals($expectedValues, getLatestRevisionNumber(self::$dbaccess, $d["initid"]) , "not good last revision number");
231  }
232  /**
233  * @dataProvider dataGetRevTDoc
234  */
235  public function testGetRevTDoc($docName, $revision, $expectedValues)
236  {
237  $d = getTDoc(self::$dbaccess, $docName);
238 
239  $d = getRevTDoc(self::$dbaccess, $d["initid"], $revision);
240  foreach ($expectedValues as $attrid => $expectedValue) {
241  $this->assertTrue(isset($d[strtolower($attrid) ]) , sprintf("attribut for latest %s not found", $attrid));
242  $this->assertEquals($expectedValue, $d[strtolower($attrid) ], sprintf("wrong value for latest %s : %s", $attrid, print_r($d, true)));
243  }
244  }
245  public function dataLatestNewDoc()
246  {
247  return array(
248  array(
249  "TST_X1",
250  0,
251  "x1-0"
252  ) ,
253  array(
254  "TST_X2",
255  0,
256  "x2-1"
257  ) ,
258  array(
259  "TST_X2",
260  1,
261  "x2-1"
262  ) ,
263  array(
264  "TST_X3",
265  0,
266  "x3-2"
267  ) ,
268  array(
269  "TST_X3",
270  1,
271  "x3-2"
272  ) ,
273  array(
274  "TST_X3",
275  2,
276  "x3-2"
277  ) ,
278  array(
279  "TST_X4",
280  0,
281  "x4M-4"
282  ) ,
283  array(
284  "TST_X4",
285  1,
286  "x4M-4"
287  ) ,
288  array(
289  "TST_X4",
290  2,
291  "x4M-4"
292  ) ,
293  array(
294  "TST_X4",
295  3,
296  "x4M-4"
297  ) ,
298  array(
299  "TST_X4",
300  4,
301  "x4M-4"
302  )
303  );
304  }
305 
306  public function dataReviseNewDoc()
307  {
308  return array(
309  array(
310  "TST_X1",
311  0,
312  "x1-0"
313  ) ,
314  array(
315  "TST_X2",
316  0,
317  "x2-0"
318  ) ,
319  array(
320  "TST_X2",
321  1,
322  "x2-1"
323  ) ,
324  array(
325  "TST_X3",
326  2,
327  "x3-2"
328  ) ,
329  array(
330  "TST_X4",
331  2,
332  "x4-2"
333  ) ,
334  array(
335  "TST_X4",
336  3,
337  "x4M-3"
338  )
339  );
340  }
341 
342  public function dataGetLatestRevisionNumber()
343  {
344  return array(
345  array(
346  "TST_X1",
347  0
348  ) ,
349  array(
350  "TST_X2",
351  1
352  ) ,
353  array(
354  "TST_X3",
355  2
356  ) ,
357  array(
358  "TST_X4",
359  4
360  )
361  );
362  }
363  public function dataSimplegetTDoc()
364  {
365  return array(
366  array(
367  "TST_X1",
368  array(
369  "title" => "x1-0"
370  )
371  ) ,
372  array(
373  "TST_X2",
374  array(
375  "title" => "x2-1"
376  )
377  ) ,
378  array(
379  "TST_X3",
380  array(
381  "title" => "x3-2"
382  )
383  ) ,
384  array(
385  "TST_X4",
386  array(
387  "title" => "x4M-4",
388  "fld_allbut" => "2"
389  )
390  )
391  );
392  }
393  public function dataGetRevTDoc()
394  {
395  return array(
396  array(
397  "TST_X1",
398  0,
399  array(
400  "title" => "x1-0"
401  )
402  ) ,
403  array(
404  "TST_X2",
405  1,
406  array(
407  "title" => "x2-1"
408  )
409  ) ,
410  array(
411  "TST_X3",
412  2,
413  array(
414  "title" => "x3-2"
415  )
416  ) ,
417  array(
418  "TST_X4",
419  0,
420  array(
421  "title" => "x4-0",
422  "ba_title" => "x4-0"
423  )
424  ) ,
425  array(
426  "TST_X4",
427  2,
428  array(
429  "title" => "x4-2",
430  "ba_title" => "x4-2"
431  )
432  ) ,
433  array(
434  "TST_X4",
435  3,
436  array(
437  "title" => "x4M-3",
438  "ba_title" => "x4M-3",
439  "fld_allbut" => "1"
440  )
441  ) ,
442  array(
443  "TST_X4",
444  4,
445  array(
446  "title" => "x4M-4",
447  "ba_title" => "x4M-4",
448  "fld_allbut" => "2"
449  )
450  )
451  );
452  }
453  public function dataSimpleNewDoc()
454  {
455  return array(
456  array(
457  "TST_X1",
458  "x1-0"
459  ) ,
460  array(
461  "TST_X2",
462  "x2-1"
463  ) ,
464  array(
465  "TST_X3",
466  "x3-2"
467  ) ,
468  array(
469  "TST_X4",
470  "x4M-4"
471  )
472  );
473  }
474  public function dataSharedNewDoc()
475  {
476  return array(
477  array(
478  "TST_ND1",
479  "Cornichon",
480  array(
481  "Hello",
482  "World",
483  "new World",
484  "antique World"
485  )
486  )
487  );
488  }
489 }
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
testLatestNewDoc($docName, $revision, $expectedTitle)
testSimpleGetTDoc($docName, $expectedValues)
$d
Definition: dav.php:77
getLatestTDoc($dbaccess, $initid, $sqlfilters=array(), $fromid=false)
testReviseNewDoc($docName, $revision, $expectedTitle)
testSimpleNewDoc($docName, $expectedTitle)
$d1
Definition: dav.php:11
testSharedNewDoc($docName, $expectedTitle, $someValues)
$d2
Definition: dav.php:67
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
setLanguage($lang)
Definition: Lib.Common.php:886
getRevTDoc($dbaccess, $initid, $rev)
getLatestRevisionNumber($dbaccess, $initid, $fromid=0)
$dbaccess
Definition: checkVault.php:17
testGetLatestRevisionNumber($docName, $expectedValues)
testGetRevTDoc($docName, $revision, $expectedValues)
← centre documentaire © anakeen