moodle2cc 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 (95) hide show
  1. data/.gitignore +20 -0
  2. data/Gemfile +4 -0
  3. data/Guardfile +14 -0
  4. data/LICENSE +661 -0
  5. data/README.md +38 -0
  6. data/Rakefile +12 -0
  7. data/bin/moodle2cc +6 -0
  8. data/lib/moodle2cc.rb +60 -0
  9. data/lib/moodle2cc/canvas/.converter.rb.swo +0 -0
  10. data/lib/moodle2cc/canvas/.wiki.rb.swo +0 -0
  11. data/lib/moodle2cc/canvas/assessment.rb +109 -0
  12. data/lib/moodle2cc/canvas/assignment.rb +108 -0
  13. data/lib/moodle2cc/canvas/converter.rb +28 -0
  14. data/lib/moodle2cc/canvas/course.rb +145 -0
  15. data/lib/moodle2cc/canvas/discussion_topic.rb +64 -0
  16. data/lib/moodle2cc/canvas/label.rb +8 -0
  17. data/lib/moodle2cc/canvas/question.rb +468 -0
  18. data/lib/moodle2cc/canvas/question_bank.rb +54 -0
  19. data/lib/moodle2cc/canvas/resource.rb +16 -0
  20. data/lib/moodle2cc/canvas/templates/assignment.html.erb +9 -0
  21. data/lib/moodle2cc/canvas/templates/syllabus.html.erb +9 -0
  22. data/lib/moodle2cc/canvas/templates/wiki_content.html.erb +10 -0
  23. data/lib/moodle2cc/canvas/web_content.rb +10 -0
  24. data/lib/moodle2cc/canvas/web_link.rb +17 -0
  25. data/lib/moodle2cc/canvas/wiki.rb +25 -0
  26. data/lib/moodle2cc/cc/assessment.rb +25 -0
  27. data/lib/moodle2cc/cc/assignment.rb +66 -0
  28. data/lib/moodle2cc/cc/cc_helper.rb +282 -0
  29. data/lib/moodle2cc/cc/converter.rb +136 -0
  30. data/lib/moodle2cc/cc/course.rb +16 -0
  31. data/lib/moodle2cc/cc/discussion_topic.rb +53 -0
  32. data/lib/moodle2cc/cc/label.rb +6 -0
  33. data/lib/moodle2cc/cc/question.rb +23 -0
  34. data/lib/moodle2cc/cc/resource.rb +30 -0
  35. data/lib/moodle2cc/cc/templates/assignment.html.erb +9 -0
  36. data/lib/moodle2cc/cc/templates/syllabus.html.erb +9 -0
  37. data/lib/moodle2cc/cc/templates/wiki_content.html.erb +10 -0
  38. data/lib/moodle2cc/cc/web_content.rb +40 -0
  39. data/lib/moodle2cc/cc/web_link.rb +53 -0
  40. data/lib/moodle2cc/cc/wiki.rb +72 -0
  41. data/lib/moodle2cc/cli.rb +14 -0
  42. data/lib/moodle2cc/error.rb +3 -0
  43. data/lib/moodle2cc/migrator.rb +23 -0
  44. data/lib/moodle2cc/moodle/backup.rb +38 -0
  45. data/lib/moodle2cc/moodle/course.rb +24 -0
  46. data/lib/moodle2cc/moodle/grade_item.rb +24 -0
  47. data/lib/moodle2cc/moodle/info.rb +8 -0
  48. data/lib/moodle2cc/moodle/mod.rb +127 -0
  49. data/lib/moodle2cc/moodle/question.rb +98 -0
  50. data/lib/moodle2cc/moodle/question_category.rb +17 -0
  51. data/lib/moodle2cc/moodle/section.rb +37 -0
  52. data/lib/moodle2cc/resource_factory.rb +32 -0
  53. data/lib/moodle2cc/version.rb +3 -0
  54. data/moodle2cc.gemspec +29 -0
  55. data/test/acceptance/migrator_test.rb +23 -0
  56. data/test/fixtures/cc.imscc +0 -0
  57. data/test/fixtures/moodle_backup/course_files/folder/test.txt +1 -0
  58. data/test/fixtures/moodle_backup/course_files/test.txt +1 -0
  59. data/test/fixtures/moodle_backup/moodle.xml +916 -0
  60. data/test/test_helper.rb +43 -0
  61. data/test/test_question_helper.rb +107 -0
  62. data/test/test_wiki_helper.rb +21 -0
  63. data/test/unit/canvas/assessment_test.rb +218 -0
  64. data/test/unit/canvas/assignment_test.rb +220 -0
  65. data/test/unit/canvas/converter_test.rb +159 -0
  66. data/test/unit/canvas/course_test.rb +176 -0
  67. data/test/unit/canvas/discussion_topic_test.rb +129 -0
  68. data/test/unit/canvas/label_test.rb +32 -0
  69. data/test/unit/canvas/question_bank_test.rb +73 -0
  70. data/test/unit/canvas/question_test.rb +824 -0
  71. data/test/unit/canvas/web_content_test.rb +37 -0
  72. data/test/unit/canvas/web_link_test.rb +48 -0
  73. data/test/unit/canvas/wiki_test.rb +74 -0
  74. data/test/unit/cc/assessment_test.rb +48 -0
  75. data/test/unit/cc/assignment_test.rb +67 -0
  76. data/test/unit/cc/cc_helper_test.rb +19 -0
  77. data/test/unit/cc/converter_test.rb +159 -0
  78. data/test/unit/cc/course_test.rb +36 -0
  79. data/test/unit/cc/discussion_topic_test.rb +83 -0
  80. data/test/unit/cc/label_test.rb +29 -0
  81. data/test/unit/cc/question_test.rb +49 -0
  82. data/test/unit/cc/web_content_test.rb +76 -0
  83. data/test/unit/cc/web_link_test.rb +79 -0
  84. data/test/unit/cc/wiki_test.rb +139 -0
  85. data/test/unit/migrator_test.rb +56 -0
  86. data/test/unit/moodle/backup_test.rb +30 -0
  87. data/test/unit/moodle/course_test.rb +57 -0
  88. data/test/unit/moodle/grade_item_test.rb +72 -0
  89. data/test/unit/moodle/info_test.rb +21 -0
  90. data/test/unit/moodle/mod_test.rb +301 -0
  91. data/test/unit/moodle/question_category_test.rb +34 -0
  92. data/test/unit/moodle/question_test.rb +185 -0
  93. data/test/unit/moodle/section_test.rb +75 -0
  94. data/test/unit/resource_factory_test.rb +119 -0
  95. metadata +342 -0
