FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_common_parm.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(__FILE__) . '/../common-parm.php');
25 
29 class test_common_parm extends \PHPUnit\Framework\TestCase
30 {
31  /* initialization */
32  protected function setUp()
33  {
34  //print "Starting unit test for common-parm.php\n";
35  }
36 
40  function test_GetParm()
41  {
42  print "Starting unit test for common-parm.php\n";
43  print "test function GetParm()\n";
44  //Test Case 1: $_GET[$Name] = "Name", $Type = PARM_INTEGER
45  $Name = "Name";
46  $_GET[$Name] = 20;
47  $Type = PARM_INTEGER;
48  $result = GetParm($Name, $Type);
49  $this->assertEquals("20", $result);
50  //Test Case 2: $_GET[$Name] = "Name", $Type = PARM_NUMBER
51  $_GET[$Name] = 20.2;
52  $Type = PARM_NUMBER;
53  $result = GetParm($Name, $Type);
54  $this->assertEquals("20.2", $result);
55  //Test Case 3: $_GET[$Name] = "Name", $Type = PARM_STRING
56  $_GET[$Name] = "/test/";
57  $Type = PARM_STRING;
58  $result = GetParm($Name, $Type);
59  $this->assertEquals("/test/", $result);
60  //Test Case 4: $_GET[$Name] = "Name", $Type = PARM_TEXT
61  $_GET[$Name] = "\\test\\";
62  $Type = PARM_TEXT;
63  $result = GetParm($Name, $Type);
64  $this->assertEquals("test", $result);
65  //Test Case 5: $_GET[$Name] = "Name", $Type = PARM_RAW
66  $_GET[$Name] = "\\test\\";
67  $Type = PARM_RAW;
68  $result = GetParm($Name, $Type);
69  $this->assertEquals("\\test\\", $result);
70  //Test Case 5: $_GET[$Name] = NULL, $_POST[$NAME] = "NAME", $Type = PARM_TEXT
71  $_POST[$Name] = $_GET[$Name];
72  $_GET[$Name] = NULL;
73  $Type = PARM_TEXT;
74  $result = GetParm($Name, $Type);
75  $this->assertEquals("test", $result);
76  //Test Case 6: $Type = NULL
77  $Type = NULL;
78  $result = GetParm($Name, $Type);
79  $this->assertEquals("", $result);
80  }
81 
85  function test_Traceback()
86  {
87  print "test function Traceback()\n";
88  $expected = "http://fossology.org/";
89  $_SERVER['REQUEST_URI'] = $expected;
90  $result = Traceback();
91  $this->assertEquals($expected, $result);
92  }
93 
97  function test_Traceback_uri()
98  {
99  print "test function Traceback_uri()\n";
100  $source = "http://fossology.org/?mod=test&parm=abc";
101  $expected = "http://fossology.org/";
102  $_SERVER['REQUEST_URI'] = $source;
103  $result = Traceback_uri();
104  $this->assertEquals($expected, $result);
105  }
106 
111  {
112  print "test function Traceback_parm()\n";
113  $source1 = "http://fossology.org/?mod=test";
114  $source2 = "http://fossology.org/?mod=test&parm=abc";
115  $expected1 = "test&parm=abc";
116  $expected2 = "&parm=abc";
117  $_SERVER['REQUEST_URI'] = $source1;
118  $result = Traceback_parm(1);
119  $this->assertEquals("test", $result);
120  $_SERVER['REQUEST_URI'] = $source2;
121  $result = Traceback_parm(1);
122  $this->assertEquals($expected1, $result);
123  $result = Traceback_parm(0);
124  $this->assertEquals($expected2, $result);
125  }
126 
131  {
132  print "test function Traceback_parm_keep()\n";
133  $List = array('parm1', 'parm2');
134  $_GET['parm1'] = "parm1";
135  $expected = "&parm1=parm1";
136  $result = Traceback_parm_keep($List);
137  $this->assertEquals($expected, $result);
138  }
139 
144  {
145  print "test function Traceback_dir()\n";
146  $source = "http://fossology.org/repo/testdir?mod=test&parm=abc";
147  $_SERVER['REQUEST_URI'] = $source;
148  $expected = "http://fossology.org/repo/";
149  $result = Traceback_dir();
150  $this->assertEquals($expected, $result);
151  print "Ending unit test for common-parm.php\n";
152  }
153 
157  protected function tearDown()
158  {
159  }
160 }
tearDown()
clean the env
const PARM_RAW
Definition: common-parm.php:33
Traceback_uri()
Get the URI without query to this location.
const PARM_TEXT
Definition: common-parm.php:31
test_Traceback_parm()
test for Traceback_parm()
Traceback_parm($ShowMod=1)
Get the URI query to this location.
test_Traceback_dir()
test for Traceback_dir()
const PARM_NUMBER
Definition: common-parm.php:27
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
const PARM_STRING
Definition: common-parm.php:29
test_Traceback_uri()
test for Traceback_uri()
test_Traceback()
test for Traceback()
const PARM_INTEGER
Definition: common-parm.php:25
Traceback_dir()
Get the directory of the URI without query.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
Traceback()
Get the URI + query to this location.
test_GetParm()
test for GetParm($Name, $Type)
test_Traceback_parm_keep()
test for Traceback_parm_keep()