moodle2cc 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,6 @@
1
+ 2013-08-15 Version 0.1.10
2
+ * improve multiple dropdown question handling
3
+
1
4
  2013-08-01 Version 0.1.9
2
5
  * fix whitespace handling issue with mod_type
3
6
 
@@ -120,9 +120,22 @@ module Moodle2CC::Canvas
120
120
  material = RDiscount.new(material).to_html if question.format == 4 # markdown
121
121
  @material = material
122
122
 
123
- if @question_type == 'multiple_dropdowns_question' && !@answers.empty?
124
- responses = @answers[@length..-1]
125
- responses.each_with_index do |response, index|
123
+ if @question_type == 'multiple_dropdowns_question' && !@answers.empty? && @length
124
+ choices = @answers[0..(@length-1)]
125
+ if @length >= @answers.length || !choices.all?{|a| !!a.text.match(/^\d/)}
126
+ # the choices don't seem to be present, so construct them
127
+ choices = (1..@length).map do |i|
128
+ Moodle2CC::OpenStruct.new(
129
+ :id => "#{i}",
130
+ :text => "#{i}"
131
+ )
132
+ end
133
+ @responses = @answers
134
+ else
135
+ @responses = @answers[@length..-1]
136
+ end
137
+ @answers = choices
138
+ @responses.each_with_index do |response, index|
126
139
  @material << "\n#{response.text} [response#{index + 1}]"
127
140
  end
128
141
  end
@@ -231,16 +244,14 @@ module Moodle2CC::Canvas
231
244
  end
232
245
  end
233
246
  when 'multiple_dropdowns_question'
234
- answers = @answers[0...@length]
235
- responses = @answers[@length..-1]
236
- responses.each_with_index do |response, index|
247
+ @responses.each_with_index do |response, index|
237
248
  response_id = index + 1
238
249
  presentation_node.response_lid(:ident => "response_response#{response_id}") do |response_node|
239
250
  response_node.material do |material_node|
240
251
  material_node.mattext "response#{response_id}"
241
252
  end
242
253
  response_node.render_choice do |choice_node|
243
- answers.each do |answer|
254
+ @answers.each do |answer|
244
255
  choice_node.response_label(:ident => "#{response_id}#{answer.id}") do |label_node|
245
256
  label_node.material do |material_node|
246
257
  material_node.mattext answer.text, :texttype => 'text/html'
@@ -340,14 +351,12 @@ module Moodle2CC::Canvas
340
351
  condition_node.setvar('100', :varname => 'SCORE', :action => 'Set')
341
352
  end
342
353
  when 'multiple_dropdowns_question'
343
- answers = @answers[0...@length]
344
- responses = @answers[@length..-1]
345
- score = 100.0 / responses.length.to_f
346
- responses.each_with_index do |response, index|
354
+ score = 100.0 / @responses.length.to_f
355
+ @responses.each_with_index do |response, index|
347
356
  response_id = index + 1
348
357
  processing_node.respcondition do |condition_node|
349
358
  condition_node.conditionvar do |var_node|
350
- var_node.varequal "#{response_id}#{answers.first.id}", :respident => "response_response#{response_id}"
359
+ var_node.varequal "#{response_id}#{@answers.first.id}", :respident => "response_response#{response_id}"
351
360
  end
352
361
  condition_node.setvar "%.2f" % score, :varname => 'SCORE', :action => 'Add'
353
362
  end
@@ -1,3 +1,3 @@
1
1
  module Moodle2CC
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
@@ -74,6 +74,21 @@ module TestQuestionHelper
74
74
  @question.choices = [choice1, choice2, choice3, choice4, choice5]
75
75
  end
76
76
 
77
+ def multiple_dropdowns_question_without_choices!
78
+ @question.type = nil
79
+ @question.type_id = 8 # rate 1..5 question
80
+ @question.length = 3
81
+ @question.text = nil
82
+ @question.content = "This is a rating question but not formatted very well"
83
+ choice1 = Moodle2CC::Moodle::Question::Choice.new
84
+ choice1.id = 1
85
+ choice1.content = "this isn't actually a choice"
86
+ choice2 = Moodle2CC::Moodle::Question::Choice.new
87
+ choice2.id = 2
88
+ choice2.content = 'so add the choices automatically'
89
+ @question.choices = [choice1, choice2]
90
+ end
91
+
77
92
  def multiple_answers_question!
