FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_common_pkg.php
Go to the documentation of this file.
1 <?php
2 /*
3  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
24 require_once(dirname(__FILE__) . '/../common-pkg.php');
25 require_once(dirname(__FILE__) . '/../common-db.php');
26 
30 class test_common_pkg extends \PHPUnit\Framework\TestCase
31 {
32  public $PG_CONN;
33  public $DB_COMMAND = "";
34  public $DB_NAME = "";
35 
36  /* initialization */
37  protected function setUp()
38  {
39  if (!is_callable('pg_connect')) {
40  $this->markTestSkipped("php-psql not found");
41  }
42  global $PG_CONN;
43  global $DB_COMMAND;
44  global $DB_NAME;
45  print "Starting unit test for common-pkg.php\n";
46 
47  $DB_COMMAND = dirname(dirname(dirname(dirname(__FILE__))))."/testing/db/createTestDB.php";
48  exec($DB_COMMAND, $dbout, $rc);
49  preg_match("/(\d+)/", $dbout[0], $matches);
50  $test_name = $matches[1];
51  $db_conf = $dbout[0];
52  $DB_NAME = "fosstest".$test_name;
53  #$sysconfig = './sysconfigDirTest';
54  $PG_CONN = DBconnect($db_conf);
55  }
56 
61  {
62  print "test function GetPkgMimetypes()\n";
63  global $PG_CONN;
64 
65  #prepare database testdata
66  $mimeType = "application/x-rpm";
68  $sql = "DELETE FROM mimetype where mimetype_name in ('$mimeType');";
69  $result = pg_query($PG_CONN, $sql);
70  pg_free_result($result);
72  $sql = "INSERT INTO mimetype(mimetype_pk, mimetype_name) VALUES(10000, '$mimeType');";
73  $result = pg_query($PG_CONN, $sql);
74  pg_free_result($result);
75 
76  #begin test GetPkgMimetypes()
77  $sql = "select * from mimetype where
78  mimetype_name='application/x-rpm'";
79  $result = pg_query($PG_CONN, $sql);
80  DBCheckResult($result, $sql, __FILE__, __LINE__);
81  $row = pg_fetch_assoc($result);
82  $expected = $row['mimetype_pk'];
83  pg_free_result($result);
84 
85  $result = GetPkgMimetypes();
86  $this->assertContains($expected, $result);
87 
89  $sql = "DELETE FROM mimetype where mimetype_name in ('$mimeType');";
90  $result = pg_query($PG_CONN, $sql);
91  pg_free_result($result);
92  }
93 
97  protected function tearDown()
98  {
99  if (!is_callable('pg_connect')) {
100  return;
101  }
102  global $PG_CONN;
103  global $DB_COMMAND;
104  global $DB_NAME;
105 
106  pg_close($PG_CONN);
107  exec("$DB_COMMAND -d $DB_NAME");
108  }
109 }
tearDown()
clean the env
GetPkgMimetypes()
Get package mimetype.
Definition: common-pkg.php:33
DBconnect($sysconfdir, $options="", $exitOnFail=true)
Connect to database engine. This is a no-op if $PG_CONN already has a value.
Definition: common-db.php:44
test_GetPkgMimetypes()
test for GetPkgMimetypes()
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198