canvas_cc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,171 @@
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('canvas')
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_invisible_sections
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 "i421aa3e876264b528cdc0c22cf9b2124", item.attributes['identifier'].value
117
+ assert_equal "i2bbef1184ce7da2a0f6d9038cb872c28", 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 "i61c91e0962069aa79c40a406a6c38e3e", item.attributes['identifier'].value
135
+ assert_equal "i9c32ce07701475bf3eb14257f2d6def4", 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
+
160
+ resource = xml.xpath('//xmlns:manifest/xmlns:resources/xmlns:resource[@identifier="ib98bb8ec201a97840ae4ed4bb40207c0"]').first
161
+ assert resource, 'resources does not exist for "web_resources/test.txt" file'
162
+ assert_equal 'webcontent', resource.attributes['type'].value
163
+ assert_equal 'web_resources/test.txt', resource.attributes['href'].value
164
+ assert resource.xpath('xmlns:file[@href="web_resources/test.txt"]').first
165
+ end
166
+
167
+ def test_it_deletes_all_files_except_imscc
168
+ refute File.exists? @converter.imscc_tmp_path
169
+ assert File.exists? @converter.imscc_path
170
+ end
171
+ end
@@ -0,0 +1,176 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCanvasCourse < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup('canvas')
11
+ @course = @backup.course
12
+ @cc_course = CanvasCc::Canvas::Course.new @course
13
+ end
14
+
15
+ def teardown
16
+ clean_tmp_folder
17
+ end
18
+
19
+ def test_it_inherits_from_cc
20
+ assert CanvasCc::Canvas::Course.ancestors.include?(CanvasCc::CC::Course), 'does not inherit from base CC class'
21
+ end
22
+
23
+ def test_it_converts_id
24
+ assert_equal 55555, @cc_course.id
25
+ end
26
+
27
+ def test_it_converts_title
28
+ assert_equal 'My Course', @cc_course.title
29
+ end
30
+
31
+ def test_it_converts_course_code
32
+ assert_equal 'EDU 101', @cc_course.course_code
33
+ end
34
+
35
+ def test_it_converts_start_at
36
+ assert_equal '2012-06-11T05:00:00', @cc_course.start_at
37
+ end
38
+
39
+ def test_it_converts_is_public
40
+ assert_equal true, @cc_course.is_public
41
+ end
42
+
43
+ def test_it_converts_syllabus_body
44
+ section = CanvasCc::Moodle::Section.new
45
+ section.summary = %(<h1>Hello World</h1><img src="$@FILEPHP@$$@SLASH@$folder$@SLASH@$stuff.jpg" />)
46
+ @course.sections = [section]
47
+ cc_course = CanvasCc::Canvas::Course.new @course
48
+ assert_equal %(<h1>Hello World</h1><img src="$IMS_CC_FILEBASE$/folder/stuff.jpg" />), cc_course.syllabus_body
49
+ end
50
+
51
+ def test_it_creates_resource_in_imsmanifest
52
+ node = Builder::XmlMarkup.new
53
+ xml = Nokogiri::XML(@cc_course.create_resource_node(node))
54
+
55
+ resource = xml.xpath('resource').first
56
+ assert resource
57
+ assert_equal 'syllabus', resource.attributes['intendeduse'].value
58
+ assert_equal 'course_settings/syllabus.html', resource.attributes['href'].value
59
+ assert_equal 'associatedcontent/imscc_xmlv1p1/learning-application-resource', resource.attributes['type'].value
60
+ assert_equal 'i056ad8a52e3d89b15c15c97434aa0e91', resource.attributes['identifier'].value
61
+
62
+ # syllabus
63
+ assert resource.xpath('file[@href="course_settings/syllabus.html"]').first
64
+ assert get_imscc_file('course_settings/syllabus.html')
65
+
66
+ # course settings
67
+ assert resource.xpath('file[@href="course_settings/course_settings.xml"]').first
68
+ assert get_imscc_file('course_settings/course_settings.xml')
69
+
70
+ # files meta
71
+ assert resource.xpath('file[@href="course_settings/files_meta.xml"]').first
72
+ assert get_imscc_file('course_settings/files_meta.xml')
73
+
74
+ # module meta
75
+ assert resource.xpath('file[@href="course_settings/module_meta.xml"]').first
76
+ assert get_imscc_file('course_settings/module_meta.xml')
77
+
78
+ # assignment groups
79
+ assert resource.xpath('file[@href="course_settings/assignment_groups.xml"]').first
80
+ assert get_imscc_file('course_settings/assignment_groups.xml')
81
+
82
+ # web resources
83
+ assert get_imscc_file('web_resources/folder/test.txt')
84
+ assert get_imscc_file('web_resources/test.txt')
85
+ end
86
+
87
+ def test_it_creates_syllabus_file
88
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
89
+ @cc_course.create_syllabus_file(tmp_dir)
90
+ html = Nokogiri::HTML(File.read(File.join(tmp_dir, 'course_settings', 'syllabus.html')))
91
+
92
+ assert html
93
+ assert_equal 'Syllabus', html.search('title').text
94
+ end
95
+
96
+ def test_it_create_course_settings_xml
97
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
98
+ @cc_course.create_course_settings_xml(tmp_dir)
99
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, 'course_settings', 'course_settings.xml')))
100
+
101
+ assert xml
102
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd", xml.root.attributes['schemaLocation'].value
103
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
104
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0", xml.namespaces['xmlns']
105
+ assert_equal @cc_course.identifier, xml.xpath('xmlns:course').first.attributes['identifier'].value
106
+
107
+ assert_equal @course.fullname, xml.search('title').text
108
+ assert_equal @course.shortname, xml.search('course_code').text
109
+ assert_equal '2012-06-11T05:00:00', xml.search('start_at').text
110
+ assert_equal 'true', xml.search('is_public').text
111
+ assert_equal 'private', xml.search('license').text
112
+ end
113
+
114
+ def test_it_creates_module_meta_xml
115
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
116
+ @cc_course.create_module_meta_xml(tmp_dir)
117
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, 'course_settings', 'module_meta.xml')))
118
+
119
+ assert xml
120
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd", xml.root.attributes['schemaLocation'].value
121
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
122
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0", xml.namespaces['xmlns']
123
+
124
+ assert_equal 'iebbd12be3d1d1ba16e241599099c4795', xml.xpath('//xmlns:modules/xmlns:module').first.attributes['identifier'].value
125
+
126
+ assert_equal 3, xml.xpath('//xmlns:modules/xmlns:module').count
127
+
128
+ module_node = xml.xpath('//xmlns:modules/xmlns:module[1]').first
129
+ assert_equal 'Week 0', module_node.xpath('xmlns:title').text
130
+ assert_equal '0', module_node.xpath('xmlns:position').text
131
+ assert_equal 'false', module_node.xpath('xmlns:require_sequential_progress').text
132
+ assert_equal 3, module_node.xpath('xmlns:items').first.xpath('xmlns:item').count
133
+
134
+ module_node = xml.xpath('//xmlns:modules/xmlns:module[2]').first
135
+ assert_equal 'Week 1', module_node.xpath('xmlns:title').text
136
+ assert_equal '1', module_node.xpath('xmlns:position').text
137
+ assert_equal 'false', module_node.xpath('xmlns:require_sequential_progress').text
138
+ assert_equal 9, module_node.xpath('xmlns:items').first.xpath('xmlns:item').count
139
+
140
+ module_node = xml.xpath('//xmlns:modules/xmlns:module[3]').first
141
+ assert_equal 'Week 3', module_node.xpath('xmlns:title').text
142
+ assert_equal '3', module_node.xpath('xmlns:position').text
143
+ assert_equal 'false', module_node.xpath('xmlns:require_sequential_progress').text
144
+ assert_equal 2, module_node.xpath('xmlns:items').first.xpath('xmlns:item').count
145
+ end
146
+
147
+ def test_it_creates_assignment_groups_xml
148
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
149
+ @cc_course.create_assignment_groups_xml(tmp_dir)
150
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, 'course_settings', 'assignment_groups.xml')))
151
+
152
+ assert xml
153
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd", xml.root.attributes['schemaLocation'].value
154
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
155
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0", xml.namespaces['xmlns']
156
+
157
+ assert_equal 1, xml.xpath('//xmlns:assignmentGroups/xmlns:assignmentGroup').count
158
+
159
+ assignment_group = xml.xpath('//xmlns:assignmentGroups/xmlns:assignmentGroup[1]').first
160
+ assert_equal 'i521ff0228432bb106b9535e8c5139df3', assignment_group.attributes['identifier'].value
161
+ assert_equal 'Week 0', assignment_group.xpath('xmlns:title').text
162
+ end
163
+
164
+ def test_it_creates_files_meta_xml
165
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
166
+ @cc_course.create_files_meta_xml(tmp_dir)
167
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, 'course_settings', 'files_meta.xml')))
168
+
169
+ assert xml
170
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd", xml.root.attributes['schemaLocation'].value
171
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
172
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0", xml.namespaces['xmlns']
173
+
174
+ assert_equal 1, xml.xpath('//xmlns:filesMeta').count
175
+ end
176
+ end
@@ -0,0 +1,129 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCanvasDiscussionTopic < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup('canvas')
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_posted_at
19
+ @mod.section_mod.added = 1340731824
20
+
21
+ discussion_topic = CanvasCc::Canvas::DiscussionTopic.new @mod
22
+ assert_equal '2012-06-26T17:30:24', discussion_topic.posted_at
23
+ end
24
+
25
+ def test_it_converts_position
26
+ discussion_topic = CanvasCc::Canvas::DiscussionTopic.new @mod, 5
27
+ assert_equal 5, discussion_topic.position
28
+ end
29
+
30
+ def test_it_converts_type
31
+ discussion_topic = CanvasCc::Canvas::DiscussionTopic.new @mod
32
+ assert_equal 'topic', discussion_topic.type
33
+ end
34
+
35
+ def test_it_has_an_identifierref
36
+ @mod.id = 123
37
+
38
+ discussion_topic = CanvasCc::Canvas::DiscussionTopic.new @mod
39
+ assert_equal 'ic2f863a4aeaa551a04dfbea65d6e72bb', discussion_topic.identifierref
40
+ end
41
+
42
+ def test_it_creates_resource_in_imsmanifest
43
+ discussion_topic = CanvasCc::Canvas::DiscussionTopic.new @mod
44
+ node = Builder::XmlMarkup.new
45
+ xml = node.root do |root_node|
46
+ discussion_topic.create_resource_node(node)
47
+ end
48
+ xml = Nokogiri::XML(xml)
49
+
50
+ resource = xml.root.xpath('resource[1]').first
51
+ assert resource
52
+ assert_equal 'imsdt_xmlv1p1', resource.attributes['type'].value
53
+ assert_equal 'if7091ac80f57e45c757345555327b248', resource.attributes['identifier'].value
54
+
55
+ file = resource.xpath('file[@href="if7091ac80f57e45c757345555327b248.xml"]').first
56
+ assert file
57
+
58
+ dependency = resource.xpath('dependency[@identifierref="i05a5b1468af5e9257a2f6b0827a0bd96"]').first
59
+ assert dependency
60
+
61
+ resource = xml.root.xpath('resource[2]').first
62
+ assert resource
63
+ assert_equal 'associatedcontent/imscc_xmlv1p1/learning-application-resource', resource.attributes['type'].value
64
+ assert_equal 'i05a5b1468af5e9257a2f6b0827a0bd96', resource.attributes['identifier'].value
65
+ assert_equal 'i05a5b1468af5e9257a2f6b0827a0bd96.xml', resource.attributes['href'].value
66
+
67
+ file = resource.xpath('file[@href="i05a5b1468af5e9257a2f6b0827a0bd96.xml"]').first
68
+ assert file
69
+
70
+ assert get_imscc_file('if7091ac80f57e45c757345555327b248.xml') # topic xml
71
+ assert get_imscc_file('i05a5b1468af5e9257a2f6b0827a0bd96.xml') # topic meta xml
72
+ end
73
+
74
+ def test_it_creates_item_in_module_meta
75
+ discussion_topic = CanvasCc::Canvas::DiscussionTopic.new @mod
76
+ node = Builder::XmlMarkup.new
77
+ xml = Nokogiri::XML(discussion_topic.create_module_meta_item_node(node, 5))
78
+
79
+ assert_equal 'item', xml.root.name
80
+ assert_equal 'ie8e11ad7a1b32660f6aeaf94948faa22', xml.root.attributes['identifier'].value
81
+ assert_equal "Announcements", xml.root.xpath('title').text
82
+ assert_equal '5', xml.root.xpath('position').text
83
+ assert_equal '', xml.root.xpath('new_tab').text
84
+ assert_equal '0', xml.root.xpath('indent').text
85
+ assert_equal 'DiscussionTopic', xml.root.xpath('content_type').text
86
+ assert_equal 'if7091ac80f57e45c757345555327b248', xml.root.xpath('identifierref').text
87
+ end
88
+
89
+ def test_it_create_topic_xml
90
+ @mod.name = "Announcements"
91
+ @mod.intro = "<h1>Hello World</h1>"
92
+
93
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
94
+ discussion_topic = CanvasCc::Canvas::DiscussionTopic.new @mod
95
+ discussion_topic.create_topic_xml(tmp_dir)
96
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, "#{discussion_topic.identifier}.xml")))
97
+
98
+ assert xml
99
+ 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
100
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
101
+ assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1", xml.namespaces['xmlns']
102
+
103
+ assert_equal 'Announcements', xml.search('title').text
104
+ assert_equal 'text/html', xml.search('text').first.attributes['texttype'].value
105
+ assert_equal '<h1>Hello World</h1>', xml.search('text').text
106
+ end
107
+
108
+ def test_it_create_topic_meta_xml
109
+ @mod.name = "Announcements"
110
+ @mod.section_mod.added = 1340731824
111
+
112
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
113
+ discussion_topic = CanvasCc::Canvas::DiscussionTopic.new @mod
114
+ discussion_topic.create_topic_meta_xml(tmp_dir)
115
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, "#{discussion_topic.identifierref}.xml")))
116
+
117
+ assert xml
118
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd", xml.root.attributes['schemaLocation'].value
119
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
120
+ assert_equal "http://canvas.instructure.com/xsd/cccv1p0", xml.namespaces['xmlns']
121
+ assert_equal discussion_topic.identifierref, xml.xpath('xmlns:topicMeta').first.attributes['identifier'].value
122
+
123
+ assert_equal discussion_topic.identifier, xml.search('topic_id').text
124
+ assert_equal 'Announcements', xml.search('title').text
125
+ assert_equal '2012-06-26T17:30:24', xml.search('posted_at').text
126
+ assert_equal '0', xml.search('position').text
127
+ assert_equal 'topic', xml.search('type').text
128
+ end
129
+ end
@@ -0,0 +1,32 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCanvasLabel < 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 == "label" }
12
+ end
13
+
14
+ def teardown
15
+ clean_tmp_folder
16
+ end
17
+
18
+ def test_it_creates_item_in_module_meta
19
+ label = CanvasCc::Canvas::Label.new @mod
20
+ node = Builder::XmlMarkup.new
21
+ xml = Nokogiri::XML(label.create_module_meta_item_node(node, 5))
22
+
23
+ assert_equal 'item', xml.root.name
24
+ assert_equal 'ifcf0624ce811c812c749c53f3c914f20', xml.root.attributes['identifier'].value
25
+ assert_equal "label123", xml.root.xpath('title').text
26
+ assert_equal '5', xml.root.xpath('position').text
27
+ assert_equal '', xml.root.xpath('new_tab').text
28
+ assert_equal '1', xml.root.xpath('indent').text
29
+ assert_equal 'ContextModuleSubHeader', xml.root.xpath('content_type').text
30
+ refute xml.root.xpath('identifierref').first, 'label should not have identifierref'
31
+ end
32
+ end
@@ -0,0 +1,92 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCanvasQuestionBank < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup 'canvas'
11
+ @course = @backup.course
12
+ @question_category = @course.question_categories.first
13
+ end
14
+
15
+ def teardown
16
+ clean_tmp_folder
17
+ end
18
+
19
+ def test_it_converts_id
20
+ @question_category.id = 121
21
+ question_bank = CanvasCc::Canvas::QuestionBank.new @question_category
22
+ assert_equal 121, question_bank.id
23
+ end
24
+
25
+ def test_it_converts_title
26
+ @question_category.name = 'Default for Beginning Ruby on Rails'
27
+ question_bank = CanvasCc::Canvas::QuestionBank.new @question_category
28
+ assert_equal 'Default for Beginning Ruby on Rails', question_bank.title
29
+ end
30
+
31
+ def test_it_converts_questions
32
+ question_bank = CanvasCc::Canvas::QuestionBank.new @question_category
33
+ assert_equal 5, question_bank.questions.length
34
+ assert_kind_of CanvasCc::Canvas::Question, question_bank.questions[0]
35
+ assert_kind_of CanvasCc::Canvas::Question, question_bank.questions[1]
36
+ assert_kind_of CanvasCc::Canvas::Question, question_bank.questions[2]
37
+ assert_kind_of CanvasCc::Canvas::Question, question_bank.questions[3]
38
+ assert_kind_of CanvasCc::Canvas::Question, question_bank.questions[4]
39
+ end
40
+
41
+ def test_it_does_not_convert_random_questions
42
+ convert_moodle_backup('canvas', 'moodle_backup_random_questions')
43
+ mod = @backup.course.mods.find { |m| m.mod_type == "quiz" }
44
+ question_category = @backup.course.question_categories.first
45
+ question_bank = CanvasCc::Canvas::QuestionBank.new question_category
46
+
47
+ assert_equal 2, question_bank.questions.length
48
+ end
49
+
50
+ def test_it_has_an_identifier
51
+ @question_category.id = 121
52
+ question_bank = CanvasCc::Canvas::QuestionBank.new @question_category
53
+ # objectbank_{id}
54
+ assert_equal 'i02849cd800255cc6c762cdafd8d8db67', question_bank.identifier
55
+ end
56
+
57
+ def test_it_creates_resource_in_imsmanifest
58
+ question_bank = CanvasCc::Canvas::QuestionBank.new @question_category
59
+ node = Builder::XmlMarkup.new
60
+ xml = Nokogiri::XML(question_bank.create_resource_node(node))
61
+
62
+ resource = xml.xpath('resource').first
63
+ assert resource
64
+ assert_equal 'associatedcontent/imscc_xmlv1p1/learning-application-resource', resource.attributes['type'].value
65
+ assert_equal 'non_cc_assessments/i02849cd800255cc6c762cdafd8d8db67.xml.qti', resource.attributes['href'].value
66
+ assert_equal 'i02849cd800255cc6c762cdafd8d8db67', resource.attributes['identifier'].value
67
+
68
+ file = resource.xpath('file[@href="non_cc_assessments/i02849cd800255cc6c762cdafd8d8db67.xml.qti"]').first
69
+ assert file
70
+ end
71
+
72
+ def test_it_creates_qti_xml
73
+ question_bank = CanvasCc::Canvas::QuestionBank.new @question_category
74
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
75
+ question_bank.create_qti_xml(tmp_dir)
76
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, 'non_cc_assessments', "i02849cd800255cc6c762cdafd8d8db67.xml.qti")))
77
+
78
+ assert xml
79
+ assert_equal "http://www.imsglobal.org/xsd/ims_qtiasiv1p2 http://www.imsglobal.org/xsd/ims_qtiasiv1p2p1.xsd", xml.root.attributes['schemaLocation'].value
80
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
81
+ assert_equal "http://www.imsglobal.org/xsd/ims_qtiasiv1p2", xml.namespaces['xmlns']
82
+ assert_equal 'questestinterop', xml.root.name
83
+
84
+ assert_equal 'i02849cd800255cc6c762cdafd8d8db67', xml.root.xpath('xmlns:objectbank').first.attributes['ident'].value
85
+
86
+ time_data = xml.root.xpath('xmlns:objectbank/xmlns:qtimetadata/xmlns:qtimetadatafield[xmlns:fieldlabel="bank_title" and xmlns:fieldentry="Default for Beginning Ruby on Rails"]').first
87
+ assert time_data, 'qtimetadata does not exist for time limit'
88
+
89
+ items = xml.root.xpath('xmlns:objectbank/xmlns:item')
90
+ assert_equal 5, items.length
91
+ end
92
+ end