FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ft_cliDelagentTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011-2013 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
11 //require_once '/usr/share/php/PHPUnit/Framework.php';
12 require_once (__DIR__ . "/../../../testing/db/createEmptyTestEnvironment.php");
13 
18 class ft_cliDelagentTest extends \PHPUnit\Framework\TestCase {
19 
20  public $EXE_PATH = "";
21  public $PG_CONN;
22  public $DB_COMMAND = "";
23  public $DB_NAME = "";
24  public $DB_CONF = "";
25 
26  /* initialization */
27  protected function setUp() : void {
28  global $EXE_PATH;
29  global $PG_CONN;
30  global $DB_COMMAND;
31  global $DB_NAME;
32  global $DB_CONF;
33 
34  $cwd = getcwd();
35  list($test_name, $DB_CONF, $DB_NAME, $PG_CONN) = setupTestEnv($cwd, "delagent", false);
36 
37  $EXE_PATH = '../../agent/delagent';
38  $usage= "";
39  $usageL = "";
40 
41  if(file_exists($EXE_PATH))
42  {
43  $usage = 'Usage: ../../agent/delagent [options]';
44  $usageL = ' -f :: List folder IDs.';
45  }
46  else
47  {
48  $this->assertFileExists($EXE_PATH,
49  $message = 'FATAL: cannot find executable file, stop testing\n');
50  }
51  // run it
52  $EXE_PATH = $EXE_PATH." -c $DB_CONF";
53  $last = exec("$EXE_PATH -h 2>&1", $out, $rtn);
54  $this->assertEquals($usage, $out[0]); // check if executable file delagent is exited
55  $this->assertEquals($usageL, $out[6]); // check if the option -L removed
56  }
65  function testDelagentu(){
66  global $EXE_PATH;
67  global $PG_CONN;
68  global $DB_NAME;
69  global $DB_CONF;
70 
71  $expected = "";
72 
73  $db_array = parse_ini_file("$DB_CONF/Db.conf");
74  $db_user = $db_array["user"];
75 
76  exec("gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
77 
78  $sql = "SELECT upload_pk, upload_filename FROM upload ORDER BY upload_pk;";
79  $result = pg_query($PG_CONN, $sql);
80  if (pg_num_rows($result) > 0){
81  $row = pg_fetch_assoc($result);
82  $expected = $row["upload_pk"] . " :: ". $row["upload_filename"];
83  }
84  pg_free_result($result);
86  $command = "$EXE_PATH -u -n fossy -p fossy";
87  exec($command, $out, $rtn);
88  //print_r($out);
89  $this->assertStringStartsWith($expected, $out[1]);
90  }
91 
92 
101  function testDelagentf(){
102  global $EXE_PATH;
103  global $PG_CONN;
104  global $DB_NAME;
105  global $DB_CONF;
106 
107  $expected = "";
108 
109  $db_array = parse_ini_file("$DB_CONF/Db.conf");
110  $db_user = $db_array["user"];
111 
112  exec("gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
113 
114  $sql = "SELECT folder_pk,parent,name,description,upload_pk FROM folderlist ORDER BY name,parent,folder_pk;";
115  $result = pg_query($PG_CONN, $sql);
116  if (pg_num_rows($result) > 0){
117  $row = pg_fetch_assoc($result);
118  $expected = " -- :: Contains: " . $row["name"];
119  }
120  pg_free_result($result);
121  $command = "$EXE_PATH -f -n fossy -p fossy";
122  exec($command, $out, $rtn);
123  #print $expected . "\n";
124  #print $out[1] . "\n";
125  $this->assertStringStartsWith($expected, $out[2]);
126  }
127 
135  function testDelagentUpload(){
136  global $EXE_PATH;
137  global $PG_CONN;
138  global $DB_NAME;
139  global $DB_CONF;
140 
141  $expected = "The upload '2' is deleted by the user 'fossy'.";
142 
143  $db_array = parse_ini_file("$DB_CONF/Db.conf");
144  $db_user = $db_array["user"];
145 
146  exec("gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
147  $sql = "UPDATE upload SET user_fk = 3;";
148  $result = pg_query($PG_CONN, $sql);
149  pg_free_result($result);
150 
151  $command = "$EXE_PATH -U 2 -n fossy -p fossy";
152  exec($command, $out, $rtn);
153  #print $expected . "\n";
154  #print $out[1] . "\n";
155  $sql = "SELECT upload_fk, uploadtree_pk FROM bucket_container, uploadtree WHERE uploadtree_fk = uploadtree_pk AND upload_fk = 2;";
156  $result = pg_query($PG_CONN, $sql);
157  if (pg_num_rows($result) > 0){
158  $this->assertFalse("bucket_container records not deleted!");
159  }
160  pg_free_result($result);
161 
162  $this->assertStringStartsWith($expected, $out[0]);
163  }
164 
165 
169  protected function tearDown() : void {
170  global $PG_CONN;
171  global $DB_COMMAND;
172  global $DB_NAME;
173  global $DB_CONF;
174 
175  pg_close($PG_CONN);
176  exec("$DB_COMMAND -d $DB_NAME");
177  exec("rm -rf $DB_CONF");
178  }
179 }
180 
181 
test the delagent agent thru command line.
testDelagentf()
test delagent -f
testDelagentu()
test delagent -u
testDelagentUpload()
test delagent -U 2
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308