mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-77959-master' of https://github.com/HuongNV13/moodle
This commit is contained in:
commit
5338fc591e
@ -120,13 +120,7 @@ class activity_sender {
|
||||
}
|
||||
|
||||
// MoodleNet only accept plaintext descriptions.
|
||||
$resourcedescription = $DB->get_field($this->cminfo->modname, 'intro', ['id' => $this->cminfo->instance]);
|
||||
$resourcedescription = strip_tags($resourcedescription);
|
||||
$resourcedescription = format_text(
|
||||
$resourcedescription,
|
||||
FORMAT_PLAIN,
|
||||
['context' => $coursecontext]
|
||||
);
|
||||
$resourcedescription = $this->get_resource_description($coursecontext);
|
||||
|
||||
$response = $this->moodlenetclient->create_resource_from_stored_file(
|
||||
$filedata,
|
||||
@ -206,4 +200,27 @@ class activity_sender {
|
||||
self::SHARE_FORMAT_BACKUP,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the description for the resource being created, in a supported text format.
|
||||
*
|
||||
* @param \context $coursecontext The course context being shared from.
|
||||
* @return string Converted activity description.
|
||||
*/
|
||||
protected function get_resource_description(
|
||||
\context $coursecontext,
|
||||
): string {
|
||||
global $PAGE, $DB;
|
||||
// We need to set the page context here because content_to_text and format_text will need the page context to work.
|
||||
$PAGE->set_context($coursecontext);
|
||||
|
||||
$intro = $DB->get_record($this->cminfo->modname, ['id' => $this->cminfo->instance], 'intro, introformat', MUST_EXIST);
|
||||
$processeddescription = strip_tags($intro->intro);
|
||||
$processeddescription = content_to_text(format_text(
|
||||
$processeddescription,
|
||||
$intro->introformat,
|
||||
), $intro->introformat);
|
||||
|
||||
return $processeddescription;
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,52 @@ class activity_sender_test extends \advanced_testcase {
|
||||
$this->assertInstanceOf(\stored_file::class, $package);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_resource_description method.
|
||||
*
|
||||
* @covers ::get_resource_description
|
||||
* @return void
|
||||
*/
|
||||
public function test_get_resource_description() {
|
||||
global $USER;
|
||||
$this->setAdminUser();
|
||||
|
||||
$activity = $this->generator->create_module('assign', [
|
||||
'course' => $this->course->id,
|
||||
'intro' => '<p>This is an example Moodle activity description.</p>
|
||||
<p> </p>
|
||||
<p>This is a formatted intro</p>
|
||||
<p> </p>
|
||||
<p>This thing has many lines.</p>
|
||||
<p> </p>
|
||||
<p>The last word of this sentence is in <strong>bold</strong></p>'
|
||||
]);
|
||||
|
||||
$httpclient = new http_client();
|
||||
$moodlenetclient = new moodlenet_client($httpclient, $this->mockoauthclient);
|
||||
|
||||
// Set get_resource_description method accessibility.
|
||||
$method = new ReflectionMethod(activity_sender::class, 'get_resource_description');
|
||||
$method->setAccessible(true);
|
||||
|
||||
// Test the processed description.
|
||||
$processeddescription = $method->invoke(new activity_sender(
|
||||
$activity->cmid,
|
||||
$USER->id,
|
||||
$moodlenetclient,
|
||||
$this->mockoauthclient,
|
||||
activity_sender::SHARE_FORMAT_BACKUP
|
||||
), $this->coursecontext);
|
||||
|
||||
$this->assertEquals('This is an example Moodle activity description.
|
||||
|
||||
This is a formatted intro
|
||||
|
||||
This thing has many lines.
|
||||
|
||||
The last word of this sentence is in bold', $processeddescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test share_activity() method.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user