15 require_once(dirname(__FILE__, 2) .
'/common-cache.php');
16 require_once(dirname(__FILE__, 2) .
'/common-db.php');
29 public $upload_pk = 0;
30 public $uploadtree_pk = 0;
31 public $UserCacheStat = 0;
36 protected function setUp() : void
38 $this->testDb =
new TestPgDb(
"fosslibtest");
39 $tables = array(
'upload',
'uploadtree',
'report_cache');
40 $this->testDb->createPlainTables($tables);
41 $sequences = array(
'upload_upload_pk_seq',
'uploadtree_uploadtree_pk_seq',
'report_cache_report_cache_pk_seq');
42 $this->testDb->createSequences($sequences);
43 $this->testDb->createConstraints([
'upload_pkey_idx',
'ufile_rel_pkey',
'report_cache_pkey',
'report_cache_report_cache_key_key']);
44 $this->testDb->alterTables($tables);
47 global $uploadtree_pk;
48 global $UserCacheStat;
50 $this->
dbManager = $this->testDb->getDbManager();
59 global $uploadtree_pk;
63 $sql =
"INSERT INTO upload (upload_filename,upload_mode,upload_ts) VALUES ('cache_test',40,now());";
64 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"insert.upload");
67 $sql =
"SELECT upload_pk from upload where upload_filename = 'cache_test';";
68 $row = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"upload.select");
69 $upload_pk= $row[
'upload_pk'];
72 $sql=
"INSERT INTO uploadtree (upload_fk) VALUES($upload_pk)";
73 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"insert.uploadtree");
76 $sql =
"SELECT uploadtree_pk from uploadtree where upload_fk = $upload_pk;";
77 $row = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"uploadtree.select");
78 $uploadtree_pk= $row[
'uploadtree_pk'];
86 print
"Start unit test for common-cache.php\n";
87 print
"test function ReportCachePut()\n";
89 global $uploadtree_pk;
93 $CacheKey =
"?mod=nomoslicense&upload=$upload_pk&item=$uploadtree_pk&show=detail";
94 $CacheValue =
"no data";
97 $sql =
"SELECT report_cache_value from report_cache where report_cache_uploadfk = $upload_pk;";
98 $row = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"select.report_cache");
99 $value = $row[
'report_cache_value'];
100 $this->assertEquals($CacheValue, $value);
109 print
"test function ReportCachePut()\n";
111 global $uploadtree_pk;
115 $CacheKey =
"?mod=nomoslicense&item=$uploadtree_pk&show=detail";
116 $CacheValue =
"no data";
119 $sql =
"SELECT report_cache_value from report_cache where report_cache_uploadfk = $upload_pk;";
120 $row = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"select.report_cache");
121 $value = $row[
'report_cache_value'];
122 $this->assertEquals($CacheValue, $value);
131 print
"test function ReportCacheGet()\n";
133 global $uploadtree_pk;
134 global $UserCacheStat;
139 $CacheKey =
"?mod=nomoslicense&upload=$upload_pk&item=$uploadtree_pk&show=detail";
140 $CacheValue =
"no data";
145 $this->assertEquals($CacheValue, $value);
147 print
"unit test for common-cache.php end\n";
158 $sql =
"DELETE from report_cache where report_cache_uploadfk = $upload_pk;";
159 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"delete.report_cache");
161 $sql=
"DELETE from uploadtree where upload_fk = $upload_pk;";
162 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"delete.uploadtree");
164 $sql =
"DELETE from upload where upload_pk = $upload_pk;";
165 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"delete.upload");
173 if (!is_callable(
'pg_connect')) {
176 $this->testDb->fullDestruct();
177 $this->testDb =
null;
resetEnv4ReportCachePut()
reset enviroment after testing ReportCachePut
testReportCachePut_upload_id_null()
test for ReportCachePut upload id is not in $CacheKey
preparation4ReportCachePut()
preparation for testing ReportCachePut
testReportCacheGet()
test for ReportCacheGet
testReportCachePut_upload_id_not_null()
test for ReportCachePut upload id is in $CacheKey
ReportCacheGet($CacheKey)
This function is used by Output() to see if the requested report is in the report cache.
ReportCachePut($CacheKey, $CacheValue)
This function is used to write a record to the report cache. If the record already exists,...
fo_dbManager * dbManager
fo_dbManager object