FOSSology  4.7.1
Open Source License Compliance by Open Source Software
test_common_cache.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
14 
15 require_once(dirname(__FILE__, 2) . '/common-cache.php');
16 require_once(dirname(__FILE__, 2) . '/common-db.php');
17 
21 class test_common_cache extends \PHPUnit\Framework\TestCase
22 {
24  private $testDb;
25 
27  private $dbManager;
28 
29  public $upload_pk = 0;
30  public $uploadtree_pk = 0;
31  public $UserCacheStat = 0;
32 
36  protected function setUp() : void
37  {
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);
45 
46  global $upload_pk;
47  global $uploadtree_pk;
48  global $UserCacheStat;
49 
50  $this->dbManager = $this->testDb->getDbManager();
51  }
52 
57  {
58  global $upload_pk;
59  global $uploadtree_pk;
60 
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");
65 
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'];
70 
72  $sql= "INSERT INTO uploadtree (upload_fk) VALUES($upload_pk)";
73  $result = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "insert.uploadtree");
74 
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'];
79  }
80 
85  {
86  global $upload_pk;
87  global $uploadtree_pk;
88 
90 
91  $CacheKey = "?mod=nomoslicense&upload=$upload_pk&item=$uploadtree_pk&show=detail";
92  $CacheValue = "no data";
93  ReportCachePut($CacheKey, $CacheValue);
95  $sql = "SELECT report_cache_value from report_cache where report_cache_uploadfk = $upload_pk;";
96  $row = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "select.report_cache");
97  $value = $row['report_cache_value'];
98  $this->assertEquals($CacheValue, $value);
99  $this->resetEnv4ReportCachePut();
100  }
101 
106  {
107  global $upload_pk;
108  global $uploadtree_pk;
109 
111 
112  $CacheKey = "?mod=nomoslicense&item=$uploadtree_pk&show=detail";
113  $CacheValue = "no data";
114  ReportCachePut($CacheKey, $CacheValue);
116  $sql = "SELECT report_cache_value from report_cache where report_cache_uploadfk = $upload_pk;";
117  $row = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "select.report_cache");
118  $value = $row['report_cache_value'];
119  $this->assertEquals($CacheValue, $value);
120  $this->resetEnv4ReportCachePut();
121  }
122 
127  {
128  global $upload_pk;
129  global $uploadtree_pk;
130  global $UserCacheStat;
131 
133 
135  $CacheKey = "?mod=nomoslicense&upload=$upload_pk&item=$uploadtree_pk&show=detail";
136  $CacheValue = "no data";
137  ReportCachePut($CacheKey, $CacheValue);
139  $UserCacheStat = 2;
140  $value = ReportCacheGet($CacheKey);
141  $this->assertEquals($CacheValue, $value);
142  $this->resetEnv4ReportCachePut();
143  }
144 
149  {
150  global $upload_pk;
153  $sql = "DELETE from report_cache where report_cache_uploadfk = $upload_pk;";
154  $result = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "delete.report_cache");
156  $sql= "DELETE from uploadtree where upload_fk = $upload_pk;";
157  $result = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "delete.uploadtree");
159  $sql = "DELETE from upload where upload_pk = $upload_pk;";
160  $result = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "delete.upload");
161  }
162 
166  protected function tearDown() : void
167  {
168  if (!is_callable('pg_connect')) {
169  return;
170  }
171  $this->testDb->fullDestruct();
172  $this->testDb = null;
173  $this->dbManager = null;
174  }
175 }
resetEnv4ReportCachePut()
reset enviroment after testing ReportCachePut
preparation4ReportCachePut()
preparation for testing ReportCachePut
setUp()
initialization
testReportCachePut_upload_id_not_null()
test for ReportCachePut upload id is in $CacheKey
tearDown()
clean the env
testReportCacheGet()
test for ReportCacheGet
testReportCachePut_upload_id_null()
test for ReportCachePut upload id is not 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
Definition: process.c:16