]> git.mjollnir.org Git - moodle.git/commitdiff
Adding testclients for create_group and add_groupmember
authorpigui <pigui>
Fri, 30 Jan 2009 11:48:50 +0000 (11:48 +0000)
committerpigui <pigui>
Fri, 30 Jan 2009 11:48:50 +0000 (11:48 +0000)
MDL-13142
MDL-13139

webservice/rest/testclient/addgroupmember.php [new file with mode: 0644]
webservice/rest/testclient/creategroup.php [new file with mode: 0644]

diff --git a/webservice/rest/testclient/addgroupmember.php b/webservice/rest/testclient/addgroupmember.php
new file mode 100644 (file)
index 0000000..e769545
--- /dev/null
@@ -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();
+
+?>
diff --git a/webservice/rest/testclient/creategroup.php b/webservice/rest/testclient/creategroup.php
new file mode 100644 (file)
index 0000000..c02ef42
--- /dev/null
@@ -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();
+
+?>