29 if (!function_exists(
'Traceback_uri')) {
32 return 'Traceback_uri_if_desired';
43 protected function setUp()
46 $this->
dbManager = $this->testDb->getDbManager();
49 protected function tearDown()
57 public function testGetCopyrightHighlights()
59 $this->testDb->createPlainTables(array(),
true);
60 $this->testDb->createInheritedTables();
61 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
62 $uploadDao->shouldReceive(
'getUploadEntry')->with(1)->andReturn(array(
'pfile_fk'=>8));
63 $uploadDao->shouldReceive(
'getUploadEntry')->with(2)->andReturn(array(
'pfile_fk'=>9));
65 $noHighlights = $copyrightDao->getHighlights($uploadTreeId=1);
66 assertThat($noHighlights,emptyArray());
68 $this->testDb->insertData(array(
'copyright'));
69 $highlights = $copyrightDao->getHighlights($uploadTreeId = 1);
70 assertThat($highlights,arrayWithSize(1));
71 $highlight0 = $highlights[0];
72 assertThat($highlight0,anInstanceOf(Highlight::class));
73 $this->assertInstanceOf(
'Fossology\Lib\Data\Highlight', $highlight0);
74 assertThat($highlight0->getEnd(),equalTo(201));
76 $hilights = $copyrightDao->getHighlights($uploadTreeId=2);
77 assertThat($hilights,arrayWithSize(1));
78 $hilight0 = $hilights[0];
79 assertThat($hilight0->getStart(),equalTo(0));
82 private function runCopyright()
84 $sysConf = $this->testDb->getFossSysConf().time();
86 copy($this->testDb->getFossSysConf().
"/Db.conf",
"$sysConf/Db.conf");
87 system(
"touch ".$sysConf.
"/fossology.conf");
88 $copyDir = dirname(dirname(dirname(dirname(__DIR__)))).
"/copyright/";
89 system(
"install -D $copyDir/VERSION-copyright $sysConf/mods-enabled/copyright/VERSION");
92 system(
"echo | ".$copyDir.
"agent/copyright -c ".$sysConf.
" 2>/dev/null", $retCode);
93 $this->assertEquals(0, $retCode,
'this test requires a working copyright agent which creates the necessary tables');
95 unlink(
"$sysConf/mods-enabled/copyright/VERSION");
96 rmdir(
"$sysConf/mods-enabled/copyright");
97 rmdir(
"$sysConf/mods-enabled");
98 unlink($sysConf.
"/fossology.conf");
99 unlink($sysConf.
"/Db.conf");
103 private function setUpClearingTables()
105 $this->testDb->createPlainTables(array(
'copyright',
'uploadtree',
'copyright_decision'));
106 $this->testDb->createInheritedTables(array(
'uploadtree_a'));
107 $this->testDb->insertData(array(
'copyright',
'uploadtree_a'));
109 $this->testDb->createSequences(array(
'copyright_pk_seq',
'copyright_decision_pk_seq'));
110 $this->testDb->alterTables(array(
'copyright',
'copyright_decision'));
113 private function searchContent($array, $content, $key=
'content')
115 foreach ($array as $entry) {
116 if (array_key_exists($key, $entry)) {
117 if ($entry[$key] === $content) {
125 public function testGetAllEntries()
127 $this->setUpClearingTables();
129 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
132 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a");
133 $this->assertEquals(14, count($entries));
134 $this->assertTrue($this->searchContent($entries,
"info@3dfx.com"));
137 public function testGetAllEntriesReport()
139 $this->setUpClearingTables();
141 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
144 $entries = $copyrightDao->getAllEntriesReport(
"copyright", 1,
"uploadtree_a");
145 $this->assertEquals(15, count($entries));
146 $this->assertTrue($this->searchContent($entries,
"copyright 3dfx interactive, inc. 1999, all rights reserved this \n"));
149 public function testGetAllEntriesOnlyStatementsAndIndentifyedIfCleared()
151 $this->setUpClearingTables();
153 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
156 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
false, DecisionTypes::IDENTIFIED);
157 $this->assertEquals(13, count($entries));
158 $this->assertFalse($this->searchContent($entries,
"info@3dfx.com"));
161 public function testGetAllEntriesOnlyStatementsWithFilterAndIndentifyedIfCleared()
163 $this->setUpClearingTables();
165 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
168 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
false, DecisionTypes::IDENTIFIED,
"content LIKE '%permission of 3dfx interactiv%'");
169 $this->assertEquals(1, count($entries));
170 $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"));
173 public function testGetAllEntriesOnlyStatementsAndOnlyClearedIndentifyed()
175 $this->setUpClearingTables();
177 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
180 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED);
181 $this->assertEquals(0, count($entries));
184 public function testGetAllEntriesForReport_afterADecision()
186 $this->setUpClearingTables();
188 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
191 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
192 $entries = $copyrightDao->getAllEntriesReport(
"copyright", 1,
"uploadtree_a",
"statement",
false, DecisionTypes::IDENTIFIED);
193 $this->assertTrue($this->searchContent($entries,
"desc",
'description'));
194 $this->assertTrue($this->searchContent($entries,
"text",
'textfinding'));
195 $this->assertTrue($this->searchContent($entries,
"comment",
'comments'));
198 public function testGetAllEntriesOnlyStatementsAndOnlyClearedIndentifyed_afterADecision()
200 $this->setUpClearingTables();
202 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
205 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
206 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED);
207 $this->assertEquals(3, count($entries));
211 "description"=>
"desc",
212 "textfinding" =>
"text",
213 "comments" =>
"comment",
214 "uploadtree_pk" =>
"7",
215 "clearing_decision_type_fk" =>
"5",
216 "content" =>
"copyright 3dfx interactive, inc. 1999, all rights reserved this \n"),
218 "description"=>
"desc",
219 "textfinding" =>
"text",
220 "comments" =>
"comment",
221 "uploadtree_pk" =>
"7",
222 "clearing_decision_type_fk" =>
"5",
223 "content" =>
"copyright laws of \nthe united states. \n\ncopyright 3dfx interactive, inc. 1999, all rights reserved\" \n"),
225 "description" =>
"desc",
226 "textfinding" =>
"text",
227 "comments" =>
"comment",
228 "uploadtree_pk" =>
"7",
229 "clearing_decision_type_fk"=>
"5",
230 "content" =>
"written permission of 3dfx interactive, \ninc. see the 3dfx glide general public license for a full text of the \n" 233 $this->assertEquals($expected, $entries);
236 public function testGetAllEntriesOnlyStatementsWithFilterAndOnlyClearedIndentifyed_afterIdentifiedDecision()
238 $this->setUpClearingTables();
240 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
243 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
244 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED,
"content LIKE 'written%'");
245 $this->assertEquals(1, count($entries));
246 $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"));
249 public function testGetAllEntriesOnlyStatementsOnlyClearedIndentifyed_irrelevantDecisionIsIrrelevant()
251 $this->setUpClearingTables();
253 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
256 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IRRELEVANT,
"desc1",
"text1",
"comment1");
257 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED);
258 $this->assertEquals(0, count($entries));
261 public function testGetAllEntriesOnlyStatementsWithFilterAndOnlyClearedIndentifyed_afterTwoDecisions()
263 $this->setUpClearingTables();
265 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
268 $decisionId = $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
269 $copyrightDao->removeDecision(
"copyright_decision", 4, $decisionId);
270 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IRRELEVANT,
"desc1",
"text1",
"comment1");
271 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED,
"content LIKE 'written%'");
272 $this->assertEquals(0, count($entries));
275 public function testGetAllEntriesOnlyStatementsWithFilterAndOnlyClearedIndentifyed_afterTwoDecisionsWinsSecond()
277 $this->setUpClearingTables();
279 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
282 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc",
"text",
"comment");
283 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IRRELEVANT,
"desc1",
"text1",
"comment1");
284 $copyrightDao->saveDecision(
"copyright_decision", 4, 2, DecisionTypes::IDENTIFIED,
"desc2",
"text",
"comment");
285 $entries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a",
"statement",
true, DecisionTypes::IDENTIFIED,
"content LIKE 'written%'");
286 $this->assertEquals(1, count($entries));
287 $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"));
288 $this->assertEquals(
"desc2", $entries[0][
'description']);
291 public function testUpdateTable()
293 $this->setUpClearingTables();
296 $hash2 =
'0x3a910990f114f12f';
299 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
301 $copyrightDao->updateTable($item, $hash2, $content=
'foo', $userId=55);
303 $updatedCp = $this->
dbManager->getSingleRow(
'SELECT * FROM copyright WHERE copyright_pk=$1',array($ctPk),__METHOD__.
'.cp');
304 assertThat($updatedCp[
'content'],is(equalTo($content)));
307 public function testDeleteCopyright()
309 $this->setUpClearingTables();
311 $uploadDao = M::mock(
'Fossology\Lib\Dao\UploadDao');
313 $initialEntries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a");
314 $initialCount = count($initialEntries);
317 $hash2 =
'0x3a910990f114f12f';
318 $copyrightDao->updateTable($item, $hash2, $content=
'', 55,
'copyright',
'delete');
320 $remainingEntries = $copyrightDao->getAllEntries(
"copyright", 1,
"uploadtree_a");
321 $remainingCount = count($remainingEntries);
322 assertThat($remainingCount,is(equalTo($initialCount-1)));
Traceback_uri()
Get the URI without query to this location.
fo_dbManager * dbManager
fo_dbManager object