35 protected function setUp()
38 $this->
dbManager = $this->testDb->getDbManager();
39 $userDao = M::mock(
'Fossology\Lib\Dao\UserDao');
40 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
43 $this->testDb->createPlainTables(array(
'folder',
'foldercontents'));
44 $this->testDb->createSequences(array(
'folder_folder_pk_seq',
'foldercontents_foldercontents_pk_seq'));
45 $this->testDb->createConstraints(array(
'folder_pkey',
'foldercontents_pkey'));
46 $this->testDb->alterTables(array(
'folder',
'foldercontents'));
48 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
51 protected function tearDown()
53 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
58 public function testGetAllFolderIds()
60 $this->testDb->insertData(array(
'folder'));
61 assertThat(
sizeof($this->folderDao->getAllFolderIds())>0);
64 public function testHasTopLevelFolder_yes()
66 $this->testDb->insertData(array(
'folder'));
67 $htlf = $this->folderDao->hasTopLevelFolder();
68 assertThat($htlf, is(TRUE));
71 public function testHasTopLevelFolder_no()
73 $htlf = $this->folderDao->hasTopLevelFolder();
74 assertThat($htlf, is(FALSE));
78 public function testInsertFolder()
80 $folderId = $this->folderDao->insertFolder($folderName =
'three', $folderDescription =
'floor(PI)');
81 assertThat($folderId, equalTo(FolderDao::TOP_LEVEL));
82 $folderInfo = $this->
dbManager->getSingleRow(
'SELECT folder_name,folder_desc FROM folder WHERE folder_pk=$1',
83 array($folderId), __METHOD__);
84 assertThat($folderInfo, is(array(
'folder_name' => $folderName,
'folder_desc' => $folderDescription)));
86 $folderIdPlusOne = $this->folderDao->insertFolder($folderName =
'four', $folderDescription =
'ceil(PI)');
87 assertThat($folderIdPlusOne, equalTo(FolderDao::TOP_LEVEL+1));
91 public function testInsertFolderContents()
93 $this->folderDao->insertFolderContents($parentId = 7, $foldercontentsMode = 2, $childId = 22);
94 $contentsInfo = $this->
dbManager->getSingleRow(
'SELECT foldercontents_mode, child_id FROM foldercontents WHERE parent_fk=$1',
95 array($parentId), __METHOD__);
96 assertThat($contentsInfo, is(equalTo(array(
'foldercontents_mode' => $foldercontentsMode,
'child_id' => $childId))));
100 public function testGetFolderPK()
102 $folderId = $this->folderDao->insertFolder($folderName =
'three', $folderDescription =
'floor(PI)');
104 assertThat($this->folderDao->getFolderId(
'three'), is($folderId));
107 public function testGetFolderPK_Null()
109 assertThat($this->folderDao->getFolderId(
'three'), is(null));
112 public function testGetFolderWithWrongParent()
114 $this->folderDao->insertFolder($folderName =
'three', $folderDescription =
'floor(PI)+Epsilon',2);
115 assertThat($this->folderDao->getFolderId(
'three'), is(null));
118 public function testEnsureTopLevelFolder()
120 $htlfFresh = $this->folderDao->hasTopLevelFolder();
121 assertThat($htlfFresh, is(
false));
122 $this->folderDao->ensureTopLevelFolder();
123 $htlfFixed = $this->folderDao->hasTopLevelFolder();
124 assertThat($htlfFixed, is(
true));
125 $this->folderDao->ensureTopLevelFolder();
126 $folders = $this->
dbManager->getSingleRow(
'SELECT count(*) FROM folder');
127 assertThat($folders[
'count'],is(1));
130 public function testIsWithoutReusableFolders()
132 assertThat($this->folderDao->isWithoutReusableFolders(array()),is(
true));
133 $filledFolder = array(FolderDao::REUSE_KEY=>array(1=>array(
'group_id'=>1,
'count'=>12,
'group_name'=>
'one')));
134 assertThat($this->folderDao->isWithoutReusableFolders(array($filledFolder)),is(
false));
135 $emptyFolder = array(FolderDao::REUSE_KEY=>array(1=>array(
'group_id'=>1,
'count'=>0,
'group_name'=>
'one')));
136 assertThat($this->folderDao->isWithoutReusableFolders(array($emptyFolder)),is(
true));
137 $multiAccessibleFolder = array(FolderDao::REUSE_KEY=>array(1=>array(
'group_id'=>1,
'count'=>0,
'group_name'=>
'one'),
138 2=>array(
'group_id'=>2,
'count'=>20,
'group_name'=>
'two')));
139 assertThat($this->folderDao->isWithoutReusableFolders(array($multiAccessibleFolder)),is(
false));
141 assertThat($this->folderDao->isWithoutReusableFolders(array($filledFolder,$emptyFolder)),is(
false));
144 public function testGetFolderChildFolders()
146 $this->folderDao->ensureTopLevelFolder();
147 $folderA = $this->folderDao->insertFolder(
'A',
'/A', FolderDao::TOP_LEVEL);
148 $this->folderDao->insertFolder(
'B',
'/A/B', $folderA);
149 $this->folderDao->insertFolder(
'C',
'/C', FolderDao::TOP_LEVEL);
150 assertThat($this->folderDao->getFolderChildFolders(FolderDao::TOP_LEVEL),is(arrayWithSize(2)));
153 public function testMoveContent()
155 $this->folderDao->ensureTopLevelFolder();
156 $folderA = $this->folderDao->insertFolder($folderName=
'A',
'/A', FolderDao::TOP_LEVEL);
157 $folderB = $this->folderDao->insertFolder($folderName=
'B',
'/A/B', $folderA);
158 $fc = $this->
dbManager->getSingleRow(
'SELECT foldercontents_pk FROM foldercontents WHERE child_id=$1',
159 array($folderB),__METHOD__.
'.needs.the.foldercontent_pk');
160 $this->folderDao->moveContent($fc[
'foldercontents_pk'], FolderDao::TOP_LEVEL);
161 assertThat($this->folderDao->getFolderChildFolders(FolderDao::TOP_LEVEL),is(arrayWithSize(2)));
169 $this->folderDao->ensureTopLevelFolder();
170 $folderA = $this->folderDao->insertFolder($folderName=
'A',
'/A', FolderDao::TOP_LEVEL);
171 $folderB = $this->folderDao->insertFolder($folderName=
'B',
'/A/B', $folderA);
172 $fc = $this->
dbManager->getSingleRow(
'SELECT foldercontents_pk FROM foldercontents WHERE child_id=$1',
173 array($folderA),__METHOD__.
'.needs.the.foldercontent_pk');
174 $this->folderDao->moveContent($fc[
'foldercontents_pk'], $folderB);
177 public function testCopyContent()
179 $this->folderDao->ensureTopLevelFolder();
180 $folderA = $this->folderDao->insertFolder($folderName=
'A',
'/A', FolderDao::TOP_LEVEL);
181 $folderB = $this->folderDao->insertFolder($folderName=
'B',
'/A/B', $folderA);
182 $this->folderDao->insertFolder($folderName=
'C',
'/C', FolderDao::TOP_LEVEL);
183 $fc = $this->
dbManager->getSingleRow(
'SELECT foldercontents_pk FROM foldercontents WHERE child_id=$1',
184 array($folderB),__METHOD__.
'.needs.the.foldercontent_pk');
185 $this->folderDao->copyContent($fc[
'foldercontents_pk'], FolderDao::TOP_LEVEL);
186 assertThat($this->folderDao->getFolderChildFolders($folderA),is(arrayWithSize(1)));
187 assertThat($this->folderDao->getFolderChildFolders(FolderDao::TOP_LEVEL),is(arrayWithSize(3)));
190 public function testGetRemovableContents()
192 $this->folderDao->ensureTopLevelFolder();
193 $folderA = $this->folderDao->insertFolder($folderName=
'A',
'/A', FolderDao::TOP_LEVEL);
194 $this->folderDao->insertFolder(
'B',
'/A/B', $folderA);
195 $folderC = $this->folderDao->insertFolder(
'C',
'/C', FolderDao::TOP_LEVEL);
196 assertThat($this->folderDao->getRemovableContents($folderA),arrayWithSize(0));
197 $this->
dbManager->insertTableRow(
'foldercontents',array(
'foldercontents_mode'=> FolderDao::MODE_UPLOAD,
'parent_fk'=>$folderA,
'child_id'=>$folderC));
198 assertThat($this->folderDao->getRemovableContents($folderA),arrayWithSize(0));
199 $this->
dbManager->insertTableRow(
'foldercontents',array(
'foldercontents_mode'=> FolderDao::MODE_FOLDER,
'parent_fk'=>$folderA,
'child_id'=>$folderC));
200 assertThat($this->folderDao->getRemovableContents($folderA),arrayWithSize(1));
203 public function testGetFolder()
205 $this->folderDao->ensureTopLevelFolder();
206 $goodFolder = $this->folderDao->getFolder(FolderDao::TOP_LEVEL);
207 assertThat($goodFolder, is(anInstanceOf(\
Fossology\Lib\Data\
Folder\Folder::class)));
208 assertThat($goodFolder->getId(), equalTo(FolderDao::TOP_LEVEL));
209 $badFolder = $this->folderDao->getFolder(987);
210 assertThat($badFolder, is(nullValue()));
testMoveContentShouldFailIfCyclesAreProduced()
Namespace used by reuser agent.
fo_dbManager * dbManager
fo_dbManager object