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