28 if (!function_exists(
'Traceback_uri'))
31 return 'Traceback_uri_if_desired';
46 private $uploadPermDao;
48 protected function setUp()
50 $this->testDb =
new TestPgDb(
"ninkaSched".time());
51 $this->
dbManager = $this->testDb->getDbManager();
54 $logger =
new Logger(
"NinkaSchedulerTest");
55 $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
59 protected function tearDown()
61 $this->testDb->fullDestruct();
64 $this->licenseDao = null;
67 private function runNinka($uploadId)
69 $sysConf = $this->testDb->getFossSysConf();
73 $agentDir = dirname(dirname(__DIR__));
74 $execDir =
"$agentDir/agent";
75 system(
"install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
77 $pipeFd = popen(
"echo $uploadId | $execDir/$agentName -c $sysConf --scheduler_start",
"r");
78 $this->assertTrue($pipeFd !==
false,
'running ninka failed');
81 while (($buffer = fgets($pipeFd, 4096)) !==
false) {
84 $retCode = pclose($pipeFd);
86 unlink(
"$sysConf/mods-enabled/$agentName/VERSION");
87 rmdir(
"$sysConf/mods-enabled/$agentName");
88 rmdir(
"$sysConf/mods-enabled");
90 return array($output,$retCode);
93 private function setUpRepo()
95 $sysConf = $this->testDb->getFossSysConf();
97 $confFile = $sysConf.
"/fossology.conf";
98 system(
"touch ".$confFile);
99 $config =
"[FOSSOLOGY]\ndepth = 0\npath = $sysConf/repo\n";
100 file_put_contents($confFile, $config);
102 $testRepoDir = dirname(dirname(dirname(__DIR__))).
"/lib/php/Test/";
103 system(
"cp -a $testRepoDir/repo $sysConf/");
106 private function rmRepo()
108 $sysConf = $this->testDb->getFossSysConf();
109 system(
"rm $sysConf/repo -rf");
111 unlink($sysConf.
"/fossology.conf");
114 private function setUpTables()
116 $this->testDb->createPlainTables(array(
'upload',
'uploadtree',
'license_ref',
'license_file',
'highlight',
'agent',
'pfile',
'ars_master'),
false);
117 $this->testDb->createSequences(array(
'agent_agent_pk_seq',
'pfile_pfile_pk_seq',
'upload_upload_pk_seq',
'nomos_ars_ars_pk_seq',
'license_file_fl_pk_seq',
'license_ref_rf_pk_seq'),
false);
118 $this->testDb->createViews(array(
'license_file_ref'),
false);
119 $this->testDb->createConstraints(array(
'agent_pkey',
'pfile_pkey',
'upload_pkey_idx',
'FileLicense_pkey',
'rf_pkpk'),
false);
120 $this->testDb->alterTables(array(
'agent',
'pfile',
'upload',
'ars_master',
'license_file',
'highlight',
'license_ref'),
false);
121 $this->testDb->createInheritedTables();
122 $this->testDb->insertData(array(
'pfile',
'upload',
'uploadtree_a'),
false);
123 $this->testDb->insertData_license_ref();
124 $this->testDb->resetSequenceAsMaxOf(
'license_ref_rf_pk_seq',
'license_ref',
'rf_pk');
128 public function testRun()
130 $this->setUpTables();
133 list($output,$retCode) = $this->runNinka($uploadId=1);
137 $this->assertEquals($retCode, 0,
'ninka failed: '.$output);
139 $bounds = $this->uploadDao->getParentItemBounds($uploadId);
140 $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds);
142 $this->assertEquals($expected=6, count($matches));
144 foreach($matches as $licenseMatch) {
146 $matchedLicense = $licenseMatch->getLicenseRef();
148 switch ($licenseMatch->getFileId()) {
151 $expectedLicense =
"GPL-3.0+";
154 $expectedLicense =
"UnclassifiedLicense";
157 $expectedLicense =
"No_license_found";
161 $this->assertEquals($expectedLicense, $matchedLicense->getShortName(),
"unexpected license for fileId ".$licenseMatch->getFileId());
164 $agentRef = $licenseMatch->getAgentRef();
165 $this->assertEquals($agentRef->getAgentName(),
"ninka");
Traceback_uri()
Get the URI without query to this location.
fo_dbManager * dbManager
fo_dbManager object