FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_fo_copyright_list.php
1 <?php
2 /*
3 Copyright (C) 2012-2014 Hewlett-Packard Development Company, L.P.
4 Copyright (C) 2015 Siemens AG
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
22 
23 class test_fo_copyright_list extends \PHPUnit\Framework\TestCase
24 {
26  public $fo_copyright_list_path;
28  private $testDb;
30  private $testInstaller;
31 
32  protected function setUp()
33  {
34  $this->testDb = new TestPgDb("fossclitest");
35  $tables = array('users','upload','uploadtree_a','uploadtree','copyright','groups','group_user_member','agent','copyright_decision','copyright_ars','ars_master');
36  $this->testDb->createPlainTables($tables);
37  $this->testDb->createInheritedTables(array('uploadtree_a'));
38  $this->testDb->createInheritedArsTables(array('copyright'));
39  $this->testDb->insertData($tables);
40 
41  $sysConf = $this->testDb->getFossSysConf();
42  $this->fo_copyright_list_path = dirname(__DIR__) . '/fo_copyright_list -c '.$sysConf;
43 
44  $this->testInstaller = new TestInstaller($sysConf);
45  $this->testInstaller->init();
46  }
47 
48  protected function tearDown()
49  {
50  return;
51  $this->testInstaller->clear();
52  $this->testDb->fullDestruct();
53  $this->testDb = null;
54  }
55 
56 
57  function test_get_copyright_list_all()
58  {
59  $upload_id = 2;
60  $auth = "--user fossy --password fossy";
61  $uploadtree_id = 13;
62  $command = "$this->fo_copyright_list_path $auth -u $upload_id -t $uploadtree_id --container 1";
63  exec("$command 2>&1", $output, $return_value);
64 
65  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
66  $this->assertEquals(27, count($output));
67  $this->assertEquals("B.zip/B/1b/AAL_B: copyright (c) 2002 by author", $output[22]);
68  }
69 
70  function test_get_copryright_list_email()
71  {
72  $upload_id = 2;
73  $auth = "--user fossy --password fossy";
74  $uploadtree_id = 13;
75  $command = "$this->fo_copyright_list_path $auth -u $upload_id -t $uploadtree_id --type email --container 1";
76  exec("$command 2>&1", $output, $return_value);
77 
78  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
79  $this->assertEquals("B.zip/B/1b/3DFX_B: info@3dfx.com", $output[7]);
80  }
81 
82  function test_get_copryright_list_withoutContainer()
83  {
84  $upload_id = 2;
85  $auth = "--user fossy --password fossy";
86  $uploadtree_id = 13;
87  $command = "$this->fo_copyright_list_path $auth -u $upload_id -t $uploadtree_id --type email --container 0";
88  exec("$command 2>&1", $output, $return_value);
89 
90  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
91  $this->assertEquals("B.zip/B/1b/3DFX_B: info@3dfx.com", $output[4]);
92  }
93 
94  public function test_help()
95  {
96  $auth = "--user fossy --password fossy";
97  $command = "$this->fo_copyright_list_path $auth -h";
98  exec("$command 2>&1", $output, $return_value);
99 
100  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
101  $this->assertEquals(11, count($output));
102  }
103 
104  public function test_help_noAuthentication()
105  {
106  $command = "$this->fo_copyright_list_path -h";
107  exec("$command 2>&1", $output, $return_value);
108 
109  $this->assertEquals(0, $return_value, "Non-zero exit status code with\n" . join('\n', $output));
110  $this->assertEquals(11, count($output));
111  }
112 }