mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Merge branch 'MDL-79041-master-2' of https://github.com/HuongNV13/moodle
This commit is contained in:
commit
336ec5580a
2
lib/amd/build/moodlenet/send_resource.min.js
vendored
2
lib/amd/build/moodlenet/send_resource.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -99,7 +99,7 @@ const responseFromMoodleNet = (status, resourceUrl = '') => {
|
||||
|
||||
if (status) {
|
||||
currentModal.setFooter(Templates.render('core/moodlenet/send_activity_modal_footer_view', {
|
||||
resourseurl: resourceUrl,
|
||||
resourceurl: resourceUrl,
|
||||
}));
|
||||
currentModal.showFooter();
|
||||
}
|
||||
|
@ -153,7 +153,10 @@ class moodlenet_send_activity extends external_api {
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return new external_single_structure([
|
||||
'status' => new external_value(PARAM_BOOL, 'Status: true if success'),
|
||||
'resourceurl' => new external_value(PARAM_URL, 'Resource URL from MoodleNet'),
|
||||
// We used PARAM_TEXT instead of PARAM_URL because the URL return from MoodleNet may contain some characters.
|
||||
// It does not match with PARAM_URL, but the URL still works.
|
||||
// Since we just show the response resource URL to the user for them to navigate to MoodleNet, it would be safe.
|
||||
'resourceurl' => new external_value(PARAM_TEXT, 'Resource URL from MoodleNet'),
|
||||
'warnings' => new external_warnings(),
|
||||
]);
|
||||
}
|
||||
|
@ -212,7 +212,10 @@ class moodlenet_send_course extends external_api {
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return new external_single_structure([
|
||||
'status' => new external_value(PARAM_BOOL, 'Status: true if success'),
|
||||
'resourceurl' => new external_value(PARAM_URL, 'Resource URL from MoodleNet'),
|
||||
// We used PARAM_TEXT instead of PARAM_URL because the URL return from MoodleNet may contain some characters.
|
||||
// It does not match with PARAM_URL, but the URL still works.
|
||||
// Since we just show the response resource URL to the user for them to navigate to MoodleNet, it would be safe.
|
||||
'resourceurl' => new external_value(PARAM_TEXT, 'Resource URL from MoodleNet'),
|
||||
'warnings' => new external_warnings(),
|
||||
]);
|
||||
}
|
||||
|
@ -95,7 +95,9 @@ class moodlenet_client {
|
||||
* Prepare the request data required for sharing a file to MoodleNet.
|
||||
* This creates an array in the format used by \core\httpclient options to send a multipart request.
|
||||
*
|
||||
* @param array $filedata An array of data relating to the file being shared (as prepared by ::prepare_share_contents).
|
||||
* @param string $filename Name of the file being shared.
|
||||
* @param string $mimetype Mime type of the file being shared.
|
||||
* @param StreamInterface $stream Stream of the file being shared.
|
||||
* @param string $resourcename The name of the resource being shared.
|
||||
* @param string $resourcedescription A description of the resource being shared.
|
||||
* @return array Data in the format required to send a file to MoodleNet using \core\httpclient.
|
||||
@ -105,7 +107,7 @@ class moodlenet_client {
|
||||
string $mimetype,
|
||||
StreamInterface $stream,
|
||||
string $resourcename,
|
||||
$resourcedescription,
|
||||
string $resourcedescription,
|
||||
): array {
|
||||
return [
|
||||
'headers' => [
|
||||
|
@ -16,11 +16,11 @@
|
||||
Render the footer for sharing activity
|
||||
Example context (json):
|
||||
{
|
||||
"resourseurl": "https://moodlenet.test/draft/activity.mbz"
|
||||
"resourceurl": "https://moodlenet.test/draft/activity.mbz"
|
||||
}
|
||||
}}
|
||||
<div class="moodlenet-action-buttons">
|
||||
<a class="btn btn-primary" href="{{resourseurl}}" target="_blank">
|
||||
<a class="btn btn-primary" href="{{resourceurl}}" target="_blank" rel="noopener noreferrer">
|
||||
{{#str}} moodlenet:gotomoodlenet, moodle {{/str}}
|
||||
</a>
|
||||
</div>
|
||||
|
@ -111,4 +111,61 @@ class moodlenet_send_activity_test extends externallib_advanced_testcase {
|
||||
$this->assertEquals($issuer->get('id'), $result['warnings'][0]['item']);
|
||||
$this->assertEquals(get_string('moodlenet:issuerisnotauthorized', 'moodle'), $result['warnings'][0]['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test execute_returns() method.
|
||||
*
|
||||
* @dataProvider return_resource_url_provider
|
||||
* @covers ::execute_returns
|
||||
*/
|
||||
public function test_moodlenet_send_activity_return_resource_url(bool $state, string $resourceurl) {
|
||||
$this->resetAfterTest();
|
||||
// Create dummy result with the resourceurl.
|
||||
$result = [
|
||||
'status' => true,
|
||||
'resourceurl' => $resourceurl,
|
||||
'warnings' => [],
|
||||
];
|
||||
if (!$state) {
|
||||
$this->expectException(\invalid_response_exception::class);
|
||||
}
|
||||
$result = external_api::clean_returnvalue(moodlenet_send_activity::execute_returns(), $result);
|
||||
if ($state) {
|
||||
$this->assertEquals($resourceurl, $result['resourceurl']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for test_moodlenet_send_activity_return_resource_url().
|
||||
*
|
||||
* @return array Test data.
|
||||
*/
|
||||
public function return_resource_url_provider(): array {
|
||||
return [
|
||||
'Success 1' => [
|
||||
true,
|
||||
'https://moodlenet.example.com/drafts/view/testactivity_backup.mbz',
|
||||
],
|
||||
'Success 2' => [
|
||||
true,
|
||||
'https://moodlenet.example.com/drafts/view/testactivity_backup with spaces.mbz',
|
||||
],
|
||||
'Success 3' => [
|
||||
true,
|
||||
'https://moodlenet.example.com/drafts/view/testactivity_backup with " character.mbz',
|
||||
],
|
||||
'Success 4' => [
|
||||
true,
|
||||
"https://moodlenet.example.com/drafts/view/testactivity_backup with ' character.mbz",
|
||||
],
|
||||
'Success 5' => [
|
||||
true,
|
||||
'https://moodlenet.example.com/drafts/view/testactivity_backup with < and > characters.mbz',
|
||||
],
|
||||
'Fail 1' => [
|
||||
false,
|
||||
'https://moodlenet.example.com/drafts/view/testactivity_backupwith<lang lang="en">a<a</lang>html.mbz',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -117,4 +117,61 @@ class moodlenet_send_course_test extends externallib_advanced_testcase {
|
||||
$this->assertEquals($issuer->get('id'), $result['warnings'][0]['item']);
|
||||
$this->assertEquals(get_string('moodlenet:issuerisnotauthorized', 'moodle'), $result['warnings'][0]['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test execute_returns() method.
|
||||
*
|
||||
* @dataProvider return_resource_url_provider
|
||||
* @covers ::execute_returns
|
||||
*/
|
||||
public function test_moodlenet_send_course_return_resource_url(bool $state, string $resourceurl) {
|
||||
$this->resetAfterTest();
|
||||
// Create dummy result with the resourceurl.
|
||||
$result = [
|
||||
'status' => true,
|
||||
'resourceurl' => $resourceurl,
|
||||
'warnings' => [],
|
||||
];
|
||||
if (!$state) {
|
||||
$this->expectException(\invalid_response_exception::class);
|
||||
}
|
||||
$result = external_api::clean_returnvalue(moodlenet_send_course::execute_returns(), $result);
|
||||
if ($state) {
|
||||
$this->assertEquals($resourceurl, $result['resourceurl']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for test_moodlenet_send_course_return_resource_url().
|
||||
*
|
||||
* @return array Test data.
|
||||
*/
|
||||
public function return_resource_url_provider(): array {
|
||||
return [
|
||||
'Success 1' => [
|
||||
true,
|
||||
'https://moodlenet.example.com/drafts/view/testcourse_backup.mbz',
|
||||
],
|
||||
'Success 2' => [
|
||||
true,
|
||||
'https://moodlenet.example.com/drafts/view/testcourse_backup with spaces.mbz',
|
||||
],
|
||||
'Success 3' => [
|
||||
true,
|
||||
'https://moodlenet.example.com/drafts/view/testcourse_backup with " character.mbz',
|
||||
],
|
||||
'Success 4' => [
|
||||
true,
|
||||
"https://moodlenet.example.com/drafts/view/testcourse_backup with ' character.mbz",
|
||||
],
|
||||
'Success 5' => [
|
||||
true,
|
||||
'https://moodlenet.example.com/drafts/view/testcourse_backup with < and > characters.mbz',
|
||||
],
|
||||
'Fail 1' => [
|
||||
false,
|
||||
'https://moodlenet.example.com/drafts/view/testcourse_backupwith<lang lang="en">a<a</lang>html.mbz',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user