16 require_once(dirname(__FILE__) .
'/../common-license-file.php');
17 require_once(dirname(__FILE__) .
'/../common-db.php');
18 require_once(dirname(__FILE__) .
'/../common-dir.php');
19 require_once(dirname(__FILE__) .
'/../common-ui.php');
26 public $upload_pk = 0;
27 public $uploadtree_pk_parent = 0;
28 public $uploadtree_pk_child = 0;
30 public $uploadtree_tablename =
'uploadtree';
43 protected function setUp() : void
45 $this->testDb =
new TestPgDb(
"fosslibtest");
46 $tables = array(
'license_ref',
'license_file',
'pfile',
'agent',
'upload',
'uploadtree');
47 $this->testDb->createPlainTables($tables);
48 $sequences = array(
'license_ref_rf_pk_seq',
'license_file_fl_pk_seq',
49 'pfile_pfile_pk_seq',
'agent_agent_pk_seq',
'upload_upload_pk_seq',
50 'uploadtree_uploadtree_pk_seq');
51 $this->testDb->createSequences($sequences);
52 $this->testDb->createConstraints([
53 'rf_pkpk',
'license_file_pkey',
'pfile_pkey',
'agent_pkey',
'upload_pkey_idx',
'ufile_rel_pkey'
55 $this->testDb->alterTables($tables);
56 $this->testDb->createViews([
'license_file_ref']);
60 global $pfile_pk_parent;
61 global $pfile_pk_child;
64 $logger =
new Monolog\Logger(
'default');
65 $this->logFileName = dirname(dirname(dirname(dirname(dirname(__FILE__))))) .
'/db.sqlite.log';
66 $logger->pushHandler(
new Monolog\Handler\StreamHandler($this->logFileName, Monolog\
Logger::ERROR));
67 $this->
dbManager = $this->testDb->getDbManager();
70 $upload_filename =
"license_file_test";
72 $this->
dbManager->prepare($stmt=
'pfile.insert',
73 $sql =
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES ($1,$2,$3)");
75 'AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC',
'2239AA7DAC291B6F8D0A56396B1B8530',
'4560')));
77 'B1938B14B9A573D59ABCBD3BF0F9200CE6E79FB6',
'55EFE7F9B9D106047718F1CE9173B869',
'1892')));
80 $this->
dbManager->queryOnce($sql=
"INSERT INTO agent (agent_name) VALUES('nomos')");
83 $this->
dbManager->prepare($stmt=
'license_ref.insert',
84 $sql=
"INSERT INTO license_ref"
85 .
" (rf_pk, rf_shortname, rf_text, marydone, rf_active, rf_text_updatable, rf_detector_type)"
86 .
" VALUES ($1,$2,$3,$4,$5,$6,$7)");
88 array(1,
'test_ref',
'test_ref',
'false',
'true',
'false', 1)));
91 $this->
dbManager->prepare($stmt=
'license_ref.select',
92 $sql =
"SELECT pfile_pk from pfile where pfile_sha1"
93 .
" IN ('AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC', 'B1938B14B9A573D59ABCBD3BF0F9200CE6E79FB6')");
94 $result = $this->
dbManager->execute($stmt);
95 $row = $this->
dbManager->fetchArray($result);
96 $pfile_pk_parent = $row[
'pfile_pk'];
97 $row = $this->
dbManager->fetchArray($result);
98 $pfile_pk_child= $row[
'pfile_pk'];
102 $agent_nomos = $this->
dbManager->getSingleRow(
"SELECT agent_pk from agent where agent_name = 'nomos'",array(),__METHOD__.
'.agent.select');
103 $agent_pk = $agent_nomos[
'agent_pk'];
104 $this->
dbManager->prepare($stmt=
'license_file.insert',
105 $sql =
"INSERT INTO license_file(rf_fk, agent_fk, pfile_fk) VALUES ($1,$2,$3)");
106 $this->
dbManager->freeResult($this->
dbManager->execute($stmt, array(1, $agent_pk, $pfile_pk_parent)));
107 $this->
dbManager->freeResult($this->
dbManager->execute($stmt, array(2, $agent_pk, $pfile_pk_child)));
109 $this->
dbManager->queryOnce(
"INSERT INTO upload (upload_filename,upload_mode,upload_ts, pfile_fk, uploadtree_tablename)"
110 .
" VALUES ('$upload_filename',40,now(), '$pfile_pk_parent', '$this->uploadtree_tablename')");
111 $row = $this->
dbManager->getSingleRow(
"SELECT upload_pk from upload where upload_filename = '$upload_filename'",array(),__METHOD__.
'.upload.select');
112 $upload_pk= $row[
'upload_pk'];
114 $this->
dbManager->prepare($stmtIn=__METHOD__.
'.uploadtree.insert',
115 "INSERT INTO uploadtree (parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name) VALUES ($1,$2,$3,$4,$5,$6,$7)");
117 $this->
dbManager->execute($stmtIn,array(NULL, $upload_pk, $pfile_pk_parent, 33188, 1, 2,
'license_test.file.parent')));
119 $this->
dbManager->prepare($stmtOut=__METHOD__.
'uploadtree.select',
120 "SELECT uploadtree_pk from uploadtree where pfile_fk=$1");
121 $res = $this->
dbManager->execute($stmtOut,array($pfile_pk_parent));
122 $row = $this->
dbManager->fetchArray($res);
124 $this->uploadtree_pk_parent = $row[
'uploadtree_pk'];
128 $this->
dbManager->execute($stmtIn,array($this->uploadtree_pk_parent, $upload_pk, $pfile_pk_child, 33188, 1, 2,
'license_test.file.child')));
130 $res = $this->
dbManager->execute($stmtOut,array($pfile_pk_child));
131 $row = $this->
dbManager->fetchArray($res);
133 $this->uploadtree_pk_child = $row[
'uploadtree_pk'];
149 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
150 $row = $this->
dbManager->getSingleRow($sql);
151 $license_value_expected = $row[
'rf_shortname'];
152 $count = count($license_array);
154 $this->assertEquals($license_value_expected, $license_array[1]);
155 $this->assertEquals(1, $count);
164 global $pfile_pk_parent;
166 $sql =
"INSERT INTO license_file(rf_fk, agent_fk, pfile_fk) VALUES(1, $agent_pk, $pfile_pk_parent);";
167 $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
".insert");
171 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
172 $row = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
".get");
173 $license_value_expected = $row[
'rf_shortname'];
175 $count = count($license_array);
176 $this->assertEquals(2, $count);
177 $this->assertEquals($license_value_expected, $license_array[1]);
178 $this->assertEquals($license_value_expected, $license_array[3]);
191 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
192 $row = $this->
dbManager->getSingleRow($sql);
193 $license_value_expected = $row[
'rf_shortname'];
195 $this->assertEquals($license_value_expected, $license_string);
203 global $pfile_pk_parent;
207 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
208 $row = $this->
dbManager->getSingleRow($sql);
209 $rf_shortname = $row[
'rf_shortname'];
212 $row = pg_fetch_assoc($files_result);
213 $pfile_id_actual = $row[
'pfile_fk'];
214 pg_free_result($files_result);
215 $this->assertEquals($pfile_pk_parent, $pfile_id_actual);
226 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
227 $row = $this->
dbManager->getSingleRow($sql);
228 $rf_shortname = $row[
'rf_shortname'];
231 $this->assertEquals(
"license_test.file.child", $file_name[$this->uploadtree_pk_child]);
240 if (!is_callable(
'pg_connect')) {
243 $this->testDb->fullDestruct();
244 $this->testDb =
null;
char * uploadtree_tablename
upload.uploadtree_tablename
testLevel1WithLicense()
testing for Level1WithLicense
testGetFilesWithLicense()
testing for GetFilesWithLicense
testGetFileLicenses()
testing from GetFileLicenses in this test case, this pfile have only one license
testGetFileLicenses_string()
testing from GetFileLicenses_tring in this test case, this pfile have only one license
testGetFileLicensesDul()
testing from GetFileLicenses in this test case, this pfile have 2 same license
GetFilesWithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly=false, $offset=0, $limit="ALL", $order="", $tag_pk=null, $uploadtree_tablename="uploadtree")
Get files with a given license (shortname).
GetFileLicenses_string($agent_pk, $pfile_pk, $uploadtree_pk, $uploadtree_tablename='uploadtree')
Same as GetFileLicenses() but returns license list as a single string.
Level1WithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly=false, $uploadtree_tablename="uploadtree")
Given an uploadtree_pk, find all the non-artifact, immediate children (uploadtree_pk's) that have lic...
GetFileLicenses($agent, $pfile_pk, $uploadtree_pk, $uploadtree_tablename='uploadtree', $duplicate="")
get all the licenses for a single file or uploadtree
FUNCTION char * GetUploadtreeTableName(PGconn *pgConn, int upload_pk)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree".
fo_dbManager * dbManager
fo_dbManager object