canvas_cc 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/canvas_cc.gemspec +37 -0
  8. data/lib/canvas_cc/canvas/assessment.rb +124 -0
  9. data/lib/canvas_cc/canvas/assignment.rb +98 -0
  10. data/lib/canvas_cc/canvas/converter.rb +30 -0
  11. data/lib/canvas_cc/canvas/course.rb +143 -0
  12. data/lib/canvas_cc/canvas/discussion_topic.rb +64 -0
  13. data/lib/canvas_cc/canvas/label.rb +8 -0
  14. data/lib/canvas_cc/canvas/question.rb +492 -0
  15. data/lib/canvas_cc/canvas/question_bank.rb +57 -0
  16. data/lib/canvas_cc/canvas/question_group.rb +35 -0
  17. data/lib/canvas_cc/canvas/resource.rb +16 -0
  18. data/lib/canvas_cc/canvas/templates/assignment.html.erb +9 -0
  19. data/lib/canvas_cc/canvas/templates/syllabus.html.erb +9 -0
  20. data/lib/canvas_cc/canvas/templates/wiki_content.html.erb +10 -0
  21. data/lib/canvas_cc/canvas/web_content.rb +15 -0
  22. data/lib/canvas_cc/canvas/web_link.rb +16 -0
  23. data/lib/canvas_cc/canvas/wiki.rb +26 -0
  24. data/lib/canvas_cc/canvas_cc/assessment_writer.rb +82 -0
  25. data/lib/canvas_cc/canvas_cc/assignment_group_writer.rb +48 -0
  26. data/lib/canvas_cc/canvas_cc/assignment_writer.rb +68 -0
  27. data/lib/canvas_cc/canvas_cc/calculated_question_writer.rb +72 -0
  28. data/lib/canvas_cc/canvas_cc/canvas_export_writer.rb +18 -0
  29. data/lib/canvas_cc/canvas_cc/cartridge_creator.rb +60 -0
  30. data/lib/canvas_cc/canvas_cc/course_setting_writer.rb +35 -0
  31. data/lib/canvas_cc/canvas_cc/discussion_writer.rb +52 -0
  32. data/lib/canvas_cc/canvas_cc/essay_question_writer.rb +19 -0
  33. data/lib/canvas_cc/canvas_cc/file_meta_writer.rb +38 -0
  34. data/lib/canvas_cc/canvas_cc/ims_manifest_generator.rb +123 -0
  35. data/lib/canvas_cc/canvas_cc/matching_question_writer.rb +43 -0
  36. data/lib/canvas_cc/canvas_cc/models/answer.rb +12 -0
  37. data/lib/canvas_cc/canvas_cc/models/assessment.rb +102 -0
  38. data/lib/canvas_cc/canvas_cc/models/assignment.rb +30 -0
  39. data/lib/canvas_cc/canvas_cc/models/assignment_group.rb +9 -0
  40. data/lib/canvas_cc/canvas_cc/models/calculated_question.rb +19 -0
  41. data/lib/canvas_cc/canvas_cc/models/canvas_file.rb +22 -0
  42. data/lib/canvas_cc/canvas_cc/models/canvas_module.rb +10 -0
  43. data/lib/canvas_cc/canvas_cc/models/course.rb +53 -0
  44. data/lib/canvas_cc/canvas_cc/models/discussion.rb +36 -0
  45. data/lib/canvas_cc/canvas_cc/models/discussion_topic.rb +5 -0
  46. data/lib/canvas_cc/canvas_cc/models/matching_question.rb +7 -0
  47. data/lib/canvas_cc/canvas_cc/models/module_item.rb +16 -0
  48. data/lib/canvas_cc/canvas_cc/models/multiple_dropdowns_question.rb +7 -0
  49. data/lib/canvas_cc/canvas_cc/models/numerical_question.rb +7 -0
  50. data/lib/canvas_cc/canvas_cc/models/page.rb +41 -0
  51. data/lib/canvas_cc/canvas_cc/models/question.rb +37 -0
  52. data/lib/canvas_cc/canvas_cc/models/question_bank.rb +42 -0
  53. data/lib/canvas_cc/canvas_cc/models/question_group.rb +10 -0
  54. data/lib/canvas_cc/canvas_cc/models/resource.rb +23 -0
  55. data/lib/canvas_cc/canvas_cc/models/web_content.rb +7 -0
  56. data/lib/canvas_cc/canvas_cc/models/web_link.rb +7 -0
  57. data/lib/canvas_cc/canvas_cc/models/workflow_state.rb +6 -0
  58. data/lib/canvas_cc/canvas_cc/module_meta_writer.rb +52 -0
  59. data/lib/canvas_cc/canvas_cc/multiple_answers_question_writer.rb +41 -0
  60. data/lib/canvas_cc/canvas_cc/multiple_blanks_question_writer.rb +51 -0
  61. data/lib/canvas_cc/canvas_cc/multiple_choice_question_writer.rb +48 -0
  62. data/lib/canvas_cc/canvas_cc/multiple_dropdowns_question_writer.rb +30 -0
  63. data/lib/canvas_cc/canvas_cc/numerical_question_writer.rb +40 -0
  64. data/lib/canvas_cc/canvas_cc/page_writer.rb +38 -0
  65. data/lib/canvas_cc/canvas_cc/question_bank_writer.rb +44 -0
  66. data/lib/canvas_cc/canvas_cc/question_group_writer.rb +23 -0
  67. data/lib/canvas_cc/canvas_cc/question_writer.rb +129 -0
  68. data/lib/canvas_cc/canvas_cc/short_answer_question_writer.rb +42 -0
  69. data/lib/canvas_cc/canvas_cc/text_only_question_writer.rb +19 -0
  70. data/lib/canvas_cc/canvas_cc/true_false_question_writer.rb +38 -0
  71. data/lib/canvas_cc/cc/assessment.rb +25 -0
  72. data/lib/canvas_cc/cc/assignment.rb +61 -0
  73. data/lib/canvas_cc/cc/cc_helper.rb +285 -0
  74. data/lib/canvas_cc/cc/converter.rb +137 -0
  75. data/lib/canvas_cc/cc/course.rb +16 -0
  76. data/lib/canvas_cc/cc/discussion_topic.rb +53 -0
  77. data/lib/canvas_cc/cc/label.rb +6 -0
  78. data/lib/canvas_cc/cc/question.rb +23 -0
  79. data/lib/canvas_cc/cc/resource.rb +30 -0
  80. data/lib/canvas_cc/cc/templates/assignment.html.erb +13 -0
  81. data/lib/canvas_cc/cc/templates/syllabus.html.erb +9 -0
  82. data/lib/canvas_cc/cc/templates/wiki_content.html.erb +10 -0
  83. data/lib/canvas_cc/cc/web_content.rb +48 -0
  84. data/lib/canvas_cc/cc/web_link.rb +75 -0
  85. data/lib/canvas_cc/cc/wiki.rb +73 -0
  86. data/lib/canvas_cc/version.rb +3 -0
  87. data/lib/canvas_cc.rb +94 -0
  88. data/spec/moodle2cc/canvas_cc/assessment_writer_spec.rb +95 -0
  89. data/spec/moodle2cc/canvas_cc/assignment_group_writer_spec.rb +51 -0
  90. data/spec/moodle2cc/canvas_cc/assignment_writer_spec.rb +74 -0
  91. data/spec/moodle2cc/canvas_cc/calculated_question_writer_spec.rb +88 -0
  92. data/spec/moodle2cc/canvas_cc/canvas_export_writer_spec.rb +26 -0
  93. data/spec/moodle2cc/canvas_cc/cartridge_creator_spec.rb +50 -0
  94. data/spec/moodle2cc/canvas_cc/course_setting_writer_spec.rb +47 -0
  95. data/spec/moodle2cc/canvas_cc/discussion_writer_spec.rb +38 -0
  96. data/spec/moodle2cc/canvas_cc/essay_question_writer_spec.rb +31 -0
  97. data/spec/moodle2cc/canvas_cc/file_meta_writer_spec.rb +57 -0
  98. data/spec/moodle2cc/canvas_cc/ims_manifest_generator_spec.rb +141 -0
  99. data/spec/moodle2cc/canvas_cc/matching_question_writer_spec.rb +51 -0
  100. data/spec/moodle2cc/canvas_cc/models/assessment_spec.rb +131 -0
  101. data/spec/moodle2cc/canvas_cc/models/assignment_group_spec.rb +9 -0
  102. data/spec/moodle2cc/canvas_cc/models/assignment_spec.rb +45 -0
  103. data/spec/moodle2cc/canvas_cc/models/calculated_question_spec.rb +25 -0
  104. data/spec/moodle2cc/canvas_cc/models/canvas_file_spec.rb +23 -0
  105. data/spec/moodle2cc/canvas_cc/models/canvas_module_spec.rb +16 -0
  106. data/spec/moodle2cc/canvas_cc/models/course_spec.rb +43 -0
  107. data/spec/moodle2cc/canvas_cc/models/discussion_spec.rb +47 -0
  108. data/spec/moodle2cc/canvas_cc/models/discussion_topic_spec.rb +7 -0
  109. data/spec/moodle2cc/canvas_cc/models/module_item_spec.rb +15 -0
  110. data/spec/moodle2cc/canvas_cc/models/page_spec.rb +34 -0
  111. data/spec/moodle2cc/canvas_cc/models/question_spec.rb +8 -0
  112. data/spec/moodle2cc/canvas_cc/models/resource_spec.rb +17 -0
  113. data/spec/moodle2cc/canvas_cc/models/web_content_spec.rb +7 -0
  114. data/spec/moodle2cc/canvas_cc/models/web_link_spec.rb +9 -0
  115. data/spec/moodle2cc/canvas_cc/module_meta_writer_spec.rb +118 -0
  116. data/spec/moodle2cc/canvas_cc/multiple_answers_question_writer_spec.rb +50 -0
  117. data/spec/moodle2cc/canvas_cc/multiple_blanks_question_writer_spec.rb +77 -0
  118. data/spec/moodle2cc/canvas_cc/multiple_choice_question_writer_spec.rb +69 -0
  119. data/spec/moodle2cc/canvas_cc/multiple_dropdowns_question_writer_spec.rb +46 -0
  120. data/spec/moodle2cc/canvas_cc/numerical_question_writer_spec.rb +69 -0
  121. data/spec/moodle2cc/canvas_cc/page_writer_spec.rb +29 -0
  122. data/spec/moodle2cc/canvas_cc/question_bank_writer_spec.rb +43 -0
  123. data/spec/moodle2cc/canvas_cc/question_writer_spec.rb +129 -0
  124. data/spec/moodle2cc/canvas_cc/short_answer_question_writer_spec.rb +50 -0
  125. data/spec/moodle2cc/canvas_cc/text_only_question_writer_spec.rb +23 -0
  126. data/spec/moodle2cc/canvas_cc/true_false_question_writer_spec.rb +62 -0
  127. data/spec/spec_helper.rb +12 -0
  128. data/spec/support/shared_examples_for_models.rb +26 -0
  129. data/test/acceptance/migrator_test.rb +24 -0
  130. data/test/fixtures/cc.imscc +0 -0
  131. data/test/fixtures/common_cartridge/ims_manifest_simple.xml +45 -0
  132. data/test/fixtures/common_cartridge/schema/cccv1p0.xsd +563 -0
  133. data/test/fixtures/common_cartridge/schema/ccv1p1_imsccauth_v1p1.xsd +203 -0
  134. data/test/fixtures/common_cartridge/schema/ccv1p1_imscp_v1p2_v1p0.xsd +827 -0
  135. data/test/fixtures/common_cartridge/schema/ccv1p1_lommanifest_v1p0.xsd +822 -0
  136. data/test/fixtures/common_cartridge/schema/ccv1p1_lomresource_v1p0.xsd +273 -0
  137. data/test/fixtures/common_cartridge/schema/xml.xsd +286 -0
  138. data/test/test_helper.rb +71 -0
  139. data/test/test_question_helper.rb +122 -0
  140. data/test/test_wiki_helper.rb +21 -0
  141. data/test/unit/canvas/assessment_test.rb +261 -0
  142. data/test/unit/canvas/assignment_test.rb +220 -0
  143. data/test/unit/canvas/converter_test.rb +171 -0
  144. data/test/unit/canvas/course_test.rb +176 -0
  145. data/test/unit/canvas/discussion_topic_test.rb +129 -0
  146. data/test/unit/canvas/label_test.rb +32 -0
  147. data/test/unit/canvas/question_bank_test.rb +92 -0
  148. data/test/unit/canvas/question_group_test.rb +90 -0
  149. data/test/unit/canvas/question_test.rb +876 -0
  150. data/test/unit/canvas/web_content_test.rb +46 -0
  151. data/test/unit/canvas/web_link_test.rb +48 -0
  152. data/test/unit/canvas/wiki_test.rb +74 -0
  153. data/test/unit/cc/assessment_test.rb +48 -0
  154. data/test/unit/cc/assignment_test.rb +72 -0
  155. data/test/unit/cc/cc_helper_test.rb +19 -0
  156. data/test/unit/cc/converter_test.rb +173 -0
  157. data/test/unit/cc/course_test.rb +36 -0
  158. data/test/unit/cc/discussion_topic_test.rb +83 -0
  159. data/test/unit/cc/label_test.rb +29 -0
  160. data/test/unit/cc/question_test.rb +54 -0
  161. data/test/unit/cc/web_content_test.rb +76 -0
  162. data/test/unit/cc/web_link_test.rb +159 -0
  163. data/test/unit/cc/wiki_test.rb +139 -0
  164. data/test/unit/logger_test.rb +33 -0
  165. data/test/unit/migrator_test.rb +67 -0
  166. data/test/unit/resource_factory_test.rb +216 -0
  167. metadata +499 -0
