FOSSology  4.7.1
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  //Test Case 1: $_GET[$Name] = "Name", $Type = PARM_INTEGER
32  $Name = "Name";
33  $_GET[$Name] = 20;
34  $Type = PARM_INTEGER;
35  $result = GetParm($Name, $Type);
36  $this->assertEquals("20", $result);
37  //Test Case 2: $_GET[$Name] = "Name", $Type = PARM_NUMBER
38  $_GET[$Name] = 20.2;
39  $Type = PARM_NUMBER;
40  $result = GetParm($Name, $Type);
41  $this->assertEquals("20.2", $result);
42  //Test Case 3: $_GET[$Name] = "Name", $Type = PARM_STRING
43  $_GET[$Name] = "/test/";
44  $Type = PARM_STRING;
45  $result = GetParm($Name, $Type);
46  $this->assertEquals("/test/", $result);
47  //Test Case 4: $_GET[$Name] = "Name", $Type = PARM_TEXT
48  $_GET[$Name] = "\\test\\";
49  $Type = PARM_TEXT;
50  $result = GetParm($Name, $Type);
51  $this->assertEquals("test", $result);
52  //Test Case 5: $_GET[$Name] = "Name", $Type = PARM_RAW
53  $_GET[$Name] = "\\test\\";
54  $Type = PARM_RAW;
55  $result = GetParm($Name, $Type);
56  $this->assertEquals("\\test\\", $result);
57  //Test Case 5: $_GET[$Name] = NULL, $_POST[$NAME] = "NAME", $Type = PARM_TEXT
58  $_POST[$Name] = $_GET[$Name];
59  $_GET[$Name] = NULL;
60  $Type = PARM_TEXT;
61  $result = GetParm($Name, $Type);
62  $this->assertEquals("test", $result);
63  //Test Case 6: $Type = NULL
64  $Type = NULL;
65  $result = GetParm($Name, $Type);
66  $this->assertEquals("", $result);
67  }
68 
72  function test_Traceback()
73  {
74  $expected = "http://fossology.org/";
75  $_SERVER['REQUEST_URI'] = $expected;
76  $result = Traceback();
77  $this->assertEquals($expected, $result);
78  }
79 
83  function test_Traceback_uri()
84  {
85  $source = "http://fossology.org/?mod=test&parm=abc";
86  $expected = "http://fossology.org/";
87  $_SERVER['REQUEST_URI'] = $source;
88  $result = Traceback_uri();
89  $this->assertEquals($expected, $result);
90  }
91 
96  {
97  $source1 = "http://fossology.org/?mod=test";
98  $source2 = "http://fossology.org/?mod=test&parm=abc";
99  $expected1 = "test&parm=abc";
100  $expected2 = "&parm=abc";
101  $_SERVER['REQUEST_URI'] = $source1;
102  $result = Traceback_parm(1);
103  $this->assertEquals("test", $result);
104  $_SERVER['REQUEST_URI'] = $source2;
105  $result = Traceback_parm(1);
106  $this->assertEquals($expected1, $result);
107  $result = Traceback_parm(0);
108  $this->assertEquals($expected2, $result);
109  }
110 
115  {
116  $List = array('parm1', 'parm2');
117  $_GET['parm1'] = "parm1";
118  $expected = "&parm1=parm1";
119  $result = Traceback_parm_keep($List);
120  $this->assertEquals($expected, $result);
121  }
122 
127  {
128  $source = "http://fossology.org/repo/testdir?mod=test&parm=abc";
129  $_SERVER['REQUEST_URI'] = $source;
130  $expected = "http://fossology.org/repo/";
131  $result = Traceback_dir();
132  $this->assertEquals($expected, $result);
133  }
134 
138  protected function tearDown() : void
139  {
140  }
141 }
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.