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