From 4e53bf22d53592d23fbfe73b63cb7debc9b67316 Mon Sep 17 00:00:00 2001
From: Tim Hunt
Date: Wed, 9 Jan 2013 18:05:59 +0000
Subject: [PATCH 1/1] Sample unit test.
---
question/format/xml/format.php | 4 ++--
question/format/xml/tests/xmlformat_test.php | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/question/format/xml/format.php b/question/format/xml/format.php
index 8532421..d4e3114 100644
--- a/question/format/xml/format.php
+++ b/question/format/xml/format.php
@@ -149,7 +149,7 @@ class qformat_xml extends qformat_default {
return $xml;
}
- protected function import_text_with_files($data, $path, $defaultvalue = '', $defaultformat = 'html') {
+ public function import_text_with_files($data, $path, $defaultvalue = '', $defaultformat = 'html') {
$text = $this->getpath($data,
array_merge($path, array('#', 'text', 0, '#')), $defaultvalue, true);
$format = $this->trans_format($this->getpath($data,
@@ -164,7 +164,7 @@ class qformat_xml extends qformat_default {
return $field;
}
- protected function import_files_as_draft($xml) {
+ public function import_files_as_draft($xml) {
global $USER;
$fs = get_file_storage();
diff --git a/question/format/xml/tests/xmlformat_test.php b/question/format/xml/tests/xmlformat_test.php
index 1c392e7..fd409c2 100644
--- a/question/format/xml/tests/xmlformat_test.php
+++ b/question/format/xml/tests/xmlformat_test.php
@@ -1401,4 +1401,30 @@ END;
$this->assert_same_xml($expectedxml, $xml);
}
+
+ public function test_import_files_as_draft() {
+ $this->resetAfterTest();
+ $this->setAdminUser();
+
+ $xml = <<
+ This text file contains the word 'Moodle'.
]]>
+ TW9vZGxl
+
+END;
+
+ $textxml = xmlize($xml);
+ $qo = new stdClass();
+
+ $importer = new qformat_xml();
+ $draftitemid = $importer->import_files_as_draft($textxml['questiontext']['#']['file']);
+ $files = file_get_drafarea_files($draftitemid);
+
+ $this->assertEquals(1, count($files->list));
+
+ $file = $files->list[0];
+ $this->assertEquals('moodle.txt', $file->filename);
+ $this->assertEquals('/', $file->filepath);
+ $this->assertEquals(6, $file->size);
+ }
}
--
1.7.9