Commit f7a8a7fd authored by Aaron Wells's avatar Aaron Wells Committed by Gerrit Code Review
Browse files

Improvements (and disabling) the webservice PHPunit tests

Bug #1402491: Some fixes to the tests, but ultimately we're setting
them to skip for now, because they need to have cURL replaced with
something that can be stub/mock-ed for PHPUnit.

Change-Id: Ic15cbbbb3979bf57471def90b7603f322881c226
parent 184f24cd
......@@ -203,14 +203,15 @@ class webservice_xml2array {
/**
* Constructor for XML parser
* @return boolean
*/
function webservice_xml2array($xml) {
public function __construct($xml) {
if (is_string($xml)) {
$this->dom = new DOMDocument;
$this->dom->loadXml($xml);
}
return FALSE;
else {
$this->dom = false;
}
}
/**
......@@ -235,7 +236,7 @@ class webservice_xml2array {
if ($node->nodeType == XML_TEXT_NODE) {
$result = html_entity_decode(htmlspecialchars($node->nodeValue, ENT_COMPAT, 'UTF-8'),
ENT_COMPAT,'ISO-8859-15');
ENT_COMPAT, 'ISO-8859-15');
}
else {
if ($node->hasChildNodes()) {
......
......@@ -57,9 +57,6 @@ class WebServiceGroupTest extends WebServiceTestBase {
// simple get groups by ID
function mahara_group_get_groups_by_id($client) {
error_log('getting groups by id');
$dbgroups = get_records_sql_array('SELECT * FROM {group} WHERE institution = ? AND shortname = ? AND deleted = 0', array('mahara', 'mytestgroup1'));
$groupids = array();
foreach ($dbgroups as $dbgroup) {
......@@ -75,9 +72,6 @@ class WebServiceGroupTest extends WebServiceTestBase {
// simple get all groups
function mahara_group_get_groups($client) {
error_log('getting all groups');
$function = 'mahara_group_get_groups';
$dbgroups = get_records_sql_array('SELECT * FROM {group} WHERE institution = ? AND shortname = ? AND deleted = 0', array('mahara', 'mytestgroup1'));
$params = array();
......@@ -88,8 +82,6 @@ class WebServiceGroupTest extends WebServiceTestBase {
// create user test
function mahara_group_create_groups($client) {
error_log('creating groups');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......@@ -184,8 +176,6 @@ class WebServiceGroupTest extends WebServiceTestBase {
// delete user test
function mahara_group_delete_groups($client) {
error_log('deleting groups');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......@@ -250,8 +240,6 @@ class WebServiceGroupTest extends WebServiceTestBase {
// update user test
function mahara_group_update_groups($client) {
error_log('updating groups');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......@@ -382,8 +370,6 @@ class WebServiceGroupTest extends WebServiceTestBase {
// update user test
function mahara_group_update_group_members($client) {
error_log('updating group members');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......
......@@ -58,7 +58,6 @@ class WebServiceInstitutionTest extends WebServiceTestBase {
// simple get users by ID
function mahara_institution_get_members($client) {
error_log('getting members');
require_once(get_config('docroot') . 'lib/searchlib.php');
$institution = new Institution('mahara');
......@@ -73,7 +72,6 @@ class WebServiceInstitutionTest extends WebServiceTestBase {
// simple get users by ID
function mahara_institution_get_requests($client) {
error_log('getting requests');
require_once(get_config('docroot') . 'lib/searchlib.php');
//Set test data
......@@ -93,8 +91,6 @@ class WebServiceInstitutionTest extends WebServiceTestBase {
// update user test
function mahara_institution_invite_members($client) {
error_log('invite members');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......@@ -114,8 +110,6 @@ class WebServiceInstitutionTest extends WebServiceTestBase {
// update user test
function mahara_institution_add_members($client) {
error_log('add members');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......@@ -139,8 +133,6 @@ class WebServiceInstitutionTest extends WebServiceTestBase {
// update user test
function mahara_institution_remove_members($client) {
error_log('remove members');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......@@ -163,8 +155,6 @@ class WebServiceInstitutionTest extends WebServiceTestBase {
// update user test
function mahara_institution_decline_members($client) {
error_log('decline members');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......
......@@ -82,9 +82,11 @@ class WebServiceTestBase extends MaharaUnitTest {
$USER->id = 1;
$USER->admin = 1;
if (!webservice_protocol_is_enabled('rest') || !webservice_protocol_is_enabled('xmlrpc') || !webservice_protocol_is_enabled('soap') || !webservice_protocol_is_enabled('oauth')) {
throw new Exception('Web Services have not been activated - cannot continue until all of them are activated');
}
set_config('webservice_enabled', true);
set_config('webservice_rest_enabled', true);
set_config('webservice_xmlrpc_enabled', true);
set_config('webservice_soap_enabled', true);
set_config('webservice_oauth_enabled', true);
//token to test
$this->servicename = 'test webservices';
......@@ -95,7 +97,18 @@ class WebServiceTestBase extends MaharaUnitTest {
$this->tearDown();
if (!$authinstance = get_record('auth_instance', 'institution', 'mahara', 'authname', 'webservice')) {
throw new Exception('missing authentication type: mahara/webservce - configure the mahara institution');
$authinstance = new stdClass();
$authinstance->instancename = 'webservice';
$authinstance->institution = 'mahara';
$authinstance->authname = 'webservice';
$lastinstance = get_records_array('auth_instance', 'institution', 'mahara', 'priority DESC', '*', '0', '1');
if ($lastinstance == false) {
$authinstance->priority = 0;
}
else {
$authinstance->priority = $lastinstance[0]->priority + 1;
}
$authinstance->id = insert_record('auth_instance', $authinstance, 'id', true);
}
$this->authinstance = $authinstance;
$this->institution = new Institution($authinstance->institution);
......@@ -103,7 +116,6 @@ class WebServiceTestBase extends MaharaUnitTest {
// create the new test user
if (!$dbuser = get_record('usr', 'username', $this->testuser)) {
db_begin();
error_log('creating test user');
$new_user = new StdClass;
$new_user->authinstance = $authinstance->id;
$new_user->username = $this->testuser;
......@@ -265,10 +277,10 @@ class WebServiceTestBase extends MaharaUnitTest {
* 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) {
print_r("Web service unit tests are not run as not setup.
(see /webservice/simpletest/testwebservice.php)");
log_debug("Web service unit tests are not run as not setup (see /webservice/simpletest/testwebservice.php)");
}
// need a token to test
......@@ -276,12 +288,12 @@ class WebServiceTestBase extends MaharaUnitTest {
// test the REST interface
if ($this->testrest) {
error_log("Testing REST");
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) {
error_log("Auth Type: " . $type);
log_debug("Auth Type: " . $type);
switch ($type) {
case 'token':
$restclient = new webservice_rest_client(get_config('wwwroot') . 'webservice/rest/server.php',
......@@ -316,7 +328,7 @@ class WebServiceTestBase extends MaharaUnitTest {
// test the XML-RPC interface
if ($this->testxmlrpc) {
error_log("Testing XML RPC");
log_debug("Testing XML RPC");
$this->timerxmlrpc = time();
require_once(get_config('docroot') . "webservice/xmlrpc/lib.php");
// iterate the token and user auth types
......@@ -344,7 +356,7 @@ class WebServiceTestBase extends MaharaUnitTest {
// test the SOAP interface
if ($this->testsoap) {
error_log("Testing SOAP");
log_debug("Testing SOAP");
$this->timersoap = time();
require_once(get_config('docroot') . "webservice/soap/lib.php");
......
......@@ -61,7 +61,9 @@ class WebServiceUserTest extends WebServiceTestBase {
error_log('getting users by id');
$dbusers = get_records_sql_array('SELECT u.id AS id FROM {usr} u INNER JOIN {auth_instance} ai ON u.authinstance = ai.id WHERE u.deleted = 0 AND ai.institution = \'mahara\'', null);
$dbusers = get_records_sql_array('SELECT u.id AS id FROM {usr} u
INNER JOIN {auth_instance} ai ON u.authinstance = ai.id
WHERE u.deleted = 0 AND ai.institution = \'mahara\'', array());
$users_in = array();
foreach ($dbusers as $dbuser) {
if ($dbuser->id == 0) continue;
......@@ -86,7 +88,9 @@ class WebServiceUserTest extends WebServiceTestBase {
error_log('getting all users');
$function = 'mahara_user_get_users';
$dbusers = get_records_sql_array('SELECT u.id AS id FROM {usr} u INNER JOIN {auth_instance} ai ON u.authinstance = ai.id WHERE u.deleted = 0 AND ai.institution = \'mahara\'', null);
$dbusers = get_records_sql_array('SELECT u.id AS id FROM {usr} u
INNER JOIN {auth_instance} ai ON u.authinstance = ai.id
WHERE u.deleted = 0 AND ai.institution = \'mahara\'', array());
$userids = array();
foreach ($dbusers as $dbuser) {
if ($dbuser->id == 0) continue;
......@@ -100,9 +104,6 @@ class WebServiceUserTest extends WebServiceTestBase {
// create user test
function mahara_user_create_users($client) {
error_log('creating users');
//Test data
//a full user: user1
$user1 = new stdClass();
......@@ -191,8 +192,6 @@ class WebServiceUserTest extends WebServiceTestBase {
// delete user test
function mahara_user_delete_users($client) {
error_log('deleting users');
//Set test data
//a full user: user1
if (!$authinstance = get_record('auth_instance', 'institution', 'mahara', 'authname', 'webservice')) {
......@@ -276,8 +275,6 @@ class WebServiceUserTest extends WebServiceTestBase {
// update user test
function mahara_user_update_users($client) {
error_log('updating users');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......@@ -332,7 +329,6 @@ class WebServiceUserTest extends WebServiceTestBase {
// update user test
function mahara_user_update_favourites($client) {
error_log('updating & reading favourites');
//Set test data
$dbuser1 = $this->create_user1_for_update();
$dbuser2 = $this->create_user2_for_update();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment