From 114f5f134b42e23ebeba3b9c4e8732f5e711e249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 14 Mar 2016 12:59:14 +0100 Subject: [PATCH] MDL-53461 assign: Fix intro images to be shown in the mobile app --- mod/assign/externallib.php | 2 +- mod/assign/tests/externallib_test.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index 4b8b29eecd9..36aa72af471 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -408,7 +408,7 @@ class mod_assign_external extends external_api { if ($assign->show_intro()) { list($assignment['intro'], $assignment['introformat']) = external_format_text($module->intro, - $module->introformat, $context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0); + $module->introformat, $context->id, 'mod_assign', 'intro', null); $fs = get_file_storage(); if ($files = $fs->get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index dbbd502397b..84a73873767 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -168,15 +168,23 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { 'category' => $category->id )); - // Create the assignment module. + // Create the assignment module with links to a filerecord. $assign1 = self::getDataGenerator()->create_module('assign', array( 'course' => $course1->id, 'name' => 'lightwork assignment', - 'intro' => 'the assignment intro text here', + 'intro' => 'the assignment intro text here link', + 'introformat' => FORMAT_HTML, 'markingworkflow' => 1, 'markingallocation' => 1 )); + // Add a file as assignment attachment. + $context = context_module::instance($assign1->cmid); + $filerecord = array('component' => 'mod_assign', 'filearea' => 'intro', 'contextid' => $context->id, 'itemid' => 0, + 'filename' => 'intro.txt', 'filepath' => '/'); + $fs = get_file_storage(); + $fs->create_file_from_string($filerecord, 'Test intro file'); + // Create manual enrolment record. $enrolid = $DB->insert_record('enrol', (object)array( 'enrol' => 'manual', @@ -218,7 +226,9 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { $this->assertEquals($assign1->id, $assignment['id']); $this->assertEquals($course1->id, $assignment['course']); $this->assertEquals('lightwork assignment', $assignment['name']); - $this->assertEquals('the assignment intro text here', $assignment['intro']); + $this->assertContains('the assignment intro text here', $assignment['intro']); + // Check the url of the file attatched. + $this->assertRegExp('/.*mod_assign\/intro\/intro\.txt.*/', $assignment['intro']); $this->assertEquals(1, $assignment['markingworkflow']); $this->assertEquals(1, $assignment['markingallocation']);