@@ -0,0 +1,159 @@
1
+ require 'minitest/autorun'
2
+ require 'test/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::ZipFile.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 "i10241816e5909d8e76da003b2814c6a4", item.attributes['identifier'].value
117
+ assert_equal "i6b162484accdf6081cea43b39219d129", item.attributes['identifierref'].value
118
+ assert_equal 'Create a Rails site', 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 "i966437b815a49aad86a356bc8aa8f24a", item.attributes['identifier'].value
123
+ assert_equal "i15aaccec404aa2ad557108a689bbba8f", item.attributes['identifierref'].value
124
+ assert_equal 'About Your Instructor', item.xpath('xmlns:title').text
125
+
126
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[2]/xmlns:item[1]').first
127
+ assert item
128
+ assert_equal "ie8e11ad7a1b32660f6aeaf94948faa22", item.attributes['identifier'].value
129
+ assert_equal "if7091ac80f57e45c757345555327b248", item.attributes['identifierref'].value
130
+ assert_equal 'Announcements', item.xpath('xmlns:title').text
131
+
132
+ item = xml.xpath('//xmlns:manifest/xmlns:organizations/xmlns:organization/xmlns:item/xmlns:item[2]/xmlns:item[2]').first
133
+ assert item
134
+ assert_equal "ifcf0624ce811c812c749c53f3c914f20", item.attributes['identifier'].value
135
+ assert_equal "iddbfacadb16c78a584f81538cd53cc72", item.attributes['identifierref'].value
136
+ assert_equal 'label123', item.xpath('xmlns:title').text
137
+ end
138
+
139
+ def test_imsmanifest_has_file_resources
140
+ xml = get_imsmanifest_xml
141
+
142
+ resource = xml.xpath('//xmlns:manifest/xmlns:resources/xmlns:resource[@identifier="i2fbc9b5ef920655b8240824d3d7b677a"]').first
143
+ assert resource, 'resources does not exist for "web_resources/folder/test.txt" file'
144
+ assert_equal 'webcontent', resource.attributes['type'].value
145
+ assert_equal 'web_resources/folder/test.txt', resource.attributes['href'].value
146
+ assert resource.xpath('xmlns:file[@href="web_resources/folder/test.txt"]').first
147
+
148
+ resource = xml.xpath('//xmlns:manifest/xmlns:resources/xmlns:resource[@identifier="ib98bb8ec201a97840ae4ed4bb40207c0"]').first
149
+ assert resource, 'resources does not exist for "web_resources/test.txt" file'
150
+ assert_equal 'webcontent', resource.attributes['type'].value
151
+ assert_equal 'web_resources/test.txt', resource.attributes['href'].value
152
+ assert resource.xpath('xmlns:file[@href="web_resources/test.txt"]').first
153
+ end
154
+
155
+ def test_it_deletes_all_files_except_imscc
156
+ refute File.exists? @converter.imscc_tmp_path
157
+ assert File.exists? @converter.imscc_path
158
+ end
159
+ end
@@ -0,0 +1,176 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test/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 = Moodle2CC::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 Moodle2CC::Canvas::Course.ancestors.include?(Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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 xml.xpath('//xmlns:modules/xmlns:module').count == 2
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 2, 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 8, module_node.xpath('xmlns:items').first.xpath('xmlns:item').count
139
+
140
+ item_node = module_node.xpath('xmlns:items/xmlns:item[9]').first
141
+ refute item_node, 'item exists for invisible mod'
142
+
143
+ module_node = xml.xpath('//xmlns:modules/xmlns:module[3]').first
144
+ refute module_node, 'module exists for invisible section'
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/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 = Moodle2CC::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 = Moodle2CC::Canvas::DiscussionTopic.new @mod, 5
27
+ assert_equal 5, discussion_topic.position
28
+ end
29
+
30
+ def test_it_converts_type
31
+ discussion_topic = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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