@@ -0,0 +1,46 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCanvasWebContent < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup 'canvas'
11
+ @mod = @backup.course.mods.find { |m| m.mod_type == "resource" && m.type == "html" }
12
+ end
13
+
14
+ def teardown
15
+ clean_tmp_folder
16
+ end
17
+
18
+ def test_it_inherits_from_cc
19
+ assert CanvasCc::Canvas::WebContent.ancestors.include?(CanvasCc::CC::WebContent), 'does not inherit from base CC class'
20
+ end
21
+
22
+ def test_it_creates_item_in_module_meta
23
+ web_content = CanvasCc::Canvas::WebContent.new @mod
24
+ node = Builder::XmlMarkup.new
25
+ xml = Nokogiri::XML(web_content.create_module_meta_item_node(node, 5))
26
+
27
+ assert_equal 'item', xml.root.name
28
+ assert_equal 'i6f06dd1384233e65fa28bd11b97c8b16', xml.root.attributes['identifier'].value
29
+ assert_equal "Instructor Resources", xml.root.xpath('title').text
30
+ assert_equal '5', xml.root.xpath('position').text
31
+ assert_equal '', xml.root.xpath('new_tab').text
32
+ assert_equal '1', xml.root.xpath('indent').text
33
+ assert_equal 'WikiPage', xml.root.xpath('content_type').text
34
+ assert_equal 'i6447ff05ab6e342a42302007a6e3bcb4', xml.root.xpath('identifierref').text
35
+ end
36
+
37
+ def test_it_creates_web_content_item_from_link_with_summary
38
+ mod = @backup.course.mods.find { |m| m.mod_type == "resource" &&
39
+ (!m.summary.nil? && m.summary.length != 0)}
40
+ mod.type = 'file'
41
+ web_content = CanvasCc::Canvas::WebContent.new mod
42
+
43
+ assert web_content.body.include?(mod.reference)
44
+ assert web_content.body.include?(mod.summary)
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCanvasWebLink < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup 'canvas'
11
+ @mod = @backup.course.mods.find { |m| m.mod_type == "resource" && m.type == "file" }
12
+ end
13
+
14
+ def teardown
15
+ clean_tmp_folder
16
+ end
17
+
18
+ def test_it_inherits_from_cc
19
+ assert CanvasCc::Canvas::WebLink.ancestors.include?(CanvasCc::CC::WebLink), 'does not inherit from base CC class'
20
+ end
21
+
22
+
23
+ def test_it_creates_item_in_module_meta
24
+ @mod.reference = "http://www.google.com/some-doc.html"
25
+ web_link = CanvasCc::Canvas::WebLink.new @mod
26
+ node = Builder::XmlMarkup.new
27
+ xml = Nokogiri::XML(web_link.create_module_meta_item_node(node, 5))
28
+
29
+ assert_equal 'item', xml.root.name
30
+ assert_equal 'i966437b815a49aad86a356bc8aa8f24a', xml.root.attributes['identifier'].value
31
+ assert_equal "About Your Instructor", xml.root.xpath('title').text
32
+ assert_equal '5', xml.root.xpath('position').text
33
+ assert_equal '', xml.root.xpath('new_tab').text
34
+ assert_equal '1', xml.root.xpath('indent').text
35
+ assert_equal 'http://www.google.com/some-doc.html', xml.root.xpath('url').text
36
+ assert_equal 'ExternalUrl', xml.root.xpath('content_type').text
37
+ assert_equal 'i15aaccec404aa2ad557108a689bbba8f', xml.root.xpath('identifierref').text
38
+
39
+ @mod.reference = "some/local/file.html"
40
+ web_link = CanvasCc::Canvas::WebLink.new @mod
41
+ node = Builder::XmlMarkup.new
42
+ xml = Nokogiri::XML(web_link.create_module_meta_item_node(node, 5))
43
+
44
+ assert_equal '', xml.root.xpath('url').text
45
+ assert_equal 'Attachment', xml.root.xpath('content_type').text
46
+ end
47
+
48
+ end
@@ -0,0 +1,74 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'test_wiki_helper'
5
+ require 'moodle2cc'
6
+
7
+ class TestUnitCanvasWiki < MiniTest::Unit::TestCase
8
+ include TestHelper
9
+ include TestWikiHelper
10
+
11
+ def setup
12
+ convert_moodle_backup 'canvas'
13
+ @mod = @backup.course.mods.find { |m| m.mod_type == "wiki" }
14
+ @wiki = CanvasCc::Canvas::Wiki.new @mod
15
+ end
16
+
17
+ def teardown
18
+ clean_tmp_folder
19
+ end
20
+
21
+ def test_it_inherits_from_cc
22
+ assert CanvasCc::Canvas::Wiki.ancestors.include?(CanvasCc::CC::Wiki), 'does not inherit from base CC class'
23
+ end
24
+
25
+ def test_it_converts_pages
26
+ pages!
27
+ wiki = CanvasCc::Canvas::Wiki.new @mod
28
+ assert_equal 2, wiki.pages.length
29
+
30
+ assert_equal 'My Wiki', wiki.pages[0].title
31
+ assert_equal 'Second version', wiki.pages[0].body
32
+ assert_equal 'wiki_content/my-wiki-my-wiki.html', wiki.pages[0].href
33
+ assert_equal 'i56eb35e2b44710c48f7aa6b6297e9c98', wiki.pages[0].identifier
34
+
35
+ assert_equal 'New Page', wiki.pages[1].title
36
+ assert_equal 'This is a link to <a href="%24WIKI_REFERENCE%24/wiki/my-wiki-my-wiki" title="My Wiki">My Wiki</a>', wiki.pages[1].body
37
+ assert_equal 'wiki_content/my-wiki-new-page.html', wiki.pages[1].href
38
+ assert_equal 'i56eb35e2b44710c48f7aa6b6297e9c98', wiki.pages[0].identifier
39
+ end
40
+
41
+
42
+ def test_it_creates_item_in_module_meta
43
+ wiki = CanvasCc::Canvas::Wiki.new @mod
44
+ node = Builder::XmlMarkup.new
45
+ xml = Nokogiri::XML(wiki.create_module_meta_item_node(node, 5))
46
+
47
+ assert_equal 'item', xml.root.name
48
+ assert_equal 'i7b382ae83ddb7cc9be1a12e517088bc4', xml.root.attributes['identifier'].value
49
+ assert_equal "My wiki", xml.root.xpath('title').text
50
+ assert_equal '5', xml.root.xpath('position').text
51
+ assert_equal '', xml.root.xpath('new_tab').text
52
+ assert_equal '0', xml.root.xpath('indent').text
53
+ assert_equal 'WikiPage', xml.root.xpath('content_type').text
54
+ assert_equal 'i56eb35e2b44710c48f7aa6b6297e9c98', xml.root.xpath('identifierref').text
55
+ end
56
+
57
+ def test_it_creates_wiki_html
58
+ wiki = CanvasCc::Canvas::Wiki.new @mod
59
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
60
+ wiki.create_html(tmp_dir)
61
+
62
+ html = Nokogiri::HTML(File.read(File.join(tmp_dir, 'wiki_content/my-wiki-my-wiki.html')))
63
+ assert html
64
+ assert_equal 'i56eb35e2b44710c48f7aa6b6297e9c98', html.search('meta[name="identifier"]').first.attributes['content'].value
65
+ assert_equal 'My Wiki', html.search('title').text
66
+ assert_equal 'Hello <a href="%24WIKI_REFERENCE%24/wiki/my-wiki-link" title="link">link</a>', html.search('body').inner_html.strip
67
+
68
+ html = Nokogiri::HTML(File.read(File.join(tmp_dir, 'wiki_content/my-wiki-link.html')))
69
+ assert html
70
+ assert_equal 'i13d1eba598141a33bd00dc38186d148a', html.search('meta[name="identifier"]').first.attributes['content'].value
71
+ assert_equal 'link', html.search('title').text
72
+ assert_equal 'This is a linked page', html.search('body').inner_html.strip
73
+ end
74
+ end
@@ -0,0 +1,48 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCCAssessment < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ @mod = @backup.course.mods.find { |m| m.mod_type == "quiz" }
12
+ @assessment = CanvasCc::CC::Assessment.new @mod
13
+ end
14
+
15
+ def teardown
16
+ clean_tmp_folder
17
+ end
18
+
19
+ def test_it_converts_id
20
+ @mod.id = 321
21
+ assessment = CanvasCc::CC::Assessment.new @mod
22
+ assert_equal 321, assessment.id
23
+ end
24
+
25
+ def test_it_converts_title
26
+ @mod.name = "First Quiz"
27
+ assessment = CanvasCc::CC::Assessment.new @mod
28
+ assert_equal "First Quiz", assessment.title
29
+ end
30
+
31
+ def test_it_has_an_identifier
32
+ @mod.id = 321
33
+ assessment = CanvasCc::CC::Assessment.new @mod
34
+ assert_equal 'i058d7533a77712b6e7757b34e66df7fc', assessment.identifier
35
+ end
36
+
37
+ def test_it_creates_resource_in_imsmanifest
38
+ node = Builder::XmlMarkup.new
39
+ xml = node.root do |root_node|
40
+ @assessment.create_resource_node(node)
41
+ end
42
+ xml = Nokogiri::XML(xml)
43
+
44
+ resource = xml.root.xpath('resource[@type="imsqti_xmlv1p2/imscc_xmlv1p1/assessment"]').first
45
+ assert resource, 'assessment resource does not exist for assessment'
46
+ assert_equal 'i058d7533a77712b6e7757b34e66df7fc', resource.attributes['identifier'].value
47
+ end
48
+ end
@@ -0,0 +1,72 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCCAssignment < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ @mod = @backup.course.mods.find { |m| m.mod_type == "assignment" }
12
+ @workshop_mod = @backup.course.mods.find { |m| m.mod_type == "workshop" }
13
+ @assignment = CanvasCc::CC::Assignment.new @mod
14
+ end
15
+
16
+ def teardown
17
+ clean_tmp_folder
18
+ end
19
+
20
+ def test_it_converts_id
21
+ @mod.id = 987
22
+ assignment = CanvasCc::CC::Assignment.new @mod
23
+ assert_equal 987, assignment.id
24
+ end
25
+
26
+ def test_it_converts_title
27
+ @mod.name = "Create a Rails site"
28
+ assignment = CanvasCc::CC::Assignment.new @mod
29
+ assert_equal "Create a Rails site", assignment.title
30
+ end
31
+
32
+ def test_it_converts_body
33
+ @mod.description = %(<h1>Hello World</h1><img src="$@FILEPHP@$$@SLASH@$folder$@SLASH@$stuff.jpg" />)
34
+ assignment = CanvasCc::CC::Assignment.new @mod
35
+ assert_equal %(<h1>Hello World</h1><img src="$IMS_CC_FILEBASE$/folder/stuff.jpg" />), assignment.body
36
+ end
37
+
38
+ def test_it_has_an_identifier
39
+ @mod.id = 987
40
+ assignment = CanvasCc::CC::Assignment.new @mod
41
+ assert_equal 'i6b162484accdf6081cea43b39219d129', assignment.identifier
42
+ end
43
+
44
+ def test_it_creates_resource_in_imsmanifest
45
+ node = Builder::XmlMarkup.new
46
+ xml = Nokogiri::XML(@assignment.create_resource_node(node))
47
+
48
+ resource = xml.xpath('resource').first
49
+ assert resource
50
+ assert_equal 'webcontent', resource.attributes['type'].value
51
+ assert_equal 'web_resources/assignments/create-a-rails-site.html', resource.attributes['href'].value
52
+ assert_equal 'i6b162484accdf6081cea43b39219d129', resource.attributes['identifier'].value
53
+
54
+ file = resource.xpath('file[@href="web_resources/assignments/create-a-rails-site.html"]').first
55
+ assert file
56
+ end
57
+
58
+ def test_it_creates_assignment_html
59
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
60
+ @assignment.create_html(tmp_dir)
61
+ html = Nokogiri::HTML(File.read(File.join(tmp_dir, CanvasCc::CC::CCHelper::CC_ASSIGNMENT_FOLDER, 'create-a-rails-site.html')))
62
+
63
+ assert html
64
+ assert_equal 'Assignment: Create a Rails site', html.search('title').text
65
+ assert_equal '<h1>Hello World</h1>', html.search('body').inner_html.strip
66
+ assert_equal 'assignment', html.at_css('meta[name=mod_type]')['content']
67
+ assert_equal 'offline', html.at_css('meta[name=assignment_type]')['content']
68
+ assert_equal '1.0', html.at_css('meta[name=grade_min]')['content']
69
+ assert_equal '150.0', html.at_css('meta[name=grade_max]')['content']
70
+ assert_equal '2', html.at_css('meta[name=grade_type]')['content']
71
+ end
72
+ end
@@ -0,0 +1,19 @@
1
+ require 'minitest/autorun'
2
+ require 'test_helper'
3
+ require 'moodle2cc'
4
+
5
+ class TestUnitCCCCHelper < MiniTest::Unit::TestCase
6
+ include TestHelper
7
+
8
+ def test_it_creates_valid_file_names
9
+ assert_equal 'psy101-isnt-this-a-cool-course', CanvasCc::CC::CCHelper.file_slug("PSY101 Isn't this a cool course?")
10
+ end
11
+
12
+ def test_that_file_names_dont_end_with_a_period
13
+ assert_equal 'some-content', CanvasCc::CC::CCHelper.file_slug('Some Content...')
14
+ end
15
+
16
+ def test_is_converts_file_path_tokens
17
+ assert_equal '$IMS_CC_FILEBASE$/folder/stuff.jpg', CanvasCc::CC::CCHelper.convert_file_path_tokens('$@FILEPHP@$$@SLASH@$folder$@SLASH@$stuff.jpg')
18
+ end
19
+ end
@@ -0,0 +1,173 @@
1
+ require 'minitest/autorun'
2
+ require 'test_helper'
3
+ require 'moodle2cc'
4
+ require 'nokogiri'
5
+
6
+ class TestUnitCCConverter < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ end
12
+
13
+ def teardown
14
+ clean_tmp_folder
15
+ end
16
+
17
+ def test_it_has_the_path_to_the_imscc_package
18
+ assert_equal File.expand_path("../../../tmp/my-course.imscc", __FILE__), @converter.imscc_path
19
+ end
20
+
21
+ def test_it_creates_imscc_package
22
+ assert File.exists?(@converter.imscc_path)
23
+ end
24
+
25
+ def test_it_creates_imsmanifest_xml
26
+ Zip::File.open(@converter.imscc_path) do |zipfile|
27
+ assert zipfile.find_entry("imsmanifest.xml")
28
+ end
29
+ end
30
+
31
+ def test_imsmanifest_has_manifest_root
32
+ xml = get_imsmanifest_xml
33
+ assert_equal "manifest", xml.root.name
34
+ assert_equal "i24f498fba015133ae97c6e6693a32b4d", xml.root.attributes['identifier'].value
35
+ end
36
+
37
+ def test_imsmanifest_has_proper_namespaces
38
+ xml = get_imsmanifest_xml
39
+ assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd", xml.root.attributes['schemaLocation'].value
40
+ assert_equal "http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource", xml.namespaces['xmlns:lom']
41
+ assert_equal "http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest", xml.namespaces['xmlns:lomimscc']
42
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
43
+ assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1", xml.namespaces['xmlns']
44
+ end
45
+
46
+ def test_imsmanifest_has_a_schema
47
+ xml = get_imsmanifest_xml
48
+ assert_equal "IMS Common Cartridge", xml.xpath('//xmlns:manifest/xmlns:metadata/xmlns:schema').text
49
+ end
50
+
51
+ def test_imsmanifest_has_a_schemaversion
52
+ xml = get_imsmanifest_xml
53
+ assert_equal "1.1.0", xml.xpath('//xmlns:manifest/xmlns:metadata/xmlns:schemaversion').text
54
+ end
55
+
56
+ def test_imsmanifest_has_the_course_fullname
57
+ xml = get_imsmanifest_xml
58
+ assert_equal "My Course", xml.xpath('//xmlns:manifest/xmlns:metadata/lomimscc:lom/lomimscc:general/lomimscc:title/lomimscc:string').text
59
+ end
60
+
61
+ def test_imsmanifest_has_the_current_date
62
+ xml = get_imsmanifest_xml
63
+ now = Time.now.utc
64
+ assert_equal now.strftime("%Y-%m-%d"), xml.xpath('//xmlns:manifest/xmlns:metadata/lomimscc:lom/lomimscc:lifeCycle/lomimscc:contribute/lomimscc:date/lomimscc:dateTime').text
65
+ end
66
+
67
+ def test_imsmanifest_has_the_copyright_restriction
68
+ xml = get_imsmanifest_xml
69
+ assert_equal "yes", xml.xpath('//xmlns:manifest/xmlns:metadata/lomimscc:lom/lomimscc:rights/lomimscc:copyrightAndOtherRestrictions/lomimscc:value').text
70
+ end
71
+
72
+ def test_imsmanifest_has_the_copyright_description
73
+ xml = get_imsmanifest_xml
74
+ assert_equal 'Private (Copyrighted) - http://en.wikipedia.org/wiki/Copyright', xml.xpath('//xmlns:manifest/xmlns:metadata/lomimscc:lom/lomimscc:rights/lomimscc:description/lomimscc:string').text
75
+ end
76
+
77
+ def test_imsmanifest_has_an_organization
78
+ xml = get_imsmanifest_xml
79
+
80
+ organization = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization').first
81
+ assert organization
82
+ assert_equal 'org_1', organization.attributes['identifier'].value
83
+ assert_equal 'rooted-hierarchy', organization.attributes['structure'].value
84
+
85
+ item = organization.xpath('xmlns:item').first
86
+ assert item
87
+ assert 'LearningModules', item.attributes['identifier'].value
88
+ end
89
+
90
+ def test_imsmanifest_has_items_under_organization
91
+ xml = get_imsmanifest_xml
92
+
93
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[1]').first
94
+ assert item
95
+ assert_equal "iebbd12be3d1d1ba16e241599099c4795", item.attributes['identifier'].value
96
+ assert_equal 'Week 0', item.xpath('xmlns:title').text
97
+
98
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[2]').first
99
+ assert item
100
+ assert_equal "i84cbfb8e81c780e847d0087e024dd2f2", item.attributes['identifier'].value
101
+ assert_equal 'Week 1', item.xpath('xmlns:title').text
102
+ end
103
+
104
+ def test_imsmanifest_does_not_create_item_for_sections_with_no_modules
105
+ xml = get_imsmanifest_xml
106
+
107
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[@identifier="i9a57aafbbb5993c28a89c2e363e97f87"]').first
108
+ refute item, 'invisible section has item node'
109
+ end
110
+
111
+ def test_imsmanifest_has_sub_items
112
+ xml = get_imsmanifest_xml
113
+
114
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[1]/xmlns:item[1]').first
115
+ assert item
116
+ assert_equal "i09cb85ba0baf2ffee6aef5f2249dea69", item.attributes['identifier'].value
117
+ assert_equal "i3b3b3e626c91e725614a6ce837b6de34", item.attributes['identifierref'].value
118
+ assert_equal 'This is the Syllabus', item.xpath('xmlns:title').text
119
+
120
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[1]/xmlns:item[2]').first
121
+ assert item
122
+ assert_equal "i10241816e5909d8e76da003b2814c6a4", item.attributes['identifier'].value
123
+ assert_equal "i6b162484accdf6081cea43b39219d129", item.attributes['identifierref'].value
124
+ assert_equal 'Create a Rails site', item.xpath('xmlns:title').text
125
+
126
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[1]/xmlns:item[3]').first
127
+ assert item
128
+ assert_equal "i966437b815a49aad86a356bc8aa8f24a", item.attributes['identifier'].value
129
+ assert_equal "i15aaccec404aa2ad557108a689bbba8f", item.attributes['identifierref'].value
130
+ assert_equal 'About Your Instructor', item.xpath('xmlns:title').text
131
+
132
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[2]/xmlns:item[1]').first
133
+ assert item
134
+ assert_equal "i66b491d95b61e87f7ae71445a82a4d22", item.attributes['identifier'].value
135
+ assert_equal "idfd13c979a2bde97c18a4bcb51752001", item.attributes['identifierref'].value
136
+ assert_equal 'Week 1 Summary', item.xpath('xmlns:title').text
137
+
138
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[2]/xmlns:item[2]').first
139
+ assert item
140
+ assert_equal "ie8e11ad7a1b32660f6aeaf94948faa22", item.attributes['identifier'].value
141
+ assert_equal "if7091ac80f57e45c757345555327b248", item.attributes['identifierref'].value
142
+ assert_equal 'Announcements', item.xpath('xmlns:title').text
143
+
144
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[2]/xmlns:item[3]').first
145
+ assert item
146
+ assert_equal "ifcf0624ce811c812c749c53f3c914f20", item.attributes['identifier'].value
147
+ assert_equal "iddbfacadb16c78a584f81538cd53cc72", item.attributes['identifierref'].value
148
+ assert_equal 'label123', item.xpath('xmlns:title').text
149
+ end
150
+
151
+ def test_imsmanifest_has_file_resources
152
+ xml = get_imsmanifest_xml
153
+
154
+ resource = xml.xpath('//xmlns:manifest/xmlns:resources/xmlns:resource[@identifier="i2fbc9b5ef920655b8240824d3d7b677a"]').first
155
+ assert resource, 'resources does not exist for "web_resources/folder/test.txt" file'
156
+ assert_equal 'webcontent', resource.attributes['type'].value
157
+ assert_equal 'web_resources/folder/test.txt', resource.attributes['href'].value
158
+ assert resource.xpath('xmlns:file[@href="web_resources/folder/test.txt"]').first
159
+ assert_equal 1, xml.search('file[href="web_resources/folder/test.txt"]').count
160
+
161
+ resource = xml.xpath('//xmlns:manifest/xmlns:resources/xmlns:resource[@identifier="ib98bb8ec201a97840ae4ed4bb40207c0"]').first
162
+ assert resource, 'resources does not exist for "web_resources/test.txt" file'
163
+ assert_equal 'webcontent', resource.attributes['type'].value
164
+ assert_equal 'web_resources/test.txt', resource.attributes['href'].value
165
+ assert resource.xpath('xmlns:file[@href="web_resources/test.txt"]').first
166
+ assert_equal 1, xml.search('file[href="web_resources/test.txt"]').count
167
+ end
168
+
169
+ def test_it_deletes_all_files_except_imscc
170
+ refute File.exists? @converter.imscc_tmp_path
171
+ assert File.exists? @converter.imscc_path
172
+ end
173
+ end
@@ -0,0 +1,36 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCCCourse < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ @course = @backup.course
12
+ @cc_course = CanvasCc::CC::Course.new @course
13
+ end
14
+
15
+ def teardown
16
+ clean_tmp_folder
17
+ end
18
+
19
+ def test_it_converts_format
20
+ @course.format = 'weeks'
21
+ cc_course = CanvasCc::CC::Course.new @course
22
+ assert_equal 'Week', cc_course.format
23
+
24
+ @course.format = 'weekscss'
25
+ cc_course = CanvasCc::CC::Course.new @course
26
+ assert_equal 'Week', cc_course.format
27
+
28
+ @course.format = 'social'
29
+ cc_course = CanvasCc::CC::Course.new @course
30
+ assert_equal 'Topic', cc_course.format
31
+
32
+ @course.format = 'topics'
33
+ cc_course = CanvasCc::CC::Course.new @course
34
+ assert_equal 'Topic', cc_course.format
35
+ end
36
+ end
@@ -0,0 +1,83 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCCDiscussionTopic < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ @mod = @backup.course.mods.find { |mod| mod.mod_type == 'forum' }
12
+ end
13
+
14
+ def teardown
15
+ clean_tmp_folder
16
+ end
17
+
18
+ def test_it_converts_id
19
+ @mod.id = 567
20
+
21
+ discussion_topic = CanvasCc::CC::DiscussionTopic.new @mod
22
+ assert_equal 567, discussion_topic.id
23
+ end
24
+
25
+ def test_it_converts_title
26
+ @mod.name = "Announcements"
27
+
28
+ discussion_topic = CanvasCc::CC::DiscussionTopic.new @mod
29
+ assert_equal "Announcements", discussion_topic.title
30
+ end
31
+
32
+ def test_it_converts_text
33
+ @mod.intro = %(<h1>Hello World</h1><img src="$@FILEPHP@$$@SLASH@$folder$@SLASH@$stuff.jpg" />)
34
+
35
+ discussion_topic = CanvasCc::CC::DiscussionTopic.new @mod
36
+ assert_equal %(<h1>Hello World</h1><img src="$IMS_CC_FILEBASE$/folder/stuff.jpg" />), discussion_topic.text
37
+ end
38
+
39
+ def test_it_has_an_identifier
40
+ @mod.id = 123
41
+
42
+ discussion_topic = CanvasCc::CC::DiscussionTopic.new @mod
43
+ assert_equal 'ifb967ca1271d3e119ae5e22d32eeae1b', discussion_topic.identifier
44
+ end
45
+
46
+ def test_it_creates_resource_in_imsmanifest
47
+ discussion_topic = CanvasCc::CC::DiscussionTopic.new @mod
48
+ node = Builder::XmlMarkup.new
49
+ xml = node.root do |root_node|
50
+ discussion_topic.create_resource_node(node)
51
+ end
52
+ xml = Nokogiri::XML(xml)
53
+
54
+ resource = xml.root.xpath('resource[1]').first
55
+ assert resource
56
+ assert_equal 'imsdt_xmlv1p1', resource.attributes['type'].value
57
+ assert_equal 'if7091ac80f57e45c757345555327b248', resource.attributes['identifier'].value
58
+
59
+ file = resource.xpath('file[@href="if7091ac80f57e45c757345555327b248.xml"]').first
60
+ assert file
61
+
62
+ assert get_imscc_file('if7091ac80f57e45c757345555327b248.xml') # topic xml
63
+ end
64
+
65
+ def test_it_create_topic_xml
66
+ @mod.name = "Announcements"
67
+ @mod.intro = "<h1>Hello World</h1>"
68
+
69
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
70
+ discussion_topic = CanvasCc::CC::DiscussionTopic.new @mod
71
+ discussion_topic.create_topic_xml(tmp_dir)
72
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, "#{discussion_topic.identifier}.xml")))
73
+
74
+ assert xml
75
+ assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imsdt_v1p1.xsd", xml.root.attributes['schemaLocation'].value
76
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
77
+ assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1", xml.namespaces['xmlns']
78
+
79
+ assert_equal 'Announcements', xml.search('title').text
80
+ assert_equal 'text/html', xml.search('text').first.attributes['texttype'].value
81
+ assert_equal '<h1>Hello World</h1>', xml.search('text').text
82
+ end
83
+ end
@@ -0,0 +1,29 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCCLabel < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ @mod = @backup.course.mods.find { |m| m.mod_type == "label" }
12
+ end
13
+
14
+ def teardown
15
+ clean_tmp_folder
16
+ end
17
+
18
+ def test_it_converts_id
19
+ @mod.id = 654
20
+ label = CanvasCc::CC::Label.new @mod
21
+ assert_equal 654, label.id
22
+ end
23
+
24
+ def test_it_converts_title
25
+ @mod.name = 'label123'
26
+ label = CanvasCc::CC::Label.new @mod
27
+ assert_equal 'label123', label.title
28
+ end
29
+ end