FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ft_cliDelagentTest.php
1 <?php
2 
3 /*
4  Copyright (C) 2011-2013 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
23 //require_once '/usr/share/php/PHPUnit/Framework.php';
24 require_once (__DIR__ . "/../../../testing/db/createEmptyTestEnvironment.php");
25 
30 class ft_cliDelagentTest extends \PHPUnit\Framework\TestCase {
31 
32  public $EXE_PATH = "";
33  public $PG_CONN;
34  public $DB_COMMAND = "";
35  public $DB_NAME = "";
36  public $DB_CONF = "";
37 
38  /* initialization */
39  protected function setUp() {
40  global $EXE_PATH;
41  global $PG_CONN;
42  global $DB_COMMAND;
43  global $DB_NAME;
44  global $DB_CONF;
45 
46  $cwd = getcwd();
47  list($test_name, $DB_CONF, $DB_NAME, $PG_CONN) = setupTestEnv($cwd, "delagent", false);
48 
49  $EXE_PATH = '../../agent/delagent';
50  $usage= "";
51  $usageL = "";
52 
53  if(file_exists($EXE_PATH))
54  {
55  $usage = 'Usage: ../../agent/delagent [options]';
56  $usageL = ' -f :: List folder IDs.';
57  }
58  else
59  {
60  $this->assertFileExists($EXE_PATH,
61  $message = 'FATAL: cannot find executable file, stop testing\n');
62  }
63  // run it
64  $EXE_PATH = $EXE_PATH." -c $DB_CONF";
65  $last = exec("$EXE_PATH -h 2>&1", $out, $rtn);
66  $this->assertEquals($usage, $out[0]); // check if executable file delagent is exited
67  $this->assertEquals($usageL, $out[6]); // check if the option -L removed
68  }
77  function testDelagentu(){
78  global $EXE_PATH;
79  global $PG_CONN;
80  global $DB_NAME;
81  global $DB_CONF;
82 
83  $expected = "";
84 
85  $db_array = parse_ini_file("$DB_CONF/Db.conf");
86  $db_user = $db_array["user"];
87 
88  exec("gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
89 
90  $sql = "SELECT upload_pk, upload_filename FROM upload ORDER BY upload_pk;";
91  $result = pg_query($PG_CONN, $sql);
92  if (pg_num_rows($result) > 0){
93  $row = pg_fetch_assoc($result);
94  $expected = $row["upload_pk"] . " :: ". $row["upload_filename"];
95  }
96  pg_free_result($result);
98  $command = "$EXE_PATH -u -n fossy -p fossy";
99  exec($command, $out, $rtn);
100  //print_r($out);
101  $this->assertStringStartsWith($expected, $out[1]);
102  }
103 
104 
113  function testDelagentf(){
114  global $EXE_PATH;
115  global $PG_CONN;
116  global $DB_NAME;
117  global $DB_CONF;
118 
119  $expected = "";
120 
121  $db_array = parse_ini_file("$DB_CONF/Db.conf");
122  $db_user = $db_array["user"];
123 
124  exec("gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
125 
126  $sql = "SELECT folder_pk,parent,name,description,upload_pk FROM folderlist ORDER BY name,parent,folder_pk;";
127  $result = pg_query($PG_CONN, $sql);
128  if (pg_num_rows($result) > 0){
129  $row = pg_fetch_assoc($result);
130  $expected = " -- :: Contains: " . $row["name"];
131  }
132  pg_free_result($result);
133  $command = "$EXE_PATH -f -n fossy -p fossy";
134  exec($command, $out, $rtn);
135  #print $expected . "\n";
136  #print $out[1] . "\n";
137  $this->assertStringStartsWith($expected, $out[2]);
138  }
139 
147  function testDelagentUpload(){
148  global $EXE_PATH;
149  global $PG_CONN;
150  global $DB_NAME;
151  global $DB_CONF;
152 
153  $expected = "The upload '2' is deleted by the user 'fossy'.";
154 
155  $db_array = parse_ini_file("$DB_CONF/Db.conf");
156  $db_user = $db_array["user"];
157 
158  exec("gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
159  $sql = "UPDATE upload SET user_fk = 3;";
160  $result = pg_query($PG_CONN, $sql);
161  pg_free_result($result);
162 
163  $command = "$EXE_PATH -U 2 -n fossy -p fossy";
164  exec($command, $out, $rtn);
165  #print $expected . "\n";
166  #print $out[1] . "\n";
167  $sql = "SELECT upload_fk, uploadtree_pk FROM bucket_container, uploadtree WHERE uploadtree_fk = uploadtree_pk AND upload_fk = 2;";
168  $result = pg_query($PG_CONN, $sql);
169  if (pg_num_rows($result) > 0){
170  $this->assertFalse("bucket_container records not deleted!");
171  }
172  pg_free_result($result);
173 
174  $this->assertStringStartsWith($expected, $out[0]);
175  }
176 
177 
181  protected function tearDown() {
182  global $PG_CONN;
183  global $DB_COMMAND;
184  global $DB_NAME;
185  global $DB_CONF;
186 
187  pg_close($PG_CONN);
188  exec("$DB_COMMAND -d $DB_NAME");
189  exec("rm -rf $DB_CONF");
190  }
191 }
192 
193 
testDelagentu()
test delagent -u
tearDown()
clean the env
test the delagent agent thru command line.
testDelagentf()
test delagent -f
testDelagentUpload()
test delagent -U 2
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321