FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_common_active.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-active.php');
14 
18 class test_common_active extends \PHPUnit\Framework\TestCase
19 {
23  protected function setUp() : void
24  {
25  }
26 
31  {
32  print "Start unit test for common-active.php\n";
33  print "test function ActiveHTTPscript\n";
35  $html_result = ActiveHTTPscript("test");
36  $script_header = "<script language='javascript'>\n<!--\n";
37  $script_foot = "\n// -->\n</script>\n";
38  $html_expect = "var test=null;\n";
39  /* Check for browser support. */
40  $html_expect .= "function test_Get(Url)\n";
41  $html_expect .= "{\n";
42  $html_expect .= "if (window.XMLHttpRequest)\n";
43  $html_expect .= " {\n";
44  $html_expect .= " test=new XMLHttpRequest();\n";
45  $html_expect .= " }\n";
46  /* Check for IE5 and IE6 */
47  $html_expect .= "else if (window.ActiveXObject)\n";
48  $html_expect .= " {\n";
49  $html_expect .= " test=new ActiveXObject('Microsoft.XMLHTTP');\n";
50  $html_expect .= " }\n";
51 
52  $html_expect .= "if (test!=null)\n";
53  $html_expect .= " {\n";
54  $html_expect .= " test.onreadystatechange=test_Reply;\n";
55  /***
56  'true' means asynchronous request.
57  Rather than waiting for the reply, the reply is
58  managed by the onreadystatechange event handler.
59  ***/
60  $html_expect .= " test.open('GET',Url,true);\n";
61  $html_expect .= " test.send(null);\n";
62  $html_expect .= " }\n";
63  $html_expect .= "else\n";
64  $html_expect .= " {\n";
65  $html_expect .= " alert('Your browser does not support XMLHTTP.');\n";
66  $html_expect .= " return;\n";
67  $html_expect .= " }\n";
68  $html_expect .= "}\n";
69  $html_expect_script = $script_header.$html_expect.$script_foot;
70  $this->assertEquals($html_expect_script, $html_result);
71 
73  $html_result = ActiveHTTPscript("test", 0);
74  $this->assertEquals($html_expect, $html_result);
75  print "unit test for common-active.php end\n";
76  }
77 
81  protected function tearDown() : void
82  {
83  }
84 }
testActiveHTTPscript()
test for ActiveHTTPscript
setUp()
initialization
tearDown()
clean the env
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.