/** * common test framework for all tests - cycles through the number * of iterations, auth types, and protocols */ public function testRun() { $this->markTestSkipped('cURL requests need to be mocked properly. Skipping for now.'); // do we have any tests if (!$this->testrest and !$this->testxmlrpc and !$this->testsoap) { log_debug("Web service unit tests are not run as not setup (see /webservice/simpletest/testwebservice.php)"); } // need a token to test if (!empty($this->testtoken)) { // test the REST interface if ($this->testrest) { log_debug("Testing REST"); $this->timerrest = time(); require_once get_config('docroot') . "webservice/rest/lib.php"; // iterate the token and user auth types foreach ($this->auths as $type) { log_debug("Auth Type: " . $type); switch ($type) { case 'token': $restclient = new webservice_rest_client(get_config('wwwroot') . 'webservice/rest/server.php', array('wstoken' => $this->testtoken), $type); break; case 'user': $restclient = new webservice_rest_client(get_config('wwwroot') . 'webservice/rest/server.php', array('wsusername' => $this->testuser, 'wspassword' => $this->testuser), $type); break; case 'oauth': $restclient = new webservice_rest_client(get_config('wwwroot') . 'webservice/rest/server.php', array(), $type); $restclient->set_oauth($this->consumer, $this->access_token); break; } for ($i = 1; $i <= $this->iteration; $i = $i + 1) { foreach ($this->readonlytests as $functionname => $run) { if ($run) { $this->{$functionname}($restclient); } } foreach ($this->writetests as $functionname => $run) { if ($run) { $this->{$functionname}($restclient); } } } } $this->timerrest = time() - $this->timerrest; } // test the XML-RPC interface if ($this->testxmlrpc) { log_debug("Testing XML RPC"); $this->timerxmlrpc = time(); require_once get_config('docroot') . "webservice/xmlrpc/lib.php"; // iterate the token and user auth types foreach (array('token', 'user') as $type) { $xmlrpcclient = new webservice_xmlrpc_client(get_config('wwwroot') . 'webservice/xmlrpc/server.php', $type == 'token' ? array('wstoken' => $this->testtoken) : array('wsusername' => $this->testuser, 'wspassword' => $this->testuser)); for ($i = 1; $i <= $this->iteration; $i = $i + 1) { foreach ($this->readonlytests as $functionname => $run) { if ($run) { $this->{$functionname}($xmlrpcclient); } } foreach ($this->writetests as $functionname => $run) { if ($run) { $this->{$functionname}($xmlrpcclient); } } } } $this->timerxmlrpc = time() - $this->timerxmlrpc; } // test the SOAP interface if ($this->testsoap) { log_debug("Testing SOAP"); $this->timersoap = time(); require_once get_config('docroot') . "webservice/soap/lib.php"; // iterate the token and user auth types foreach (array(array('wstoken' => $this->testtoken), array('wsusername' => $this->testuser, 'wspassword' => $this->testuser), array('wsse' => 1)) as $parms) { // stop failed to load external entity error libxml_disable_entity_loader(false); if (isset($parms['wsse'])) { //force SOAP synchronous mode $soapclient = new webservice_soap_client(get_config('wwwroot') . 'webservice/soap/server.php', array('wsservice' => $this->servicename), array("features" => SOAP_WAIT_ONE_WAY_CALLS)); //when function return null $wsseSoapClient = new webservice_soap_client_wsse(array($soapclient, '_doRequest'), $soapclient->wsdl, $soapclient->getOptions()); $wsseSoapClient->__setUsernameToken($this->testuser, $this->testuser); $soapclient->setSoapClient($wsseSoapClient); } else { //force SOAP synchronous mode $soapclient = new webservice_soap_client(get_config('wwwroot') . 'webservice/soap/server.php', $parms, array("features" => SOAP_WAIT_ONE_WAY_CALLS)); //when function return null } $soapclient->setWsdlCache(false); for ($i = 1; $i <= $this->iteration; $i = $i + 1) { foreach ($this->readonlytests as $functionname => $run) { if ($run) { $this->{$functionname}($soapclient); } } foreach ($this->writetests as $functionname => $run) { if ($run) { $this->{$functionname}($soapclient); } } } } $this->timersoap = time() - $this->timersoap; } } }