Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_addArrayRow.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';
15 {
16  /**
17  * import TST_UPDTATTR
18  * @static
19  * @return array|string
20  */
21  protected static function getCommonImportFile()
22  {
23  return array(
24  "PU_data_dcp_addArrayRow_family.csv"
25  );
26  }
27  /**
28  * @dataProvider dataAddArrayRow
29  */
30  public function testExecuteAddArrayRow($data)
31  {
32  $doc = createDoc(self::$dbaccess, $data['fam'], false);
33  $this->assertTrue(is_object($doc) , sprintf("Could not create new document from family '%s'.", $data['fam']));
34 
35  $err = $doc->add();
36  $this->assertEmpty($err, sprintf("Error adding new document in database: %s", $err));
37 
38  $err = $doc->setLogicalName($data['name']);
39  $this->assertEmpty($err, sprintf("Error setting logical identifier '%s' on new document: %s", $data['name'], $err));
40 
41  foreach ($data['rows'] as & $row) {
42  $err = $doc->addArrayRow($data['array_attr_name'], $row['data'], $row['index']);
43  $this->assertEmpty($err, sprintf("Error adding row {%s} to '%s': %s", join(', ', $row['data']) , $data['name'], $err));
44  }
45  unset($row);
46  $this->assertTrue($doc->isChanged() , sprintf("no changed value detected"));
47  $err = $doc->store();
48  $this->assertEmpty($err, sprintf("modify() on '%s' returned with error: %s", $data['name'], $err));
49 
50  self::resetDocumentCache();
51 
52  $doc = new_Doc(self::$dbaccess, $data['name'], true);
53  $this->assertTrue(is_object($doc) , sprintf("Error retrieving document '%s': %s", $data['name'], $err));
54 
55  foreach ($data['expected_tvalues'] as $colName => & $colData) {
56  $tvalue = $doc->getMultipleRawValues($colName);
57  $this->assertTrue(is_array($tvalue) , sprintf("getMultipleRawValues(%s) on document '%s' did not returned an array.", $colName, $data['name']));
58 
59  $tvalueCount = count($tvalue);
60  $expectedCount = count($colData);
61  $this->assertTrue(($tvalueCount == $expectedCount) , sprintf("Column size mismatch on column '%s' from document '%s' (actual size is '%s', while expecting '%s').", $colName, $data['name'], $tvalueCount, $expectedCount));
62 
63  foreach ($colData as $i => $expectedCellContent) {
64  $tvalueCellContent = $tvalue[$i];
65  $this->assertTrue(($tvalueCellContent == $expectedCellContent) , sprintf("Cell content '%s' did not matched expected content '%s' (document '%s' / column '%s' / line '%s' / column cells {%s})", $tvalueCellContent, $expectedCellContent, $data['name'], $colName, $i, join(', ', $tvalue)));
66  }
67  }
68  unset($colData);
69  }
70 
71  public function dataAddArrayRow()
72  {
73  return array(
74  array(
75  array(
76  'fam' => 'TST_ADDARRAYROW',
77  'name' => 'TST_ADDARRAYROW_DOC_01',
78  'array_attr_name' => 'ARR',
79  'rows' => array(
80  array(
81  'index' => - 1,
82  'data' => array(
83  'COL_1' => '1_1',
84  'COL_2' => '1_2',
85  'COL_3' => '1_3',
86  'COL_4' => '1_4'
87  )
88  ) ,
89  array(
90  'index' => - 1,
91  'data' => array(
92  'cOl_1' => '2_1'
93  )
94  ) ,
95  array(
96  'index' => - 1,
97  'data' => array()
98  ) ,
99  array(
100  'index' => - 1,
101  'data' => array(
102  'col_2' => '4_2',
103  'col_3' => '4_3',
104  'col_4' => '4_4'
105  )
106  )
107  ) ,
108  'expected_tvalues' => array(
109  'col_1' => array(
110  '1_1',
111  '2_1',
112  '',
113  ''
114  ) ,
115  'col_2' => array(
116  '1_2',
117  '',
118  '',
119  '4_2'
120  ) ,
121  'col_3' => array(
122  '1_3',
123  '',
124  '',
125  '4_3'
126  ) ,
127  'col_4' => array(
128  '1_4',
129  '',
130  '',
131  '4_4'
132  )
133  )
134  )
135  ) ,
136  array(
137  array(
138  'fam' => 'TST_ADDARRAYROW',
139  'name' => 'TST_ADDARRAYROW_DOC_02',
140  'array_attr_name' => 'ARR',
141  'rows' => array(
142  array(
143  'index' => 0,
144  'data' => array(
145  'col_2' => '4_2',
146  'col_3' => '4_3',
147  'col_4' => '4_4'
148  )
149  ) ,
150  array(
151  'index' => 0,
152  'data' => array()
153  ) ,
154  array(
155  'index' => 0,
156  'data' => array(
157  'cOl_1' => '2_1'
158  )
159  ) ,
160  array(
161  'index' => 0,
162  'data' => array(
163  'COL_1' => '1_1',
164  'COL_2' => '1_2',
165  'COL_3' => '1_3',
166  'COL_4' => '1_4'
167  )
168  )
169  ) ,
170  'expected_tvalues' => array(
171  'col_1' => array(
172  '1_1',
173  '2_1',
174  '',
175  ''
176  ) ,
177  'col_2' => array(
178  '1_2',
179  '',
180  '',
181  '4_2'
182  ) ,
183  'col_3' => array(
184  '1_3',
185  '',
186  '',
187  '4_3'
188  ) ,
189  'col_4' => array(
190  '1_4',
191  '',
192  '',
193  '4_4'
194  )
195  )
196  )
197  ) ,
198  array(
199  array(
200  'fam' => 'TST_ADDARRAYROW',
201  'name' => 'TST_ADDARRAYROW_DOC_03',
202  'array_attr_name' => 'ARR',
203  'rows' => array(
204  array(
205  'index' => - 1,
206  'data' => array(
207  'col_2' => '2_2',
208  'col_3' => '2_3',
209  'col_4' => '2_4'
210  )
211  ) ,
212  array(
213  'index' => 1,
214  'data' => array()
215  ) ,
216  array(
217  'index' => 2,
218  'data' => array(
219  'cOl_1' => '4_1'
220  )
221  ) ,
222  array(
223  'index' => 0,
224  'data' => array(
225  'COL_1' => '1_1',
226  'COL_2' => '1_2',
227  'COL_3' => '1_3',
228  'COL_4' => '1_4'
229  )
230  )
231  ) ,
232  'expected_tvalues' => array(
233  'col_1' => array(
234  '1_1',
235  '',
236  '',
237  '4_1'
238  ) ,
239  'col_2' => array(
240  '1_2',
241  '2_2',
242  '',
243  ''
244  ) ,
245  'col_3' => array(
246  '1_3',
247  '2_3',
248  '',
249  ''
250  ) ,
251  'col_4' => array(
252  '1_4',
253  '2_4',
254  '',
255  ''
256  )
257  )
258  )
259  ) ,
260  array(
261  array(
262  'fam' => 'TST_ADDARRAYROW_DEV_5361',
263  'name' => 'TST_ADDARRAYROW_DEV_5361_DOC_01',
264  'array_attr_name' => 'ARR',
265  'rows' => array(
266  array(
267  'index' => - 1,
268  'data' => array(
269  'col_1' => 'Line 1, Col 1',
270  'col_2' => ''
271  )
272  ) ,
273  array(
274  'index' => - 1,
275  'data' => array(
276  'col_1' => '',
277  'col_2' => 'Line 2, Col 2'
278  )
279  ) ,
280  ) ,
281  'expected_tvalues' => array(
282  'col_1' => array(
283  'Line 1, Col 1',
284  ''
285  ) ,
286  'col_2' => array(
287  '',
288  'Line 2, Col 2'
289  )
290  )
291  )
292  )
293  );
294  }
295 }
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
new_Doc($dbaccess, $id= '', $latest=false)
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
$data
← centre documentaire © anakeen