moodle2cc 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +7 -0
- data/lib/moodle2cc.rb +3 -0
- data/lib/moodle2cc/canvas_cc/calculated_question_writer.rb +11 -0
- data/lib/moodle2cc/canvas_cc/matching_question_writer.rb +6 -4
- data/lib/moodle2cc/canvas_cc/models/assessment.rb +1 -1
- data/lib/moodle2cc/canvas_cc/models/calculated_question.rb +13 -1
- data/lib/moodle2cc/canvas_cc/models/course.rb +2 -2
- data/lib/moodle2cc/canvas_cc/models/multiple_dropdowns_question.rb +7 -0
- data/lib/moodle2cc/canvas_cc/models/page.rb +7 -1
- data/lib/moodle2cc/canvas_cc/models/question.rb +1 -0
- data/lib/moodle2cc/canvas_cc/multiple_answers_question_writer.rb +7 -6
- data/lib/moodle2cc/canvas_cc/multiple_dropdowns_question_writer.rb +30 -0
- data/lib/moodle2cc/canvas_cc/question_writer.rb +2 -1
- data/lib/moodle2cc/moodle2/extractor.rb +7 -0
- data/lib/moodle2cc/moodle2/models.rb +1 -1
- data/lib/moodle2cc/moodle2/models/course.rb +3 -2
- data/lib/moodle2cc/moodle2/models/label.rb +5 -5
- data/lib/moodle2cc/moodle2/models/questionnaire.rb +1 -1
- data/lib/moodle2cc/moodle2/models/quizzes.rb +1 -0
- data/lib/moodle2cc/moodle2/models/quizzes/calculated_question.rb +2 -1
- data/lib/moodle2cc/moodle2/models/quizzes/multichoice_question.rb +6 -0
- data/lib/moodle2cc/moodle2/models/quizzes/question.rb +1 -1
- data/lib/moodle2cc/moodle2/models/wiki.rb +10 -0
- data/lib/moodle2cc/moodle2/parsers.rb +1 -0
- data/lib/moodle2cc/moodle2/parsers/course_parser.rb +5 -5
- data/lib/moodle2cc/moodle2/parsers/parser_helper.rb +7 -2
- data/lib/moodle2cc/moodle2/parsers/question_parsers/calculated_parser.rb +11 -1
- data/lib/moodle2cc/moodle2/parsers/question_parsers/match_parser.rb +2 -1
- data/lib/moodle2cc/moodle2/parsers/question_parsers/multichoice_parser.rb +2 -0
- data/lib/moodle2cc/moodle2/parsers/questionnaire_parser.rb +5 -0
- data/lib/moodle2cc/moodle2/parsers/quiz_parser.rb +5 -0
- data/lib/moodle2cc/moodle2/parsers/section_parser.rb +5 -1
- data/lib/moodle2cc/moodle2/parsers/wiki_parser.rb +47 -0
- data/lib/moodle2cc/moodle2converter/assessment_converter.rb +6 -4
- data/lib/moodle2cc/moodle2converter/assignment_converter.rb +1 -1
- data/lib/moodle2cc/moodle2converter/book_converter.rb +4 -4
- data/lib/moodle2cc/moodle2converter/converter_helper.rb +14 -0
- data/lib/moodle2cc/moodle2converter/discussion_converter.rb +1 -1
- data/lib/moodle2cc/moodle2converter/feedback_converter.rb +3 -3
- data/lib/moodle2cc/moodle2converter/html_converter.rb +16 -1
- data/lib/moodle2cc/moodle2converter/label_converter.rb +2 -2
- data/lib/moodle2cc/moodle2converter/migrator.rb +70 -2
- data/lib/moodle2cc/moodle2converter/question_bank_converter.rb +1 -1
- data/lib/moodle2cc/moodle2converter/question_converters.rb +1 -0
- data/lib/moodle2cc/moodle2converter/question_converters/calculated_converter.rb +1 -0
- data/lib/moodle2cc/moodle2converter/question_converters/matching_converter.rb +3 -0
- data/lib/moodle2cc/moodle2converter/question_converters/multichoice_converter.rb +15 -0
- data/lib/moodle2cc/moodle2converter/question_converters/multiple_blanks_converter.rb +1 -1
- data/lib/moodle2cc/moodle2converter/question_converters/question_converter.rb +3 -5
- data/lib/moodle2cc/moodle2converter/questionnaire_converter.rb +44 -8
- data/lib/moodle2cc/moodle2converter/section_converter.rb +3 -3
- data/lib/moodle2cc/moodle2converter/wiki_converter.rb +37 -0
- data/lib/moodle2cc/version.rb +1 -1
- data/spec/moodle2cc/canvas_cc/calculated_question_writer_spec.rb +7 -0
- data/spec/moodle2cc/canvas_cc/matching_question_writer_spec.rb +2 -2
- data/spec/moodle2cc/canvas_cc/models/assessment_spec.rb +1 -1
- data/spec/moodle2cc/canvas_cc/models/calculated_question_spec.rb +25 -0
- data/spec/moodle2cc/canvas_cc/models/page_spec.rb +6 -0
- data/spec/moodle2cc/canvas_cc/multiple_answers_question_writer_spec.rb +4 -1
- data/spec/moodle2cc/canvas_cc/multiple_blanks_question_writer_spec.rb +1 -1
- data/spec/moodle2cc/canvas_cc/multiple_dropdowns_question_writer_spec.rb +46 -0
- data/spec/moodle2cc/moodle2/extractor_spec.rb +8 -0
- data/spec/moodle2cc/moodle2/models/label_spec.rb +4 -4
- data/spec/moodle2cc/moodle2/parsers/parser_helper_spec.rb +10 -0
- data/spec/moodle2cc/moodle2/parsers/question_parsers/calculated_parser_spec.rb +17 -0
- data/spec/moodle2cc/moodle2/parsers/questionnaire_parser_spec.rb +4 -0
- data/spec/moodle2cc/moodle2/parsers/quiz_parser_spec.rb +1 -1
- data/spec/moodle2cc/moodle2/parsers/wiki_parser_spec.rb +23 -0
- data/spec/moodle2cc/moodle2converter/assessment_converter_spec.rb +12 -7
- data/spec/moodle2cc/moodle2converter/converter_helper_spec.rb +5 -0
- data/spec/moodle2cc/moodle2converter/html_converter_spec.rb +7 -2
- data/spec/moodle2cc/moodle2converter/label_converter_spec.rb +17 -0
- data/spec/moodle2cc/moodle2converter/migrator_spec.rb +83 -2
- data/spec/moodle2cc/moodle2converter/question_converters/calculated_converter_spec.rb +2 -0
- data/spec/moodle2cc/moodle2converter/question_converters/matching_converter_spec.rb +2 -3
- data/spec/moodle2cc/moodle2converter/question_converters/multichoice_converter_spec.rb +26 -0
- data/spec/moodle2cc/moodle2converter/question_converters/question_converter_spec.rb +0 -3
- data/spec/moodle2cc/moodle2converter/wiki_converter_spec.rb +36 -0
- data/test/fixtures/moodle2/backup/activities/quiz_5/quiz.xml +1 -1
- data/test/fixtures/moodle2/backup/activities/wiki_58541/calendar.xml +3 -0
- data/test/fixtures/moodle2/backup/activities/wiki_58541/completion.xml +3 -0
- data/test/fixtures/moodle2/backup/activities/wiki_58541/grades.xml +7 -0
- data/test/fixtures/moodle2/backup/activities/wiki_58541/inforef.xml +47 -0
- data/test/fixtures/moodle2/backup/activities/wiki_58541/module.xml +28 -0
- data/test/fixtures/moodle2/backup/activities/wiki_58541/roles.xml +7 -0
- data/test/fixtures/moodle2/backup/activities/wiki_58541/wiki.xml +70 -0
- data/test/fixtures/moodle2/backup/moodle_backup.xml +7 -0
- metadata +33 -2
@@ -6,7 +6,7 @@ module Moodle2CC::Moodle2Converter
|
|
6
6
|
canvas_bank = Moodle2CC::CanvasCC::Models::QuestionBank.new
|
7
7
|
|
8
8
|
canvas_bank.identifier = generate_unique_identifier_for(moodle_category.id, QUESTION_BANK_SUFFIX)
|
9
|
-
canvas_bank.title = moodle_category.name
|
9
|
+
canvas_bank.title = truncate_text(moodle_category.name)
|
10
10
|
|
11
11
|
question_converter = Moodle2CC::Moodle2Converter::QuestionConverters::QuestionConverter.new
|
12
12
|
moodle_category.questions.each do |moodle_question|
|
@@ -3,6 +3,7 @@ module Moodle2CC::Moodle2Converter
|
|
3
3
|
require_relative 'question_converters/question_converter'
|
4
4
|
require_relative 'question_converters/calculated_converter'
|
5
5
|
require_relative 'question_converters/matching_converter'
|
6
|
+
require_relative 'question_converters/multichoice_converter'
|
6
7
|
require_relative 'question_converters/multiple_blanks_converter'
|
7
8
|
require_relative 'question_converters/numerical_converter'
|
8
9
|
require_relative 'question_converters/random_sa_converter'
|
@@ -9,6 +9,7 @@ module Moodle2CC::Moodle2Converter
|
|
9
9
|
canvas_question.correct_answer_format = moodle_question.correct_answer_format
|
10
10
|
canvas_question.correct_answer_length = moodle_question.correct_answer_length
|
11
11
|
canvas_question.dataset_definitions = moodle_question.dataset_definitions
|
12
|
+
canvas_question.var_sets = moodle_question.var_sets
|
12
13
|
canvas_question.tolerance = moodle_question.tolerance
|
13
14
|
canvas_question
|
14
15
|
end
|
@@ -13,6 +13,9 @@ module Moodle2CC::Moodle2Converter
|
|
13
13
|
copy[:question_text] ||= ''
|
14
14
|
copy[:question_text].gsub(/\{(.*?)\}/, '[\1]')
|
15
15
|
copy[:question_text] = RDiscount.new(copy[:question_text]).to_html if copy[:question_text_format].to_i == 4 # markdown
|
16
|
+
copy[:question_text] = Nokogiri::HTML(copy[:question_text]).text
|
17
|
+
copy[:answer_text] = Nokogiri::HTML(copy[:answer_text]).text
|
18
|
+
|
16
19
|
canvas_question.matches << copy
|
17
20
|
end
|
18
21
|
canvas_question
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Moodle2CC::Moodle2Converter
|
2
|
+
module QuestionConverters
|
3
|
+
class MultichoiceConverter < QuestionConverter
|
4
|
+
register_converter_type 'multichoice'
|
5
|
+
|
6
|
+
def create_canvas_question(question_type, moodle_question)
|
7
|
+
if moodle_question.single
|
8
|
+
Moodle2CC::CanvasCC::Models::Question.create('multiple_choice_question')
|
9
|
+
else
|
10
|
+
Moodle2CC::CanvasCC::Models::Question.create('multiple_answers_question')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -15,7 +15,6 @@ module Moodle2CC::Moodle2Converter
|
|
15
15
|
STANDARD_CONVERSIONS = {
|
16
16
|
'description' => 'text_only_question',
|
17
17
|
'essay' => 'essay_question',
|
18
|
-
'multichoice' => 'multiple_choice_question',
|
19
18
|
'shortanswer' => 'short_answer_question'
|
20
19
|
}
|
21
20
|
|
@@ -31,10 +30,10 @@ module Moodle2CC::Moodle2Converter
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def convert_question(moodle_question, question_type = nil)
|
34
|
-
canvas_question = create_canvas_question(question_type)
|
33
|
+
canvas_question = create_canvas_question(question_type, moodle_question)
|
35
34
|
canvas_question.identifier = generate_unique_identifier_for(moodle_question.id, '_quiz_question')
|
36
35
|
canvas_question.original_identifier = moodle_question.id
|
37
|
-
canvas_question.title = moodle_question.name
|
36
|
+
canvas_question.title = truncate_text(moodle_question.name)
|
38
37
|
canvas_question.general_feedback = moodle_question.general_feedback
|
39
38
|
canvas_question.answers = moodle_question.answers.map do |moodle_answer|
|
40
39
|
Moodle2CC::CanvasCC::Models::Answer.new(moodle_answer)
|
@@ -45,12 +44,11 @@ module Moodle2CC::Moodle2Converter
|
|
45
44
|
|
46
45
|
def convert_question_text(moodle_question)
|
47
46
|
material = moodle_question.question_text || ''
|
48
|
-
material = material.gsub(/\{(.*?)\}/, '[\1]')
|
49
47
|
material = RDiscount.new(material).to_html if moodle_question.question_text_format.to_i == 4 # markdown
|
50
48
|
material
|
51
49
|
end
|
52
50
|
|
53
|
-
def create_canvas_question(question_type = nil)
|
51
|
+
def create_canvas_question(question_type = nil, question = nil)
|
54
52
|
question_type ||= self.class.canvas_question_type
|
55
53
|
raise 'set canvas_question_type in question converter subclasses' unless question_type
|
56
54
|
Moodle2CC::CanvasCC::Models::Question.create(question_type)
|
@@ -5,7 +5,7 @@ module Moodle2CC::Moodle2Converter
|
|
5
5
|
def convert_questionnaire(moodle_questionnaire)
|
6
6
|
canvas_assessment = Moodle2CC::CanvasCC::Models::Assessment.new
|
7
7
|
canvas_assessment.identifier = generate_unique_identifier_for(moodle_questionnaire.id, QUESTIONNAIRE_ASSESSMENT_SUFFIX)
|
8
|
-
canvas_assessment.title = moodle_questionnaire.name
|
8
|
+
canvas_assessment.title = truncate_text(moodle_questionnaire.name)
|
9
9
|
canvas_assessment.description = moodle_questionnaire.intro
|
10
10
|
canvas_assessment.workflow_state = workflow_state(moodle_questionnaire.visible)
|
11
11
|
|
@@ -17,6 +17,7 @@ module Moodle2CC::Moodle2Converter
|
|
17
17
|
|
18
18
|
canvas_assessment.items = []
|
19
19
|
moodle_questionnaire.questions.each do |question|
|
20
|
+
next if question.deleted
|
20
21
|
if canvas_question = convert_questionnaire_question(question)
|
21
22
|
canvas_assessment.items << canvas_question
|
22
23
|
end
|
@@ -32,7 +33,7 @@ module Moodle2CC::Moodle2Converter
|
|
32
33
|
4 => 'multiple_choice_question', # radio buttons question
|
33
34
|
5 => 'multiple_answers_question', # check boxes question
|
34
35
|
6 => 'multiple_choice_question', # dropdown box question
|
35
|
-
8 => '
|
36
|
+
8 => 'multiple_dropdowns_question', # rate 1..5 question
|
36
37
|
9 => 'essay_question', # date question
|
37
38
|
10 => 'numerical_question', # numeric question
|
38
39
|
100 => 'text_only_question', # label question
|
@@ -43,16 +44,51 @@ module Moodle2CC::Moodle2Converter
|
|
43
44
|
|
44
45
|
canvas_question = Moodle2CC::CanvasCC::Models::Question.create(canvas_type)
|
45
46
|
canvas_question.identifier = generate_unique_identifier_for(moodle_question.id, "_questionnaire_question")
|
46
|
-
canvas_question.title = moodle_question.name
|
47
|
+
canvas_question.title = truncate_text(moodle_question.name)
|
47
48
|
canvas_question.material = moodle_question.content
|
48
49
|
canvas_question.answers = []
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
|
51
|
+
if canvas_type == 'multiple_dropdowns_question'
|
52
|
+
# rating scale question
|
53
|
+
convert_rating_question(moodle_question, canvas_question)
|
54
|
+
else
|
55
|
+
moodle_question.choices.each do |choice|
|
56
|
+
answer = Moodle2CC::CanvasCC::Models::Answer.new
|
57
|
+
answer.id = choice[:id]
|
58
|
+
answer.answer_text = choice[:content]
|
59
|
+
canvas_question.answers << answer
|
60
|
+
end
|
54
61
|
end
|
62
|
+
|
55
63
|
canvas_question
|
56
64
|
end
|
65
|
+
|
66
|
+
# For l..x rating questions
|
67
|
+
def convert_rating_question(moodle_question, canvas_question)
|
68
|
+
choices = create_rating_choices(moodle_question)
|
69
|
+
canvas_question.responses = []
|
70
|
+
|
71
|
+
moodle_question.choices.each_with_index do |answer, answer_idx|
|
72
|
+
response = {:id => "response#{answer_idx + 1}", :choices => []}
|
73
|
+
|
74
|
+
# add dropdown to the question text
|
75
|
+
canvas_question.material = canvas_question.material.to_s + "<p>#{answer[:content]} [#{response[:id]}]</p>"
|
76
|
+
|
77
|
+
choices.each_with_index do |choice, choice_idx|
|
78
|
+
response[:choices] << {:id => "#{moodle_question.id}_choice_#{answer_idx}_#{choice_idx}", :text => choice}
|
79
|
+
end
|
80
|
+
|
81
|
+
canvas_question.responses << response
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_rating_choices(moodle_question)
|
86
|
+
scale = (moodle_question.length || 5).to_i
|
87
|
+
choices = (1..scale).map(&:to_s)
|
88
|
+
if moodle_question.precise.to_i == 1
|
89
|
+
choices << "N/A"
|
90
|
+
end
|
91
|
+
choices
|
92
|
+
end
|
57
93
|
end
|
58
94
|
end
|
@@ -14,7 +14,7 @@ module Moodle2CC
|
|
14
14
|
def convert(moodle_section)
|
15
15
|
canvas_module = CanvasCC::Models::CanvasModule.new
|
16
16
|
canvas_module.identifier = generate_unique_identifier_for(moodle_section.id, MODULE_SUFFIX)
|
17
|
-
canvas_module.title = moodle_section.name
|
17
|
+
canvas_module.title = truncate_text(moodle_section.name)
|
18
18
|
canvas_module.workflow_state = workflow_state(moodle_section.visible)
|
19
19
|
|
20
20
|
canvas_module.module_items += convert_activity(moodle_section) if moodle_section.summary && !moodle_section.summary.strip.empty?
|
@@ -27,7 +27,7 @@ module Moodle2CC
|
|
27
27
|
def convert_to_summary_page(moodle_section)
|
28
28
|
canvas_page = CanvasCC::Models::Page.new
|
29
29
|
canvas_page.identifier = generate_unique_identifier_for_activity(moodle_section)
|
30
|
-
canvas_page.title = moodle_section.name
|
30
|
+
canvas_page.title = truncate_text(moodle_section.name)
|
31
31
|
canvas_page.workflow_state = workflow_state(moodle_section.visible)
|
32
32
|
canvas_page.editing_roles = CanvasCC::Models::Page::EDITING_ROLE_TEACHER
|
33
33
|
canvas_page.body = moodle_section.summary
|
@@ -48,7 +48,7 @@ module Moodle2CC
|
|
48
48
|
module_item = CanvasCC::Models::ModuleItem.new
|
49
49
|
module_item.identifier = generate_unique_identifier
|
50
50
|
module_item.workflow_state = workflow_state(moodle_activity.visible)
|
51
|
-
module_item.title = moodle_activity.name
|
51
|
+
module_item.title = truncate_text(moodle_activity.name)
|
52
52
|
unless moodle_activity.is_a? Moodle2::Models::Label
|
53
53
|
if moodle_activity.is_a? Moodle2::Models::ExternalUrl
|
54
54
|
module_item.identifierref = module_item.identifier
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Moodle2CC::Moodle2Converter
|
2
|
+
class WikiConverter
|
3
|
+
include ConverterHelper
|
4
|
+
|
5
|
+
def convert(moodle_wiki)
|
6
|
+
canvas_pages = []
|
7
|
+
|
8
|
+
moodle_wiki.pages.each do |moodle_page|
|
9
|
+
canvas_page = Moodle2CC::CanvasCC::Models::Page.new
|
10
|
+
canvas_page.identifier = generate_unique_identifier_for("#{moodle_wiki.id}#{moodle_page[:id]}") + PAGE_SUFFIX
|
11
|
+
canvas_page.page_name = truncate_text(moodle_page[:title])
|
12
|
+
canvas_page.workflow_state = workflow_state(moodle_wiki.visible)
|
13
|
+
canvas_page.editing_roles = 'teachers'
|
14
|
+
canvas_page.body = moodle_page[:content]
|
15
|
+
canvas_pages << canvas_page
|
16
|
+
end
|
17
|
+
|
18
|
+
if moodle_wiki.first_page_title.to_s.strip.length > 0 &&
|
19
|
+
(first_page = canvas_pages.detect{|page| page.title.to_s.strip == moodle_wiki.first_page_title.to_s.strip})
|
20
|
+
first_page.identifier = generate_unique_identifier_for("#{moodle_wiki.id}") + PAGE_SUFFIX
|
21
|
+
first_page.body = moodle_wiki.intro.to_s + first_page.body.to_s
|
22
|
+
first_page.page_name = moodle_wiki.name
|
23
|
+
else
|
24
|
+
first_page = Moodle2CC::CanvasCC::Models::Page.new
|
25
|
+
first_page.identifier = generate_unique_identifier_for("#{moodle_wiki.id}") + PAGE_SUFFIX
|
26
|
+
first_page.body = moodle_wiki.intro
|
27
|
+
first_page.workflow_state = workflow_state(moodle_wiki.visible)
|
28
|
+
first_page.editing_roles = 'teachers'
|
29
|
+
first_page.page_name = moodle_wiki.name
|
30
|
+
canvas_pages << first_page
|
31
|
+
end
|
32
|
+
|
33
|
+
canvas_pages
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/moodle2cc/version.rb
CHANGED
@@ -31,6 +31,8 @@ module Moodle2CC::CanvasCC
|
|
31
31
|
}
|
32
32
|
]
|
33
33
|
|
34
|
+
question.var_sets = [{:ident => '1', :vars => {'A' => '3.6', 'B' => '3.1'}}]
|
35
|
+
|
34
36
|
xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |node|
|
35
37
|
QuestionWriter.write_question(node, question)
|
36
38
|
end.doc
|
@@ -76,6 +78,11 @@ module Moodle2CC::CanvasCC
|
|
76
78
|
b_var = calculated.at_xpath('vars/var[@scale="1"][@name="B"]')
|
77
79
|
expect(b_var.at_xpath('min').text).to eq '10.0'
|
78
80
|
expect(b_var.at_xpath('max').text).to eq '20.0'
|
81
|
+
|
82
|
+
# Var sets
|
83
|
+
var_set = calculated.at_xpath('var_sets/var_set[@ident="3631"]')
|
84
|
+
expect(var_set.at_xpath('var[@name="A"]').text).to eq "3.6"
|
85
|
+
expect(var_set.at_xpath('var[@name="B"]').text).to eq "3.1"
|
79
86
|
end
|
80
87
|
end
|
81
88
|
end
|
@@ -24,12 +24,12 @@ module Moodle2CC::CanvasCC
|
|
24
24
|
expect(xml.at_xpath("item/itemmetadata/qtimetadata/qtimetadatafield[fieldlabel=\"question_type\" and fieldentry=\"#{question.question_type}\"]")).to_not be_nil
|
25
25
|
|
26
26
|
response = xml.at_xpath("item/presentation/response_lid[@ident=\"response_#{match1[:id]}\"]")
|
27
|
-
expect(response.at_xpath('material/mattext[@texttype="text/
|
27
|
+
expect(response.at_xpath('material/mattext[@texttype="text/plain"]').text).to eq match1[:question_text]
|
28
28
|
expect(response.at_xpath("render_choice/response_label[@ident=\"#{match1[:id]}\"]/material/mattext").text).to eq match1[:answer_text]
|
29
29
|
expect(response.at_xpath("render_choice/response_label[@ident=\"#{match2[:id]}\"]/material/mattext").text).to eq match2[:answer_text]
|
30
30
|
|
31
31
|
response = xml.at_xpath("item/presentation/response_lid[@ident=\"response_#{match2[:id]}\"]")
|
32
|
-
expect(response.at_xpath('material/mattext[@texttype="text/
|
32
|
+
expect(response.at_xpath('material/mattext[@texttype="text/plain"]').text).to eq match2[:question_text]
|
33
33
|
expect(response.at_xpath("render_choice/response_label[@ident=\"#{match1[:id]}\"]/material/mattext").text).to eq match1[:answer_text]
|
34
34
|
expect(response.at_xpath("render_choice/response_label[@ident=\"#{match2[:id]}\"]/material/mattext").text).to eq match2[:answer_text]
|
35
35
|
|
@@ -72,7 +72,7 @@ describe Moodle2CC::CanvasCC::Models::Assessment do
|
|
72
72
|
group.questions = [q2]
|
73
73
|
qb2.question_groups = [group]
|
74
74
|
|
75
|
-
subject.resolve_question_references([qb1, qb2])
|
75
|
+
subject.resolve_question_references!([qb1, qb2])
|
76
76
|
|
77
77
|
expect(subject.items.count).to eq 3
|
78
78
|
expect(subject.items[0].points_possible).to eq '2'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Moodle2CC::CanvasCC::Models::CalculatedQuestion do
|
4
|
+
|
5
|
+
context '#post_process!' do
|
6
|
+
it 'should replace {variables} with [variables] in material' do
|
7
|
+
subject.material = "{varname} {not * s valid var name and stuff}"
|
8
|
+
|
9
|
+
subject.post_process!
|
10
|
+
|
11
|
+
expect(subject.material).to eq "[varname] {not * s valid var name and stuff}"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should replace {variables} with variables in formulae (and strip =)' do
|
15
|
+
answer = Moodle2CC::CanvasCC::Models::Answer.new
|
16
|
+
answer.answer_text = "={A}*{B}"
|
17
|
+
subject.answers = [answer]
|
18
|
+
|
19
|
+
subject.post_process!
|
20
|
+
|
21
|
+
expect(subject.answers.first.answer_text).to eq "A*B"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -24,5 +24,11 @@ module Moodle2CC::CanvasCC::Models
|
|
24
24
|
expect(page.title).to eq 'My Page Name'
|
25
25
|
end
|
26
26
|
|
27
|
+
it "truncates urls that are too long" do
|
28
|
+
page.page_name = 'a' * 500
|
29
|
+
expected = "wiki_content/#{'a' * Moodle2CC::CanvasCC::Models::Page::MAX_URL_LENGTH}.html"
|
30
|
+
expect(page.href).to eq expected
|
31
|
+
end
|
32
|
+
|
27
33
|
end
|
28
34
|
end
|
@@ -14,12 +14,15 @@ module Moodle2CC::CanvasCC
|
|
14
14
|
answer1 = Moodle2CC::CanvasCC::Models::Answer.new
|
15
15
|
answer1.id = '1'
|
16
16
|
answer1.answer_text = 'something'
|
17
|
+
answer1.fraction = '0.5'
|
17
18
|
answer2 = Moodle2CC::CanvasCC::Models::Answer.new
|
18
19
|
answer2.id = '2'
|
19
20
|
answer2.answer_text = 'something else'
|
21
|
+
answer2.fraction = '0'
|
20
22
|
answer3 = Moodle2CC::CanvasCC::Models::Answer.new
|
21
23
|
answer3.id = '3'
|
22
24
|
answer3.answer_text = 'something something else'
|
25
|
+
answer3.fraction = '0.5'
|
23
26
|
question.answers = [answer1, answer2, answer3]
|
24
27
|
|
25
28
|
xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |node|
|
@@ -41,7 +44,7 @@ module Moodle2CC::CanvasCC
|
|
41
44
|
condition = xml.at_xpath("item/resprocessing/respcondition[@continue=\"No\"]")
|
42
45
|
expect(condition.at_xpath("conditionvar/and/varequal[@respident=\"response1\" and text()=\"#{answer1.id}\"]")).not_to be_nil
|
43
46
|
expect(condition.at_xpath("conditionvar/and/not/varequal[@respident=\"response1\" and text()=\"#{answer2.id}\"]")).not_to be_nil
|
44
|
-
expect(condition.at_xpath("conditionvar/and/
|
47
|
+
expect(condition.at_xpath("conditionvar/and/varequal[@respident=\"response1\" and text()=\"#{answer3.id}\"]")).not_to be_nil
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
@@ -5,7 +5,7 @@ module Moodle2CC::CanvasCC
|
|
5
5
|
|
6
6
|
let(:question) { Moodle2CC::CanvasCC::Models::Question.create('fill_in_multiple_blanks_question')}
|
7
7
|
|
8
|
-
it 'creates the question item xml for a
|
8
|
+
it 'creates the question item xml for a multiple blanks question' do
|
9
9
|
question.identifier = 4200
|
10
10
|
question.title = 'hello'
|
11
11
|
question.general_feedback = 'feedbacks'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Moodle2CC::CanvasCC
|
4
|
+
describe MultipleDropdownsQuestionWriter do
|
5
|
+
|
6
|
+
let(:question) { Moodle2CC::CanvasCC::Models::Question.create('multiple_dropdowns_question')}
|
7
|
+
|
8
|
+
it 'creates the question item xml for a multiple_dropdowns_question' do
|
9
|
+
question.identifier = 4200
|
10
|
+
question.title = 'hello'
|
11
|
+
question.general_feedback = 'feedbacks'
|
12
|
+
question.material = 'the first question is [response1] and the second is [response2]'
|
13
|
+
question.answers = []
|
14
|
+
question.responses = [
|
15
|
+
{:id => "response1", :choices => [
|
16
|
+
{:id => "3_choice_0_0", :text => "1"},
|
17
|
+
{:id => "3_choice_0_1", :text => "2"}
|
18
|
+
]},
|
19
|
+
{:id => "response2", :choices => [
|
20
|
+
{:id => "3_choice_1_0", :text => "1"},
|
21
|
+
{:id => "3_choice_1_1", :text => "2"}
|
22
|
+
]}
|
23
|
+
]
|
24
|
+
|
25
|
+
xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |node|
|
26
|
+
QuestionWriter.write_question(node, question)
|
27
|
+
end.doc
|
28
|
+
|
29
|
+
expect(xml.at_xpath('item/@ident').value).to eq question.identifier.to_s
|
30
|
+
expect(xml.at_xpath('item/@title').value).to eq question.title
|
31
|
+
expect(xml.at_xpath("item/itemmetadata/qtimetadata/qtimetadatafield[fieldlabel=\"question_type\" and fieldentry=\"#{question.question_type}\"]")).to_not be_nil
|
32
|
+
|
33
|
+
# first response
|
34
|
+
response = xml.xpath('item/presentation/response_lid')[0]
|
35
|
+
expect(response.attributes['ident'].value).to eq 'response_response1'
|
36
|
+
expect(response.at_xpath("render_choice/response_label[@ident=\"3_choice_0_0\"]/material/mattext[@texttype=\"text/plain\" and text()=\"1\"]")).not_to be_nil
|
37
|
+
expect(response.at_xpath("render_choice/response_label[@ident=\"3_choice_0_1\"]/material/mattext[@texttype=\"text/plain\" and text()=\"2\"]")).not_to be_nil
|
38
|
+
|
39
|
+
# second response
|
40
|
+
response = xml.xpath('item/presentation/response_lid')[1]
|
41
|
+
expect(response.attributes['ident'].value).to eq 'response_response2'
|
42
|
+
expect(response.at_xpath("render_choice/response_label[@ident=\"3_choice_1_0\"]/material/mattext[@texttype=\"text/plain\" and text()=\"1\"]")).not_to be_nil
|
43
|
+
expect(response.at_xpath("render_choice/response_label[@ident=\"3_choice_1_1\"]/material/mattext[@texttype=\"text/plain\" and text()=\"2\"]")).not_to be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -11,6 +11,7 @@ module Moodle2CC::Moodle2
|
|
11
11
|
Parsers::SectionParser.any_instance.stub(:parse)
|
12
12
|
Parsers::FileParser.any_instance.stub(:parse)
|
13
13
|
Parsers::PageParser.any_instance.stub(:parse)
|
14
|
+
Parsers::WikiParser.any_instance.stub(:parse)
|
14
15
|
Parsers::ForumParser.any_instance.stub(:parse)
|
15
16
|
Parsers::AssignmentParser.any_instance.stub(:parse)
|
16
17
|
Parsers::BookParser.any_instance.stub(:parse)
|
@@ -103,6 +104,13 @@ module Moodle2CC::Moodle2
|
|
103
104
|
expect(course.pages).to eq [page]
|
104
105
|
end
|
105
106
|
|
107
|
+
it 'parses wikis' do
|
108
|
+
wiki = Models::Wiki.new
|
109
|
+
Parsers::WikiParser.any_instance.stub(:parse).and_return([wiki])
|
110
|
+
extractor.extract {}
|
111
|
+
expect(course.wikis).to eq [wiki]
|
112
|
+
end
|
113
|
+
|
106
114
|
it 'parses forums' do
|
107
115
|
forum = Models::Forum.new
|
108
116
|
Parsers::ForumParser.any_instance.stub(:parse).and_return([forum])
|