9 namespace Fossology\Lib\Dao;
19 if (!function_exists(
'Traceback_uri')) {
22 return 'Traceback_uri_if_desired';
33 protected function setUp() :
void
36 $this->
dbManager = $this->testDb->getDbManager();
39 protected function tearDown() :
void
47 public function testGetCopyrightHighlights()
49 $this->testDb->createPlainTables(array(),
true);
50 $this->testDb->createInheritedTables();
51 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
52 $uploadDao->shouldReceive(
'getUploadEntry')->with(1)->andReturn(array(
'pfile_fk'=>8));
53 $uploadDao->shouldReceive(
'getUploadEntry')->with(2)->andReturn(array(
'pfile_fk'=>9));
55 $noHighlights = $copyrightDao->getHighlights($uploadTreeId=1);
56 assertThat($noHighlights,emptyArray());
58 $this->testDb->insertData(array(
'copyright'));
59 $highlights = $copyrightDao->getHighlights($uploadTreeId = 1);
60 assertThat($highlights,arrayWithSize(1));
61 $highlight0 = $highlights[0];
62 assertThat($highlight0,anInstanceOf(Highlight::class));
63 $this->assertInstanceOf(
'Fossology\Lib\Data\Highlight', $highlight0);
64 assertThat($highlight0->getEnd(),equalTo(201));
66 $hilights = $copyrightDao->getHighlights($uploadTreeId=2);
67 assertThat($hilights,arrayWithSize(1));
68 $hilight0 = $hilights[0];
69 assertThat($hilight0->getStart(),equalTo(0));
72 private function runCopyright()
74 $sysConf = $this->testDb->getFossSysConf().time();
76 copy($this->testDb->getFossSysConf().
"/Db.conf",
"$sysConf/Db.conf");
77 system(
"touch ".$sysConf.
"/fossology.conf");
78 $copyDir = dirname(dirname(dirname(dirname(__DIR__)))).
"/copyright/";
79 system(
"install -D $copyDir/VERSION-copyright $sysConf/mods-enabled/copyright/VERSION");
82 system(
"echo | ".$copyDir.
"agent/copyright -c ".$sysConf.
" 2>/dev/null", $retCode);
83 $this->assertEquals(0, $retCode,
'this test requires a working copyright agent which creates the necessary tables');
85 unlink(
"$sysConf/mods-enabled/copyright/VERSION");
86 rmdir(
"$sysConf/mods-enabled/copyright");
87 rmdir(
"$sysConf/mods-enabled");
88 unlink($sysConf.
"/fossology.conf");
89 unlink($sysConf.
"/Db.conf");
93 private function setUpClearingTables()
95 $this->testDb->createPlainTables(array(
'copyright',
'uploadtree',
'copyright_decision',
'copyright_event'));
96 $this->testDb->createInheritedTables(array(
'uploadtree_a'));
97 $this->testDb->insertData(array(
'copyright',
'uploadtree_a'));
99 $this->testDb->createSequences(array(
'copyright_pk_seq',
'copyright_decision_pk_seq'));
100 $this->testDb->alterTables(array(
'copyright',
'copyright_decision'));
103 private function searchContent($array, $content, $key=
'content')
105 foreach ($array as $entry) {
106 if (array_key_exists($key, $entry)) {
107 if ($entry[$key] === $content) {
115 public function testGetAllEntries()
117 $this->setUpClearingTables();
119 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
122 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a");
123 $this->assertEquals(14, count($entries));
124 $this->assertTrue($this->searchContent($entries,
"info@3dfx.com"));
127 public function testGetAllEntriesReport()
129 $this->setUpClearingTables();
131 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
134 $entries = $copyrightDao->getAllEntriesReport(
"copyright", 1,
"uploadtree_a");
135 $this->assertEquals(15, count($entries));
136 $this->assertTrue($this->searchContent($entries,
"copyright 3dfx interactive, inc. 1999, all rights reserved this \n"));
139 public function testGetAllEntriesOnlyStatementsAndIndentifyedIfCleared()
141 $this->setUpClearingTables();
143 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
146 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
false, DecisionTypes::IDENTIFIED);
147 $this->assertEquals(13, count($entries));
148 $this->assertFalse($this->searchContent($entries,
"info@3dfx.com"));
151 public function testGetAllEntriesOnlyStatementsWithFilterAndIndentifyedIfCleared()
153 $this->setUpClearingTables();
155 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
158 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
false, DecisionTypes::IDENTIFIED,
"C.content LIKE '%permission of 3dfx interactiv%'");
159 $this->assertEquals(1, count($entries));
160 $this->assertTrue($this->searchContent($entries,
"written permission of 3dfx interactive, \ninc. see the 3dfx glide general public license for a full text of the \n"));
163 public function testGetAllEntriesOnlyStatementsAndOnlyClearedIndentifyed()
165 $this->setUpClearingTables();
167 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
170 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED);
171 $this->assertEquals(0, count($entries));
174 public function testGetAllEntriesForReport_afterADecision()
176 $this->setUpClearingTables();
178 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
181 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
182 $entries = $copyrightDao->getAllEntriesReport(
"copyright", 1,
"uploadtree_a",
"statement",
false, DecisionTypes::IDENTIFIED);
183 $this->assertTrue($this->searchContent($entries,
"desc",
'description'));
184 $this->assertTrue($this->searchContent($entries,
"text",
'textfinding'));
185 $this->assertTrue($this->searchContent($entries,
"comment",
'comments'));
188 public function testGetAllEntriesOnlyStatementsAndOnlyClearedIndentifyed_afterADecision()
190 $this->setUpClearingTables();
192 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
195 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
196 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED);
197 $this->assertEquals(3, count($entries));
201 "description"=>
"desc",
202 "textfinding" =>
"text",
203 "comments" =>
"comment",
204 "uploadtree_pk" =>
"7",
205 "clearing_decision_type_fk" =>
"5",
206 "content" =>
"copyright 3dfx interactive, inc. 1999, all rights reserved this \n"),
208 "description"=>
"desc",
209 "textfinding" =>
"text",
210 "comments" =>
"comment",
211 "uploadtree_pk" =>
"7",
212 "clearing_decision_type_fk" =>
"5",
213 "content" =>
"copyright laws of \nthe united states. \n\ncopyright 3dfx interactive, inc. 1999, all rights reserved\" \n"),
215 "description" =>
"desc",
216 "textfinding" =>
"text",
217 "comments" =>
"comment",
218 "uploadtree_pk" =>
"7",
219 "clearing_decision_type_fk"=>
"5",
220 "content" =>
"written permission of 3dfx interactive, \ninc. see the 3dfx glide general public license for a full text of the \n"
223 $this->assertEquals($expected, $entries);
226 public function testGetAllEntriesOnlyStatementsWithFilterAndOnlyClearedIndentifyed_afterIdentifiedDecision()
228 $this->setUpClearingTables();
230 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
233 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
234 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED,
"C.content LIKE 'written%'");
235 $this->assertEquals(1, count($entries));
236 $this->assertTrue($this->searchContent($entries,
"written permission of 3dfx interactive, \ninc. see the 3dfx glide general public license for a full text of the \n"));
239 public function testGetAllEntriesOnlyStatementsOnlyClearedIndentifyed_irrelevantDecisionIsIrrelevant()
241 $this->setUpClearingTables();
243 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
246 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IRRELEVANT,
"desc1",
"text1",
"comment1");
247 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED);
248 $this->assertEquals(0, count($entries));
251 public function testGetAllEntriesOnlyStatementsWithFilterAndOnlyClearedIndentifyed_afterTwoDecisions()
253 $this->setUpClearingTables();
255 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
258 $decisionId = $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
259 $copyrightDao->removeDecision(
"copyright_decision", 4, $decisionId);
260 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IRRELEVANT,
"desc1",
"text1",
"comment1");
261 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED,
"C.content LIKE 'written%'");
262 $this->assertEquals(0, count($entries));
265 public function testGetAllEntriesOnlyStatementsWithFilterAndOnlyClearedIndentifyed_afterTwoDecisionsWinsSecond()
267 $this->setUpClearingTables();
269 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
272 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
273 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IRRELEVANT,
"desc1",
"text1",
"comment1");
274 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc2",
"text",
"comment");
275 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED,
"C.content LIKE 'written%'");
276 $this->assertEquals(1, count($entries));
277 $this->assertTrue($this->searchContent($entries,
"written permission of 3dfx interactive, \ninc. see the 3dfx glide general public license for a full text of the \n"));
278 $this->assertEquals(
"desc2", $entries[0][
'description']);
281 public function testUpdateTable()
283 $this->setUpClearingTables();
285 $container = M::mock(
'ContainerBuilder');
286 $agentDao = M::mock(
'Fossology\Lib\Dao\AgentDao');
287 $agentDao->shouldReceive(
'arsTableExists')->withArgs([
'copyright'])
289 $agentDao->shouldReceive(
'arsTableExists')->withArgs([
'reso'])
291 $agentDao->shouldReceive(
'getSuccessfulAgentEntries')
292 ->withArgs([
'copyright', 1])->andReturn([[
'agent_id' =>
'8',
293 'agent_rev' =>
'trunk.271e3e',
'agent_name' =>
'copyright']]);
294 $agentDao->shouldReceive(
'getSuccessfulAgentEntries')
295 ->withArgs([
'reso', 1])->andReturn([[
'agent_id' =>
'8',
296 'agent_rev' =>
'trunk.271e3e',
'agent_name' =>
'reso']]);
297 $agentDao->shouldReceive(
'getCurrentAgentRef')->withArgs([
'copyright'])
298 ->andReturn(
new AgentRef(8,
'copyright',
'trunk.271e3e'));
299 $agentDao->shouldReceive(
'getCurrentAgentRef')->withArgs([
'reso'])
300 ->andReturn(
new AgentRef(8,
'reso',
'trunk.271e3e'));
302 $container->shouldReceive(
'get')->withArgs([
'dao.agent'])
303 ->andReturn($agentDao);
304 $GLOBALS[
'container'] = $container;
307 $hash2 =
'0x3a910990f114f12f';
311 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
313 $copyrightDao->updateTable($item, $hash2, $content,
'55',
'copyright',
'update',
'1');
315 $updatedCp = $this->
dbManager->getSingleRow(
'SELECT * FROM copyright_event WHERE copyright_fk=$1',array($ctPk),__METHOD__.
'.cp');
316 assertThat($updatedCp[
'content'],is(equalTo($content)));
319 public function testDeleteCopyright()
321 $this->setUpClearingTables();
323 $container = M::mock(
'ContainerBuilder');
324 $agentDao = M::mock(
'Fossology\Lib\Dao\AgentDao');
325 $agentDao->shouldReceive(
'arsTableExists')->withArgs([
'copyright'])
327 $agentDao->shouldReceive(
'arsTableExists')->withArgs([
'reso'])
329 $agentDao->shouldReceive(
'getSuccessfulAgentEntries')
330 ->withArgs([
'copyright', 1])->andReturn([[
'agent_id' =>
'8',
331 'agent_rev' =>
'trunk.271e3e',
'agent_name' =>
'copyright']]);
332 $agentDao->shouldReceive(
'getSuccessfulAgentEntries')
333 ->withArgs([
'reso', 1])->andReturn([[
'agent_id' =>
'8',
334 'agent_rev' =>
'trunk.271e3e',
'agent_name' =>
'reso']]);
335 $agentDao->shouldReceive(
'getCurrentAgentRef')->withArgs([
'copyright'])
336 ->andReturn(
new AgentRef(8,
'copyright',
'trunk.271e3e'));
337 $agentDao->shouldReceive(
'getCurrentAgentRef')->withArgs([
'reso'])
338 ->andReturn(
new AgentRef(8,
'reso',
'trunk.271e3e'));
340 $container->shouldReceive(
'get')->withArgs([
'dao.agent'])
341 ->andReturn($agentDao);
342 $GLOBALS[
'container'] = $container;
344 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
346 $initialEntries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a");
347 $initialCount = count($initialEntries);
350 $copyrightDao->updateTable($item,
'0x3a910990f114f12f',
'',
'55',
'copyright',
'delete',
'1');
351 $updatedCp = $this->
dbManager->getSingleRow(
'SELECT * FROM copyright_event WHERE copyright_fk=$1',array(2),__METHOD__.
'.cpDel');
352 $deletedIdCheck = array_search($updatedCp[
'uploadtree_fk'], array_column($initialEntries,
'uploadtree_pk'));
353 unset($initialEntries[$deletedIdCheck]);
354 $remainingCount = count($initialEntries);
355 assertThat($remainingCount,is(equalTo($initialCount-1)));
Traceback_uri()
Get the URI without query to this location.
fo_dbManager * dbManager
fo_dbManager object