|
@@ -2,7 +2,7 @@
|
|
/* For licensing terms, see /license.txt */
|
|
/* For licensing terms, see /license.txt */
|
|
/**
|
|
/**
|
|
* Set of unit tests for the web services
|
|
* Set of unit tests for the web services
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author Guillaume Viguier <guillaume.viguier@beeznest.com>
|
|
* @author Guillaume Viguier <guillaume.viguier@beeznest.com>
|
|
* @package chamilo.tests
|
|
* @package chamilo.tests
|
|
*/
|
|
*/
|
|
@@ -19,20 +19,20 @@ require_once(dirname(__FILE__).'/simpletest/autorun.php');
|
|
*/
|
|
*/
|
|
class TestSoapWebService extends UnitTestCase {
|
|
class TestSoapWebService extends UnitTestCase {
|
|
protected $_secret_key;
|
|
protected $_secret_key;
|
|
-
|
|
|
|
|
|
+
|
|
protected $_encrypt_method;
|
|
protected $_encrypt_method;
|
|
-
|
|
|
|
|
|
+
|
|
protected $_client;
|
|
protected $_client;
|
|
-
|
|
|
|
|
|
+
|
|
public function __construct() {
|
|
public function __construct() {
|
|
$configuration = $GLOBALS['_configuration'];
|
|
$configuration = $GLOBALS['_configuration'];
|
|
$security_key = $configuration['security_key'];
|
|
$security_key = $configuration['security_key'];
|
|
$ip_address = '::1';
|
|
$ip_address = '::1';
|
|
$this->_secret_key = sha1($ip_address.$security_key);
|
|
$this->_secret_key = sha1($ip_address.$security_key);
|
|
$this->_encrypt_method = $configuration['password_encryption'];
|
|
$this->_encrypt_method = $configuration['password_encryption'];
|
|
- $this->_client = new SoapClient($configuration['root_web'].'main/webservices/soap.php?wsdl');
|
|
|
|
|
|
+ $this->_client = new SoapClient(api_get_path(WEB_CODE_PATH).'webservices/soap.php?wsdl');
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected function getUserArray() {
|
|
protected function getUserArray() {
|
|
$user = array(
|
|
$user = array(
|
|
'firstname' => 'Guillaume',
|
|
'firstname' => 'Guillaume',
|
|
@@ -51,7 +51,7 @@ class TestSoapWebService extends UnitTestCase {
|
|
'extras' => array());
|
|
'extras' => array());
|
|
return $user;
|
|
return $user;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected function getCourseArray() {
|
|
protected function getCourseArray() {
|
|
$course = array(
|
|
$course = array(
|
|
'title' => 'My test course',
|
|
'title' => 'My test course',
|
|
@@ -66,7 +66,7 @@ class TestSoapWebService extends UnitTestCase {
|
|
'extras' => array());
|
|
'extras' => array());
|
|
return $course;
|
|
return $course;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected function getSessionArray() {
|
|
protected function getSessionArray() {
|
|
$end_date = date('Y') + 1;
|
|
$end_date = date('Y') + 1;
|
|
$end_date .= '-'.date('m-d');
|
|
$end_date .= '-'.date('m-d');
|
|
@@ -80,33 +80,33 @@ class TestSoapWebService extends UnitTestCase {
|
|
'visibility' => 1,
|
|
'visibility' => 1,
|
|
'user_id_field_name' => 'chamilo_user_id',
|
|
'user_id_field_name' => 'chamilo_user_id',
|
|
'user_id_value' => '1',
|
|
'user_id_value' => '1',
|
|
- 'session_id_field_name' => 'chamilo_session_id',
|
|
|
|
|
|
+ 'session_id_field_name' => 'chamilo_session_id',
|
|
'session_id_value' => '',
|
|
'session_id_value' => '',
|
|
'extras' => array());
|
|
'extras' => array());
|
|
return $session;
|
|
return $session;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected function soapCall($method, $arguments) {
|
|
protected function soapCall($method, $arguments) {
|
|
return $this->_client->__soapCall($method, $arguments);
|
|
return $this->_client->__soapCall($method, $arguments);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected function createUser() {
|
|
protected function createUser() {
|
|
$user = $this->getUserArray();
|
|
$user = $this->getUserArray();
|
|
$result = $this->soapCall('WSUser.CreateUser', array_merge(array('secret_key' => $this->_secret_key), $user));
|
|
$result = $this->soapCall('WSUser.CreateUser', array_merge(array('secret_key' => $this->_secret_key), $user));
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
protected function createCourse() {
|
|
protected function createCourse() {
|
|
$course = $this->getCourseArray();
|
|
$course = $this->getCourseArray();
|
|
$result = $this->soapCall('WSCourse.CreateCourse', array_merge(array('secret_key' => $this->_secret_key), $course));
|
|
$result = $this->soapCall('WSCourse.CreateCourse', array_merge(array('secret_key' => $this->_secret_key), $course));
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function testTest() {
|
|
public function testTest() {
|
|
$result = $this->soapCall('WS.test', array());
|
|
$result = $this->soapCall('WS.test', array());
|
|
$this->assertEqual($result, "success");
|
|
$this->assertEqual($result, "success");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function testInvalidKey() {
|
|
public function testInvalidKey() {
|
|
$secret_key = 'invalid';
|
|
$secret_key = 'invalid';
|
|
try {
|
|
try {
|
|
@@ -116,7 +116,7 @@ class TestSoapWebService extends UnitTestCase {
|
|
$this->pass();
|
|
$this->pass();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function testCreateUser() {
|
|
public function testCreateUser() {
|
|
$user = $this->getUserArray();
|
|
$user = $this->getUserArray();
|
|
$result = $this->soapCall('WSUser.CreateUser', array_merge(array('secret_key' => $this->_secret_key), $user));
|
|
$result = $this->soapCall('WSUser.CreateUser', array_merge(array('secret_key' => $this->_secret_key), $user));
|
|
@@ -124,7 +124,7 @@ class TestSoapWebService extends UnitTestCase {
|
|
//Delete user created
|
|
//Delete user created
|
|
$this->soapCall('WSUser.DeleteUser', array('secret_key' => $this->_secret_key, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => $result));
|
|
$this->soapCall('WSUser.DeleteUser', array('secret_key' => $this->_secret_key, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => $result));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function testCreateUserEncrypted() {
|
|
public function testCreateUserEncrypted() {
|
|
$user = $this->getUserArray();
|
|
$user = $this->getUserArray();
|
|
$user['encrypt_method'] = $this->_encrypt_method;
|
|
$user['encrypt_method'] = $this->_encrypt_method;
|
|
@@ -139,7 +139,7 @@ class TestSoapWebService extends UnitTestCase {
|
|
//Delete user created
|
|
//Delete user created
|
|
$this->soapCall('WSUser.DeleteUser', array('secret_key' => $this->_secret_key, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => $result));
|
|
$this->soapCall('WSUser.DeleteUser', array('secret_key' => $this->_secret_key, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => $result));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function testCourseCreation() {
|
|
public function testCourseCreation() {
|
|
$course = $this->getCourseArray();
|
|
$course = $this->getCourseArray();
|
|
$result = $this->soapCall('WSCourse.CreateCourse', array_merge(array('secret_key' => $this->_secret_key), $course));
|
|
$result = $this->soapCall('WSCourse.CreateCourse', array_merge(array('secret_key' => $this->_secret_key), $course));
|
|
@@ -147,7 +147,7 @@ class TestSoapWebService extends UnitTestCase {
|
|
// Delete course created
|
|
// Delete course created
|
|
$this->soapCall('WSCourse.DeleteCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => $result));
|
|
$this->soapCall('WSCourse.DeleteCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => $result));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/*public function testCourseSubscriptionAndUnsubscription() {
|
|
/*public function testCourseSubscriptionAndUnsubscription() {
|
|
//$course_id = $this->createCourse();
|
|
//$course_id = $this->createCourse();
|
|
//$user_id = $this->createUser();
|
|
//$user_id = $this->createUser();
|
|
@@ -155,7 +155,7 @@ class TestSoapWebService extends UnitTestCase {
|
|
//$this->soapCall('WSCourse.SubscribeUserToCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => 38, 'status' => 1));
|
|
//$this->soapCall('WSCourse.SubscribeUserToCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => 38, 'status' => 1));
|
|
//$this->soapCall('WSCourse.UnsubscribeUserFromCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => 38));
|
|
//$this->soapCall('WSCourse.UnsubscribeUserFromCourse', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => 38));
|
|
}*/
|
|
}*/
|
|
-
|
|
|
|
|
|
+
|
|
/*public function testCourseDescriptions() {
|
|
/*public function testCourseDescriptions() {
|
|
//$this->soapCall('WSCourse.EditCourseDescription', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'course_desc_id' => 1, 'course_desc_title' => 'My description', 'course_desc_content' => 'This is my new description'));
|
|
//$this->soapCall('WSCourse.EditCourseDescription', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'course_desc_id' => 1, 'course_desc_title' => 'My description', 'course_desc_content' => 'This is my new description'));
|
|
//$result = $this->soapCall('WSCourse.GetCourseDescriptions', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8));
|
|
//$result = $this->soapCall('WSCourse.GetCourseDescriptions', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8));
|
|
@@ -163,20 +163,20 @@ class TestSoapWebService extends UnitTestCase {
|
|
$result = $this->soapCall('WSCourse.ListCourses', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id'));
|
|
$result = $this->soapCall('WSCourse.ListCourses', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id'));
|
|
var_dump($result);
|
|
var_dump($result);
|
|
}*/
|
|
}*/
|
|
-
|
|
|
|
|
|
+
|
|
public function testSessionCreation() {
|
|
public function testSessionCreation() {
|
|
$session = $this->getSessionArray();
|
|
$session = $this->getSessionArray();
|
|
$result = $this->soapCall('WSSession.CreateSession', array_merge(array('secret_key' => $this->_secret_key), $session));
|
|
$result = $this->soapCall('WSSession.CreateSession', array_merge(array('secret_key' => $this->_secret_key), $session));
|
|
$this->assertIsA($result, 'int');
|
|
$this->assertIsA($result, 'int');
|
|
$this->soapCall('WSSession.DeleteSession', array('secret_key' => $this->_secret_key, 'session_id_field_name' => 'chamilo_session_id', 'session_id_value' => $result));
|
|
$this->soapCall('WSSession.DeleteSession', array('secret_key' => $this->_secret_key, 'session_id_field_name' => 'chamilo_session_id', 'session_id_value' => $result));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/*public function testUserSessionSubscriptionAndUnsubscription() {
|
|
/*public function testUserSessionSubscriptionAndUnsubscription() {
|
|
$this->soapCall('WSSession.UnsubscribeCourseFromSession', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'session_id_field_name' => 'chamilo_session_id', 'session_id_value' => 3));
|
|
$this->soapCall('WSSession.UnsubscribeCourseFromSession', array('secret_key' => $this->_secret_key, 'course_id_field_name' => 'chamilo_course_id', 'course_id_value' => 8, 'session_id_field_name' => 'chamilo_session_id', 'session_id_value' => 3));
|
|
//$this->soapCall('WSSession.UnsubscribeUserFromSession', array('secret_key' => $this->_secret_key, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => 38, 'session_id_field_name' => 'chamilo_session_id', 'session_id_value' => 3));
|
|
//$this->soapCall('WSSession.UnsubscribeUserFromSession', array('secret_key' => $this->_secret_key, 'user_id_field_name' => 'chamilo_user_id', 'user_id_value' => 38, 'session_id_field_name' => 'chamilo_session_id', 'session_id_value' => 3));
|
|
}*/
|
|
}*/
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|