Permalink
Browse files

Adding testclients for create_group and add_groupmember

MDL-13142
MDL-13139
  • Loading branch information...
1 parent 8805a4f commit 37acca4dd252cf1ab50435ae014072a86550e8c6 pigui committed Jan 30, 2009
Showing with 139 additions and 0 deletions.
  1. +69 −0 webservice/rest/testclient/addgroupmember.php
  2. +70 −0 webservice/rest/testclient/creategroup.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ *
+ * Rest Test Client
+ *
+ * @author David Castro Garcia
+ * @author Ferran Recio Calderó
+ * @author Jordi Piguillem
+ */
+
+require_once ('config_rest.php');
+
+$params = array('groupid', 'userid');
+
+foreach ($params as $param) {
+ $$param = (isset($_POST[$param]))?$_POST[$param]:'';
+}
+
+start_interface("Add group member to group");
+?>
+
+<form action="addgroupmember.php" method="post">
+<table border="0">
+ <tr><td>Group id: </td><td><input type="text" name="groupid" value="<?php echo $groupid; ?>"/></td></tr>
+ <tr><td>User id: </td><td><input type="text" name="userid" value="<?php echo $userid; ?>"/></td></tr>
+ <tr><td></td><td><input type="submit" value="Add member"></td></tr>
+</table>
+</form>
+
+<?php
+
+if ($groupid && $userid) {
+
+ var_dump($CFG->serverurl.'/group/tmp_add_groupmember');
+
+
+ //we are asking for a token
+ $connectiondata['username'] = 'wsuser';
+ $connectiondata['password'] = 'wspassword';
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_get_token');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($connectiondata));
+ $token = curl_exec($ch);
+
+ $data['token'] = $token;
+ $data['groupid'] = $groupid;
+ $data['userid'] = $userid;
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/group/tmp_add_groupmember');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($data));
+ $out = curl_exec($ch);
+
+ $res = basicxml_xml_to_object($out);
+
+ show_object($res->result);
+
+ show_xml ($out);
+} else {
+ echo "<p>Fill the form first</p>";
+}
+
+end_interface();
+
+?>
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Created on 10/17/2008
+ *
+ * Rest Test Client
+ *
+ * @author David Castro Garcia
+ * @author Ferran Recio Calderó
+ * @author Jordi Piguillem
+ */
+
+require_once ('config_rest.php');
+
+$params = array('groupname', 'courseid');
+
+foreach ($params as $param) {
+ $$param = (isset($_POST[$param]))?$_POST[$param]:'';
+}
+
+start_interface("Create Group");
+?>
+
+<form action="creategroup.php" method="post">
+<table border="0">
+ <tr><td>Group name: </td><td><input type="text" name="groupname" value="<?php echo $groupname; ?>"/></td></tr>
+ <tr><td>Course id: </td><td><input type="text" name="courseid" value="<?php echo $groupid; ?>"/></td></tr>
+ <tr><td></td><td><input type="submit" value="Create Group"></td></tr>
+</table>
+</form>
+
+<?php
+
+if ($groupname && $courseid) {
+
+ var_dump($CFG->serverurl.'/group/tmp_create_group');
+
+
+ //we are asking for a token
+ $connectiondata['username'] = 'wsuser';
+ $connectiondata['password'] = 'wspassword';
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/user/tmp_get_token');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($connectiondata));
+ $token = curl_exec($ch);
+
+ $data['token'] = $token;
+ $data['groupname'] = $groupname;
+ $data['courseid'] = $courseid;
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $CFG->serverurl.'/group/tmp_create_group');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, format_postdata($data));
+ $out = curl_exec($ch);
+
+ $res = basicxml_xml_to_object($out);
+
+ show_object($res->groupid);
+
+ show_xml ($out);
+} else {
+ echo "<p>Fill the form first</p>";
+}
+
+end_interface();
+
+?>

0 comments on commit 37acca4

Please sign in to comment.