37 protected function setUp()
40 $this->
dbManager = &$this->testDb->getDbManager();
42 $this->testDb->createPlainTables(array(
'upload',
'uploadtree'));
44 $this->
dbManager->prepare($stmt =
'insert.upload',
45 "INSERT INTO upload (upload_pk, uploadtree_tablename) VALUES ($1, $2)");
46 $uploadArray = array(array(1,
'uploadtree'), array(2,
'uploadtree_a'));
47 foreach ($uploadArray as $uploadEntry) {
50 $logger = M::mock(
'Monolog\Logger');
51 $logger->shouldReceive(
'debug');
52 $uploadPermissionDao = M::mock(
'Fossology\Lib\Dao\UploadPermissionDao');
55 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
58 protected function tearDown()
60 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
65 public function testGetFileTreeBounds()
70 $this->
dbManager->queryOnce(
"INSERT INTO uploadtree (uploadtree_pk, parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name)" 71 .
" VALUES ($uploadTreeId, NULL, $uploadId, 1, 33792, $left, 2, 'WXwindows.txt');",
72 __METHOD__ .
'.insert.data');
74 $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId);
75 assertThat($itemTreeBounds, anInstanceOf(
'Fossology\Lib\Data\Tree\ItemTreeBounds'));
77 assertThat($uploadId, equalTo($itemTreeBounds->getUploadId()));
78 assertThat($left, equalTo($itemTreeBounds->getLeft()));
81 public function testGetNextItemWithEmptyArchive()
85 $nextItem = $this->uploadDao->getNextItem(1, 1);
86 assertThat($nextItem, is(nullValue()));
89 public function testGetPreviousItemWithEmptyArchive()
93 $nextItem = $this->uploadDao->getPreviousItem(1, 1);
94 assertThat($nextItem, is(nullValue()));
97 public function testGetNextItemWithSingleFile()
102 $nextItem = $this->uploadDao->getNextItem(1, 1);
103 assertThat($nextItem->getId(), is(6));
106 public function testGetPreviousItemWithSingleFile()
111 $nextItem = $this->uploadDao->getPreviousItem(1, 1);
112 assertThat($nextItem, is(nullValue()));
115 public function testGetNextItemWithNestedFile()
120 $nextItem = $this->uploadDao->getNextItem(1, 1);
121 assertThat($nextItem->getId(), is(8));
124 public function testGetPreviousItemWithNestedFile()
129 $nextItem = $this->uploadDao->getPreviousItem(1, 1);
130 assertThat($nextItem, is(nullValue()));
133 public function testGetNextItemWithFileAfterEmptyDirectory()
138 $nextItem = $this->uploadDao->getNextItem(1, 1);
139 assertThat($nextItem->getId(), is(8));
142 public function testGetPreviousItemWithFileAfterEmptyDirectory()
147 $nextItem = $this->uploadDao->getPreviousItem(1, 1);
148 assertThat($nextItem, is(nullValue()));
151 public function testGetNextItemWithMultipleFiles()
156 $nextItem = $this->uploadDao->getNextItem(1, 6);
157 assertThat($nextItem->getId(), is(7));
160 public function testGetPreviousItemWithMultipleFiles()
165 $nextItem = $this->uploadDao->getPreviousItem(1, 6);
166 assertThat($nextItem, anInstanceOf(Item::class));
167 assertThat($nextItem->getId(), is(8));
176 $this->
dbManager->prepare($stmt =
'insert.uploadtree',
177 "INSERT INTO uploadtree (uploadtree_pk, parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)");
178 foreach ($uploadTreeArray as $uploadTreeEntry) {
190 $right_base = 5 + count($subentries) * 2;
192 $uploadTreeArray = array_merge(
194 array(1, null, 1, 1, 536904704, 1, $right_base + 5,
'archive.tar.gz'),
195 array(2, 1, 1, 0, 805323776, 2, $right_base + 4,
'artifact.dir'),
196 array(3, 2, 1, 2, 536903680, 3, $right_base + 3,
'archive.tar'),
197 array(4, 3, 1, 0, 805323776, 4, $right_base + 2,
'artifact.dir'),
198 array(5, 4, 1, 0, 536888320, 5, $right_base + 1,
'archive')),
208 return array(array(6, 5, 1, 3, 33188, 6, 10,
'README'));
217 array(6, 5, 1, 0, 536888320, 7, 12,
'docs'),
218 array(7, 6, 1, 0, 536888320, 8, 11,
'txt'),
219 array(8, 7, 1, 3, 33188, 9, 10,
'README')
235 array(6, 5, 1, 0, 536888320, 7, 10,
'docs'),
236 array(7, 6, 1, 0, 536888320, 8, 9,
'txt'),
237 array(8, 5, 1, 3, 33188, 11, 12,
'README')
247 array(6, 5, 1, 3, 33188, 9, 10,
'INSTALL'),
248 array(7, 5, 1, 4, 33188, 11, 12,
'README'),
249 array(8, 5, 1, 5, 33188, 7, 8,
'COPYING')
296 3653, 3668, 3683, 3685, 3671, 3665, 3676, 3675, 3681, 3677, 3673, 3658, 3660, 3686,
299 protected function getTestFileStructure()
302 $isContainer = 536888320;
304 array(3650, NULL, 32, 3286, 536904704, 1, 76,
'uploadDaoTest.tar'),
305 array(3651, 3650, 32, 0, 805323776, 2, 75,
'artifact.dir'),
306 array(3652, 3651, 32, 0, 536888320, 3, 74,
'uploadDaoTest'),
308 array(3653, 3652, 32, 3287, $isFile, 4, 5,
'A'),
309 array(3663, 3652, 32, 3287, $isContainer, 6, 7,
'B'),
310 array(3668, 3652, 32, 3294, $isFile, 8, 9,
'C'),
311 array(3682, 3652, 32, 0, $isContainer, 10, 16,
'D'),
312 array(3683, 3682, 32, 3303, $isFile, 11, 12,
'E'),
314 array(3685, 3682, 32, 3305, $isFile, 14, 15,
'G'),
315 array(3669, 3652, 32, 0, $isContainer, 16, 23,
'H'),
317 array(3671, 3669, 32, 3296, $isFile, 19, 20,
'J'),
319 array(3661, 3652, 32, 0, $isContainer, 24, 37,
'L'),
320 array(3666, 3661, 32, 0, $isContainer, 25, 28,
'L1'),
321 array(3667, 3666, 32, 0, $isContainer, 26, 27,
'L1a'),
322 array(3664, 3661, 32, 0, $isContainer, 29, 32,
'L2'),
323 array(3665, 3664, 32, 3292, $isFile, 30, 31,
'L2a'),
324 array(3662, 3661, 32, 0, $isContainer, 33, 36,
'L3'),
326 array(3654, 3652, 32, 0, $isContainer, 38, 41,
'M'),
327 array(3655, 3654, 32, 0, $isContainer, 39, 40,
'M1'),
328 array(3674, 3652, 32, 0, $isContainer, 42, 57,
'N'),
329 array(3676, 3674, 32, 3293, $isFile, 43, 44,
'N1'),
330 array(3678, 3674, 32, 0, $isContainer, 45, 48,
'N2'),
332 array(3675, 3674, 32, 3299, $isFile, 49, 50,
'N3'),
333 array(3680, 3674, 32, 0, $isContainer, 51, 54,
'N4'),
334 array(3681, 3680, 32, 3302, $isFile, 52, 53,
'N4a'),
335 array(3677, 3674, 32, 3300, $isFile, 55, 56,
'N5'),
336 array(3673, 3652, 32, 3298, $isFile, 58, 59,
'O'),
337 array(3656, 3652, 32, 0, $isContainer, 60, 69,
'P'),
339 array(3657, 3656, 32, 0, $isContainer, 63, 66,
'P2'),
340 array(3658, 3657, 32, 3288, $isFile, 64, 65,
'P2a'),
341 array(3660, 3656, 32, 3290, 33188, 67, 68,
'P3'),
342 array(3686, 3652, 32, 3306, 33188, 70, 71,
'R'),
347 public function testGetNextItemUsesRecursiveAndRegularSearchAsFallback()
352 $nextItem = $this->uploadDao->getNextItem(32, 3666);
353 assertThat($nextItem->getId(), is(3665));
356 public function testGetPrevItemUsesRecursiveAndRegularSearchAsFallback()
360 $nextItem = $this->uploadDao->getPreviousItem(32, 3666);
361 assertThat($nextItem->getId(), is(3671));
364 public function testGetNextItemUsesRecursiveOnly()
368 $nextItem = $this->uploadDao->getNextItem(32, 3674);
369 assertThat($nextItem->getId(), is(3676));
372 public function testGetPrevItemUsesRecursiveOnly()
376 $nextItem = $this->uploadDao->getPreviousItem(32, 3674);
377 assertThat($nextItem->getId(), is(3665));
380 public function testGetNextFull()
385 foreach ($this->entries as $entry) {
386 $nextItem = $this->uploadDao->getNextItem(32, $previousId);
387 assertThat($nextItem->getId(), is($entry));
388 $previousId = $entry;
391 $nextItem = $this->uploadDao->getNextItem(32, $previousId);
392 assertThat($nextItem, is(nullValue()));
395 public function testGetPreviousFull()
399 $entries = array_reverse($this->entries);
402 foreach (array_slice(
$entries, 1) as $entry) {
403 $previousItem = $this->uploadDao->getPreviousItem(32, $previousId);
404 assertThat($previousItem->getId(), is($entry));
405 $previousId = $entry;
408 $previousItem = $this->uploadDao->getPreviousItem(32, $previousId);
409 assertThat($previousItem, is(nullValue()));
413 public function testCountNonArtifactDescendants()
415 $this->
dbManager->queryOnce(
'ALTER TABLE uploadtree RENAME TO uploadtree_a');
416 $this->testDb->insertData(array(
'uploadtree_a'));
419 $artifactDescendants = $this->uploadDao->countNonArtifactDescendants($artifact);
420 assertThat($artifactDescendants, is(0));
423 $zipDescendants = $this->uploadDao->countNonArtifactDescendants($zip);
424 assertThat($zipDescendants, is(count(array(6,7,8,10,11,12)) ) );
428 public function testGetUploadParent()
431 $topId = $this->uploadDao->getUploadParent(32);
432 assertThat($topId,equalTo(3650));
440 $this->
prepareUploadTree(array(array(4651, 3650, 33, 0, 805323776, 2, 75,
'artifact.dir')));
441 $this->uploadDao->getUploadParent(33);
449 $this->uploadDao->getUploadParent(34);
452 public function testGetUploadHashes()
454 $this->testDb->createPlainTables(array(
'pfile'));
455 $this->
dbManager->queryOnce(
'TRUNCATE upload');
456 $this->testDb->insertData(array(
'upload',
'pfile'));
458 $hashes = $this->uploadDao->getUploadHashes(44);
459 assertThat($hashes,equalTo(array(
'md5'=>
'E7295A5773D0EA17D53CBE6293924DD4',
'sha1'=>
'93247C8DB814F0A224B75B522C1FA4DC92DC3078',
'sha256'=>
'E29ABC32DB8B6241D598BC7C76681A7623D176D85F99E738A56C0CB684C367E1')));
462 public function testGetFatItem()
465 $isContainer = 536888320;
467 $this->
prepareUploadTree(array(array($itemM1a, 3655, 32, 0, $isContainer, 39+0, 40-0,
'M1a')));
468 $this->
dbManager->queryOnce(
'UPDATE uploadtree SET realparent=parent WHERE ufile_mode&(1<<28)=0',__METHOD__.
'.fixRealparent');
470 $fatA = $this->uploadDao->getFatItemId($itemA=3653, 32,
'uploadtree');
471 assertThat($fatA,equalTo($itemA));
472 $fatB = $this->uploadDao->getFatItemId($itemBEmpty=3663, 32,
'uploadtree');
473 assertThat($fatB, equalTo($itemBEmpty));
474 $fatD = $this->uploadDao->getFatItemId($itemDFolder=3682, 32,
'uploadtree');
475 assertThat($fatD, equalTo($itemDFolder));
476 $fatL1 = $this->uploadDao->getFatItemId($itemL1ToFolder=3666, 32,
'uploadtree');
477 assertThat($fatL1, equalTo(3667));
478 $fatL2 = $this->uploadDao->getFatItemId($itemL2ToItem=3664, 32,
'uploadtree');
479 assertThat($fatL2, equalTo(3665));
481 $fatM = $this->uploadDao->getFatItemId(3654, 32,
'uploadtree');
482 assertThat($fatM, equalTo($itemM1a));
testGetUploadParentFromNonExistingTree()
prepareUploadTree($uploadTreeArray=array())
prepareModularTable($subentries=array())
getSubentriesForFileAfterEmptyDirectory()
getSubentriesForNestedFile()
getSubentriesForMultipleFiles()
getSubentriesForSingleFile()
fo_dbManager * dbManager
fo_dbManager object
testGetUploadParentFromBrokenTree()