FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_common_sysconfig.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(dirname(__FILE__)) . '/common-container.php');
25 require_once(dirname(dirname(__FILE__)) . '/common-db.php');
26 require_once(dirname(dirname(__FILE__)) . '/common-sysconfig.php');
27 
31 class test_common_sysconfig extends \PHPUnit\Framework\TestCase
32 {
33  public $PG_CONN;
34  public $DB_COMMAND = "";
35  public $DB_NAME = "";
36  public $sys_conf = "";
37 
41  protected function setUpDb()
42  {
43  if (!is_callable('pg_connect')) {
44  $this->markTestSkipped("php-psql not found");
45  }
46  global $PG_CONN;
47  global $DB_COMMAND;
48  global $sys_conf;
49 
50  $DB_COMMAND = dirname(dirname(dirname(dirname(__FILE__))))."/testing/db/createTestDB.php";
51  exec($DB_COMMAND, $dbout, $rc);
52  $sys_conf = $dbout[0];
53  $PG_CONN = DBconnect($sys_conf);
54  }
55 
62  function testConfigInit()
63  {
64  $this->setUpDb();
65  global $sys_conf;
66  ConfigInit($sys_conf, $SysConf);
67  $this->assertEquals("FOSSology Support", $SysConf['SYSCONFIG']['SupportEmailSubject']);
68  $hostname = exec("hostname -f");
69  if (empty($hostname)) {
70  $hostname = "localhost";
71  }
72  $FOSSologyURL = $hostname."/repo/";
73  $this->assertEquals($FOSSologyURL, $SysConf['SYSCONFIG']['FOSSologyURL']);
74  $this->tearDownDb();
75  }
76 
80  protected function tearDownDb()
81  {
82  if (!is_callable('pg_connect')) {
83  return;
84  }
85  global $PG_CONN;
86  global $DB_COMMAND;
87  global $DB_NAME;
88 
89  pg_close($PG_CONN);
90  exec("$DB_COMMAND -d $DB_NAME");
91  }
92 
96  public function test_check_IP()
97  {
98  foreach (array(''=>false,'1.2.3.4'=>true,'1.7.49.343'=>false,'255.249.199.0'=>true) as $ip=>$correct) {
99  $this->assertEquals(check_IP($ip),$correct,$message="result for IP $ip is false");
100  print('.');
101  }
102  }
103 }
104 
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
testConfigInit()
test for ConfigInit() after ConfigInit() is executed, we can get some sysconfig information, include: SupportEmailLabel, SupportEmailAddr, SupportEmailSubject, BannerMsg, LogoImage, LogoLink, FOSSologyURL
tearDownDb()
clean the env db
setUpDb()
initialization with db
ConfigInit($sysconfdir, &$SysConf)
Initialize the fossology system after bootstrap().
check_IP($ip)
Check if the ip address is valid.