27 require_once(dirname(__FILE__) .
'/../common-license-file.php');
28 require_once(dirname(__FILE__) .
'/../common-db.php');
29 require_once(dirname(__FILE__) .
'/../common-dir.php');
30 require_once(dirname(__FILE__) .
'/../common-ui.php');
37 public $upload_pk = 0;
38 public $uploadtree_pk_parent = 0;
39 public $uploadtree_pk_child = 0;
41 public $uploadtree_tablename =
'uploadtree';
43 public $DB_COMMAND =
"";
60 global $pfile_pk_parent;
61 global $pfile_pk_child;
67 $DB_COMMAND = dirname(dirname(dirname(dirname(__FILE__)))).
"/testing/db/createTestDB.php";
68 print
"*** path to test db creation command: " . $DB_COMMAND;
69 exec($DB_COMMAND, $dbout, $rc);
71 throw new Exception(implode(
"\n", $dbout));
73 preg_match(
"/(\d+)/", $dbout[0], $matches);
74 $test_name = $matches[1];
76 $DB_NAME =
"fosstest".$test_name;
81 $this->logFileName = dirname(dirname(dirname(dirname(dirname(__FILE__))))) .
'/db.sqlite.log';
82 $logger->pushHandler(
new Monolog\Handler\StreamHandler($this->logFileName, Monolog\
Logger::ERROR));
87 $upload_filename =
"license_file_test";
89 $this->
dbManager->prepare($stmt=
'pfile.insert',
90 $sql =
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES ($1,$2,$3)");
92 'AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC',
'2239AA7DAC291B6F8D0A56396B1B8530',
'4560')));
94 'B1938B14B9A573D59ABCBD3BF0F9200CE6E79FB6',
'55EFE7F9B9D106047718F1CE9173B869',
'1892')));
97 $this->
dbManager->queryOnce($sql=
"INSERT INTO agent (agent_name) VALUES('nomos')");
100 $this->
dbManager->prepare($stmt=
'license_ref.insert',
101 $sql=
"INSERT INTO license_ref" 102 .
" (rf_pk, rf_shortname, rf_text, marydone, rf_active, rf_text_updatable, rf_detector_type)" 103 .
" VALUES ($1,$2,$3,$4,$5,$6,$7)");
105 array(1,
'test_ref',
'test_ref',
'false',
'true',
'false', 1)));
108 $this->
dbManager->prepare($stmt=
'license_ref.select',
109 $sql =
"SELECT pfile_pk from pfile where pfile_sha1" 110 .
" IN ('AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC', 'B1938B14B9A573D59ABCBD3BF0F9200CE6E79FB6')");
111 $result = $this->
dbManager->execute($stmt);
112 $row = $this->
dbManager->fetchArray($result);
113 $pfile_pk_parent = $row[
'pfile_pk'];
114 $row = $this->
dbManager->fetchArray($result);
115 $pfile_pk_child= $row[
'pfile_pk'];
119 $agent_nomos = $this->
dbManager->getSingleRow(
"SELECT agent_pk from agent where agent_name = 'nomos'",array(),__METHOD__.
'.agent.select');
120 $agent_pk = $agent_nomos[
'agent_pk'];
121 $this->
dbManager->prepare($stmt=
'license_file.insert',
122 $sql =
"INSERT INTO license_file(rf_fk, agent_fk, pfile_fk) VALUES ($1,$2,$3)");
123 $this->
dbManager->freeResult($this->
dbManager->execute($stmt, array(1, $agent_pk, $pfile_pk_parent)));
124 $this->
dbManager->freeResult($this->
dbManager->execute($stmt, array(2, $agent_pk, $pfile_pk_child)));
126 $this->
dbManager->queryOnce(
"INSERT INTO upload (upload_filename,upload_mode,upload_ts, pfile_fk, uploadtree_tablename)" 127 .
" VALUES ('$upload_filename',40,now(), '$pfile_pk_parent', '$this->uploadtree_tablename')");
128 $row = $this->
dbManager->getSingleRow(
"SELECT upload_pk from upload where upload_filename = '$upload_filename'",array(),__METHOD__.
'.upload.select');
129 $upload_pk= $row[
'upload_pk'];
131 $this->
dbManager->prepare($stmtIn=__METHOD__.
'.uploadtree.insert',
132 "INSERT INTO uploadtree (parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name) VALUES ($1,$2,$3,$4,$5,$6,$7)");
134 $this->
dbManager->execute($stmtIn,array(NULL, $upload_pk, $pfile_pk_parent, 33188, 1, 2,
'license_test.file.parent')));
136 $this->
dbManager->prepare($stmtOut=__METHOD__.
'uploadtree.select',
137 "SELECT uploadtree_pk from uploadtree where pfile_fk=$1");
138 $res = $this->
dbManager->execute($stmtOut,array($pfile_pk_parent));
139 $row = $this->
dbManager->fetchArray($res);
141 $this->uploadtree_pk_parent = $row[
'uploadtree_pk'];
145 $this->
dbManager->execute($stmtIn,array($this->uploadtree_pk_parent, $upload_pk, $pfile_pk_child, 33188, 1, 2,
'license_test.file.child')));
147 $res = $this->
dbManager->execute($stmtOut,array($pfile_pk_child));
148 $row = $this->
dbManager->fetchArray($res);
150 $this->uploadtree_pk_child = $row[
'uploadtree_pk'];
167 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
168 $result = pg_query($PG_CONN, $sql);
170 $row = pg_fetch_assoc($result);
171 $license_value_expected = $row[
'rf_shortname'];
172 pg_free_result($result);
173 $count = count($license_array);
175 $this->assertEquals($license_value_expected, $license_array[1]);
176 $this->assertEquals(1, $count);
186 global $pfile_pk_parent;
188 $sql =
"INSERT INTO license_file(rf_fk, agent_fk, pfile_fk) VALUES(1, $agent_pk, $pfile_pk_parent);";
189 $result = pg_query($PG_CONN, $sql);
191 pg_free_result($result);
195 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
196 $result = pg_query($PG_CONN, $sql);
198 $row = pg_fetch_assoc($result);
199 $license_value_expected = $row[
'rf_shortname'];
200 pg_free_result($result);
202 $count = count($license_array);
203 $this->assertEquals(2, $count);
204 $this->assertEquals($license_value_expected, $license_array[1]);
205 $this->assertEquals($license_value_expected, $license_array[3]);
219 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
220 $result = pg_query($PG_CONN, $sql);
222 $row = pg_fetch_assoc($result);
223 $license_value_expected = $row[
'rf_shortname'];
224 pg_free_result($result);
226 $this->assertEquals($license_value_expected, $license_string);
235 global $pfile_pk_parent;
239 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
240 $result = pg_query($PG_CONN, $sql);
242 $row = pg_fetch_assoc($result);
243 $rf_shortname = $row[
'rf_shortname'];
244 pg_free_result($result);
247 $row = pg_fetch_assoc($files_result);
248 $pfile_id_actual = $row[
'pfile_fk'];
249 pg_free_result($files_result);
250 $this->assertEquals($pfile_pk_parent, $pfile_id_actual);
262 $sql =
"SELECT rf_shortname from license_ref where rf_pk = 1;";
263 $result = pg_query($PG_CONN, $sql);
265 $row = pg_fetch_assoc($result);
266 $rf_shortname = $row[
'rf_shortname'];
267 pg_free_result($result);
270 $this->assertEquals(
"license_test.file.child", $file_name[$this->uploadtree_pk_child]);
279 if (!is_callable(
'pg_connect')) {
283 global $pfile_pk_parent;
284 global $pfile_pk_child;
290 $sql =
"DELETE FROM uploadtree where upload_fk = $upload_pk;";
291 $result = pg_query($PG_CONN, $sql);
293 pg_free_result($result);
296 $sql =
"DELETE FROM license_file where pfile_fk IN ($pfile_pk_parent, $pfile_pk_child);";
297 $result = pg_query($PG_CONN, $sql);
299 pg_free_result($result);
302 $sql =
"DELETE FROM upload where upload_pk = $upload_pk;";
303 $result = pg_query($PG_CONN, $sql);
305 pg_free_result($result);
308 $sql =
"DELETE FROM pfile where pfile_pk IN ($pfile_pk_parent, $pfile_pk_child);";
309 $result = pg_query($PG_CONN, $sql);
311 pg_free_result($result);
314 $sql =
"DELETE FROM agent where agent_name = 'nomos';";
315 $result = pg_query($PG_CONN, $sql);
317 pg_free_result($result);
320 exec(
"$DB_COMMAND -d $DB_NAME");
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"...
testGetFilesWithLicense()
testing for GetFilesWithLicense
DBconnect($sysconfdir, $options="", $exitOnFail=true)
Connect to database engine. This is a no-op if $PG_CONN already has a value.
testGetFileLicensesDul()
testing from GetFileLicenses in this test case, this pfile have 2 same license
testGetFileLicenses_string()
testing from GetFileLicenses_tring in this test case, this pfile have only one license ...
GetFileLicenses_string($agent_pk, $pfile_pk, $uploadtree_pk, $uploadtree_tablename='uploadtree')
Same as GetFileLicenses() but returns license list as a single string.
testGetFileLicenses()
testing from GetFileLicenses in this test case, this pfile have only one license
testLevel1WithLicense()
testing for Level1WithLicense
Namespace used by reuser agent.
char * uploadtree_tablename
upload.uploadtree_tablename
fo_dbManager * dbManager
fo_dbManager object
Level1WithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly=false, $uploadtree_tablename)
Given an uploadtree_pk, find all the non-artifact, immediate children (uploadtree_pk's) that have lic...
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetFileLicenses($agent, $pfile_pk, $uploadtree_pk, $uploadtree_tablename='uploadtree', $duplicate="")
get all the licenses for a single file or uploadtree
GetFilesWithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly=false, $offset=0, $limit="ALL", $order="", $tag_pk=null, $uploadtree_tablename)
Get files with a given license (shortname).