FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_common_pkg.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(__FILE__) . '/../common-pkg.php');
17 require_once(dirname(__FILE__) . '/../common-db.php');
18 
22 class test_common_pkg extends \PHPUnit\Framework\TestCase
23 {
25  private $testDb;
26 
28  private $dbManager;
29 
30  /* initialization */
31  protected function setUp() : void
32  {
33 
34  $this->testDb = new TestPgDb("fosslibtest");
35  $tables = array('mimetype');
36  $this->testDb->createPlainTables($tables);
37  $sequences = array('mimetype_mimetype_pk_seq');
38  $this->testDb->createSequences($sequences);
39  $this->testDb->createConstraints(['dirmodemask', 'mimetype_pk']);
40  $this->testDb->alterTables($tables);
41  $this->dbManager = $this->testDb->getDbManager();
42  }
43 
48  {
49  print "test function GetPkgMimetypes()\n";
50 
51  #prepare database testdata
52  $mimeType = "application/x-rpm";
54  $sql = "DELETE FROM mimetype where mimetype_name in ('$mimeType');";
55  $result = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "delete.mimetype");
57  $sql = "INSERT INTO mimetype(mimetype_pk, mimetype_name) VALUES(10000, '$mimeType');";
58  $result = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "insert.mimetype");
59 
60  #begin test GetPkgMimetypes()
61  $sql = "select * from mimetype where
62  mimetype_name='application/x-rpm'";
63  $row = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "select.mimetype");
64  $expected = $row['mimetype_pk'];
65 
66  $result = GetPkgMimetypes();
67  $this->assertContains($expected, $result);
68 
70  $sql = "DELETE FROM mimetype where mimetype_name in ('$mimeType');";
71  $result = $this->dbManager->getSingleRow($sql, [], __METHOD__ . "delete.mimetype");
72  }
73 
77  protected function tearDown() : void
78  {
79  if (!is_callable('pg_connect')) {
80  return;
81  }
82  $this->testDb->fullDestruct();
83  $this->testDb = null;
84  $this->dbManager = null;
85  }
86 }
tearDown()
clean the env
test_GetPkgMimetypes()
test for GetPkgMimetypes()
GetPkgMimetypes()
Get package mimetype.
Definition: common-pkg.php:22
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16