Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_workflowtransitions.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_DEFAULTFAMILY1 family
19  * @static
20  * @return string
21  */
22  protected static function getCommonImportFile()
23  {
24  return "PU_data_dcp_impworkflowfamilym0m3.ods";
25  }
26  /**
27  * @dataProvider dataTransitionCondition
28  * @param $start
29  * @param $end
30  * @param $passExpectedError
31  */
32  public function testTransitionCondition($famId, $start, $end, $passExpectedError, $customStore = null, $customSetState = null)
33  {
34  $wf = new_doc(self::$dbaccess, "WTST_M0M3");
35  $this->assertTrue($wf->isAlive() , "cannot find document WTST_M0M3");
36 
38  $d->setTitle('zou');
39  $d->wid = $wf->id;
40  $d->state = $start;
41  if (is_callable($customStore)) {
42  $err = $customStore($d);
43  } else {
44  $err = $d->store();
45  }
46  $this->assertEmpty($err, "cannot create ${famId} document: ${err}");
47 
48  if (is_callable($customSetState)) {
49  $err = $customSetState($d, $end);
50  } else {
51  $err = $d->setState($end);
52  }
53  if ($passExpectedError == '') {
54  $this->assertEmpty($err, sprintf("transition %s -> %s is not passed : %s", $start, $end, $err));
55  } else {
56 
57  $this->assertContains($passExpectedError, $err, sprintf("transition %s -> %s is passed and must not", $start, $end));
58  }
59  if (isset(self::$user)) {
60  $this->exitSudo();
61  }
62  }
63  /**
64  * @dataProvider dataTransitionPostAction
65  * @param $start
66  * @param $end
67  * @param $passExpectedMsg
68  */
69  public function testTransitionPostAction($famId, $start, $end, $passExpectedMsg)
70  {
71  $wf = new_doc(self::$dbaccess, "WTST_M0M3");
72  $this->assertTrue($wf->isAlive() , "cannot find document WTST_M0M3");
73 
75  $d->setTitle('zou');
76  $d->wid = $wf->id;
77  $d->state = $start;
78  $err = $d->store();
79  $this->assertEmpty($err, "cannot create ${famId} document");
80 
81  $err = $d->setState($end, '', false, true, true, true, true, true, true, $msg);
82  $this->assertEmpty($err, sprintf("transition %s -> %s is not passed : %s", $start, $end, $err));
83 
84  if ($passExpectedMsg == '') {
85  $this->assertEmpty($err, sprintf("transition %s -> %s is not passed : %s", $start, $end, $err));
86  } else {
87  $this->assertContains($passExpectedMsg, $msg, sprintf("transition %s -> %s is passed and must not", $start, $end));
88  }
89  }
90  public function dataTransitionCondition()
91  {
92  return array(
93  array(
94  'TST_WFFAMM0M3',
97  ''
98  ) ,
99  array(
100  'TST_WFFAMM0M3',
101  \WTestM0M3::SA,
102  \WTestM0M3::SB,
103  'm0 forbidden'
104  ) ,
105  array(
106  'TST_WFFAMM0M3',
107  \WTestM0M3::SA,
108  \WTestM0M3::SD,
109  ''
110  ) ,
111  array(
112  'TST_WFFAMM0M3',
113  \WTestM0M3::SB,
114  \WTestM0M3::SC,
115  'm1 forbidden'
116  ) ,
117  array(
118  'TST_WFFAMM0M3',
119  \WTestM0M3::SB,
120  \WTestM0M3::SD,
121  ''
122  ) ,
123  array(
124  'TST_WFFAM_DEV_7061',
125  \WTestM0M3::SB,
126  \WTestM0M3::SD,
127  ''
128  ) ,
129  array(
130  'TST_WFFAM_DEV_7061',
131  \WTestM0M3::SB,
132  \WTestM0M3::SD,
133  'Texte colonne 1 doit être rempli',
134  function (\Dcp\Family\Document & $doc)
135  {
136  $doc->setVAlue('TXT_COLTEXT_1', array(
137  // Missing/empty TST_COLTEXT_1 altogether
138 
139  ));
140  $doc->setValue('TST_COLTEXT_2', array(
141  'Row 1',
142  'Row 2'
143  ));
144  return $doc->store();
145  }
146  ) ,
147  array(
148  'TST_WFFAM_DEV_7061',
149  \WTestM0M3::SB,
150  \WTestM0M3::SD,
151  'Texte colonne 1 doit être rempli',
152  function (\Dcp\Family\Document & $doc)
153  {
154  $doc->setValue('TXT_COLTEXT_1', array(
155  '', // First cell is empty
156  'Row 2'
157  ));
158  $doc->setValue('TST_COLTEXT_2', array(
159  'Row 1',
160  'Row 2'
161  ));
162  return $doc->store();
163  }
164  ) ,
165  array(
166  'TST_WFFAM_DEV_7061',
167  \WTestM0M3::SB,
168  \WTestM0M3::SD,
169  'Texte colonne 1 doit être rempli',
170  function (\Dcp\Family\Document & $doc)
171  {
172  $doc->setValue('TXT_COLTEXT_1', array(
173  'Row 1',
174  ''
175  // Last cell is empty
176 
177  ));
178  $doc->setValue('TST_COLTEXT_2', array(
179  'Row 1',
180  'Row 2'
181  ));
182  return $doc->store();
183  }
184  ) ,
185  /*
186  * Locked documents
187  */
188  array(
189  /*
190  * Locked by myself: transition is allowed
191  */
192  'TST_WFFAM_DEV_7062',
193  \WTestM0M3::SB,
194  \WTestM0M3::SD,
195  '',
196  function (\Dcp\Family\Document & $doc)
197  {
198  /*
199  * Lock document with User #1
200  */
201  /** @var \Dcp\Family\Iuser $user1 */
202  $user1 = new_Doc('', 'DEV_6072_U1');
203  $userId1 = $user1->getRawValue('us_whatid');
204  $err = array();
205  $err[] = $doc->store();
206  $err[] = $doc->lock(true, $userId1);
207  $err[] = $doc->store();
208  return join("\n", array_filter($err, function ($elmt)
209  {
210  return strlen($elmt) > 0;
211  }));
212  }
213  ,
214  function (\Dcp\Family\Document & $doc, $newState)
215  {
216  /*
217  * Change state with User #1
218  */
219  $this->sudo('dev_6072_u1');
220  /* Re-fetch document from database */
221  $doc = new_Doc(self::$dbaccess, $doc->id);
222  $err = $doc->setState($newState);
223  return $err;
224  }
225  ) ,
226  array(
227  /*
228  * Document being modified by another user: transition not allowed
229  */
230  'TST_WFFAM_DEV_7062',
231  \WTestM0M3::SB,
232  \WTestM0M3::SD,
233  sprintf(_("Could not perform transition because the document is being edited by '%s'") , 'User #1') ,
234  function (\Dcp\Family\Document & $doc)
235  {
236  /*
237  * (auto)Lock document with User #1
238  */
239  /** @var \Dcp\Family\Iuser $user1 */
240  $user1 = new_Doc('', 'DEV_6072_U1');
241  $userId1 = $user1->getRawValue('us_whatid');
242  $err = array();
243  $err[] = $doc->store();
244  $err[] = $doc->lock(true, $userId1);
245  $err[] = $doc->store();
246  return join("\n", array_filter($err, function ($elmt)
247  {
248  return strlen($elmt) > 0;
249  }));
250  }
251  ,
252  function (\Dcp\Family\Document & $doc, $newState)
253  {
254  /*
255  * Change state with User #2
256  */
257  $this->sudo('dev_6072_u2');
258  /* Re-fetch document from database */
259  $doc = new_Doc(self::$dbaccess, $doc->id);
260  $err = $doc->setState($newState);
261  return $err;
262  }
263  ) ,
264  array(
265  /*
266  * Document explicitly locked by another user: transition not allowed
267  */
268  'TST_WFFAM_DEV_7062',
269  \WTestM0M3::SB,
270  \WTestM0M3::SD,
271  sprintf(_("Could not perform transition because the document is locked by '%s'") , 'User #1') ,
272  function (\Dcp\Family\Document & $doc)
273  {
274  /*
275  * Lock document with User #1
276  */
277  /** @var \Dcp\Family\Iuser $user1 */
278  $user1 = new_Doc('', 'DEV_6072_U1');
279  $userId1 = $user1->getRawValue('us_whatid');
280  $err = array();
281  $err[] = $doc->store();
282  $err[] = $doc->lock(false, $userId1);
283  $err[] = $doc->store();
284  return join("\n", array_filter($err, function ($elmt)
285  {
286  return strlen($elmt) > 0;
287  }));
288  }
289  ,
290  function (\Dcp\Family\Document & $doc, $newState)
291  {
292  /*
293  * Change state with User #2
294  */
295  $this->sudo('dev_6072_u2');
296  /* Re-fetch document from database */
297  $doc = new_Doc(self::$dbaccess, $doc->id);
298  $err = $doc->setState($newState);
299  return $err;
300  }
301  )
302  );
303  }
304 
305  public function dataTransitionPostAction()
306  {
307  return array(
308  array(
309  'TST_WFFAMM0M3',
310  \WTestM0M3::SA,
311  \WTestM0M3::SC,
312  ''
313  ) ,
314  array(
315  'TST_WFFAMM0M3',
316  \WTestM0M3::SA,
317  \WTestM0M3::SD,
318  'm3 pass'
319  ) ,
320  array(
321  'TST_WFFAMM0M3',
322  \WTestM0M3::SB,
323  \WTestM0M3::SD,
324  'm2 pass'
325  )
326  );
327  }
328 }
static sudo($login)
$d
Definition: dav.php:77
testTransitionCondition($famId, $start, $end, $passExpectedError, $customStore=null, $customSetState=null)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
new_Doc($dbaccess, $id= '', $latest=false)
$dbaccess
Definition: checkVault.php:17
testTransitionPostAction($famId, $start, $end, $passExpectedMsg)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen