3 * Copyright (C) 2009 Olivier Berger, Institut TELECOM
5 * This file is part of FusionForge.
7 * FusionForge is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License,
10 * or (at your option) any later version.
12 * FusionForge is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with FusionForge; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 require_once 'PHPUnit/Framework/TestCase.php';
25 class SoapLoginProcess extends PHPUnit_Framework_TestCase
31 // print_r("setup\n");
33 $this->session = NULL;
34 $this->soapclient = NULL;
38 // This is to check that the SoapClient instanciation will
39 // work. There's aparently a different behaviour if
40 // resolving the hostname doesn't work under phpunit. If
41 // this fails, the hostname and IP address should be
42 // different and the WSDL retrieval should work
43 $ip = gethostbyname(FORGE_HOSTNAME);
44 if ($ip != FORGE_HOSTNAME)
47 // Instantiate the SOAP client with WSDL
48 $this->soapclient = new SoapClient(WSDL_URL,
49 array('cache_wsdl' => WSDL_CACHE_NONE,
52 // } catch (SoapFault $fault) {
53 // $fault->faultstring;
56 // print_r($this->soapclient);
64 $response = $this->soapclient->logout($this->session);
70 // performs a login and returns a session "cookie"
71 function login($userid, $passwd)
73 $this->assertNotNull($this->soapclient);
75 $response = $this->soapclient->login($userid, $passwd);
78 $this->session = $response;
79 // print_r($this->session);
86 // Binding: GForgeAPIBinding
89 // message: versionRequest
93 // message: versionResponse
95 // versionResponse: xsd:string
97 function testVersion()
99 $this->assertNotNull($this->soapclient);
101 $version = $this->soapclient->version();
103 $this->assertEquals('4.8.50', $version);
108 * @depends testVersion
110 function testGETFUNCTIONS()
112 $this->assertNotNull($this->soapclient);
113 $response = $this->soapclient->__getFunctions();
114 // print_r($response);
118 // Binding: GForgeAPIBinding
121 // message: loginRequest
123 // userid: xsd:string
124 // passwd: xsd:string
127 // message: loginResponse
129 // loginResponse: xsd:string
132 * @depends testVersion
134 function testLoginNonExistantUser()
136 $this->assertNotNull($this->soapclient);
141 $response = $this->soapclient->login($userid, 'pan');
143 catch (SoapFault $expected) {
145 $this->assertEquals("Unable to log in with userid of ".$userid, $expected->faultstring);
146 // print_r($response);
150 $this->fail('An expected exception has not been raised.');
154 * @depends testVersion
156 function testLoginWrongPwd()
158 $this->assertNotNull($this->soapclient);
160 $userid = EXISTING_USER;
163 $response = $this->soapclient->login($userid, 'xxxxxx');
165 catch (SoapFault $expected) {
167 $this->assertEquals("Unable to log in with userid of ".$userid, $expected->faultstring);
169 // print_r($response);
173 $this->fail('An expected exception has not been raised.');
177 * @depends testVersion
179 function testLoginSuccesful()
181 $userid = EXISTING_USER;
182 $passwd = PASSWD_OF_EXISTING_USER;
184 $response = $this->login($userid, $passwd);
186 $this->assertNotNull($response);
191 // Binding: GForgeAPIBinding
194 // message: logoutRequest
196 // session_ser: xsd:string
199 // message: logoutResponse
201 // logoutResponse: xsd:string
204 * @depends testLoginSuccesful
206 /* function testLogout()
211 $response = $this->soapclient->logout('coin');
213 print_r('logout response :'. $response);