Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_multiplealive.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.php';
14 
16 {
17  /**
18  * @param string $a
19  * @return \Doc
20  */
21  public function testFixed()
22  {
23  $d = createDoc(self::$dbaccess, "BASE");
24  $d->setValue("ba_title", "Initial");
25  $this->assertTrue(is_object($d) , sprintf("cannot create BASE document"));
26  $err = $d->add();
27  $this->assertEmpty($err, sprintf("add error : $err"));
28  $id0 = $d->id;
29 
30  $err = $d->revise();
31  $id1 = $d->id;
32  $this->assertEmpty($err, sprintf("revision rev.1 error : $err"));
33 
34  clearCacheDoc();
35 
36  $nd0 = new_doc(self::$dbaccess, $id0);
37  $nd0->setValue("ba_title", "a");
38  $err = $nd0->store(); // cannot modify fixed document
39  $this->assertContains("DOC0118", $err, sprintf("modify rev.1 error : $err"));
40 
41  $nd1 = new_doc(self::$dbaccess, $id1);
42  $nd1->setValue("ba_title", "a");
43  $err = $nd1->store(); // can modify alive document
44  $this->assertEmpty($err, sprintf("modify rev.1 error : $err"));
45 
46  $err = $d->revise(); // $nd1 is fixed now
47  $this->assertEmpty($err, sprintf("revision rev.2 error : $err"));
48  $id2 = $d->id;
49 
50  $nd1->setValue("ba_title", "b");
51  $err = $nd1->store(); // cannot modify fixed document
52  $this->assertContains("DOC0118", $err, sprintf("modify rev.1 error : $err"));
53 
54  error_log($err);
55  // corrupt integraty => $nd1 becomes alives
56  $nd1->locked = 0;
57  $err = $nd1->modify(true, array(
58  "locked"
59  ) , true);
60  $this->assertEmpty($err, sprintf("modify lock rev.1 error : $err"));
61  // two documents are alive now $nd1 /$nd2
62  clearCacheDoc();
63  simpleQuery(self::$dbaccess, sprintf("select id, title, revision, locked from only doc%d where initid=%d order by id", $nd1->fromid, $nd1->initid) , $r);
64 
65  $nd1 = new_doc(self::$dbaccess, $id1);
66  $this->assertTrue($nd1->isAlive() , "nd1 is not alive");
67  $nd1->setValue("ba_title", "c");
68  $err = $nd1->store(); // cannot modify fixed document
69  error_log($err);
70  $this->assertContains("DOC0119", $err, sprintf("modify rev.1 error : $err"));
71 
72  $nd2 = new_doc(self::$dbaccess, $id2);
73  $nd2->setValue("ba_title", "d");
74  $err = $nd2->store(); // can modify clean document
75  $this->assertEmpty($err, sprintf("modify rev.2 error : $err"));
76  // corrupt integraty => $nd0 becomes alives
77  $nd0->locked = 0;
78  $err = $nd0->modify(true, array(
79  "locked"
80  ) , true);
81  $this->assertEmpty($err, sprintf("modify lock rev.0 error : $err"));
82  // corrupt again integraty => $nd1 becomes alives
83  $nd1->locked = 0;
84  $err = $nd1->modify(true, array(
85  "locked"
86  ) , true);
87  $this->assertEmpty($err, sprintf("modify lock rev.1 error : $err"));
88 
89  clearCacheDoc();
90 
91  $nd2 = new_doc(self::$dbaccess, $id2);
92  $this->assertTrue($nd1->isAlive() , "nd2 is not alive");
93  $nd2->setValue("ba_title", "e");
94  $err = $nd2->store(); // clean and modify can modify clean document
95  $this->assertEmpty($err, sprintf("modify rev.1 error : $err"));
96 
97  return $d;
98  }
99 }
100 ?>
clearCacheDoc($id=0)
$d
Definition: dav.php:77
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
$dbaccess
Definition: checkVault.php:17
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen