FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_common_sysconfig.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 
15 
16 require_once(dirname(dirname(__FILE__)) . '/common-container.php');
17 require_once(dirname(dirname(__FILE__)) . '/common-db.php');
18 
22 class test_common_sysconfig extends \PHPUnit\Framework\TestCase
23 {
24  public $sys_conf = "";
25 
30  private $testDb;
35  private $testInstaller;
36 
40  protected function setUpDb()
41  {
42  if (!is_callable('pg_connect')) {
43  $this->markTestSkipped("php-psql not found");
44  }
45  global $sys_conf;
46 
47  $this->testDb = new TestPgDb("sysconfTest");
48  $sys_conf = $this->testDb->getFossSysConf();
49  $this->testDb->getDbManager()->getDriver();
50 
51  $this->testDb->createPlainTables(['sysconfig'],false);
52  $this->testDb->createSequences(['sysconfig_sysconfig_pk_seq'], false);
53  $this->testDb->alterTables(['sysconfig'], false);
55 
56  $this->testInstaller = new TestInstaller($sys_conf);
57  $this->testInstaller->init();
58  }
59 
66  function testConfigInit()
67  {
68  $this->setUpDb();
69  global $sys_conf;
70  ConfigInit($sys_conf, $SysConf);
71  $this->assertEquals("FOSSology Support", $SysConf['SYSCONFIG']['SupportEmailSubject']);
72  $hostname = exec("hostname -f");
73  if (empty($hostname)) {
74  $hostname = "localhost";
75  }
76  $FOSSologyURL = $hostname."/repo/";
77  $this->assertEquals($FOSSologyURL, $SysConf['SYSCONFIG']['FOSSologyURL']);
78  $this->tearDownDb();
79  }
80 
84  protected function tearDownDb()
85  {
86  if (!is_callable('pg_connect')) {
87  return;
88  }
89 
90  $this->testInstaller->clear();
91  $this->testDb->fullDestruct();
92  $this->testDb = null;
93  }
94 
98  public function test_check_IP()
99  {
100  foreach (array(''=>false,'1.2.3.4'=>true,'1.7.49.343'=>false,'255.249.199.0'=>true) as $ip=>$correct) {
101  $this->assertEquals(check_IP($ip),$correct,"result for IP $ip is false");
102  }
103  }
104 }
testConfigInit()
test for ConfigInit() after ConfigInit() is executed, we can get some sysconfig information,...
setUpDb()
initialization with db
Populate_sysconfig()
Populate the sysconfig table with core variables.
check_IP($ip)
Check if the ip address is valid.
ConfigInit($sysconfdir, &$SysConf, $exitOnDbFail=true)
Initialize the fossology system after bootstrap().