FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_fo_copyright_list.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2012-2014 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2015 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
11 
12 class test_fo_copyright_list extends \PHPUnit\Framework\TestCase
13 {
15  public $fo_copyright_list_path;
17  private $testDb;
19  private $testInstaller;
20 
21  protected function setUp() : void
22  {
23  $this->testDb = new TestPgDb("fossclitest");
24  $tables = array('users','upload','uploadtree_a','uploadtree','copyright','groups','group_user_member','agent','copyright_decision','copyright_ars','ars_master','copyright_event');
25  $this->testDb->createPlainTables($tables);
26  $this->testDb->createInheritedTables(array('uploadtree_a'));
27  $this->testDb->createInheritedArsTables(array('copyright'));
28  $this->testDb->insertData($tables);
29  $this->testDb->setupSysconfig();
30 
31  $sysConf = $this->testDb->getFossSysConf();
32  // Create softlink to fo_wrapper.php
33  $target = dirname(__DIR__, 3) . '/build/src/cli/gen/fo_wrapper.php';
34  $link = dirname(__DIR__) . '/fo_copyright_list';
35  if (file_exists($link)) {
36  unlink($link);
37  }
38  symlink($target, $link);
39  $this->fo_copyright_list_path = "$link -c $sysConf";
40 
41  $this->testInstaller = new TestInstaller($sysConf);
42  $this->testInstaller->init();
43  }
44 
45  protected function tearDown() : void
46  {
47  unlink(dirname(__DIR__) . "/fo_copyright_list");
48  $this->testInstaller->clear();
49  $this->testDb->fullDestruct();
50  $this->testDb = null;
51  }
52 
53 
54  function test_get_copyright_list_all()
55  {
56  $upload_id = 2;
57  $auth = "--user fossy --password fossy";
58  $uploadtree_id = 13;
59  $command = "$this->fo_copyright_list_path $auth -u $upload_id -t $uploadtree_id --container 1";
60  exec("$command 2>&1", $output, $return_value);
61 
62  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
63  $this->assertEquals(27, count($output));
64  $this->assertEquals("B.zip/B/1b/AAL_B: copyright (c) 2002 by author", $output[22]);
65  }
66 
67  function test_get_copyright_list_email()
68  {
69  $upload_id = 2;
70  $auth = "--user fossy --password fossy";
71  $uploadtree_id = 13;
72  $command = "$this->fo_copyright_list_path $auth -u $upload_id -t $uploadtree_id --type email --container 1";
73  exec("$command 2>&1", $output, $return_value);
74 
75  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
76  $this->assertEquals("B.zip/B/1b/3DFX_B: info@3dfx.com", $output[7]);
77  }
78 
79  function test_get_copyright_list_withoutContainer()
80  {
81  $upload_id = 2;
82  $auth = "--user fossy --password fossy";
83  $uploadtree_id = 13;
84  $command = "$this->fo_copyright_list_path $auth -u $upload_id -t $uploadtree_id --type email --container 0";
85  exec("$command 2>&1", $output, $return_value);
86 
87  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
88  $this->assertEquals("B.zip/B/1b/3DFX_B: info@3dfx.com", $output[4]);
89  }
90 
91  public function test_help()
92  {
93  $auth = "--user fossy --password fossy";
94  $command = "$this->fo_copyright_list_path $auth -h";
95  exec("$command 2>&1", $output, $return_value);
96 
97  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
98  $this->assertEquals(11, count($output));
99  }
100 
101  public function test_help_noAuthentication()
102  {
103  $command = "$this->fo_copyright_list_path -h";
104  exec("$command 2>&1", $output, $return_value);
105 
106  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
107  $this->assertEquals(11, count($output));
108  }
109 }