Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_tag.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_document.php';
14 
16 {
17  protected static $outputDir;
18 
19  protected function setUp()
20  {
21  $err = simpleQuery(self::$dbaccess, "savepoint z", $r);
22  }
23 
24  protected function tearDown()
25  {
26  $err = simpleQuery(self::$dbaccess, "rollback to savepoint z", $r);
27  }
28 
29  public static function setUpBeforeClass()
30  {
31  parent::setUpBeforeClass();
32 
33  self::connectUser();
34  self::beginTransaction();
35 
36  self::importDocument("testTag.ods");
37  }
38  public static function tearDownAfterClass()
39  {
40  self::rollbackTransaction();
41  }
42  /**
43  * @dataProvider dataTags
44  */
45  public function testAddUTag($docName, $login, $otherLogin, $tag, $value)
46  {
47  $this->resetDocumentCache();
48 
49  $this->sudo($login);
50  $df = new_doc(self::$dbaccess, $docName);
51  $this->assertTrue($df->isAlive() , "document $docName is not alive");
52  $err = $df->addUTag(\Doc::getSystemUserId() , $tag, $value);
53  $this->assertEmpty($err, sprintf("utag error"));
54 
55  $utag = $df->getUTag($tag);
56 
57  $this->assertTrue($utag !== false, sprintf("utag %s not retrieved", $tag));
58  $this->assertEquals($value, $utag->comment);
59 
60  $this->exitSudo();
61  // test it is only for login not aoth people
62  $this->sudo($otherLogin);
63 
64  $this->resetDocumentCache();
65  $df = new_doc(self::$dbaccess, $docName);
66  $this->assertTrue($df->isAlive() , "document $docName is not alive");
67  $utag = $df->getUTag($tag);
68 
69  $this->assertTrue($utag === false, sprintf("utag %s of other user is retrieved", $tag));
70 
71  $this->exitSudo();
72  }
73  /**
74  *
75  * @dataProvider dataTags
76  * @---depends testAddUTag
77  */
78  public function testChangeUTag($docName, $login, $otherLogin, $tag, $value)
79  {
80  $this->resetDocumentCache();
81 
82  $this->sudo($login);
83  $df = new_doc(self::$dbaccess, $docName);
84  $this->assertTrue($df->isAlive() , "document $docName is not alive");
85  $err = $df->addUTag(\Doc::getSystemUserId() , $tag, "__first__");
86  $this->assertEmpty($err, sprintf("utag error"));
87 
88  $err = $df->addUTag(\Doc::getSystemUserId() , $tag, $value);
89  $this->assertEmpty($err, sprintf("utag error"));
90 
91  $utag = $df->getUTag($tag);
92 
93  $this->assertTrue($utag !== false, sprintf("utag %s not retrieved", $tag));
94  $this->assertEquals($value, $utag->comment);
95 
96  $this->exitSudo();
97  }
98  /**
99  *
100  * @dataProvider dataTags
101  * @---depends testAddUTag
102  */
103  public function testDelUTag($docName, $login, $otherLogin, $tag, $value)
104  {
105  $this->resetDocumentCache();
106 
107  $this->sudo($login);
108  $df = new_doc(self::$dbaccess, $docName);
109  $this->assertTrue($df->isAlive() , "document $docName is not alive");
110  $err = $df->addUTag(\Doc::getSystemUserId() , $tag, $value);
111  $this->assertEmpty($err, sprintf("utag error"));
112 
113  $utag = $df->getUTag($tag);
114 
115  $this->assertTrue($utag !== false, sprintf("utag %s not retrieved", $tag));
116  $this->assertEquals($value, $utag->comment);
117 
118  $err = $df->delUTag(\Doc::getSystemUserId() , $tag);
119  $this->assertEmpty($err, sprintf("utag del error"));
120  $utag = $df->getUTag($tag);
121 
122  $this->assertTrue($utag === false, sprintf("utag %s not deleted", $tag));
123 
124  $this->exitSudo();
125  }
126  /**
127  *
128  * @dataProvider dataTags
129  * @---depends testAddUTag
130  */
131  public function testDelUTags($docName, $login, $otherLogin, $tag, $value)
132  {
133  $this->resetDocumentCache();
134 
135  $this->sudo($login);
136  $df = new_doc(self::$dbaccess, $docName);
137  $this->assertTrue($df->isAlive() , "document $docName is not alive");
138  $err = $df->addUTag(\Doc::getSystemUserId() , $tag, $value);
139  $this->assertEmpty($err, sprintf("utag error"));
140 
141  $utag = $df->getUTag($tag);
142 
143  $this->assertTrue($utag !== false, sprintf("utag %s not retrieved", $tag));
144  $this->assertEquals($value, $utag->comment);
145 
146  $err = $df->delUTags(\Doc::getSystemUserId());
147  $this->assertEmpty($err, sprintf("utag del error"));
148  $utag = $df->getUTag($tag);
149 
150  $this->assertTrue($utag === false, sprintf("utag %s not deleted", $tag));
151 
152  $this->exitSudo();
153  }
154  /**
155  * @dataProvider dataATags
156  */
157  public function testAddATag($docName, array $tags)
158  {
159  $this->resetDocumentCache();
160 
161  $df = new_doc(self::$dbaccess, $docName);
162  $this->assertTrue($df->isAlive() , "document $docName is not alive");
163  foreach ($tags as $tag) {
164  $err = $df->addATag($tag);
165  $this->assertEmpty($err, sprintf("utag error"));
166  }
167 
168  foreach ($tags as $tag) {
169  $atag = $df->getATag($tag);
170 
171  $this->assertTrue($atag, sprintf("atag %s not retrieved : \n found [%s]", $tag, $df->atags));
172  }
173  // test it is only for login not aoth people
174  $this->resetDocumentCache();
175  $df = new_doc(self::$dbaccess, $docName);
176  $this->assertTrue($df->isAlive() , "document $docName is not alive");
177  foreach ($tags as $tag) {
178  $atag = $df->getATag($tag);
179  $this->assertTrue($atag, sprintf("atag %s from new is not retrieved", $tag));
180  }
181  }
182  /**
183  * @dataProvider dataDeleteATag
184  */
185  public function testDeleteATag($docName, array $addTags, array $delTags, array $expectedTags)
186  {
187  $this->resetDocumentCache();
188 
189  $df = new_doc(self::$dbaccess, $docName);
190  $this->assertTrue($df->isAlive() , "document $docName is not alive");
191  foreach ($addTags as $tag) {
192  $err = $df->addATag($tag);
193  $this->assertEmpty($err, sprintf("utag error"));
194  }
195 
196  foreach ($addTags as $tag) {
197  $atag = $df->getATag($tag);
198  $this->assertTrue($atag, sprintf("atag %s not retrieved : \n found [%s]", $tag, $df->atags));
199  }
200 
201  foreach ($delTags as $tag) {
202  $err = $df->delATag($tag);
203  $this->assertEmpty($err, sprintf("utag delete error : $err"));
204  }
205  // test it is only for login not aoth people
206  $this->resetDocumentCache();
207  $df = new_doc(self::$dbaccess, $docName);
208  $this->assertTrue($df->isAlive() , "document $docName is not alive");
209 
210  $nbTags = (!$df->atags) ? 0 : count(explode("\n", $df->atags));
211  $this->assertEquals(count($expectedTags) , $nbTags, sprintf(" found [%s]", $df->atags));
212 
213  foreach ($expectedTags as $tag) {
214  $atag = $df->getATag($tag);
215  $this->assertTrue($atag, sprintf("atag %s from new is not retrieved", $tag));
216  }
217  }
218  /**
219  * @dataProvider dataAddAErrorTag
220  */
221  public function testAddAErrorTag($docName, $tag, $error)
222  {
223  $this->resetDocumentCache();
224 
225  $df = new_doc(self::$dbaccess, $docName);
226  $this->assertTrue($df->isAlive() , "document $docName is not alive");
227 
228  $err = $df->addATag($tag);
229  $this->assertContains($error, $err, sprintf("atag error"));
230  }
231  /**
232  * @dataProvider dataImportATag
233  */
234  public function testImportATag($docName, array $expectedTags)
235  {
236  $df = new_doc(self::$dbaccess, $docName);
237  $this->assertTrue($df->isAlive() , "document $docName is not alive");
238 
239  foreach ($expectedTags as $tag) {
240  $atag = $df->getATag($tag);
241  $this->assertTrue($atag, sprintf("atag %s not retrieved : \n found [%s]", $tag, $df->atags));
242  }
243  $tags = [];
244  if ($df->atags) {
245  $tags = explode("\n", $df->atags);
246  }
247  $this->assertEquals(count($tags) , count($expectedTags) , sprintf("wrong count for [%s]", $df->atags));
248  }
249 
250  public function dataImportATag()
251  {
252  return array(
253  array(
254  "TST_BASETAG1",
255  ["Red",
256  "Blue"]
257  ) ,
258  array(
259  "TST_BASETAG2",
260  ["Yellow"]
261  ) ,
262  array(
263  "TST_BASETAG3",
264  ["Green"]
265  ) ,
266  array(
267  "TST_BASETAG4",
268  []
269  )
270  );
271  }
272 
273  public function dataAddAErrorTag()
274  {
275  return array(
276  array(
277  "TST_BASETAG",
278  "MY_TAG\nMY",
279  "DOC0121"
280  ) ,
281  array(
282  "TST_BASETAG",
283  "",
284  "DOC0122"
285  )
286  );
287  }
288 
289  public function dataDeleteATag()
290  {
291  return array(
292  array(
293  "TST_BASETAG",
294  array(
295  "MY_TAG"
296  ) ,
297  array(
298  "MY_TAG"
299  ) ,
300  array()
301  ) ,
302  array(
303  "TST_BASETAG",
304  array(
305  "MY_TAG"
306  ) ,
307  array() ,
308  array(
309  "MY_TAG"
310  )
311  ) ,
312  array(
313  "TST_BASETAG",
314  array(
315  "MY_TAG1",
316  "MY_TAG:2",
317  'MY_TAG$3'
318  ) ,
319  array(
320  'MY_TAG$3'
321  ) ,
322  array(
323  "MY_TAG1",
324  "MY_TAG:2"
325  )
326  ) ,
327  array(
328  "TST_BASETAG",
329  array(
330  "MY_TAG1",
331  'MY_TAG/2',
332  'MY_TAG^3',
333  '{a:123}'
334  ) ,
335  array(
336  'MY_TAG1'
337  ) ,
338  array(
339  'MY_TAG/2',
340  'MY_TAG^3',
341  '{a:123}'
342  )
343  ) ,
344  array(
345  "TST_BASETAG",
346  array(
347  "MY_TAG1",
348  'MY_TAG/2',
349  'MY_TAG^3',
350  '{a:123}'
351  ) ,
352  array(
353  'MY_TAG/2',
354  'MY_TAG^3',
355  '{a:123}',
356  'MY_TAG1'
357  ) ,
358  array()
359  ) ,
360  array(
361  "TST_BASETAG",
362  array(
363  "MY_TAG1",
364  'MY_TAG/2',
365  'MY_TAG^3',
366  '{a:123}'
367  ) ,
368  array(
369  'MY_TAG/2',
370  'MY_TAG^3',
371  'MY_TAG1',
372  ) ,
373  array(
374  '{a:123}'
375  )
376  ) ,
377  array(
378  "TST_BASETAG",
379  array(
380  "MY_TAG1",
381  'MY_TAG/2',
382  'MY_TAG^3',
383  '{a:123}'
384  ) ,
385  array(
386  'MY_TAG/2',
387  ) ,
388  array(
389  "MY_TAG1",
390  'MY_TAG^3',
391  '{a:123}'
392  )
393  )
394  );
395  }
396 
397  public function dataATags()
398  {
399  return array(
400  array(
401  "TST_BASETAG",
402  array(
403  "MY_TAG"
404  )
405  ) ,
406  array(
407  "TST_BASETAG",
408  array(
409  "MY_TAG",
410  "MY_TAGTWO"
411  )
412  ) ,
413  array(
414  "TST_BASETAG",
415  array(
416  "MY_TAG",
417  "MY_TAG:a"
418  )
419  ) ,
420  array(
421  "TST_BASETAG",
422  array(
423  "MY_TAG",
424  "MY_TAG:"
425  )
426  ) ,
427  array(
428  "TST_BASETAG",
429  array(
430  "MY_TAG:",
431  "MY_TAG"
432  )
433  ) ,
434  array(
435  "TST_BASETAG",
436  array(
437  "MY_TAG 2",
438  "MY_TAG-3"
439  )
440  )
441  );
442  }
443 
444  public function dataTags()
445  {
446  return array(
447  array(
448  "TST_BASETAG",
449  "john",
450  "jane",
451  "one",
452  "un"
453  ) ,
454  array(
455  "TST_BASETAG",
456  "jane",
457  "john",
458  "two",
459  "deux"
460  ) ,
461  array(
462  "TST_BASETAG",
463  "jane",
464  "john",
465  "empty",
466  ""
467  )
468  );
469  }
470 }
471 ?>
static sudo($login)
static tearDownAfterClass()
static getSystemUserId()
Definition: Class.Doc.php:8981
static setUpBeforeClass()
testImportATag($docName, array $expectedTags)
testAddUTag($docName, $login, $otherLogin, $tag, $value)
testDelUTags($docName, $login, $otherLogin, $tag, $value)
testDelUTag($docName, $login, $otherLogin, $tag, $value)
testAddAErrorTag($docName, $tag, $error)
testDeleteATag($docName, array $addTags, array $delTags, array $expectedTags)
$login
Definition: dav.php:40
testChangeUTag($docName, $login, $otherLogin, $tag, $value)
testAddATag($docName, array $tags)
$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
$value
← centre documentaire © anakeen