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