moodle2cc 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +37 -29
- data/lib/moodle2cc.rb +2 -0
- data/lib/moodle2cc/canvas_cc/assignment_writer.rb +2 -1
- data/lib/moodle2cc/canvas_cc/models/assessment.rb +14 -4
- data/lib/moodle2cc/canvas_cc/models/assignment.rb +1 -1
- data/lib/moodle2cc/canvas_cc/models/course.rb +7 -1
- data/lib/moodle2cc/canvas_cc/models/page.rb +5 -1
- data/lib/moodle2cc/canvas_cc/models/question.rb +3 -3
- data/lib/moodle2cc/canvas_cc/multiple_answers_question_writer.rb +40 -0
- data/lib/moodle2cc/canvas_cc/question_writer.rb +1 -0
- data/lib/moodle2cc/moodle2/extractor.rb +23 -0
- data/lib/moodle2cc/moodle2/models.rb +5 -1
- data/lib/moodle2cc/moodle2/models/choice.rb +12 -0
- data/lib/moodle2cc/moodle2/models/course.rb +8 -3
- data/lib/moodle2cc/moodle2/models/feedback.rb +15 -0
- data/lib/moodle2cc/moodle2/models/label.rb +66 -0
- data/lib/moodle2cc/moodle2/models/questionnaire.rb +19 -0
- data/lib/moodle2cc/moodle2/parsers.rb +3 -0
- data/lib/moodle2cc/moodle2/parsers/choice_parser.rb +52 -0
- data/lib/moodle2cc/moodle2/parsers/course_parser.rb +2 -0
- data/lib/moodle2cc/moodle2/parsers/feedback_parser.rb +54 -0
- data/lib/moodle2cc/moodle2/parsers/questionnaire_parser.rb +58 -0
- data/lib/moodle2cc/moodle2converter/assessment_converter.rb +37 -1
- data/lib/moodle2cc/moodle2converter/assignment_converter.rb +1 -1
- data/lib/moodle2cc/moodle2converter/book_converter.rb +1 -0
- data/lib/moodle2cc/moodle2converter/converter_helper.rb +7 -1
- data/lib/moodle2cc/moodle2converter/feedback_converter.rb +70 -0
- data/lib/moodle2cc/moodle2converter/folder_converter.rb +2 -1
- data/lib/moodle2cc/moodle2converter/glossary_converter.rb +3 -3
- data/lib/moodle2cc/moodle2converter/label_converter.rb +39 -0
- data/lib/moodle2cc/moodle2converter/migrator.rb +17 -3
- data/lib/moodle2cc/moodle2converter/question_converters/question_converter.rb +4 -1
- data/lib/moodle2cc/moodle2converter/questionnaire_converter.rb +58 -0
- data/lib/moodle2cc/moodle2converter/section_converter.rb +4 -3
- data/lib/moodle2cc/version.rb +1 -1
- data/spec/moodle2cc/canvas_cc/assignment_writer_spec.rb +2 -0
- data/spec/moodle2cc/canvas_cc/models/assessment_spec.rb +25 -18
- data/spec/moodle2cc/canvas_cc/multiple_answers_question_writer_spec.rb +47 -0
- data/spec/moodle2cc/moodle2/extractor_spec.rb +24 -0
- data/spec/moodle2cc/moodle2/models/label_spec.rb +71 -0
- data/spec/moodle2cc/moodle2/parsers/choice_parser_spec.rb +32 -0
- data/spec/moodle2cc/moodle2/parsers/course_parser_spec.rb +1 -0
- data/spec/moodle2cc/moodle2/parsers/feedback_parser_spec.rb +31 -0
- data/spec/moodle2cc/moodle2/parsers/questionnaire_parser_spec.rb +32 -0
- data/spec/moodle2cc/moodle2converter/assessment_converter_spec.rb +158 -3
- data/spec/moodle2cc/moodle2converter/converter_helper_spec.rb +24 -0
- data/spec/moodle2cc/moodle2converter/folder_converter_spec.rb +2 -0
- data/spec/moodle2cc/moodle2converter/glossary_converter_spec.rb +2 -3
- data/spec/moodle2cc/moodle2converter/label_converter_spec.rb +86 -0
- data/spec/moodle2cc/moodle2converter/migrator_spec.rb +2 -0
- data/spec/moodle2cc/moodle2converter/question_bank_converter_spec.rb +2 -2
- data/spec/moodle2cc/moodle2converter/question_converters/calculated_converter_spec.rb +1 -1
- data/spec/moodle2cc/moodle2converter/question_converters/matching_converter_spec.rb +1 -1
- data/spec/moodle2cc/moodle2converter/question_converters/multiple_blanks_converter_spec.rb +1 -1
- data/spec/moodle2cc/moodle2converter/question_converters/numerical_converter_spec.rb +1 -1
- data/spec/moodle2cc/moodle2converter/question_converters/question_converter_spec.rb +1 -1
- data/spec/moodle2cc/moodle2converter/question_converters/true_false_converter_spec.rb +1 -1
- data/spec/moodle2cc/moodle2converter/section_converter_spec.rb +7 -22
- data/test/fixtures/moodle2/backup/activities/choice_56547/calendar.xml +3 -0
- data/test/fixtures/moodle2/backup/activities/choice_56547/choice.xml +32 -0
- data/test/fixtures/moodle2/backup/activities/choice_56547/comments.xml +3 -0
- data/test/fixtures/moodle2/backup/activities/choice_56547/completion.xml +3 -0
- data/test/fixtures/moodle2/backup/activities/choice_56547/filters.xml +7 -0
- data/test/fixtures/moodle2/backup/activities/choice_56547/grades.xml +7 -0
- data/test/fixtures/moodle2/backup/activities/choice_56547/inforef.xml +3 -0
- data/test/fixtures/moodle2/backup/activities/choice_56547/module.xml +28 -0
- data/test/fixtures/moodle2/backup/activities/choice_56547/roles.xml +7 -0
- data/test/fixtures/moodle2/backup/activities/feedback_58588/feedback.xml +147 -0
- data/test/fixtures/moodle2/backup/activities/feedback_58588/filters.xml +7 -0
- data/test/fixtures/moodle2/backup/activities/feedback_58588/grades.xml +7 -0
- data/test/fixtures/moodle2/backup/activities/feedback_58588/inforef.xml +3 -0
- data/test/fixtures/moodle2/backup/activities/feedback_58588/module.xml +28 -0
- data/test/fixtures/moodle2/backup/activities/feedback_58588/roles.xml +7 -0
- data/test/fixtures/moodle2/backup/moodle_backup.xml +14 -0
- metadata +52 -2
@@ -14,13 +14,17 @@ module Moodle2CC::Moodle2Converter
|
|
14
14
|
cc_course.discussions += convert_discussions(moodle_course.forums)
|
15
15
|
cc_course.assignments += convert_assignments(moodle_course.assignments)
|
16
16
|
|
17
|
-
cc_course.
|
17
|
+
cc_course.mute_assignments! unless moodle_course.show_grades
|
18
|
+
|
19
|
+
cc_course.assessments += convert_assessments(moodle_course.quizzes, moodle_course.choices,
|
20
|
+
moodle_course.feedbacks, moodle_course.questionnaires)
|
18
21
|
cc_course.question_banks += convert_question_banks(moodle_course.question_categories)
|
19
22
|
cc_course.resolve_question_references
|
20
23
|
|
21
24
|
cc_course.pages += convert_sections_to_pages(moodle_course.sections)
|
22
25
|
cc_course.pages += convert_folders(moodle_course)
|
23
26
|
cc_course.pages += convert_books(moodle_course.books)
|
27
|
+
cc_course.pages += convert_labels(moodle_course.labels)
|
24
28
|
cc_course.pages += convert_glossaries(moodle_course)
|
25
29
|
|
26
30
|
cc_course.canvas_modules += convert_sections(moodle_course.sections)
|
@@ -82,15 +86,25 @@ module Moodle2CC::Moodle2Converter
|
|
82
86
|
books.map { |book| book_converter.convert_to_pages(book) }.flatten
|
83
87
|
end
|
84
88
|
|
89
|
+
def convert_labels(labels)
|
90
|
+
label_converter = Moodle2CC::Moodle2Converter::LabelConverter.new
|
91
|
+
labels.map { |label| label_converter.convert_to_pages(label) }.flatten
|
92
|
+
end
|
93
|
+
|
85
94
|
def convert_glossaries(moodle_course)
|
86
95
|
glossary_converter = Moodle2CC::Moodle2Converter::GlossaryConverter.new(moodle_course)
|
87
96
|
moodle_course.glossaries.map { |glossary| glossary_converter.convert(glossary) }
|
88
97
|
end
|
89
98
|
|
90
99
|
# convert quizzes to assessments
|
91
|
-
def convert_assessments(quizzes)
|
100
|
+
def convert_assessments(quizzes, choices, feedbacks, questionnaires)
|
92
101
|
assessment_converter = Moodle2CC::Moodle2Converter::AssessmentConverter.new
|
93
|
-
|
102
|
+
assessments = []
|
103
|
+
assessments += quizzes.map { |quiz| assessment_converter.convert_quiz(quiz) }
|
104
|
+
assessments += choices.map { |choice| assessment_converter.convert_choice(choice) }
|
105
|
+
assessments += feedbacks.map { |feedback| assessment_converter.convert_feedback(feedback) }
|
106
|
+
assessments += questionnaires.map { |questionnaire| assessment_converter.convert_questionnaire(questionnaire) }
|
107
|
+
assessments
|
94
108
|
end
|
95
109
|
|
96
110
|
# convert question categories to question banks
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Moodle2CC::Moodle2Converter
|
2
2
|
module QuestionConverters
|
3
3
|
class QuestionConverter
|
4
|
+
include ConverterHelper
|
5
|
+
|
4
6
|
class << self
|
5
7
|
attr_accessor :canvas_question_type
|
6
8
|
end
|
@@ -30,7 +32,8 @@ module Moodle2CC::Moodle2Converter
|
|
30
32
|
|
31
33
|
def convert_question(moodle_question, question_type = nil)
|
32
34
|
canvas_question = create_canvas_question(question_type)
|
33
|
-
canvas_question.identifier = moodle_question.id
|
35
|
+
canvas_question.identifier = generate_unique_identifier_for(moodle_question.id, '_quiz_question')
|
36
|
+
canvas_question.original_identifier = moodle_question.id
|
34
37
|
canvas_question.title = moodle_question.name
|
35
38
|
canvas_question.general_feedback = moodle_question.general_feedback
|
36
39
|
canvas_question.answers = moodle_question.answers.map do |moodle_answer|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Moodle2CC::Moodle2Converter
|
2
|
+
module QuestionnaireConverter
|
3
|
+
include ConverterHelper
|
4
|
+
|
5
|
+
def convert_questionnaire(moodle_questionnaire)
|
6
|
+
canvas_assessment = Moodle2CC::CanvasCC::Models::Assessment.new
|
7
|
+
canvas_assessment.identifier = generate_unique_identifier_for(moodle_questionnaire.id, QUESTIONNAIRE_ASSESSMENT_SUFFIX)
|
8
|
+
canvas_assessment.title = moodle_questionnaire.name
|
9
|
+
canvas_assessment.description = moodle_questionnaire.intro
|
10
|
+
canvas_assessment.workflow_state = workflow_state(moodle_questionnaire.visible)
|
11
|
+
|
12
|
+
canvas_assessment.lock_at = Time.at(Integer(moodle_questionnaire.close_date)) if moodle_questionnaire.close_date
|
13
|
+
canvas_assessment.unlock_at = Time.at(Integer(moodle_questionnaire.open_date)) if moodle_questionnaire.open_date
|
14
|
+
|
15
|
+
canvas_assessment.scoring_policy = 'keep_latest'
|
16
|
+
canvas_assessment.quiz_type = 'survey'
|
17
|
+
|
18
|
+
canvas_assessment.items = []
|
19
|
+
moodle_questionnaire.questions.each do |question|
|
20
|
+
if canvas_question = convert_questionnaire_question(question)
|
21
|
+
canvas_assessment.items << canvas_question
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
canvas_assessment
|
26
|
+
end
|
27
|
+
|
28
|
+
QUESTION_TYPE_ID_MAP = {
|
29
|
+
1 => 'true_false_question', # yes/no question
|
30
|
+
2 => 'essay_question', # text box question
|
31
|
+
3 => 'essay_question', # essay box question
|
32
|
+
4 => 'multiple_choice_question', # radio buttons question
|
33
|
+
5 => 'multiple_answers_question', # check boxes question
|
34
|
+
6 => 'multiple_choice_question', # dropdown box question
|
35
|
+
8 => 'multiple_choice_question', # rate 1..5 question
|
36
|
+
9 => 'essay_question', # date question
|
37
|
+
10 => 'numerical_question', # numeric question
|
38
|
+
100 => 'text_only_question', # label question
|
39
|
+
}
|
40
|
+
|
41
|
+
def convert_questionnaire_question(moodle_question)
|
42
|
+
return unless canvas_type = QUESTION_TYPE_ID_MAP[moodle_question.type_id.to_i]
|
43
|
+
|
44
|
+
canvas_question = Moodle2CC::CanvasCC::Models::Question.create(canvas_type)
|
45
|
+
canvas_question.identifier = generate_unique_identifier_for(moodle_question.id, "_questionnaire_question")
|
46
|
+
canvas_question.title = moodle_question.name
|
47
|
+
canvas_question.material = moodle_question.content
|
48
|
+
canvas_question.answers = []
|
49
|
+
moodle_question.choices.each do |choice|
|
50
|
+
answer = Moodle2CC::CanvasCC::Models::Answer.new
|
51
|
+
answer.id = choice[:id]
|
52
|
+
answer.answer_text = choice[:content]
|
53
|
+
canvas_question.answers << answer
|
54
|
+
end
|
55
|
+
canvas_question
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -3,7 +3,8 @@ module Moodle2CC
|
|
3
3
|
include Moodle2Converter::ConverterHelper
|
4
4
|
|
5
5
|
ACTIVITY_CONVERTERS = {
|
6
|
-
Moodle2::Models::Book => Moodle2Converter::BookConverter
|
6
|
+
Moodle2::Models::Book => Moodle2Converter::BookConverter,
|
7
|
+
Moodle2::Models::Label => Moodle2Converter::LabelConverter,
|
7
8
|
}
|
8
9
|
|
9
10
|
def initialize
|
@@ -30,7 +31,7 @@ module Moodle2CC
|
|
30
31
|
canvas_page.workflow_state = workflow_state(moodle_section.visible)
|
31
32
|
canvas_page.editing_roles = CanvasCC::Models::Page::EDITING_ROLE_TEACHER
|
32
33
|
canvas_page.body = moodle_section.summary
|
33
|
-
canvas_page.href = generate_unique_resource_path(CanvasCC::Models::Page::WIKI_CONTENT,
|
34
|
+
canvas_page.href = generate_unique_resource_path(CanvasCC::Models::Page::WIKI_CONTENT, Moodle2CC::CanvasCC::Models::Page.convert_name_to_url("#{moodle_section.name}-summary"))
|
34
35
|
|
35
36
|
canvas_page
|
36
37
|
end
|
@@ -49,7 +50,7 @@ module Moodle2CC
|
|
49
50
|
module_item.workflow_state = workflow_state(moodle_activity.visible)
|
50
51
|
module_item.title = moodle_activity.name
|
51
52
|
unless moodle_activity.is_a? Moodle2::Models::Label
|
52
|
-
if
|
53
|
+
if moodle_activity.is_a? Moodle2::Models::ExternalUrl
|
53
54
|
module_item.identifierref = module_item.identifier
|
54
55
|
module_item.url = moodle_activity.external_url.gsub(/\s/, '%20')
|
55
56
|
elsif moodle_activity.is_a? Moodle2::Models::Resource
|
data/lib/moodle2cc/version.rb
CHANGED
@@ -29,6 +29,7 @@ describe Moodle2CC::CanvasCC::AssignmentWriter do
|
|
29
29
|
assignment.peer_reviews = 'false'
|
30
30
|
assignment.automatic_peer_reviews = 'true'
|
31
31
|
assignment.grade_group_students_individually = 'false'
|
32
|
+
assignment.muted = true
|
32
33
|
|
33
34
|
subject.write
|
34
35
|
xml = Nokogiri::XML(File.read(File.join(work_dir, assignment.assignment_resource.files.select{ |f| f.split(//).last(4).join("").to_s == '.xml'}.first)))
|
@@ -51,6 +52,7 @@ describe Moodle2CC::CanvasCC::AssignmentWriter do
|
|
51
52
|
expect(xml.%('assignment/peer_reviews').text).to eq 'false'
|
52
53
|
expect(xml.%('assignment/automatic_peer_reviews').text).to eq 'true'
|
53
54
|
expect(xml.%('assignment/grade_group_students_individually').text).to eq 'false'
|
55
|
+
expect(xml.%('assignment/muted').text).to eq 'true'
|
54
56
|
|
55
57
|
end
|
56
58
|
|
@@ -19,23 +19,30 @@ describe Moodle2CC::CanvasCC::Models::Assessment do
|
|
19
19
|
it_behaves_like 'it has an attribute for', :question_references, []
|
20
20
|
it_behaves_like 'it has an attribute for', :items
|
21
21
|
|
22
|
-
it '
|
23
|
-
subject.stub(:
|
24
|
-
|
22
|
+
it 'returns both resources' do
|
23
|
+
subject.stub(:cc_assessment_resource) {:cc_resource}
|
24
|
+
subject.stub(:canvas_assessment_resource) {:canvas_resource}
|
25
|
+
expect(subject.resources).to eq [:cc_resource, :canvas_resource]
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
+
it 'creates resources' do
|
28
29
|
subject.identifier = 'assessment_id'
|
29
30
|
subject.title = 'My Assessment'
|
30
31
|
|
31
|
-
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
expect(
|
35
|
-
expect(
|
36
|
-
|
37
|
-
|
38
|
-
expect(
|
32
|
+
cc_resource = subject.cc_assessment_resource
|
33
|
+
expect(cc_resource).to be_a_kind_of Moodle2CC::CanvasCC::Models::Resource
|
34
|
+
expect(cc_resource.type).to eq 'imsqti_xmlv1p2/imscc_xmlv1p1/assessment'
|
35
|
+
expect(cc_resource.identifier).to eq 'assessment_id'
|
36
|
+
expect(cc_resource.dependencies).to include 'assessment_id_meta'
|
37
|
+
|
38
|
+
canvas_resource = subject.canvas_assessment_resource
|
39
|
+
expect(canvas_resource).to be_a_kind_of Moodle2CC::CanvasCC::Models::Resource
|
40
|
+
expect(canvas_resource.files.count).to eq 2
|
41
|
+
expect(canvas_resource.identifier).to eq 'assessment_id_meta'
|
42
|
+
expect(canvas_resource.type).to eq 'associatedcontent/imscc_xmlv1p1/learning-application-resource'
|
43
|
+
expect(canvas_resource.href).to eq 'assessment_id/assessment_meta.xml'
|
44
|
+
expect(canvas_resource.files).to include 'assessment_id/assessment_meta.xml'
|
45
|
+
expect(canvas_resource.files).to include 'non_cc_assessments/assessment_id.xml.qti'
|
39
46
|
end
|
40
47
|
|
41
48
|
it 'resolves assessment questions' do
|
@@ -49,14 +56,14 @@ describe Moodle2CC::CanvasCC::Models::Assessment do
|
|
49
56
|
|
50
57
|
qb1 = Moodle2CC::CanvasCC::Models::QuestionBank.new
|
51
58
|
q1 = Moodle2CC::CanvasCC::Models::Question.new
|
52
|
-
q1.
|
59
|
+
q1.original_identifier = '1'
|
53
60
|
q2 = Moodle2CC::CanvasCC::Models::Question.new
|
54
|
-
q2.
|
61
|
+
q2.original_identifier = '3'
|
55
62
|
qb1.questions = [q1, q2]
|
56
63
|
|
57
64
|
qb2 = Moodle2CC::CanvasCC::Models::QuestionBank.new
|
58
65
|
q3 = Moodle2CC::CanvasCC::Models::Question.new
|
59
|
-
q3.
|
66
|
+
q3.original_identifier = '2'
|
60
67
|
qb2.questions = [q3]
|
61
68
|
|
62
69
|
group = Moodle2CC::CanvasCC::Models::QuestionGroup.new
|
@@ -68,10 +75,10 @@ describe Moodle2CC::CanvasCC::Models::Assessment do
|
|
68
75
|
subject.resolve_question_references([qb1, qb2])
|
69
76
|
|
70
77
|
expect(subject.items.count).to eq 3
|
71
|
-
expect(subject.items.
|
72
|
-
expect(subject.items.
|
78
|
+
expect(subject.items[0].points_possible).to eq '2'
|
79
|
+
expect(subject.items[1].points_possible).to eq '3'
|
73
80
|
# should not include q2 because it's already part of the group
|
74
|
-
expect(subject.items.
|
81
|
+
expect(subject.items[2].points_per_item).to eq 2
|
75
82
|
end
|
76
83
|
|
77
84
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Moodle2CC::CanvasCC
|
4
|
+
describe MultipleAnswersQuestionWriter do
|
5
|
+
|
6
|
+
let(:question) { Moodle2CC::CanvasCC::Models::Question.create('multiple_answers_question')}
|
7
|
+
|
8
|
+
it 'creates the question item xml for a multiple_choice_question' do
|
9
|
+
question.identifier = 420
|
10
|
+
question.title = 'hello'
|
11
|
+
question.general_feedback = 'feedbacks'
|
12
|
+
question.material = 'materiaru'
|
13
|
+
|
14
|
+
answer1 = Moodle2CC::CanvasCC::Models::Answer.new
|
15
|
+
answer1.id = '1'
|
16
|
+
answer1.answer_text = 'something'
|
17
|
+
answer2 = Moodle2CC::CanvasCC::Models::Answer.new
|
18
|
+
answer2.id = '2'
|
19
|
+
answer2.answer_text = 'something else'
|
20
|
+
answer3 = Moodle2CC::CanvasCC::Models::Answer.new
|
21
|
+
answer3.id = '3'
|
22
|
+
answer3.answer_text = 'something something else'
|
23
|
+
question.answers = [answer1, answer2, answer3]
|
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
|
+
response = xml.at_xpath('item/presentation/response_lid')
|
34
|
+
expect(response.attributes['rcardinality'].value).to eq 'Multiple'
|
35
|
+
expect(response.attributes['ident'].value).to eq 'response1'
|
36
|
+
|
37
|
+
expect(response.at_xpath("render_choice/response_label[@ident=\"#{answer1.id}\"]/material/mattext[@texttype=\"text/html\" and text()=\"#{answer1.answer_text}\"]")).not_to be_nil
|
38
|
+
expect(response.at_xpath("render_choice/response_label[@ident=\"#{answer2.id}\"]/material/mattext[@texttype=\"text/html\" and text()=\"#{answer2.answer_text}\"]")).not_to be_nil
|
39
|
+
expect(response.at_xpath("render_choice/response_label[@ident=\"#{answer3.id}\"]/material/mattext[@texttype=\"text/html\" and text()=\"#{answer3.answer_text}\"]")).not_to be_nil
|
40
|
+
|
41
|
+
condition = xml.at_xpath("item/resprocessing/respcondition[@continue=\"No\"]")
|
42
|
+
expect(condition.at_xpath("conditionvar/and/varequal[@respident=\"response1\" and text()=\"#{answer1.id}\"]")).not_to be_nil
|
43
|
+
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/not/varequal[@respident=\"response1\" and text()=\"#{answer3.id}\"]")).not_to be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -17,6 +17,9 @@ module Moodle2CC::Moodle2
|
|
17
17
|
Parsers::FolderParser.any_instance.stub(:parse)
|
18
18
|
Parsers::QuestionCategoryParser.any_instance.stub(:parse)
|
19
19
|
Parsers::QuizParser.any_instance.stub(:parse)
|
20
|
+
Parsers::ChoiceParser.any_instance.stub(:parse)
|
21
|
+
Parsers::FeedbackParser.any_instance.stub(:parse)
|
22
|
+
Parsers::QuestionnaireParser.any_instance.stub(:parse)
|
20
23
|
Parsers::GlossaryParser.any_instance.stub(:parse)
|
21
24
|
Parsers::LabelParser.any_instance.stub(:parse)
|
22
25
|
Parsers::ExternalUrlParser.any_instance.stub(:parse)
|
@@ -144,6 +147,27 @@ module Moodle2CC::Moodle2
|
|
144
147
|
expect(course.quizzes).to eq [quiz]
|
145
148
|
end
|
146
149
|
|
150
|
+
it 'parses choices' do
|
151
|
+
choice = Models::Choice.new
|
152
|
+
Parsers::ChoiceParser.any_instance.stub(:parse).and_return([choice])
|
153
|
+
extractor.extract {}
|
154
|
+
expect(course.choices).to eq [choice]
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'parses feedbacks' do
|
158
|
+
feedback = Models::Feedback.new
|
159
|
+
Parsers::FeedbackParser.any_instance.stub(:parse).and_return([feedback])
|
160
|
+
extractor.extract {}
|
161
|
+
expect(course.feedbacks).to eq [feedback]
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'parses questionnaires' do
|
165
|
+
questionnaire = Models::Questionnaire.new
|
166
|
+
Parsers::QuestionnaireParser.any_instance.stub(:parse).and_return([questionnaire])
|
167
|
+
extractor.extract {}
|
168
|
+
expect(course.questionnaires).to eq [questionnaire]
|
169
|
+
end
|
170
|
+
|
147
171
|
it 'parses glossaries' do
|
148
172
|
glossary = Models::Glossary.new
|
149
173
|
Parsers::GlossaryParser.any_instance.stub(:parse).and_return([glossary])
|
@@ -9,5 +9,76 @@ module Moodle2CC::Moodle2::Models
|
|
9
9
|
it_behaves_like 'it has an attribute for', :intro_format
|
10
10
|
it_behaves_like 'it has an attribute for', :visible
|
11
11
|
|
12
|
+
|
13
|
+
describe '#process_for_conversion!' do
|
14
|
+
it 'should use the intro text if the name has no text' do
|
15
|
+
subject.name = '<hr>'
|
16
|
+
subject.intro = 'use me'
|
17
|
+
|
18
|
+
expect(subject.converted_title).to eq 'use me'
|
19
|
+
expect(subject.convert_to_page?).to eq false
|
20
|
+
expect(subject.convert_to_header?).to eq true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should use the intro text if the name is just "Label"' do
|
24
|
+
subject.name = 'Label'
|
25
|
+
subject.intro = 'use me'
|
26
|
+
|
27
|
+
expect(subject.converted_title).to eq 'use me'
|
28
|
+
expect(subject.convert_to_page?).to eq false
|
29
|
+
expect(subject.convert_to_header?).to eq true
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should use the intro text if the name was truncated' do
|
33
|
+
subject.name = ("a" * 50) + "..."
|
34
|
+
subject.intro = ("a" * 70)
|
35
|
+
|
36
|
+
expect(subject.converted_title).to eq ("a" * 70)
|
37
|
+
expect(subject.convert_to_page?).to eq false
|
38
|
+
expect(subject.convert_to_header?).to eq true
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should truncate the intro text if it is too long' do
|
42
|
+
subject.name = '<hr>'
|
43
|
+
subject.intro = ("a" * 90)
|
44
|
+
|
45
|
+
expect(subject.converted_title).to eq (("a" * 80) + '...')
|
46
|
+
expect(subject.convert_to_page?).to eq true
|
47
|
+
expect(subject.convert_to_header?).to eq false
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should come up with a label if there is nothing else' do
|
51
|
+
subject.name = '<hr>'
|
52
|
+
subject.intro = '<img src="somelinky">'
|
53
|
+
|
54
|
+
expect(subject.converted_title).to eq Moodle2CC::Moodle2::Models::Label::DEFAULT_PAGE_TITLE
|
55
|
+
expect(subject.convert_to_page?).to eq true
|
56
|
+
expect(subject.convert_to_header?).to eq false
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should not convert to anything if there is no content' do
|
60
|
+
subject.name = '<hr>'
|
61
|
+
subject.intro = '<br>'
|
62
|
+
|
63
|
+
expect(subject.convert_to_page?).to eq false
|
64
|
+
expect(subject.convert_to_header?).to eq false
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should not convert to page if the name and intro have the same text' do
|
68
|
+
subject.name = 'blah'
|
69
|
+
subject.intro = '<p>blah</p>'
|
70
|
+
|
71
|
+
expect(subject.convert_to_page?).to eq false
|
72
|
+
expect(subject.convert_to_header?).to eq true
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should convert to page if the intro has different text' do
|
76
|
+
subject.name = 'blah'
|
77
|
+
subject.intro = '<p>blah blah</p>'
|
78
|
+
|
79
|
+
expect(subject.convert_to_page?).to eq true
|
80
|
+
expect(subject.convert_to_header?).to eq false
|
81
|
+
end
|
82
|
+
end
|
12
83
|
end
|
13
84
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Moodle2CC::Moodle2::Parsers::ChoiceParser do
|
4
|
+
subject { Moodle2CC::Moodle2::Parsers::ChoiceParser.new(fixture_path(File.join('moodle2', 'backup'))) }
|
5
|
+
|
6
|
+
it 'should parse a choice activity' do
|
7
|
+
choices = subject.parse
|
8
|
+
expect(choices.count).to eq 1
|
9
|
+
choice = choices.first
|
10
|
+
|
11
|
+
expect(choice.id).to eq '1'
|
12
|
+
|
13
|
+
expect(choice.module_id).to eq '56547'
|
14
|
+
expect(choice.name).to eq 'Example Choice Activity'
|
15
|
+
expect(choice.intro).to eq 'Choice activity description'
|
16
|
+
expect(choice.intro_format).to eq '1'
|
17
|
+
expect(choice.time_open).to eq '0'
|
18
|
+
expect(choice.time_close).to eq '0'
|
19
|
+
expect(choice.time_modified).to eq '1376437841'
|
20
|
+
|
21
|
+
expect(choice.publish).to eq '0'
|
22
|
+
expect(choice.show_results).to eq '0'
|
23
|
+
expect(choice.display).to eq '1'
|
24
|
+
expect(choice.allow_update).to eq '1'
|
25
|
+
expect(choice.show_unanswered).to eq '1'
|
26
|
+
expect(choice.limit_answers).to eq '1'
|
27
|
+
expect(choice.completion_submit).to eq '0'
|
28
|
+
|
29
|
+
expect(choice.options).to eq ['Option 1', 'Option 2']
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|