canvas_cc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/canvas_cc.gemspec +37 -0
- data/lib/canvas_cc/canvas/assessment.rb +124 -0
- data/lib/canvas_cc/canvas/assignment.rb +98 -0
- data/lib/canvas_cc/canvas/converter.rb +30 -0
- data/lib/canvas_cc/canvas/course.rb +143 -0
- data/lib/canvas_cc/canvas/discussion_topic.rb +64 -0
- data/lib/canvas_cc/canvas/label.rb +8 -0
- data/lib/canvas_cc/canvas/question.rb +492 -0
- data/lib/canvas_cc/canvas/question_bank.rb +57 -0
- data/lib/canvas_cc/canvas/question_group.rb +35 -0
- data/lib/canvas_cc/canvas/resource.rb +16 -0
- data/lib/canvas_cc/canvas/templates/assignment.html.erb +9 -0
- data/lib/canvas_cc/canvas/templates/syllabus.html.erb +9 -0
- data/lib/canvas_cc/canvas/templates/wiki_content.html.erb +10 -0
- data/lib/canvas_cc/canvas/web_content.rb +15 -0
- data/lib/canvas_cc/canvas/web_link.rb +16 -0
- data/lib/canvas_cc/canvas/wiki.rb +26 -0
- data/lib/canvas_cc/canvas_cc/assessment_writer.rb +82 -0
- data/lib/canvas_cc/canvas_cc/assignment_group_writer.rb +48 -0
- data/lib/canvas_cc/canvas_cc/assignment_writer.rb +68 -0
- data/lib/canvas_cc/canvas_cc/calculated_question_writer.rb +72 -0
- data/lib/canvas_cc/canvas_cc/canvas_export_writer.rb +18 -0
- data/lib/canvas_cc/canvas_cc/cartridge_creator.rb +60 -0
- data/lib/canvas_cc/canvas_cc/course_setting_writer.rb +35 -0
- data/lib/canvas_cc/canvas_cc/discussion_writer.rb +52 -0
- data/lib/canvas_cc/canvas_cc/essay_question_writer.rb +19 -0
- data/lib/canvas_cc/canvas_cc/file_meta_writer.rb +38 -0
- data/lib/canvas_cc/canvas_cc/ims_manifest_generator.rb +123 -0
- data/lib/canvas_cc/canvas_cc/matching_question_writer.rb +43 -0
- data/lib/canvas_cc/canvas_cc/models/answer.rb +12 -0
- data/lib/canvas_cc/canvas_cc/models/assessment.rb +102 -0
- data/lib/canvas_cc/canvas_cc/models/assignment.rb +30 -0
- data/lib/canvas_cc/canvas_cc/models/assignment_group.rb +9 -0
- data/lib/canvas_cc/canvas_cc/models/calculated_question.rb +19 -0
- data/lib/canvas_cc/canvas_cc/models/canvas_file.rb +22 -0
- data/lib/canvas_cc/canvas_cc/models/canvas_module.rb +10 -0
- data/lib/canvas_cc/canvas_cc/models/course.rb +53 -0
- data/lib/canvas_cc/canvas_cc/models/discussion.rb +36 -0
- data/lib/canvas_cc/canvas_cc/models/discussion_topic.rb +5 -0
- data/lib/canvas_cc/canvas_cc/models/matching_question.rb +7 -0
- data/lib/canvas_cc/canvas_cc/models/module_item.rb +16 -0
- data/lib/canvas_cc/canvas_cc/models/multiple_dropdowns_question.rb +7 -0
- data/lib/canvas_cc/canvas_cc/models/numerical_question.rb +7 -0
- data/lib/canvas_cc/canvas_cc/models/page.rb +41 -0
- data/lib/canvas_cc/canvas_cc/models/question.rb +37 -0
- data/lib/canvas_cc/canvas_cc/models/question_bank.rb +42 -0
- data/lib/canvas_cc/canvas_cc/models/question_group.rb +10 -0
- data/lib/canvas_cc/canvas_cc/models/resource.rb +23 -0
- data/lib/canvas_cc/canvas_cc/models/web_content.rb +7 -0
- data/lib/canvas_cc/canvas_cc/models/web_link.rb +7 -0
- data/lib/canvas_cc/canvas_cc/models/workflow_state.rb +6 -0
- data/lib/canvas_cc/canvas_cc/module_meta_writer.rb +52 -0
- data/lib/canvas_cc/canvas_cc/multiple_answers_question_writer.rb +41 -0
- data/lib/canvas_cc/canvas_cc/multiple_blanks_question_writer.rb +51 -0
- data/lib/canvas_cc/canvas_cc/multiple_choice_question_writer.rb +48 -0
- data/lib/canvas_cc/canvas_cc/multiple_dropdowns_question_writer.rb +30 -0
- data/lib/canvas_cc/canvas_cc/numerical_question_writer.rb +40 -0
- data/lib/canvas_cc/canvas_cc/page_writer.rb +38 -0
- data/lib/canvas_cc/canvas_cc/question_bank_writer.rb +44 -0
- data/lib/canvas_cc/canvas_cc/question_group_writer.rb +23 -0
- data/lib/canvas_cc/canvas_cc/question_writer.rb +129 -0
- data/lib/canvas_cc/canvas_cc/short_answer_question_writer.rb +42 -0
- data/lib/canvas_cc/canvas_cc/text_only_question_writer.rb +19 -0
- data/lib/canvas_cc/canvas_cc/true_false_question_writer.rb +38 -0
- data/lib/canvas_cc/cc/assessment.rb +25 -0
- data/lib/canvas_cc/cc/assignment.rb +61 -0
- data/lib/canvas_cc/cc/cc_helper.rb +285 -0
- data/lib/canvas_cc/cc/converter.rb +137 -0
- data/lib/canvas_cc/cc/course.rb +16 -0
- data/lib/canvas_cc/cc/discussion_topic.rb +53 -0
- data/lib/canvas_cc/cc/label.rb +6 -0
- data/lib/canvas_cc/cc/question.rb +23 -0
- data/lib/canvas_cc/cc/resource.rb +30 -0
- data/lib/canvas_cc/cc/templates/assignment.html.erb +13 -0
- data/lib/canvas_cc/cc/templates/syllabus.html.erb +9 -0
- data/lib/canvas_cc/cc/templates/wiki_content.html.erb +10 -0
- data/lib/canvas_cc/cc/web_content.rb +48 -0
- data/lib/canvas_cc/cc/web_link.rb +75 -0
- data/lib/canvas_cc/cc/wiki.rb +73 -0
- data/lib/canvas_cc/version.rb +3 -0
- data/lib/canvas_cc.rb +94 -0
- data/spec/moodle2cc/canvas_cc/assessment_writer_spec.rb +95 -0
- data/spec/moodle2cc/canvas_cc/assignment_group_writer_spec.rb +51 -0
- data/spec/moodle2cc/canvas_cc/assignment_writer_spec.rb +74 -0
- data/spec/moodle2cc/canvas_cc/calculated_question_writer_spec.rb +88 -0
- data/spec/moodle2cc/canvas_cc/canvas_export_writer_spec.rb +26 -0
- data/spec/moodle2cc/canvas_cc/cartridge_creator_spec.rb +50 -0
- data/spec/moodle2cc/canvas_cc/course_setting_writer_spec.rb +47 -0
- data/spec/moodle2cc/canvas_cc/discussion_writer_spec.rb +38 -0
- data/spec/moodle2cc/canvas_cc/essay_question_writer_spec.rb +31 -0
- data/spec/moodle2cc/canvas_cc/file_meta_writer_spec.rb +57 -0
- data/spec/moodle2cc/canvas_cc/ims_manifest_generator_spec.rb +141 -0
- data/spec/moodle2cc/canvas_cc/matching_question_writer_spec.rb +51 -0
- data/spec/moodle2cc/canvas_cc/models/assessment_spec.rb +131 -0
- data/spec/moodle2cc/canvas_cc/models/assignment_group_spec.rb +9 -0
- data/spec/moodle2cc/canvas_cc/models/assignment_spec.rb +45 -0
- data/spec/moodle2cc/canvas_cc/models/calculated_question_spec.rb +25 -0
- data/spec/moodle2cc/canvas_cc/models/canvas_file_spec.rb +23 -0
- data/spec/moodle2cc/canvas_cc/models/canvas_module_spec.rb +16 -0
- data/spec/moodle2cc/canvas_cc/models/course_spec.rb +43 -0
- data/spec/moodle2cc/canvas_cc/models/discussion_spec.rb +47 -0
- data/spec/moodle2cc/canvas_cc/models/discussion_topic_spec.rb +7 -0
- data/spec/moodle2cc/canvas_cc/models/module_item_spec.rb +15 -0
- data/spec/moodle2cc/canvas_cc/models/page_spec.rb +34 -0
- data/spec/moodle2cc/canvas_cc/models/question_spec.rb +8 -0
- data/spec/moodle2cc/canvas_cc/models/resource_spec.rb +17 -0
- data/spec/moodle2cc/canvas_cc/models/web_content_spec.rb +7 -0
- data/spec/moodle2cc/canvas_cc/models/web_link_spec.rb +9 -0
- data/spec/moodle2cc/canvas_cc/module_meta_writer_spec.rb +118 -0
- data/spec/moodle2cc/canvas_cc/multiple_answers_question_writer_spec.rb +50 -0
- data/spec/moodle2cc/canvas_cc/multiple_blanks_question_writer_spec.rb +77 -0
- data/spec/moodle2cc/canvas_cc/multiple_choice_question_writer_spec.rb +69 -0
- data/spec/moodle2cc/canvas_cc/multiple_dropdowns_question_writer_spec.rb +46 -0
- data/spec/moodle2cc/canvas_cc/numerical_question_writer_spec.rb +69 -0
- data/spec/moodle2cc/canvas_cc/page_writer_spec.rb +29 -0
- data/spec/moodle2cc/canvas_cc/question_bank_writer_spec.rb +43 -0
- data/spec/moodle2cc/canvas_cc/question_writer_spec.rb +129 -0
- data/spec/moodle2cc/canvas_cc/short_answer_question_writer_spec.rb +50 -0
- data/spec/moodle2cc/canvas_cc/text_only_question_writer_spec.rb +23 -0
- data/spec/moodle2cc/canvas_cc/true_false_question_writer_spec.rb +62 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/shared_examples_for_models.rb +26 -0
- data/test/acceptance/migrator_test.rb +24 -0
- data/test/fixtures/cc.imscc +0 -0
- data/test/fixtures/common_cartridge/ims_manifest_simple.xml +45 -0
- data/test/fixtures/common_cartridge/schema/cccv1p0.xsd +563 -0
- data/test/fixtures/common_cartridge/schema/ccv1p1_imsccauth_v1p1.xsd +203 -0
- data/test/fixtures/common_cartridge/schema/ccv1p1_imscp_v1p2_v1p0.xsd +827 -0
- data/test/fixtures/common_cartridge/schema/ccv1p1_lommanifest_v1p0.xsd +822 -0
- data/test/fixtures/common_cartridge/schema/ccv1p1_lomresource_v1p0.xsd +273 -0
- data/test/fixtures/common_cartridge/schema/xml.xsd +286 -0
- data/test/test_helper.rb +71 -0
- data/test/test_question_helper.rb +122 -0
- data/test/test_wiki_helper.rb +21 -0
- data/test/unit/canvas/assessment_test.rb +261 -0
- data/test/unit/canvas/assignment_test.rb +220 -0
- data/test/unit/canvas/converter_test.rb +171 -0
- data/test/unit/canvas/course_test.rb +176 -0
- data/test/unit/canvas/discussion_topic_test.rb +129 -0
- data/test/unit/canvas/label_test.rb +32 -0
- data/test/unit/canvas/question_bank_test.rb +92 -0
- data/test/unit/canvas/question_group_test.rb +90 -0
- data/test/unit/canvas/question_test.rb +876 -0
- data/test/unit/canvas/web_content_test.rb +46 -0
- data/test/unit/canvas/web_link_test.rb +48 -0
- data/test/unit/canvas/wiki_test.rb +74 -0
- data/test/unit/cc/assessment_test.rb +48 -0
- data/test/unit/cc/assignment_test.rb +72 -0
- data/test/unit/cc/cc_helper_test.rb +19 -0
- data/test/unit/cc/converter_test.rb +173 -0
- data/test/unit/cc/course_test.rb +36 -0
- data/test/unit/cc/discussion_topic_test.rb +83 -0
- data/test/unit/cc/label_test.rb +29 -0
- data/test/unit/cc/question_test.rb +54 -0
- data/test/unit/cc/web_content_test.rb +76 -0
- data/test/unit/cc/web_link_test.rb +159 -0
- data/test/unit/cc/wiki_test.rb +139 -0
- data/test/unit/logger_test.rb +33 -0
- data/test/unit/migrator_test.rb +67 -0
- data/test/unit/resource_factory_test.rb +216 -0
- metadata +499 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
4
|
+
require 'test_question_helper'
|
5
|
+
require 'moodle2cc'
|
6
|
+
|
7
|
+
class TestUnitCCQuestion < MiniTest::Unit::TestCase
|
8
|
+
include TestHelper
|
9
|
+
include TestQuestionHelper
|
10
|
+
|
11
|
+
def setup
|
12
|
+
convert_moodle_backup
|
13
|
+
@mod = @backup.course.mods.find { |mod| mod.mod_type == 'quiz' }
|
14
|
+
@question = @mod.questions.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
clean_tmp_folder
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_it_converts_id
|
22
|
+
@question.id = 989
|
23
|
+
question = CanvasCc::CC::Question.new @question
|
24
|
+
assert_equal 989, question.id
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_it_converts_title
|
28
|
+
@question.name = "Basic Arithmetic"
|
29
|
+
question = CanvasCc::CC::Question.new @question
|
30
|
+
assert_equal "Basic Arithmetic", question.title
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_it_converts_title_with_escaped_html
|
34
|
+
@question.name = "the <div> tag"
|
35
|
+
question = CanvasCc::Canvas::Question.new @question
|
36
|
+
assert_equal "the <div> tag", question.title
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_it_has_an_identifier_based_on_id
|
40
|
+
@question.id = 989
|
41
|
+
@question.instance_id = nil
|
42
|
+
question = CanvasCc::CC::Question.new @question
|
43
|
+
assert_equal 'i04823ed56ffd4fd5f9c21db0cf25be6c', question.identifier
|
44
|
+
# question_989
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_it_has_an_identifier_based_on_instance_id
|
48
|
+
@question.instance_id = 787
|
49
|
+
question = CanvasCc::CC::Question.new @question
|
50
|
+
assert_equal 'i2edcb021d100c968ba3f570253a6aa1c', question.identifier
|
51
|
+
# question_instance_787
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
4
|
+
require 'moodle2cc'
|
5
|
+
|
6
|
+
class TestUnitCCWebContent < MiniTest::Unit::TestCase
|
7
|
+
include TestHelper
|
8
|
+
|
9
|
+
def setup
|
10
|
+
convert_moodle_backup
|
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_converts_id
|
19
|
+
@mod.id = 543
|
20
|
+
|
21
|
+
web_content = CanvasCc::CC::WebContent.new @mod
|
22
|
+
assert_equal 543, web_content.id
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_it_converts_title
|
26
|
+
@mod.name = "Instructor Resources"
|
27
|
+
|
28
|
+
web_content = CanvasCc::CC::WebContent.new @mod
|
29
|
+
assert_equal "Instructor Resources", web_content.title
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_it_converts_body
|
33
|
+
@mod.alltext = %(<h1>Hello World</h1><img src="$@FILEPHP@$$@SLASH@$folder$@SLASH@$stuff.jpg" />)
|
34
|
+
|
35
|
+
web_content = CanvasCc::CC::WebContent.new @mod
|
36
|
+
assert_equal %(<h1>Hello World</h1><img src="$IMS_CC_FILEBASE$/folder/stuff.jpg" />), web_content.body
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_it_has_an_identifier
|
40
|
+
@mod.id = 543
|
41
|
+
|
42
|
+
web_content = CanvasCc::CC::WebContent.new @mod
|
43
|
+
assert_equal 'i6447ff05ab6e342a42302007a6e3bcb4', web_content.identifier
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_it_creates_resource_in_imsmanifest
|
47
|
+
web_content = CanvasCc::CC::WebContent.new @mod
|
48
|
+
node = Builder::XmlMarkup.new
|
49
|
+
xml = Nokogiri::XML(web_content.create_resource_node(node))
|
50
|
+
|
51
|
+
resource = xml.xpath('resource').first
|
52
|
+
assert resource
|
53
|
+
assert_equal 'webcontent', resource.attributes['type'].value
|
54
|
+
assert_equal 'i6447ff05ab6e342a42302007a6e3bcb4', resource.attributes['identifier'].value
|
55
|
+
assert_equal CanvasCc::CC::CCHelper::CC_WIKI_FOLDER + '/instructor-resources.html', resource.attributes['href'].value
|
56
|
+
|
57
|
+
file = resource.xpath(%{file[@href="#{CanvasCc::CC::CCHelper::CC_WIKI_FOLDER}/instructor-resources.html"]}).first
|
58
|
+
assert file
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_it_creates_html
|
62
|
+
@mod.id = 543
|
63
|
+
@mod.name = "Instructor Resources"
|
64
|
+
@mod.alltext = "<p><strong>Instructor Resources</strong></p>"
|
65
|
+
|
66
|
+
tmp_dir = File.expand_path('../../../tmp', __FILE__)
|
67
|
+
web_content = CanvasCc::CC::WebContent.new @mod
|
68
|
+
web_content.create_html(tmp_dir)
|
69
|
+
html = Nokogiri::HTML(File.read(File.join(tmp_dir, CanvasCc::CC::CCHelper::CC_WIKI_FOLDER, 'instructor-resources.html')))
|
70
|
+
|
71
|
+
assert html
|
72
|
+
assert_equal 'i6447ff05ab6e342a42302007a6e3bcb4', html.search('head meta[name="identifier"]').first.attributes['content'].value
|
73
|
+
assert_equal "Instructor Resources", html.search('title').text
|
74
|
+
assert_equal "<p><strong>Instructor Resources</strong></p>", html.search('body').inner_html.strip
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
4
|
+
require 'moodle2cc'
|
5
|
+
|
6
|
+
class TestUnitCCWebLink < MiniTest::Unit::TestCase
|
7
|
+
include TestHelper
|
8
|
+
|
9
|
+
def setup
|
10
|
+
convert_moodle_backup
|
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_converts_id
|
19
|
+
@mod.id = 123
|
20
|
+
|
21
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
22
|
+
assert_equal 123, web_link.id
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_it_converts_title
|
26
|
+
@mod.name = "About Your Instructor"
|
27
|
+
|
28
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
29
|
+
assert_equal "About Your Instructor", web_link.title
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_it_converts_url
|
33
|
+
@mod.reference = "http://en.wikipedia.org/wiki/Einstein"
|
34
|
+
|
35
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
36
|
+
assert_equal "http://en.wikipedia.org/wiki/Einstein", web_link.url
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_it_strips_whitespace_from_url
|
40
|
+
@mod.reference = " http://en.wikipedia.org/wiki/Einstein "
|
41
|
+
|
42
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
43
|
+
assert_equal "http://en.wikipedia.org/wiki/Einstein", web_link.url
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_it_converts_external_link
|
47
|
+
@mod.reference = "http://en.wikipedia.org/wiki/Einstein"
|
48
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
49
|
+
assert_equal true, web_link.external_link
|
50
|
+
|
51
|
+
@mod.reference = "files/myfile.txt"
|
52
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
53
|
+
assert_equal false, web_link.external_link
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_it_converts_external_link_with_spaces_in_the_url
|
57
|
+
@mod.reference = "http://en.wikipedia.org/wiki/Einstein with a Space"
|
58
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
59
|
+
assert_equal true, web_link.external_link
|
60
|
+
|
61
|
+
@mod.reference = "files/my file.txt"
|
62
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
63
|
+
assert_equal false, web_link.external_link
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_it_converts_external_link_with_completely_invalid_url
|
67
|
+
@mod.reference = 'http://!@#$%^&*'
|
68
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
69
|
+
assert_equal true, web_link.external_link
|
70
|
+
|
71
|
+
@mod.reference = 'files/!@#$%^&*.txt'
|
72
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
73
|
+
assert_equal false, web_link.external_link
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_if_converts_href
|
77
|
+
@mod.reference = "http://en.wikipedia.org/wiki/Einstein"
|
78
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
79
|
+
assert_equal "#{web_link.identifier}.xml", web_link.href
|
80
|
+
|
81
|
+
@mod.reference = "files/myfile.txt"
|
82
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
83
|
+
assert_equal 'web_resources/files/myfile.txt', web_link.href
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_it_has_an_identifier_for_external_link
|
87
|
+
@mod.id = 123
|
88
|
+
|
89
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
90
|
+
assert_equal 'iecc4b622fbc1adf8b8a2085e0974ac7d', web_link.identifier
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_it_has_an_identifier_for_local_file
|
94
|
+
@mod.reference = "files/myfile.txt"
|
95
|
+
|
96
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
97
|
+
assert_equal 'i5cfabae035bff8857137d83c2a067809', web_link.identifier
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_it_creates_resource_in_imsmanifest_for_external_link
|
101
|
+
@mod.reference = "http://en.wikipedia.org/wiki/Einstein"
|
102
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
103
|
+
node = Builder::XmlMarkup.new
|
104
|
+
xml = Nokogiri::XML(web_link.create_resource_node(node))
|
105
|
+
|
106
|
+
resource = xml.xpath('resource').first
|
107
|
+
assert resource
|
108
|
+
assert_equal 'imswl_xmlv1p1', resource.attributes['type'].value
|
109
|
+
assert_equal 'i15aaccec404aa2ad557108a689bbba8f', resource.attributes['identifier'].value
|
110
|
+
|
111
|
+
file = resource.xpath('file[@href="i15aaccec404aa2ad557108a689bbba8f.xml"]').first
|
112
|
+
assert file
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_it_creates_resource_in_imsmanifest_for_local_file
|
116
|
+
@mod.reference = "files/myfile.txt"
|
117
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
118
|
+
node = Builder::XmlMarkup.new
|
119
|
+
xml = Nokogiri::XML(web_link.create_resource_node(node))
|
120
|
+
|
121
|
+
resource = xml.xpath('resource').first
|
122
|
+
assert resource
|
123
|
+
assert_equal 'webcontent', resource.attributes['type'].value
|
124
|
+
assert_equal 'web_resources/files/myfile.txt', resource.attributes['href'].value
|
125
|
+
assert_equal 'i5cfabae035bff8857137d83c2a067809', resource.attributes['identifier'].value
|
126
|
+
|
127
|
+
file = resource.xpath('file[@href="web_resources/files/myfile.txt"]').first
|
128
|
+
assert file
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_it_creates_xml
|
132
|
+
@mod.id = 123
|
133
|
+
@mod.name = "About Your Instructor"
|
134
|
+
@mod.reference = "http://en.wikipedia.org/wiki/Einstein"
|
135
|
+
|
136
|
+
tmp_dir = File.expand_path('../../../tmp', __FILE__)
|
137
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
138
|
+
web_link.create_xml(tmp_dir)
|
139
|
+
xml = Nokogiri::XML(File.read(File.join(tmp_dir, "#{web_link.identifier}.xml")))
|
140
|
+
|
141
|
+
assert xml
|
142
|
+
assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd", xml.root.attributes['schemaLocation'].value
|
143
|
+
assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
|
144
|
+
assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1", xml.namespaces['xmlns']
|
145
|
+
assert_equal web_link.identifier, xml.xpath('xmlns:webLink').first.attributes['identifier'].value
|
146
|
+
|
147
|
+
assert_equal "About Your Instructor", xml.xpath('xmlns:webLink/xmlns:title').text
|
148
|
+
assert xml.xpath('xmlns:webLink/xmlns:url[@href="http://en.wikipedia.org/wiki/Einstein"]').first
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_it_does_not_create_xml_for_local_files
|
152
|
+
@mod.reference = "files/myfile.txt"
|
153
|
+
|
154
|
+
tmp_dir = File.expand_path('../../../tmp', __FILE__)
|
155
|
+
web_link = CanvasCc::CC::WebLink.new @mod
|
156
|
+
web_link.create_xml(tmp_dir)
|
157
|
+
refute File.exists?(File.join(tmp_dir, "#{web_link.identifier}.xml")), 'xml file was created for local file'
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'test_helper'
|
4
|
+
require 'test_wiki_helper'
|
5
|
+
require 'moodle2cc'
|
6
|
+
|
7
|
+
class TestUnitCCWiki < MiniTest::Unit::TestCase
|
8
|
+
include TestHelper
|
9
|
+
include TestWikiHelper
|
10
|
+
|
11
|
+
def setup
|
12
|
+
convert_moodle_backup
|
13
|
+
@mod = @backup.course.mods.find { |m| m.mod_type == "wiki" }
|
14
|
+
@wiki = CanvasCc::CC::Wiki.new @mod
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
clean_tmp_folder
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_it_converts_id
|
22
|
+
@mod.id = 210
|
23
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
24
|
+
assert_equal 210, wiki.id
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_it_converts_title
|
28
|
+
@mod.name = 'My Wiki'
|
29
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
30
|
+
assert_equal 'My Wiki', wiki.title
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_it_converts_page_name
|
34
|
+
@mod.name = 'My Wiki'
|
35
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
36
|
+
assert_equal 'My Wiki', wiki.title
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_it_converts_pages
|
40
|
+
pages!
|
41
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
42
|
+
assert_equal 2, wiki.pages.length
|
43
|
+
|
44
|
+
assert_equal 'My Wiki', wiki.pages[0].title
|
45
|
+
assert_equal 'Second version', wiki.pages[0].body
|
46
|
+
assert_equal CanvasCc::CC::CCHelper::CC_WIKI_FOLDER + '/my-wiki-my-wiki.html', wiki.pages[0].href
|
47
|
+
assert_equal 'i2eb0de275c9d8430f49bbf4cdf96286c', wiki.pages[0].identifier
|
48
|
+
|
49
|
+
assert_equal 'New Page', wiki.pages[1].title
|
50
|
+
assert_equal 'This is a link to [My Wiki]', wiki.pages[1].body
|
51
|
+
assert_equal CanvasCc::CC::CCHelper::CC_WIKI_FOLDER + '/my-wiki-new-page.html', wiki.pages[1].href
|
52
|
+
assert_equal 'i2eb0de275c9d8430f49bbf4cdf96286c', wiki.pages[0].identifier
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_it_converts_summary_to_page_if_no_pages_exist
|
56
|
+
@mod.page_name = 'My Wiki'
|
57
|
+
@mod.summary = 'This is the summary'
|
58
|
+
@mod.pages = []
|
59
|
+
|
60
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
61
|
+
assert_equal 1, wiki.pages.length
|
62
|
+
|
63
|
+
assert_equal 'My wiki', wiki.pages[0].title
|
64
|
+
assert_equal 'This is the summary', wiki.pages[0].body
|
65
|
+
assert_equal CanvasCc::CC::CCHelper::CC_WIKI_FOLDER + '/my-wiki.html', wiki.pages[0].href
|
66
|
+
assert_equal 'ib1bfc2398c654e88470adb5a882f83e5', wiki.pages[0].identifier
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_it_has_a_root_page_for_defined_pages
|
70
|
+
pages!
|
71
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
72
|
+
page = wiki.pages.find { |page| page.title == 'My Wiki' }
|
73
|
+
assert_equal page, wiki.root_page
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_it_has_a_root_page_for_summary
|
77
|
+
@mod.page_name = 'My Wiki'
|
78
|
+
@mod.summary = 'This is the summary'
|
79
|
+
@mod.pages = []
|
80
|
+
|
81
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
82
|
+
page = wiki.pages.first
|
83
|
+
assert_equal page, wiki.root_page
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_it_has_a_identifier_for_root_page
|
87
|
+
@mod.page_name = 'My Wiki'
|
88
|
+
@mod.summary = 'This is the summary'
|
89
|
+
@mod.pages = []
|
90
|
+
|
91
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
92
|
+
assert_equal 'ib1bfc2398c654e88470adb5a882f83e5', wiki.identifier
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_it_creates_resource_in_imsmanifest
|
96
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
97
|
+
node = Builder::XmlMarkup.new
|
98
|
+
xml = node.root do |root_node|
|
99
|
+
wiki.create_resource_node(node)
|
100
|
+
end
|
101
|
+
xml = Nokogiri::XML(xml)
|
102
|
+
|
103
|
+
resource = xml.root.xpath('resource[1]').first
|
104
|
+
assert resource
|
105
|
+
assert_equal 'webcontent', resource.attributes['type'].value
|
106
|
+
assert_equal CanvasCc::CC::CCHelper::CC_WIKI_FOLDER + '/my-wiki-link.html', resource.attributes['href'].value
|
107
|
+
assert_equal 'ie8b2c8b5a9156a6994b13abae6b18da6', resource.attributes['identifier'].value
|
108
|
+
|
109
|
+
file = resource.xpath(%{file[@href="#{CanvasCc::CC::CCHelper::CC_WIKI_FOLDER}/my-wiki-link.html"]}).first
|
110
|
+
assert file
|
111
|
+
|
112
|
+
resource = xml.root.xpath('resource[2]').first
|
113
|
+
assert resource
|
114
|
+
assert_equal 'webcontent', resource.attributes['type'].value
|
115
|
+
assert_equal CanvasCc::CC::CCHelper::CC_WIKI_FOLDER + '/my-wiki-my-wiki.html', resource.attributes['href'].value
|
116
|
+
assert_equal 'i2eb0de275c9d8430f49bbf4cdf96286c', resource.attributes['identifier'].value
|
117
|
+
|
118
|
+
file = resource.xpath(%{file[@href="#{CanvasCc::CC::CCHelper::CC_WIKI_FOLDER}/my-wiki-my-wiki.html"]}).first
|
119
|
+
assert file
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_it_creates_wiki_html
|
123
|
+
wiki = CanvasCc::CC::Wiki.new @mod
|
124
|
+
tmp_dir = File.expand_path('../../../tmp', __FILE__)
|
125
|
+
wiki.create_html(tmp_dir)
|
126
|
+
|
127
|
+
html = Nokogiri::HTML(File.read(File.join(tmp_dir, CanvasCc::CC::CCHelper::CC_WIKI_FOLDER + '/my-wiki-my-wiki.html')))
|
128
|
+
assert html
|
129
|
+
assert_equal 'i2eb0de275c9d8430f49bbf4cdf96286c', html.search('meta[name="identifier"]').first.attributes['content'].value
|
130
|
+
assert_equal 'My Wiki', html.search('title').text
|
131
|
+
assert_equal 'Hello [link]', html.search('body').inner_html.strip
|
132
|
+
|
133
|
+
html = Nokogiri::HTML(File.read(File.join(tmp_dir, CanvasCc::CC::CCHelper::CC_WIKI_FOLDER + '/my-wiki-link.html')))
|
134
|
+
assert html
|
135
|
+
assert_equal 'ie8b2c8b5a9156a6994b13abae6b18da6', html.search('meta[name="identifier"]').first.attributes['content'].value
|
136
|
+
assert_equal 'link', html.search('title').text
|
137
|
+
assert_equal 'This is a linked page', html.search('body').inner_html.strip
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'moodle2cc'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class TestUnitLogger < MiniTest::Unit::TestCase
|
6
|
+
class MyLogger
|
7
|
+
attr_accessor :message, :exception
|
8
|
+
|
9
|
+
def add_warning(message, exception)
|
10
|
+
@message = message
|
11
|
+
@exception = exception
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_it_logs_a_warning
|
16
|
+
stdout = StringIO.new
|
17
|
+
CanvasCc::Logger.logger = ::Logger.new(stdout)
|
18
|
+
ex = StandardError.new 'Kablooey!!!'
|
19
|
+
CanvasCc::Logger.add_warning 'got an error', ex
|
20
|
+
assert_match /got an error/, stdout.string
|
21
|
+
assert_match /Kablooey!!!/, stdout.string
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_it_adds_a_warning
|
25
|
+
my_logger = MyLogger.new
|
26
|
+
CanvasCc::Logger.logger = my_logger
|
27
|
+
ex = StandardError.new 'Kablooey!!!'
|
28
|
+
msg = 'got an error'
|
29
|
+
CanvasCc::Logger.add_warning msg, ex
|
30
|
+
assert_equal msg, my_logger.message
|
31
|
+
assert_equal ex, my_logger.exception
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'test_helper'
|
3
|
+
require 'moodle2cc'
|
4
|
+
|
5
|
+
class TestUnitMigrator < MiniTest::Unit::TestCase
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@valid_source = create_moodle_backup_zip
|
10
|
+
@valid_destination = File.expand_path("../../tmp", __FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
clean_tmp_folder
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_it_accepts_a_source_and_destination
|
18
|
+
migrator = CanvasCc::Migrator.new @valid_source, @valid_destination
|
19
|
+
assert migrator
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_source_must_exist
|
23
|
+
assert_raises CanvasCc::Error, "'does_not_exist' does not exist" do
|
24
|
+
CanvasCc::Migrator.new 'does_not_exist', 'there'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_destination_must_be_a_directory
|
29
|
+
assert_raises CanvasCc::Error, "'is_not_a_directory' is not a directory" do
|
30
|
+
CanvasCc::Migrator.new @valid_source, 'is_not_a_directory'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_it_allows_cc_format
|
35
|
+
migrator = CanvasCc::Migrator.new @valid_source, @valid_destination, 'format' => 'cc'
|
36
|
+
assert_equal CanvasCc::CC::Converter, migrator.instance_variable_get(:@converter_class)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_it_allows_canvas_format
|
40
|
+
migrator = CanvasCc::Migrator.new @valid_source, @valid_destination, 'format' => 'canvas'
|
41
|
+
assert_equal CanvasCc::Canvas::Converter, migrator.instance_variable_get(:@converter_class)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_it_does_not_allow_any_other_format
|
45
|
+
assert_raises CanvasCc::Error, "'angel' is not a valid format. Please use 'cc' or 'canvas'." do
|
46
|
+
CanvasCc::Migrator.new @valid_source, @valid_destination, 'format' => 'angel'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_it_converts_moodle_backup
|
51
|
+
migrator = CanvasCc::Migrator.new @valid_source, @valid_destination
|
52
|
+
migrator.migrate
|
53
|
+
imscc_file = File.join(@valid_destination, "my-course.imscc")
|
54
|
+
assert File.exists?(imscc_file), "#{imscc_file} does not exist"
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_it_detects_moodle2_package
|
58
|
+
migrator = CanvasCc::Migrator.new(fixture_path(File.join('moodle2', 'moodle2_shell.mbz')), @valid_destination)
|
59
|
+
expect(migrator, :migrate_moodle_2) { migrator.migrate }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_it_detects_moodle_1_9_package
|
63
|
+
migrator = CanvasCc::Migrator.new(@valid_source, @valid_destination)
|
64
|
+
expect(migrator, :migrate_moodle_1_9) { migrator.migrate }
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|