FOSSology  4.4.0
Open Source License Compliance by Open Source Software
LicenseCsvImportTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
10 use Exception;
16 use Mockery as M;
17 
22 class LicenseCsvImportTest extends \PHPUnit\Framework\TestCase
23 {
28  protected function setUp() : void
29  {
30  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
31  }
32 
37  protected function tearDown() : void
38  {
39  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
40  M::close();
41  }
42 
52  public function testGetKeyFromShortname()
53  {
54  $testDb = new TestLiteDb();
55  $testDb->createPlainTables(array('license_ref'));
56  $shortname = 'licA';
57  $knownId = 101;
58  $knownGroup = 4;
59  /*** @var DbManager ***/
60  $dbManager = &$testDb->getDbManager();
61  $dbManager->insertTableRow('license_ref', array('rf_pk'=>$knownId,'rf_shortname'=>$shortname));
62  $this->createCandidateTable($dbManager);
63  $dbManager->insertTableRow('license_candidate', array(
64  'rf_pk' => $knownId + 2,
65  'rf_shortname' => "candidate-$shortname",
66  'group_fk' => $knownGroup
67  ));
68  $userDao = M::mock(UserDao::class);
69  $userDao->shouldReceive('getGroupIdByName')
70  ->with("fossy")
71  ->once()
72  ->andReturn(4);
73  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
74 
75  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,'getKeyFromShortname', array($shortname)), equalTo($knownId));
76  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,'getKeyFromShortname', array("no $shortname")), equalTo(false));
77  // Candidates
78  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
79  'getKeyFromShortname',
80  array("candidate-$shortname", "fossy")),
81  equalTo($knownId + 2));
82  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
83  'getKeyFromShortname',
84  array("candidate-$shortname")),
85  equalTo(false));
86  }
87 
97  public function testGetKeyFromMd5()
98  {
99  $licenseText = 'I am a strong license';
100  $knownId = 101;
101  $falseLicenseText = "I am a weak license";
102 
103  $dbManager = M::mock(DbManager::class);
104  $dbManager->shouldReceive('getSingleRow')
105  ->with('SELECT rf_pk FROM ONLY license_ref WHERE rf_md5=md5($1)',
106  array($licenseText))
107  ->once()
108  ->andReturn(array('rf_pk' => $knownId));
109  $dbManager->shouldReceive('getSingleRow')
110  ->with('SELECT rf_pk FROM ONLY license_ref WHERE rf_md5=md5($1)',
111  array($falseLicenseText))
112  ->andReturnNull();
113  $userDao = M::mock(UserDao::class);
114  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
115 
116  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
117  'getKeyFromMd5', array($licenseText)), equalTo($knownId));
118  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
119  'getKeyFromMd5', array($falseLicenseText)), equalTo(false));
120  }
121 
129  public function testHandleCsvLicense()
130  {
131  $dbManager = M::mock(DbManager::class);
132  $nkMap = array(
133  'licA' => 101,
134  'licB' => false,
135  'licC' => false,
136  'licE' => false,
137  'licF' => false,
138  'licG' => false,
139  'licH' => false,
140  'licZ' => 100,
141  'canLicAfossy' => 200,
142  'canLicBfossy' => false
143  );
144  $mdkMap = array(
145  md5('txA') => 101,
146  md5('txB') => false,
147  md5('txC') => false,
148  md5('txD') => 102,
149  md5('txE') => false,
150  md5('txF') => false,
151  md5('txG') => false,
152  md5('txH') => false,
153  md5('txZ') => 100,
154  md5('txCan') => 200,
155  md5('Text of candidate license') => false
156  );
157  $userDao = M::mock(UserDao::class);
158  $userDao->shouldReceive('getGroupIdByName')
159  ->with("fossy")
160  ->times(3)
161  ->andReturn(4);
162 
163  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
164  Reflectory::setObjectsProperty($licenseCsvImport, 'nkMap', $nkMap);
165  Reflectory::setObjectsProperty($licenseCsvImport, 'mdkMap', $mdkMap);
166 
167  $singleRowA = array(
168  'rf_shortname' => 'licA',
169  'rf_spdx_id' => 'lrf-licA',
170  'rf_fullname' => 'licennnseA',
171  'rf_text' => 'someRandom',
172  'rf_md5' => md5('someRandom'),
173  'rf_detector_type' => 1,
174  'rf_url' => '',
175  'rf_notes' => '',
176  'rf_source' => '',
177  'rf_risk' => 4
178  );
179  $dbManager->shouldReceive('getSingleRow')
180  ->with(
181  'SELECT rf_shortname, rf_fullname, rf_spdx_id, rf_text, rf_url, rf_notes, rf_source, rf_risk ' .
182  'FROM license_ref WHERE rf_pk = $1', array(101), anything())
183  ->once()
184  ->andReturn($singleRowA);
185 
186  // Test for licB insert
187  $dbManager->shouldReceive('insertTableRow')
188  ->withArgs(array(
189  'license_map', array(
190  'rf_fk' => 103, 'rf_parent' => 101, 'usage' => LicenseMap::CONCLUSION
191  )))
192  ->once();
193  $singleRowB = $singleRowA;
194  $singleRowB["rf_shortname"] = "licB";
195  $singleRowB["rf_fullname"] = "liceB";
196  $singleRowB["rf_spdx_id"] = "lrf-B";
197  $singleRowB["rf_text"] = "txB";
198  $singleRowB["rf_md5"] = md5("txB");
199  $singleRowB["rf_risk"] = 0;
200  $this->addLicenseInsertToDbManager($dbManager, $singleRowB, 103);
201  $returnB = Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
202  'handleCsvLicense', array(array(
203  'shortname' => 'licB',
204  'spdx_id' => 'lrf-B',
205  'fullname' => 'liceB',
206  'text' => 'txB',
207  'url' => '',
208  'notes' => '',
209  'source' => '',
210  'risk' => 0,
211  'parent_shortname' => 'licA',
212  'report_shortname' => null,
213  'group' => null
214  )));
215  assertThat($returnB, is("Inserted 'licB' in DB with conclusion 'licA'"));
216 
217  // Test for licF insert
218  $singleRowF = $singleRowA;
219  $singleRowF["rf_shortname"] = "licF";
220  $singleRowF["rf_fullname"] = "liceF";
221  $singleRowF["rf_spdx_id"] = null;
222  $singleRowF["rf_text"] = "txF";
223  $singleRowF["rf_md5"] = md5("txF");
224  $singleRowF["rf_risk"] = 1;
225  $this->addLicenseInsertToDbManager($dbManager, $singleRowF, 104);
226  $dbManager->shouldReceive('insertTableRow')
227  ->withArgs(array(
228  'license_map', array(
229  'rf_fk' => 104,
230  'rf_parent' => 100,
231  'usage' => LicenseMap::REPORT
232  )))
233  ->once();
234  $returnF = Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
235  'handleCsvLicense', array(array(
236  'shortname' => 'licF',
237  'fullname' => 'liceF',
238  'spdx_id' => null,
239  'text' => 'txF',
240  'url' => '',
241  'notes' => '',
242  'source' => '',
243  'risk' => 1,
244  'parent_shortname' => null,
245  'report_shortname' => 'licZ',
246  'group' => null
247  )));
248  assertThat($returnF, is("Inserted 'licF' in DB reporting 'licZ'"));
249 
250  // Test licC insert
251  $singleRowC = $singleRowA;
252  $singleRowC["rf_shortname"] = "licC";
253  $singleRowC["rf_fullname"] = "liceC";
254  $singleRowC["rf_spdx_id"] = "lrf-licC";
255  $singleRowC["rf_text"] = "txC";
256  $singleRowC["rf_md5"] = md5("txC");
257  $singleRowC["rf_risk"] = 2;
258  $this->addLicenseInsertToDbManager($dbManager, $singleRowC, 105);
259  $returnC = Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
260  'handleCsvLicense', array(array(
261  'shortname' => 'licC',
262  'fullname' => 'liceC',
263  'spdx_id' => 'lrf-licC',
264  'text' => 'txC',
265  'url' => '',
266  'notes' => '',
267  'source' => '',
268  'risk' => 2,
269  'parent_shortname' => null,
270  'report_shortname' => null,
271  'group' => null
272  )));
273  assertThat($returnC, is("Inserted 'licC' in DB"));
274 
275  // Test canlicC update
276  $canLicA = $singleRowA;
277  $canLicA["rf_shortname"] = "canLicA";
278  $canLicA["rf_fullname"] = "canLiceA";
279  $canLicA["rf_spdx_id"] = null;
280  $canLicA["rf_text"] = "txcan";
281  $canLicA["rf_risk"] = 0;
282  $canLicA["rf_group"] = 4;
283  $dbManager->shouldReceive('getSingleRow')
284  ->with(
285  'SELECT rf_shortname, rf_fullname, rf_spdx_id, rf_text, rf_url, rf_notes, rf_source, rf_risk ' .
286  'FROM license_ref WHERE rf_pk = $1', array(200), anything())
287  ->once()
288  ->andReturn($canLicA);
289  $dbManager->shouldReceive('getSingleRow')
290  ->with(
291  "UPDATE license_candidate SET " .
292  "rf_fullname=$2,rf_spdx_id=$3,rf_text=$4,rf_md5=md5($4) WHERE rf_pk=$1;",
293  array(200, 'canDidateLicenseA', 'lrf-canLicA', 'Text of candidate license'),
294  anything())
295  ->once();
296  $dbManager->shouldReceive('getSingleRow')
297  ->with(
298  'SELECT rf_parent FROM license_map WHERE rf_fk = $1 AND usage = $2;',
299  anyof(array(200, LicenseMap::CONCLUSION), array(200, LicenseMap::REPORT)),
300  anything())
301  ->twice()
302  ->andReturn(array('rf_parent' => null));
303  $returnC = Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
304  'handleCsvLicense', array(array(
305  'shortname' => 'canLicA',
306  'fullname' => 'canDidateLicenseA',
307  'spdx_id' => 'lrf-canLicA',
308  'text' => 'Text of candidate license',
309  'url' => '', 'notes' => '', 'source' => '', 'risk' => 0,
310  'parent_shortname' => null, 'report_shortname' => null,
311  'group' => 'fossy'
312  )));
313  assertThat($returnC, is(
314  "License 'canLicA' already exists in DB (id = 200)" .
315  ", updated fullname, updated SPDX ID, updated text"
316  ));
317 
318  // Test licA update
319  $dbManager->shouldReceive('getSingleRow')
320  ->with(
321  "UPDATE license_ref SET " .
322  "rf_fullname=$2,rf_text=$3,rf_md5=md5($3),rf_risk=$4 WHERE rf_pk=$1;",
323  array(101, 'liceB', 'txA', 2), anything())
324  ->once();
325  $dbManager->shouldReceive('getSingleRow')
326  ->with(
327  'SELECT rf_parent FROM license_map WHERE rf_fk = $1 AND usage = $2;',
328  anyof(array(101, LicenseMap::CONCLUSION), array(101, LicenseMap::REPORT)),
329  anything())
330  ->twice()
331  ->andReturn(array('rf_parent' => null));
332  $returnA = Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
333  'handleCsvLicense', array(array(
334  'shortname' => 'licA',
335  'fullname' => 'liceB',
336  'text' => 'txA',
337  'url' => '',
338  'notes' => '',
339  'source' => '',
340  'risk' => 2,
341  'parent_shortname' => null,
342  'report_shortname' => null,
343  'group' => null
344  )));
345  assertThat($returnA, is(
346  "License 'licA' already exists in DB (id = 101)" .
347  ", updated fullname, updated text, updated the risk level"));
348 
349  // Test licE md5 collision
350  $returnE = Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
351  'handleCsvLicense', array(array(
352  'shortname' => 'licE',
353  'fullname' => 'liceE',
354  'text' => 'txD',
355  'url' => '',
356  'notes' => '',
357  'source' => '',
358  'risk' => false,
359  'parent_shortname' => null,
360  'report_shortname' => null,
361  'group' => null
362  )));
363  assertThat($returnE, is(
364  "Error: MD5 checksum of 'licE' collides with license id=102"));
365 
366  // Test licG md5 collision
367  $returnG = Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
368  'handleCsvLicense', array(array(
369  'shortname' => 'licG',
370  'fullname' => 'liceG',
371  'text' => 'txD',
372  'url' => '',
373  'notes' => '',
374  'source' => '_G_go_G_',
375  'parent_shortname' => null,
376  'report_shortname' => null,
377  'risk' => false,
378  'group' => null
379  )));
380  assertThat($returnG, is(
381  "Error: MD5 checksum of 'licG' collides with license id=102"));
382 
383  // Test canlicB insert
384  $canlicB = $singleRowA;
385  $canlicB["rf_shortname"] = "canLicB";
386  $canlicB["rf_fullname"] = "canLiceB";
387  $canlicB["rf_spdx_id"] = null;
388  $canlicB["rf_text"] = "txCan";
389  $canlicB["rf_md5"] = md5("txCan");
390  $canlicB["rf_risk"] = 2;
391  $canlicB["group_fk"] = 4;
392  $canlicB["marydone"] = 't';
393  $this->addLicenseInsertToDbManager($dbManager, $canlicB, 201,
394  "license_candidate");
395  $dbManager->shouldReceive('booleanToDb')
396  ->with(true)
397  ->once()
398  ->andReturn('t');
399  $returnC = Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
400  'handleCsvLicense', array(array(
401  'shortname' => 'canLicB',
402  'fullname' => 'canLiceB',
403  'spdx_id' => null,
404  'text' => 'txCan',
405  'url' => '',
406  'notes' => '',
407  'source' => '',
408  'risk' => 2,
409  'parent_shortname' => null,
410  'report_shortname' => null,
411  'group' => 'fossy'
412  )));
413  assertThat($returnC, is("Inserted 'canLicB' in DB" .
414  " as candidate license under group fossy"));
415  }
416 
427  public function testHandleHeadCsv()
428  {
429  $dbManager = M::mock(DbManager::class);
430  $userDao = M::mock(UserDao::class);
431  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
432 
433  assertThat(
434  Reflectory::invokeObjectsMethodnameWith($licenseCsvImport, 'handleHeadCsv',
435  array(array(
436  'shortname', 'foo', 'text', 'fullname', 'notes', 'bar', 'spdx_id'
437  ))),
438  is(array(
439  'shortname' => 0, 'fullname' => 3, 'text' => 2, 'spdx_id' => 6,
440  'parent_shortname' => false, 'report_shortname' => false,
441  'url' => false, 'notes' => 4, 'source' => false, 'risk' => 0,
442  'group' => false
443  )));
444 
445  assertThat(
446  Reflectory::invokeObjectsMethodnameWith($licenseCsvImport, 'handleHeadCsv',
447  array(array(
448  'Short Name', 'URL', 'text', 'fullname', 'notes', 'Foreign ID', 'SPDX ID',
449  'License group'
450  ))),
451  is(array(
452  'shortname' => 0, 'fullname' => 3, 'spdx_id' => 6, 'text' => 2,
453  'parent_shortname' => false, 'report_shortname' => false, 'url' => 1,
454  'notes' => 4, 'source' => 5, 'risk' => false, 'group' => 7
455  )));
456  }
457 
466  {
467  $this->expectException(Exception::class);
468  $dbManager = M::mock(DbManager::class);
469  $userDao = M::mock(UserDao::class);
470  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
471  Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,'handleHeadCsv',array(array('shortname','foo','text')));
472  }
473 
483  public function testSetDelimiter()
484  {
485  $dbManager = M::mock(DbManager::class);
486  $userDao = M::mock(UserDao::class);
487  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
488 
489  $licenseCsvImport->setDelimiter('|');
490  assertThat(Reflectory::getObjectsProperty($licenseCsvImport,'delimiter'),is('|'));
491 
492  $licenseCsvImport->setDelimiter('<>');
493  assertThat(Reflectory::getObjectsProperty($licenseCsvImport,'delimiter'),is('<'));
494  }
495 
505  public function testSetEnclosure()
506  {
507  $dbManager = M::mock(DbManager::class);
508  $userDao = M::mock(UserDao::class);
509  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
510 
511  $licenseCsvImport->setEnclosure('|');
512  assertThat(Reflectory::getObjectsProperty($licenseCsvImport,'enclosure') ,is('|'));
513 
514  $licenseCsvImport->setEnclosure('<>');
515  assertThat(Reflectory::getObjectsProperty($licenseCsvImport,'enclosure'),is('<'));
516  }
517 
525  public function testHandleCsv()
526  {
527  $dbManager = M::mock(DbManager::class);
528  $userDao = M::mock(UserDao::class);
529  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
530 
531  Reflectory::invokeObjectsMethodnameWith($licenseCsvImport, 'handleCsv',
532  array(array('shortname', 'foo', 'text', 'fullname', 'notes', 'spdx_id')));
533  assertThat(Reflectory::getObjectsProperty($licenseCsvImport, 'headrow'),
534  is(notNullValue()));
535 
536  $dbManager->shouldReceive('getSingleRow')
537  ->with(
538  'SELECT rf_shortname,rf_source,rf_pk,rf_risk FROM license_ref WHERE rf_md5=md5($1)',
539  anything())
540  ->andReturn(false);
541  $licenseRow = array(
542  "rf_shortname" => "licA",
543  "rf_fullname" => "liceA",
544  "rf_spdx_id" => null,
545  "rf_text" => "txA",
546  "rf_md5" => md5("txA"),
547  "rf_detector_type" => 1,
548  "rf_url" => '',
549  "rf_notes" => 'noteA',
550  "rf_source" => '',
551  "rf_risk" => 0
552  );
553  $this->addLicenseInsertToDbManager($dbManager, $licenseRow, 101);
554  Reflectory::setObjectsProperty($licenseCsvImport, 'nkMap', array(
555  'licA' => false
556  ));
557  Reflectory::setObjectsProperty($licenseCsvImport, 'mdkMap', array(
558  md5('txA') => false
559  ));
560  Reflectory::invokeObjectsMethodnameWith($licenseCsvImport, 'handleCsv',
561  array(array('licA', 'bar', 'txA', 'liceA', 'noteA')));
562  assertThat(Reflectory::getObjectsProperty($licenseCsvImport, 'nkMap'),
563  is(array('licA' => 101)));
564  assertThat(Reflectory::getObjectsProperty($licenseCsvImport, 'mdkMap'),
565  is(array(md5('txA') => 101)));
566  }
567 
575  {
576  $dbManager = M::mock(DbManager::class);
577  $userDao = M::mock(UserDao::class);
578  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
579  $msg = $licenseCsvImport->handleFile('/tmp/thisFileNameShouldNotExists');
580  assertThat($msg, is(equalTo(_('Internal error'))));
581  }
582 
590  {
591  $dbManager = M::mock(DbManager::class);
592  $userDao = M::mock(UserDao::class);
593  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
594  $msg = $licenseCsvImport->handleFile(__FILE__);
595  assertThat($msg, startsWith( _('Error while parsing file')));
596  }
597 
605  public function testHandleFile()
606  {
607  $dbManager = M::mock(DbManager::class);
608  $userDao = M::mock(UserDao::class);
609  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
610  $filename = tempnam("/tmp", "FOO");
611  $handle = fopen($filename, 'w');
612  fwrite($handle, "shortname,fullname,text,spdx_id");
613  fclose($handle);
614  $msg = $licenseCsvImport->handleFile($filename);
615  assertThat($msg, startsWith( _('head okay')));
616  unlink($filename);
617  }
618 
626  public function testSetMapTrue()
627  {
628  $testDb = new TestLiteDb();
629  $testDb->createPlainTables(array('license_ref', 'license_map'));
630  $licenseId = 101;
631  $parentId = 102;
632  $reportId = 103;
634  $dbManager = &$testDb->getDbManager();
635  $dbManager->insertTableRow('license_ref', array(
636  'rf_pk' => $licenseId,
637  'rf_shortname' => "Main License"
638  ));
639  $dbManager->insertTableRow('license_ref', array(
640  'rf_pk' => $parentId,
641  'rf_shortname' => "Parent License"
642  ));
643  $dbManager->insertTableRow('license_ref', array(
644  'rf_pk' => $reportId,
645  'rf_shortname' => "Reported License"
646  ));
647  $userDao = M::mock(UserDao::class);
648  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
649 
650  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
651  'setMap', array($parentId, $licenseId, LicenseMap::CONCLUSION)),
652  equalTo(true));
653  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
654  'setMap', array($reportId, $licenseId, LicenseMap::REPORT)),
655  equalTo(true));
656 
657  $sql = "SELECT rf_parent FROM license_map WHERE rf_fk = $1 AND usage = $2;";
658  $statement = __METHOD__ . ".getMap";
659  $row = $dbManager->getSingleRow($sql, array($licenseId,
660  LicenseMap::CONCLUSION), $statement);
661 
662  assertThat($row['rf_parent'], equalTo($parentId));
663  $row = $dbManager->getSingleRow($sql, array($licenseId,
664  LicenseMap::REPORT), $statement);
665  assertThat($row['rf_parent'], equalTo($reportId));
666  }
667 
676  public function testSetMapFalse()
677  {
678  $testDb = new TestLiteDb();
679  $testDb->createPlainTables(array('license_ref', 'license_map'));
680  $licenseId = 101;
681  $parentId = false;
682  $reportId = false;
684  $dbManager = &$testDb->getDbManager();
685  $dbManager->insertTableRow('license_ref', array(
686  'rf_pk' => $licenseId,
687  'rf_shortname' => "Main License"
688  ));
689  $userDao = M::mock(UserDao::class);
690  $licenseCsvImport = new LicenseCsvImport($dbManager, $userDao);
691 
692  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
693  'setMap', array($parentId, $licenseId, LicenseMap::CONCLUSION)),
694  equalTo(false));
695  assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport,
696  'setMap', array($reportId, $licenseId, LicenseMap::REPORT)),
697  equalTo(false));
698 
699  $sql = "SELECT rf_parent FROM license_map WHERE rf_fk = $1 AND usage = $2;";
700  $statement = __METHOD__ . ".getMap";
701  $row = $dbManager->getSingleRow($sql, array($licenseId,
702  LicenseMap::CONCLUSION), $statement);
703 
704  assertThat($row, equalTo(false));
705  $row = $dbManager->getSingleRow($sql, array($licenseId,
706  LicenseMap::REPORT), $statement);
707  assertThat($row, equalTo(false));
708  }
709 
714  private function createCandidateTable($dbManager)
715  {
716  $sql = "CREATE TABLE license_candidate (" .
717  "rf_pk, rf_shortname, rf_fullname, rf_text, rf_md5, rf_url, rf_notes, " .
718  "marydone, rf_source, rf_risk, rf_detector_type, group_fk)";
719  $dbManager->queryOnce($sql);
720  }
721 
729  private function addLicenseInsertToDbManager(&$dbManager, $row, $return,
730  $table = "license_ref")
731  {
732  $dbManager->shouldReceive('insertTableRow')
733  ->with($table, $row, anything(), 'rf_pk')
734  ->once()
735  ->andReturn($return);
736  }
737 }
testHandleFile()
Test for LicenseCsvImport::handleFile() (csv file with header)
testHandleFileIfFileIsNotParsable()
Test for LicenseCsvImport::handleFile() (non-csv file)
testGetKeyFromMd5()
Test for LicenseCsvImport::getKeyFromMd5()
testGetKeyFromShortname()
Test for LicenseCsvImport::getKeyFromShortname()
testSetDelimiter()
Test for LicenseCsvImport::setDelimiter()
testHandleHeadCsv_missingMandidatoryKey()
Test for LicenseCsvImport::handleHeadCsv()
testHandleHeadCsv()
Test for LicenseCsvImport::handleHeadCsv()
addLicenseInsertToDbManager(&$dbManager, $row, $return, $table="license_ref")
testSetEnclosure()
Test for LicenseCsvImport::setEnclosure()
testHandleCsvLicense()
Test for LicenseCsvImport::handleCsvLicense()
testHandleFileIfFileNotExists()
Test for LicenseCsvImport::handleFile() (non-existing file)
testHandleCsv()
Test for LicenseCsvImport::handleCsv()
Wrapper class for license map.
Definition: LicenseMap.php:19
Utility functions for specific applications.