78
93
  @question.type = nil
79
94
  @question.type_id = 5 # check boxes question
@@ -142,6 +142,12 @@ class TestUnitCanvasQuestion < MiniTest::Unit::TestCase
142
142
  assert_equal "This is a rating question\nI test my code [response1]\nI am happy [response2]", question.material
143
143
  end
144
144
 
145
+ def test_it_converts_material_for_multiple_dropdowns_question_without_choices
146
+ multiple_dropdowns_question_without_choices!
147
+ question = Moodle2CC::Canvas::Question.new @question
148
+ assert_equal "This is a rating question but not formatted very well\nthis isn't actually a choice [response1]\nso add the choices automatically [response2]", question.material
149
+ end
150
+
145
151
  def test_it_converts_general_feedback
146
152
  @question.general_feedback = "This should be easy"
147
153
  question = Moodle2CC::Canvas::Question.new @question
@@ -662,6 +668,44 @@ class TestUnitCanvasQuestion < MiniTest::Unit::TestCase
662
668
  assert var, 'score does not exist for second answer'
663
669
  end
664
670
 
671
+ def test_it_creates_item_xml_for_multiple_dropdowns_question_without_choices
672
+ multiple_dropdowns_question_without_choices!
673
+
674
+ question = Moodle2CC::Canvas::Question.new @question
675
+ node = Builder::XmlMarkup.new
676
+ xml = Nokogiri::XML(question.create_item_xml(node))
677
+
678
+ # Responses
679
+ response = xml.root.xpath('presentation/response_lid[@ident="response_response1"]').first
680
+ assert response, 'first response for multiple dropdowns question does not exist'
681
+ assert response.xpath('material/mattext["response1"]').first, 'material text does not exist for multiple dropdowns question first response'
682
+ assert_equal '1', response.xpath('render_choice/response_label[@ident="11"]/material/mattext[@texttype="text/html"]').text
683
+ assert_equal '2', response.xpath('render_choice/response_label[@ident="12"]/material/mattext[@texttype="text/html"]').text
684
+ assert_equal '3', response.xpath('render_choice/response_label[@ident="13"]/material/mattext[@texttype="text/html"]').text
685
+ refute response.xpath('render_choice/response_label[4]').first, 'there should not be a response for answer text'
686
+ refute response.xpath('render_choice/response_label[5]').first, 'there should not be a response for answer text'
687
+
688
+ response = xml.root.xpath('presentation/response_lid[@ident="response_response2"]').first
689
+ assert response, 'second response for multiple dropdowns question does not exist'
690
+ assert response.xpath('material/mattext["response2"]').first, 'material text does not exist for multiple dropdowns question second response'
691
+ assert_equal '1', response.xpath('render_choice/response_label[@ident="21"]/material/mattext[@texttype="text/html"]').text
692
+ assert_equal '2', response.xpath('render_choice/response_label[@ident="22"]/material/mattext[@texttype="text/html"]').text
693
+ assert_equal '3', response.xpath('render_choice/response_label[@ident="23"]/material/mattext[@texttype="text/html"]').text
694
+ refute response.xpath('render_choice/response_label[4]').first, 'there should not be a response for answer text'
695
+ refute response.xpath('render_choice/response_label[5]').first, 'there should not be a response for answer text'
696
+
697
+ # Conditions
698
+ condition = xml.root.xpath('resprocessing/respcondition/conditionvar/varequal[@respident="response_response1" and text()="11"]/../..').first
699
+ assert condition, 'condition does not exist for first answer'
700
+ var = condition.xpath('setvar[@varname="SCORE" and @action="Add" and text()="50.00"]').first
701
+ assert var, 'score does not exist for first answer'
702
+
703
+ condition = xml.root.xpath('resprocessing/respcondition/conditionvar/varequal[@respident="response_response2" and text()="21"]/../..').first
704
+ assert condition, 'condition does not exist for first answer'
705
+ var = condition.xpath('setvar[@varname="SCORE" and @action="Add" and text()="50.00"]').first
706
+ assert var, 'score does not exist for second answer'
707
+ end
708
+
665
709
  def test_it_create_item_xml_for_multiple_answers_question
666
710
  multiple_answers_question!
667
711
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moodle2cc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-08-01 00:00:00.000000000 Z
14
+ date: 2013-08-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rubyzip