FOSSology  4.4.0
Open Source License Compliance by Open Source Software
UploadTreeProxyTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Proxy;
9 
14 
15 class UploadTreeProxyTest extends \PHPUnit\Framework\TestCase
16 {
17  private $testDb;
18 
19  protected function setUp() : void
20  {
21  $this->testDb = new TestPgDb();
22  $this->testDb->createPlainTables( array('uploadtree', 'report_info') );
23  $this->dbManager = $this->testDb->getDbManager();
24  $this->dbManager->queryOnce('ALTER TABLE uploadtree RENAME TO uploadtree_a');
25  $this->testDb->insertData(array('uploadtree_a'));
26  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
27  }
28 
29  protected function tearDown() : void
30  {
31  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
32  $this->testDb = null;
33  }
34 
35  public function testGetNonArtifactDescendantsWithMaterialize()
36  {
37  $uploadTreeProxy = new UploadTreeProxy($uploadId=1, $options=array(), $uploadTreeTableName='uploadtree_a');
38  $uploadTreeProxy->materialize();
39 
40  $artifact = new ItemTreeBounds(2,'uploadtree_a', $uploadId, 2, 3);
41  $artifactDescendants = $uploadTreeProxy->getNonArtifactDescendants($artifact);
42  assertThat($artifactDescendants, emptyArray());
43 
44  $zip = new ItemTreeBounds(1,'uploadtree_a', $uploadId, 1, 24);
45  $zipDescendants = $uploadTreeProxy->getNonArtifactDescendants($zip);
46  assertThat(array_keys($zipDescendants), arrayContainingInAnyOrder(array(6,7,8,10,11,12)) );
47 
48  $uploadTreeProxy->unmaterialize();
49  }
50 
51  public function testGetNonArtifactDescendantsWithoutMaterialize()
52  {
53  $uploadTreeProxy = new UploadTreeProxy($uploadId=1, $options=array(), $uploadTreeTableName='uploadtree_a');
54 
55  $artifact = new ItemTreeBounds(2,'uploadtree_a', $uploadId, 2, 3);
56  $artifactDescendants = $uploadTreeProxy->getNonArtifactDescendants($artifact);
57  assertThat($artifactDescendants, emptyArray());
58 
59  $zip = new ItemTreeBounds(1,'uploadtree_a', $uploadId, 1, 24);
60  $zipDescendants = $uploadTreeProxy->getNonArtifactDescendants($zip);
61  assertThat(array_keys($zipDescendants), arrayContainingInAnyOrder(array(6,7,8,10,11,12)) );
62  }
63 
64  protected function prepareUploadTree($upload=4)
65  {
66  $this->dbManager->prepare($stmt = 'insert.uploadtree',
67  "INSERT INTO uploadtree_a (uploadtree_pk, parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name, realparent)"
68  . " VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)");
69  foreach (array(
70  array(301, null, $upload, null, 2<<28, 1, 16, 'topDir',null)
71  ,array(302, 301, $upload, null, 2<<28, 2, 5, 'dirA', 301)
72  ,array(303, 302, $upload, 101, 0, 3, 4, 'fileAB.txt', 302)
73  ,array(304, 301, $upload, null, 3<<28, 6, 13, 'metaC', 301)
74  ,array(305, 304, $upload, null, 2<<28, 7, 10, 'dirCD', 301)
75  ,array(306, 305, $upload, 102, 0, 8, 9,'fileCDE.c', 305)
76  ,array(307, 304, $upload, 103, 0,11, 12, 'fileCF.cpp', 301)
77  ,array(308, 301, $upload, 104, 0,14, 15, 'fileG.h', 301)
78  ) as $itemEntry) {
79  $this->dbManager->freeResult($this->dbManager->execute($stmt, $itemEntry));
80  }
81  }
82 
83 
84  public function testOptionRealParent()
85  {
86  $this->prepareUploadTree($upload=4);
87 
88  $uploadTreeProxy = new UploadTreeProxy($upload, $options=array(UploadTreeProxy::OPT_REALPARENT=>301), $uploadTreeTableName='uploadtree_a');
89  $stmt = __METHOD__;
90  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT uploadtree_pk FROM ".$uploadTreeProxy->getDbViewName());
91  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
92  $descendants = $this->dbManager->fetchAll($res);
93  $this->dbManager->freeResult($res);
94  $zipDescendants = array_reduce($descendants, function($foo,$bar)
95  {
96  $foo[] = $bar['uploadtree_pk'];
97  return $foo;
98  }, array());
99  assertThat($zipDescendants, equalTo(array(302,305,307,308)) );
100  }
101 
102  public function testOptionRange()
103  {
104  $this->prepareUploadTree($upload=4);
105 
106  $itemBounds = new ItemTreeBounds(302, $uploadTreeTableName='uploadtree_a', $upload, 2, 5);
107  $uploadTreeProxyA = new UploadTreeProxy($upload, array(UploadTreeProxy::OPT_RANGE=>$itemBounds), $uploadTreeTableName, 'viewDirA');
108  $stmt = __METHOD__.'A';
109  $this->dbManager->prepare($stmt, $uploadTreeProxyA->asCTE()." SELECT uploadtree_pk FROM ".$uploadTreeProxyA->getDbViewName());
110  $res = $this->dbManager->execute($stmt, $uploadTreeProxyA->getParams());
111  $descendants = $this->dbManager->fetchAll($res);
112  $this->dbManager->freeResult($res);
113  $zipDescendantsA = array_reduce($descendants, function($foo,$bar){
114  $foo[] = $bar['uploadtree_pk'];
115  return $foo;
116  }, array());
117  assertThat($zipDescendantsA, equalTo(array(303)) );
118 
119  $itemBoundsT = new ItemTreeBounds(301, $uploadTreeTableName='uploadtree_a', $upload, 1, 16);
120  $uploadTreeProxyT = new UploadTreeProxy($upload, array(UploadTreeProxy::OPT_RANGE=>$itemBoundsT), $uploadTreeTableName, 'viewTop');
121  $stmtT = __METHOD__;
122  $this->dbManager->prepare($stmtT, $uploadTreeProxyT->asCTE()." SELECT uploadtree_pk FROM ".$uploadTreeProxyT->getDbViewName());
123  $res = $this->dbManager->execute($stmt, $uploadTreeProxyT->getParams());
124  $descendantsT = $this->dbManager->fetchAll($res);
125  $this->dbManager->freeResult($res);
126  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
127  $foo[] = $bar['uploadtree_pk'];
128  return $foo;
129  }, array());
130  assertThat($zipDescendantsT, equalTo(array(303,306,307,308)) );
131  }
132 
133  public function testOptionExt()
134  {
135  $this->prepareUploadTree($upload=4);
136 
137  $uploadTreeProxy = new UploadTreeProxy($upload, $options=array(UploadTreeProxy::OPT_EXT=>'c'), 'uploadtree_a');
138  $stmt = __METHOD__;
139  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT ufile_name FROM ".$uploadTreeProxy->getDbViewName());
140  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
141  $descendants = $this->dbManager->fetchAll($res);
142  $this->dbManager->freeResult($res);
143  $zipDescendants = array_reduce($descendants, function($foo,$bar){
144  $foo[] = $bar['ufile_name'];
145  return $foo;
146  }, array());
147  assertThat($zipDescendants, equalTo(array('fileCDE.c')) );
148  }
149 
150  public function testOptionHead()
151  {
152  $this->prepareUploadTree($upload=4);
153 
154  $uploadTreeProxy = new UploadTreeProxy($upload, $options=array(UploadTreeProxy::OPT_HEAD=>'filEc'), 'uploadtree_a');
155  $stmt = __METHOD__;
156  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT ufile_name FROM ".$uploadTreeProxy->getDbViewName());
157  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
158  $descendants = $this->dbManager->fetchAll($res);
159  $this->dbManager->freeResult($res);
160  $zipDescendants = array_reduce($descendants, function($foo,$bar){
161  $foo[] = $bar['ufile_name'];
162  return $foo;
163  }, array());
164  assertThat($zipDescendants, equalTo(array('fileCDE.c','fileCF.cpp')) );
165  }
166 
167  public function testOptionScanRefParented()
168  {
169  $this->testDb->createPlainTables( array('license_map','license_file') );
170  $rfId = 201;
171  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>103,'agent_fk'=>401));
172  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>102,'agent_fk'=>402));
173  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId+1,'pfile_fk'=>101,'agent_fk'=>401));
174 
175  $this->prepareUploadTree($upload=4);
176 
177  $itemBoundsT = new ItemTreeBounds(301, $uploadTreeTableName='uploadtree_a', $upload, 1, 16);
178  $options = array(UploadTreeProxy::OPT_RANGE=>$itemBoundsT, UploadTreeProxy::OPT_AGENT_SET=>array(401), UploadTreeProxy::OPT_SCAN_REF=>$rfId);
179  $uploadTreeProxy = new UploadTreeProxy($upload, $options, $uploadTreeTableName, 'viewTop');
180  $stmt = __METHOD__;
181  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT pfile_fk FROM ".$uploadTreeProxy->getDbViewName());
182  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
183  $descendantsT = $this->dbManager->fetchAll($res);
184  $this->dbManager->freeResult($res);
185  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
186  $foo[] = $bar['pfile_fk'];
187  return $foo;
188  }, array());
189  assertThat($zipDescendantsT, equalTo(array(103)) );
190  }
191 
192  public function testOptionScanRefRanged()
193  {
194  $this->testDb->createPlainTables( array('license_map','license_file') );
195  $rfId = 201;
196  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>103,'agent_fk'=>401));
197  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>102,'agent_fk'=>402));
198  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId+1,'pfile_fk'=>104,'agent_fk'=>401));
199 
200  $this->prepareUploadTree($upload=4);
201 
202  $options = array(UploadTreeProxy::OPT_REALPARENT=>301, UploadTreeProxy::OPT_AGENT_SET=>array(401), UploadTreeProxy::OPT_SCAN_REF=>$rfId);
203  $uploadTreeProxy = new UploadTreeProxy($upload, $options, 'uploadtree_a', 'viewTop');
204  $stmt = __METHOD__;
205  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT pfile_fk FROM ".$uploadTreeProxy->getDbViewName());
206  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
207  $descendantsT = $this->dbManager->fetchAll($res);
208  $this->dbManager->freeResult($res);
209  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
210  $foo[] = $bar['pfile_fk'];
211  return $foo;
212  }, array());
213  assertThat($zipDescendantsT, equalTo(array(103)) );
214  }
215 
216  protected function insertDecisionEvent($decisionId,$eventId,$rfId,$groupId,$item,$pfileId,$type,$removed,$date,$scope=DecisionScopes::ITEM)
217  {
218  $this->dbManager->insertTableRow('clearing_decision',array('clearing_decision_pk'=>$decisionId,'pfile_fk'=>$pfileId,'uploadtree_fk'=>$item,
219  'group_fk'=>$groupId,'date_added'=>$date,'decision_type'=> $type,'scope'=>$scope));
220  $this->dbManager->insertTableRow('clearing_event',array('clearing_event_pk'=>$eventId,'rf_fk'=>$rfId,'group_fk'=>$groupId,'uploadtree_fk'=>$item,
221  'date_added'=>$date,'removed'=>$removed));
222  if ($type != DecisionTypes::WIP) {
223  $this->dbManager->insertTableRow('clearing_decision_event', array('clearing_event_fk' => $eventId, 'clearing_decision_fk' => $decisionId));
224  }
225  }
226 
227  public function testOptionConRefParented()
228  {
229  $this->testDb->createPlainTables( array('clearing_decision','clearing_decision_event','clearing_event') );
230 
231  $rfId = 201;
232  $groupId = 301;
233  $decisionId = 501;
234  $eventId = 601;
235 
236  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 307, 103, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:13');
237  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 307, 103, DecisionTypes::IDENTIFIED, 'true', '2015-05-11 12:15');
238 
239  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 306, 102, DecisionTypes::IDENTIFIED, 'true', '2015-05-11 12:13');
240  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 306, 102, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:15');
241 
242  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 308, 104, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:13');
243  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 308, 104, DecisionTypes::WIP, 'true', '2015-05-11 12:15');
244 
245  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 303, 101, DecisionTypes::WIP, 'false', '2015-05-11 12:15');
246 
247  $this->prepareUploadTree($upload=4);
248 
249  $options = array(UploadTreeProxy::OPT_GROUP_ID=>$groupId, UploadTreeProxy::OPT_REALPARENT=>301, UploadTreeProxy::OPT_CONCLUDE_REF=>$rfId);
250  $uploadTreeProxy = new UploadTreeProxy($upload, $options, $uploadTreeTableName='uploadtree_a', 'viewTop');
251  $stmt = __METHOD__;
252  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT uploadtree_pk FROM ".$uploadTreeProxy->getDbViewName());
253  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
254  $descendantsT = $this->dbManager->fetchAll($res);
255  $this->dbManager->freeResult($res);
256  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
257  $foo[] = $bar['uploadtree_pk'];
258  return $foo;
259  }, array());
260  $parentOf306 = 305;
261  assertThat($zipDescendantsT, equalTo(array($parentOf306,308)) );
262  }
263 
264  public function testOptionConRefRanged()
265  {
266  $this->testDb->createPlainTables( array('clearing_decision','clearing_decision_event','clearing_event') );
267 
268  $rfId = 201;
269  $groupId = 301;
270  $decisionId = 501;
271  $eventId = 601;
272 
273  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 307, 103, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:13');
274  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 307, 103, DecisionTypes::IDENTIFIED, 'true', '2015-05-11 12:15');
275 
276  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 306, 102, DecisionTypes::IDENTIFIED, 'true', '2015-05-11 12:13');
277  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 306, 102, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:15');
278 
279  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 308, 104, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:13');
280  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 308, 104, DecisionTypes::WIP, 'true', '2015-05-11 12:15');
281 
282  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 303, 101, DecisionTypes::WIP, 'false', '2015-05-11 12:15');
283 
284  $this->prepareUploadTree($upload=4);
285 
286  $itemBoundsT = new ItemTreeBounds(301, $uploadTreeTableName='uploadtree_a', $upload, 1, 16);
287  $options = array(UploadTreeProxy::OPT_GROUP_ID=>$groupId, UploadTreeProxy::OPT_RANGE=>$itemBoundsT, UploadTreeProxy::OPT_CONCLUDE_REF=>$rfId);
288  $uploadTreeProxy = new UploadTreeProxy($upload, $options, $uploadTreeTableName, 'viewTop');
289  $stmt = __METHOD__;
290  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT uploadtree_pk FROM ".$uploadTreeProxy->getDbViewName());
291  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
292  $descendantsT = $this->dbManager->fetchAll($res);
293  $this->dbManager->freeResult($res);
294  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
295  $foo[] = $bar['uploadtree_pk'];
296  return $foo;
297  }, array());
298  assertThat($zipDescendantsT, equalTo(array(306,308)) );
299  }
300 
301  public function testOptionSkipAlreadyClearedRanged()
302  {
303  $this->testDb->createPlainTables( array('license_file','clearing_decision','clearing_decision_event','clearing_event','license_ref') );
304  $this->testDb->createInheritedTables( array('license_candidate') );
305 
306  $rfId = 201;
307  $groupId = 301;
308  $decisionId = 501;
309  $eventId = 601;
310 
311  $this->dbManager->insertTableRow('license_ref',array('rf_pk'=>$rfId,'rf_shortname'=>'any_license_found'));
312 
313  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 307, 103, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:13');
314  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 306, 102, DecisionTypes::IDENTIFIED, 'true', '2015-05-11 12:13');
315 
316  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>103,'agent_fk'=>401));
317  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>104,'agent_fk'=>401));
318 
319  $this->prepareUploadTree($upload=4);
320 
321  $itemBoundsT = new ItemTreeBounds(301, $uploadTreeTableName='uploadtree_a', $upload, 1, 16);
322  $options = array(UploadTreeProxy::OPT_GROUP_ID=>$groupId, UploadTreeProxy::OPT_RANGE=>$itemBoundsT, UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED=>true, UploadTreeProxy::OPT_AGENT_SET=>array(401));
323  $uploadTreeProxy = new UploadTreeProxy($upload, $options, $uploadTreeTableName, 'viewTop');
324  $stmt = __METHOD__;
325  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT pfile_fk FROM ".$uploadTreeProxy->getDbViewName());
326  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
327  $descendantsT = $this->dbManager->fetchAll($res);
328  $this->dbManager->freeResult($res);
329  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
330  $foo[] = $bar['pfile_fk'];
331  return $foo;
332  }, array());
333  assertThat($zipDescendantsT, equalTo(array(104)) );
334  }
335 
336  public function testOptionSkipAlreadyClearedParented()
337  {
338  $this->testDb->createPlainTables( array('license_file','clearing_decision','clearing_decision_event','clearing_event','license_ref') );
339  $this->testDb->createInheritedTables( array('license_candidate') );
340 
341  $rfId = 201;
342  $groupId = 301;
343  $decisionId = 501;
344  $eventId = 601;
345 
346  $this->dbManager->insertTableRow('license_ref',array('rf_pk'=>$rfId,'rf_shortname'=>'any_license_found'));
347 
348  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 307, 103, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:13');
349  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 306, 102, DecisionTypes::IDENTIFIED, 'true', '2015-05-11 12:13');
350 
351  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>103,'agent_fk'=>401));
352  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>104,'agent_fk'=>401));
353 
354  $this->prepareUploadTree($upload=4);
355 
356  $options = array(UploadTreeProxy::OPT_GROUP_ID=>$groupId, UploadTreeProxy::OPT_REALPARENT=>301, UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED=>true, UploadTreeProxy::OPT_AGENT_SET=>array(401));
357  $uploadTreeProxy = new UploadTreeProxy($upload, $options, $uploadTreeTableName='uploadtree_a', 'viewTop');
358  $stmt = __METHOD__;
359  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT pfile_fk FROM ".$uploadTreeProxy->getDbViewName());
360  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
361  $descendantsT = $this->dbManager->fetchAll($res);
362  $this->dbManager->freeResult($res);
363  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
364  $foo[] = $bar['pfile_fk'];
365  return $foo;
366  }, array());
367  assertThat($zipDescendantsT, equalTo(array(104)) );
368  }
369 
370  public function testOptionSkipTheseThatAreAlreadyCleared()
371  {
372  $this->testDb->createPlainTables( array('license_file','clearing_decision','clearing_decision_event','clearing_event','license_ref') );
373  $this->testDb->createInheritedTables( array('license_candidate') );
374 
375  $rfId = 201;
376  $groupId = 301;
377  $decisionId = 501;
378  $eventId = 601;
379 
380  $this->dbManager->insertTableRow('license_ref',array('rf_pk'=>$rfId,'rf_shortname'=>'any_license_found'));
381 
382  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 307, 103, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:13');
383  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 306, 102, DecisionTypes::IDENTIFIED, 'true', '2015-05-11 12:13');
384 
385  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>103,'agent_fk'=>401));
386  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>104,'agent_fk'=>401));
387 
388  $this->prepareUploadTree($upload=4);
389 
390  $options = array(UploadTreeProxy::OPT_GROUP_ID=>$groupId, UploadTreeProxy::OPT_REALPARENT=>301, UploadTreeProxy::OPT_SKIP_THESE=>UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED, UploadTreeProxy::OPT_AGENT_SET=>array(401));
391  $uploadTreeProxy = new UploadTreeProxy($upload, $options, $uploadTreeTableName='uploadtree_a', 'viewTop');
392  $stmt = __METHOD__;
393  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT pfile_fk FROM ".$uploadTreeProxy->getDbViewName());
394  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
395  $descendantsT = $this->dbManager->fetchAll($res);
396  $this->dbManager->freeResult($res);
397  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
398  $foo[] = $bar['pfile_fk'];
399  return $foo;
400  }, array());
401  assertThat($zipDescendantsT, equalTo(array(104)) );
402  }
403 
404  public function testOptionSkipAlreadyClearedButScanRanged()
405  {
406  $this->testDb->createPlainTables( array('license_file','clearing_decision','clearing_decision_event','clearing_event','license_ref','license_map') );
407  $this->testDb->createInheritedTables( array('license_candidate') );
408 
409  $rfId = 201;
410  $groupId = 301;
411  $decisionId = 501;
412  $eventId = 601;
413 
414  $this->dbManager->insertTableRow('license_ref',array('rf_pk'=>$rfId,'rf_shortname'=>'any_license_found'));
415  $this->dbManager->insertTableRow('license_ref',array('rf_pk'=>$rfId+1,'rf_shortname'=>'license_found'));
416 
417  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 307, 103, DecisionTypes::IDENTIFIED, 'false', '2015-05-11 12:13');
418  $this->insertDecisionEvent($decisionId++, $eventId++, $rfId, $groupId, 306, 102, DecisionTypes::IDENTIFIED, 'true', '2015-05-11 12:13');
419 
420  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>103,'agent_fk'=>401));
421  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId,'pfile_fk'=>104,'agent_fk'=>401));
422  $this->dbManager->insertTableRow('license_file',array('rf_fk'=>$rfId+1,'pfile_fk'=>101,'agent_fk'=>401));
423 
424  $this->prepareUploadTree($upload=4);
425 
426  $itemBoundsT = new ItemTreeBounds(301, $uploadTreeTableName='uploadtree_a', $upload, 1, 16);
427  $options = array(UploadTreeProxy::OPT_GROUP_ID=>$groupId, UploadTreeProxy::OPT_RANGE=>$itemBoundsT,
428  UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED=>true, UploadTreeProxy::OPT_AGENT_SET=>array(401), UploadTreeProxy::OPT_SCAN_REF=>$rfId);
429  $uploadTreeProxy = new UploadTreeProxy($upload, $options, $uploadTreeTableName, 'viewTop');
430  $stmt = __METHOD__;
431  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT pfile_fk FROM ".$uploadTreeProxy->getDbViewName());
432  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
433  $descendantsT = $this->dbManager->fetchAll($res);
434  $this->dbManager->freeResult($res);
435  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
436  $foo[] = $bar['pfile_fk'];
437  return $foo;
438  }, array());
439  assertThat($zipDescendantsT, equalTo(array(104)) );
440  }
441 
442  public function testCount()
443  {
444  $uploadTreeProxy = new UploadTreeProxy(1, array(), 'uploadtree_a');
445  assertThat($uploadTreeProxy->count(), is(12));
446 
447  $uploadTreeProxy->materialize();
448  assertThat($uploadTreeProxy->count(), is(12));
449 
450  $uploadTreeProxyAd = new UploadTreeProxy(1, array(UploadTreeProxy::OPT_ITEM_FILTER=>" AND ufile_name LIKE 'Ad%'"), 'uploadtree_a', 'viewWithHead');
451  assertThat($uploadTreeProxyAd->count(), is(2));
452  }
453 
454  public function testGetUploadTreeTableName()
455  {
456  $uploadTreeProxy = new UploadTreeProxy(1, array(), $tableName='uploadtree_a');
457  assertThat($uploadTreeProxy->getUploadTreeTableName(), is(equalTo($tableName)));
458  }
459 
460  public function testGetDefaultUploadTreeView()
461  {
462  $this->prepareUploadTree($upload=4);
463  $options = array(UploadTreeProxy::OPT_ITEM_FILTER=>"AND ufile_name='dirA'");
464  $uploadTreeProxy = new UploadTreeProxy(4, $options, $uploadTreeTableName='uploadtree_a');
465 
466  $stmt = __METHOD__;
467  $this->dbManager->prepare($stmt, $uploadTreeProxy->asCTE()." SELECT uploadtree_pk FROM ".$uploadTreeProxy->getDbViewName());
468  $res = $this->dbManager->execute($stmt, $uploadTreeProxy->getParams());
469  $descendantsT = $this->dbManager->fetchAll($res);
470  $this->dbManager->freeResult($res);
471  $zipDescendantsT = array_reduce($descendantsT, function($foo,$bar){
472  $foo[] = $bar['uploadtree_pk'];
473  return $foo;
474  }, array());
475  assertThat($zipDescendantsT, equalTo(array(302)) );
476  }
477 }
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16