Show
Notice: You need to be able to use CURL in a console and run SQL in a DB.
Setup
Login as admin.
Create a course "Course 1".
Create a teacher t1 user and enrolled in the Course 1.
Create a student s1 user and enrolled in the Course 1.
Ensure webservices is enabled (Site Administration > Advanced features), select "Enable Webservices" ( enablewebservices ).
Setup a webservices in Moodle (Site Administration ► Plugins ► Webservices > External Service).
Turn on the Rest protocol (Site Administration ► Plugins ► Webservices ► Manage protocols).
Enable "Mobile services": Site administration ► Mobile app ► Mobile settings
Click on Site administration ► Plugins ► Web services ► Manage tokens
Create two tokens, one for the teacher t1 and other for the student s1 to service (Mobile Service).
Testing Scenario 1: Teacher Call WS to get a valid export H5P and is not deployed in the site.
Login as admin.
Go to the "Course 1".
Add a new activity page,
Edit the page content of the new activity page and upload an H5P file attached in the issue arithmetic-quiz.h5p using the "Manage files" button in the Atto editor.
Now click the "Link" button, click "Browse repositories", select "Embedded files" and select the h5p file you just uploaded.
Save the changes.
Copy the URL of the h5p file.
Next, you can do a CURL REST in the console, call simulating a WS client:
You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.
curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURURLH5PFILE&frame=0&export=0©right=0&embed=0&wstoken=WSTOKENTEACHER' | python -m "json.tool"
Execute this SQL in the Database:
SELECT id, filename, filepath, filesize, mimetype, timemodified FROM mdl_files WHERE component LIKE 'core_h5p' AND filearea LIKE 'export' AND filename LIKE 'arithmetic-quiz%' ORDER BY timemodified DESC LIMIT 1;
Expected result: Check that the responses' values from the CURL call has the same values like the results from the SQL. The filename, filepath, filesize, mimetype and timemodified should be part of the files record response from CURL call.
Confirm that : the fileurl value in the response from the CURL call you should get the file using a new tab on the browser.
Testing Scenario 2: Student Call WS to get a valid export H5P and is already deployed in the site.
Login as admin.
Go to the "Course 1".
Add a new activity page,
Edit the page content of the new activity page and upload an H5P file attached in the issue find-the-words-7-7.h5p using the "Manage files" button in the Atto editor.
Now click the "Link" button, click "Browse repositories", select "Embedded files" and select the h5p file you just uploaded.
Save the changes.
Copy the URL of the h5p file.
Paste the next URL and change YOURURLH5PFILE for the url copied in step 7.
http://YOURMOODLESITE/h5p/embed.php?url=YOURURLH5PFILE
You have to see the H5P file. So, the H5P file has been deployed.
Next, you can do a CURL REST in the console, call simulating a WS client:
You need to replace the wstoken for the token created for the student in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.
curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURMOODLEURLH5P&embed=0&wstoken=STUDENTWSTOKEN' | python -m "json.tool"
Execute this SQL in the Database:
SELECT id, filename, filepath, filesize, mimetype, timemodified FROM mdl_files WHERE component LIKE 'core_h5p' AND filearea LIKE 'export' AND filename LIKE 'find-the-words%'
Expected result: Check that the responses' values from the CURL call has the same values like the results from the SQL. The filename, filepath, filesize, mimetype and timemodified should be part of the files record response from CURL call
Confirm that :the fileurl value in the response from the CURL call you should get the file using a new tab on the browser.
Testing Scenario 3: Call WS with an empty url.
Do a CURL REST in the console, call simulating a WS client:
You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance and the URL parameter will be empty.
curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=&frame=0&export=0©right=0&embed=0&wstoken=WSTOKENTEACHER' | python -m "json.tool"
Expected result: You have to get a response like thiis:
{
"files": [],
"warnings": [
{
"item": "",
"message": "Invalid H5P content URL.",
"warningcode": "0"
}
]
}
Testing Scenario 4: Call WS with an h5p file unknown.
Do a CURL REST in the console, call simulating a WS client:
You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance. For the URL parameter you could use the step 7 on the testing scenario 1 and change the name of the file for this, h5pfile.h5p.
curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURURLH5PFILE&frame=0&export=0©right=0&embed=0&wstoken=WSTOKENTEACHER' | python -m "json.tool"
Expected result: You have to get a response like this:
{
"files": [],
"warnings": [
{
"item": "http://localhost/m/h5pmobile_master/pluginfile.php/43/mod_page/content/2/h5pfile.h5p",
"message": "H5P file not found",
"warningcode": null
}
]
}
The item value has to be the same like your YOURURLH5PFILE.
Testing Scenario 5: Call WS with an invalid h5p.
Login as admin.
Go to the "Course 1".
Add a new activity page,
Edit the page content of the new activity page and upload an H5P file attached in the issue invalid.h5p using the "Manage files" button in the Atto editor.
Now click the "Link" button, click "Browse repositories", select "Embedded files" and select the h5p file you just uploaded.
Save the changes.
Copy the URL of the h5p file.
Next, you can do a CURL REST in the console, call simulating a WS client:
You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.
curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURMOODLEURLH5P&embed=0&wstoken=STUDENTWSTOKEN' | python -m "json.tool"
Expected result: You have to get a response like this:
{
"files": [],
"warnings": [
{
"item": "http://localhost/m/stable_master/pluginfile.php/649/mod_page/content/1/invalid.h5p",
"message": "File \"content/phet.html\" not allowed. Only files with the following extensions are allowed: json png jpg jpeg gif bmp tif tiff svg eot ttf woff woff2 otf webm mp4 ogg mp3 m4a wav txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile vtt webvtt.",
"warningcode": "notinwhitelist"
}
]
}