Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_docrel.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 TST_FAMSETVALUE family
19  * @static
20  * @return string
21  */
22  protected static function getCommonImportFile()
23  {
24  return array(
25  "PU_data_dcp_docrel_family.ods"
26  );
27  }
28  private $base = array();
29  /**
30  * init 3 docs with 3 revisions
31  */
32  private function initBaseDocuments()
33  {
34 
35  $n = array(
36  "A",
37  "B",
38  "C"
39  );
40 
41  foreach ($n as $L) {
42  $d = createDoc("", "TST_DOCREL");
43  for ($i = 0; $i < 3; $i++) {
44  $bid = sprintf("%s%d", $L, $i);
45  $d->setValue("tst_title", $bid);
46  $d->store();
47  $this->base[$bid] = $d->id;
48  if ($i < 2) $d->revise();
49  }
50  }
51 
52  $d = createDoc("", "TST_DOCREL");
53  $d->setLogicalName("TST_DOCREL_TITLE_CR");
54  $d->setTitle("xxx\rxxx");
55  $d->store();
56 
57  $d = createDoc("", "TST_DOCREL");
58  $d->setLogicalName("TST_DOCREL_TITLE_LF");
59  $d->setTitle("xxx\nxxx");
60  $d->store();
61 
62  $d = createDoc("", "TST_DOCREL");
63  $d->setLogicalName("TST_DOCREL_TITLE_TAB");
64  $d->setTitle("xxx\txxx");
65  $d->store();
66 
67  $d = createDoc("", "TST_DOCREL");
68  $d->setLogicalName("TST_DOCREL_TITLE_BACKSLASH");
69  $d->setTitle("nnn\\nnn");
70  $d->store();
71 
72  $d = createDoc("", "TST_DOCREL");
73  $d->setLogicalName("TST_DOCREL_TITLE_BACKSLASH_N");
74  $d->setTitle("\\N");
75  $d->store();
76  }
77  /**
78  * to search real ids
79  * @param $val
80  * @return array
81  */
82  private function translateName($val)
83  {
84  if (is_array($val)) {
85  $tb = array();
86  foreach ($val as $ka => $aVal) {
87  $tbs = explode("<BR>", $aVal);
88  $tids = array();
89  foreach ($tbs as $single) {
90  if (isset($this->base[$single])) {
91  $tids[] = $this->base[$single];
92  } else {
93  $tids[] = getIdFromName(self::$dbaccess, $single);
94  }
95  }
96 
97  $tb[] = implode('<BR>', $tids);
98  }
99  return $tb;
100  } else {
101  if (isset($this->base[$val])) {
102  return $this->base[$val];
103  } else {
104  return getIdFromName(self::$dbaccess, $val);
105  }
106  }
107  }
108  /**
109  * @dataProvider dataDocRelUpdate
110  */
111  public function testDocRelUpdate($initValues, $updateValues, $expectValues)
112  {
113  $this->initBaseDocuments();
114  $d = createDoc("", "TST_DOCREL");
115  $err = '';
116  foreach ($initValues as $aid => $val) {
117  $err.= $d->setValue($aid, $this->translateName($val));
118  }
119  $err.= $d->store();
120  $this->assertEmpty($err, "add error $err");
121  foreach ($updateValues as $aid => $val) {
122  $err.= $d->setValue($aid, $this->translateName($val));
123  }
124  $err.= $d->store();
125  $this->assertEmpty($err, "update error $err");
126 
127  $rel = new \DocRel();
128  $rel->sinitid = $d->id;
129  $rels = $rel->getRelations();
130 
131  $this->assertEquals(count($expectValues) , count($rels) , sprintf("Not correct relations %s", print_r($rels, true)));
132  foreach ($expectValues as $expectProps) {
133  $aid = $expectProps["aid"];
134  $this->assertEquals($expectProps["title"], $this->getRelTitle($rels, $aid, $expectProps["title"]) , sprintf("not correct title $aid expect %s : %s", $expectProps["title"], print_r($rels, true)));
135  $this->assertEquals($this->translateName($expectProps["id"]) , $this->getRelId($rels, $aid, $this->translateName($expectProps["id"])) , "not correct id $aid");
136  }
137  }
138 
139  private function getRelTitle(array $rels, $key, $expect)
140  {
141  foreach ($rels as $rel) {
142  if ($rel["type"] == $key && $rel["ctitle"] == $expect) return $rel["ctitle"];
143  }
144  return '';
145  }
146 
147  private function getRelId(array $rels, $key, $expect)
148  {
149  foreach ($rels as $rel) {
150  if ($rel["type"] == $key && $rel["cinitid"] == $expect) return $rel["cinitid"];
151  }
152  return '';
153  }
154  public function dataDocRelUpdate()
155  {
156  return array(
157  array(
158  "init" => array(
159  "tst_rel1" => "B2"
160  ) ,
161  "update" => array(
162  "tst_rel1" => "A2",
163  "tst_rel2" => "C2"
164  ) ,
165  "expect" => array(
166  array(
167  "aid" => "tst_rel1",
168  "id" => "A0",
169  "title" => "A2"
170  ) ,
171  array(
172  "aid" => "tst_rel2",
173  "id" => "C0",
174  "title" => "C2"
175  )
176  )
177  ) ,
178 
179  array(
180  "init" => array(
181  "tst_rel1" => "B2"
182  ) ,
183  "update" => array() ,
184  "expect" => array(
185  array(
186  "aid" => "tst_rel1",
187  "id" => "B0",
188  "title" => "B2"
189  )
190  )
191  ) ,
192  array(
193  "init" => array(
194  "tst_rel1" => "B2",
195  "tst_rel2" => "B0",
196  "tst_rels3" => "B1",
197  ) ,
198  "update" => array() ,
199  "expect" => array(
200  array(
201  "aid" => "tst_rel1",
202  "id" => "B0",
203  "title" => "B2"
204  ) ,
205  array(
206  "aid" => "tst_rel2",
207  "id" => "B0",
208  "title" => "B2"
209  ) ,
210  array(
211  "aid" => "tst_rels3",
212  "id" => "B0",
213  "title" => "B2"
214  )
215  )
216  ) ,
217  array(
218  "init" => array(
219  "tst_rel1" => "B2",
220  "tst_rel2" => "C0",
221  "tst_rels3" => array(
222  "B1",
223  "B0",
224  "B2"
225  ) ,
226  ) ,
227  "update" => array() ,
228  "expect" => array(
229  array(
230  "aid" => "tst_rel1",
231  "id" => "B0",
232  "title" => "B2"
233  ) ,
234  array(
235  "aid" => "tst_rel2",
236  "id" => "C0",
237  "title" => "C2"
238  ) ,
239  array(
240  "aid" => "tst_rels3",
241  "id" => "B0",
242  "title" => "B2"
243  )
244  )
245  ) ,
246  array(
247  "init" => array(
248  "tst_rels3" => array(
249  "B1",
250  "C0",
251  "B2"
252  ) ,
253  ) ,
254  "update" => array() ,
255  "expect" => array(
256 
257  array(
258  "aid" => "tst_rels3",
259  "id" => "B0",
260  "title" => "B2"
261  ) ,
262  array(
263  "aid" => "tst_rels3",
264  "id" => "B0",
265  "title" => "B2"
266  )
267  )
268  ) ,
269 
270  array(
271  "init" => array(
272  "tst_rels2" => array(
273  "B1<BR>A0",
274  "C0",
275  "B2<BR>A2"
276  ) ,
277  ) ,
278  "update" => array() ,
279  "expect" => array(
280 
281  array(
282  "aid" => "tst_rels2",
283  "id" => "B0",
284  "title" => "B2"
285  ) ,
286  array(
287  "aid" => "tst_rels2",
288  "id" => "A0",
289  "title" => "A2"
290  ) ,
291  array(
292  "aid" => "tst_rels2",
293  "id" => "B0",
294  "title" => "B2"
295  )
296  )
297  ) ,
298 
299  array(
300  "init" => array(
301  "tst_rel1" => "TST_DOCREL_TITLE_CR"
302  ) ,
303  "update" => array() ,
304  "expect" => array(
305  array(
306  "aid" => "tst_rel1",
307  "id" => "TST_DOCREL_TITLE_CR",
308  "title" => "xxx xxx"
309  )
310  )
311  ) ,
312 
313  array(
314  "init" => array(
315  "tst_rel1" => "TST_DOCREL_TITLE_LF"
316  ) ,
317  "update" => array() ,
318  "expect" => array(
319  array(
320  "aid" => "tst_rel1",
321  "id" => "TST_DOCREL_TITLE_LF",
322  "title" => "xxx xxx"
323  )
324  )
325  ) ,
326 
327  array(
328  "init" => array(
329  "tst_rel1" => "TST_DOCREL_TITLE_TAB"
330  ) ,
331  "update" => array() ,
332  "expect" => array(
333  array(
334  "aid" => "tst_rel1",
335  "id" => "TST_DOCREL_TITLE_TAB",
336  "title" => "xxx xxx"
337  )
338  )
339  ) ,
340 
341  array(
342  "init" => array(
343  "tst_rel1" => "TST_DOCREL_TITLE_BACKSLASH"
344  ) ,
345  "update" => array() ,
346  "expect" => array(
347  array(
348  "aid" => "tst_rel1",
349  "id" => "TST_DOCREL_TITLE_BACKSLASH",
350  "title" => "nnn\\nnn"
351  )
352  )
353  ) ,
354 
355  array(
356  "init" => array(
357  "tst_rel1" => "TST_DOCREL_TITLE_BACKSLASH_N"
358  ) ,
359  "update" => array() ,
360  "expect" => array(
361  array(
362  "aid" => "tst_rel1",
363  "id" => "TST_DOCREL_TITLE_BACKSLASH_N",
364  "title" => "\\N"
365  )
366  )
367  )
368  );
369  }
370 }
testDocRelUpdate($initValues, $updateValues, $expectValues)
$d
Definition: dav.php:77
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
$dbaccess
Definition: checkVault.php:17
getIdFromName($dbaccess, $name)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen