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,36 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test/test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCCCourse < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ @course = @backup.course
12
+ @cc_course = Moodle2CC::CC::Course.new @course
13
+ end
14
+
15
+ def teardown
16
+ clean_tmp_folder
17
+ end
18
+
19
+ def test_it_converts_format
20
+ @course.format = 'weeks'
21
+ cc_course = Moodle2CC::CC::Course.new @course
22
+ assert_equal 'Week', cc_course.format
23
+
24
+ @course.format = 'weekscss'
25
+ cc_course = Moodle2CC::CC::Course.new @course
26
+ assert_equal 'Week', cc_course.format
27
+
28
+ @course.format = 'social'
29
+ cc_course = Moodle2CC::CC::Course.new @course
30
+ assert_equal 'Topic', cc_course.format
31
+
32
+ @course.format = 'topics'
33
+ cc_course = Moodle2CC::CC::Course.new @course
34
+ assert_equal 'Topic', cc_course.format
35
+ end
36
+ end
@@ -0,0 +1,83 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test/test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCCDiscussionTopic < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ @mod = @backup.course.mods.find { |mod| mod.mod_type == 'forum' }
12
+ end
13
+
14
+ def teardown
15
+ clean_tmp_folder
16
+ end
17
+
18
+ def test_it_converts_id
19
+ @mod.id = 567
20
+
21
+ discussion_topic = Moodle2CC::CC::DiscussionTopic.new @mod
22
+ assert_equal 567, discussion_topic.id
23
+ end
24
+
25
+ def test_it_converts_title
26
+ @mod.name = "Announcements"
27
+
28
+ discussion_topic = Moodle2CC::CC::DiscussionTopic.new @mod
29
+ assert_equal "Announcements", discussion_topic.title
30
+ end
31
+
32
+ def test_it_converts_text
33
+ @mod.intro = %(<h1>Hello World</h1><img src="$@FILEPHP@$$@SLASH@$folder$@SLASH@$stuff.jpg" />)
34
+
35
+ discussion_topic = Moodle2CC::CC::DiscussionTopic.new @mod
36
+ assert_equal %(<h1>Hello World</h1><img src="$IMS_CC_FILEBASE$/folder/stuff.jpg" />), discussion_topic.text
37
+ end
38
+
39
+ def test_it_has_an_identifier
40
+ @mod.id = 123
41
+
42
+ discussion_topic = Moodle2CC::CC::DiscussionTopic.new @mod
43
+ assert_equal 'ifb967ca1271d3e119ae5e22d32eeae1b', discussion_topic.identifier
44
+ end
45
+
46
+ def test_it_creates_resource_in_imsmanifest
47
+ discussion_topic = Moodle2CC::CC::DiscussionTopic.new @mod
48
+ node = Builder::XmlMarkup.new
49
+ xml = node.root do |root_node|
50
+ discussion_topic.create_resource_node(node)
51
+ end
52
+ xml = Nokogiri::XML(xml)
53
+
54
+ resource = xml.root.xpath('resource[1]').first
55
+ assert resource
56
+ assert_equal 'imsdt_xmlv1p1', resource.attributes['type'].value
57
+ assert_equal 'if7091ac80f57e45c757345555327b248', resource.attributes['identifier'].value
58
+
59
+ file = resource.xpath('file[@href="if7091ac80f57e45c757345555327b248.xml"]').first
60
+ assert file
61
+
62
+ assert get_imscc_file('if7091ac80f57e45c757345555327b248.xml') # topic xml
63
+ end
64
+
65
+ def test_it_create_topic_xml
66
+ @mod.name = "Announcements"
67
+ @mod.intro = "<h1>Hello World</h1>"
68
+
69
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
70
+ discussion_topic = Moodle2CC::CC::DiscussionTopic.new @mod
71
+ discussion_topic.create_topic_xml(tmp_dir)
72
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, "#{discussion_topic.identifier}.xml")))
73
+
74
+ assert xml
75
+ assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imsdt_v1p1.xsd", xml.root.attributes['schemaLocation'].value
76
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
77
+ assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1", xml.namespaces['xmlns']
78
+
79
+ assert_equal 'Announcements', xml.search('title').text
80
+ assert_equal 'text/html', xml.search('text').first.attributes['texttype'].value
81
+ assert_equal '<h1>Hello World</h1>', xml.search('text').text
82
+ end
83
+ end
@@ -0,0 +1,29 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test/test_helper'
4
+ require 'moodle2cc'
5
+
6
+ class TestUnitCCLabel < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def setup
10
+ convert_moodle_backup
11
+ @mod = @backup.course.mods.find { |m| m.mod_type == "label" }
12
+ end
13
+
14
+ def teardown
15
+ clean_tmp_folder
16
+ end
17
+
18
+ def test_it_converts_id
19
+ @mod.id = 654
20
+ label = Moodle2CC::CC::Label.new @mod
21
+ assert_equal 654, label.id
22
+ end
23
+
24
+ def test_it_converts_title
25
+ @mod.name = 'label123'
26
+ label = Moodle2CC::CC::Label.new @mod
27
+ assert_equal 'label123', label.title
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test/test_helper'
4
+ require 'test/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
+
22
+ def test_it_converts_id
23
+ @question.id = 989
24
+ question = Moodle2CC::CC::Question.new @question
25
+ assert_equal 989, question.id
26
+ end
27
+
28
+ def test_it_converts_title
29
+ @question.name = "Basic Arithmetic"
30
+ question = Moodle2CC::CC::Question.new @question
31
+ assert_equal "Basic Arithmetic", question.title
32
+ end
33
+
34
+ def test_it_has_an_identifier_based_on_id
35
+ @question.id = 989
36
+ @question.instance_id = nil
37
+ question = Moodle2CC::CC::Question.new @question
38
+ assert_equal 'i04823ed56ffd4fd5f9c21db0cf25be6c', question.identifier
39
+ # question_989
40
+ end
41
+
42
+ def test_it_has_an_identifier_based_on_instance_id
43
+ @question.instance_id = 787
44
+ question = Moodle2CC::CC::Question.new @question
45
+ assert_equal 'i2edcb021d100c968ba3f570253a6aa1c', question.identifier
46
+ # question_instance_787
47
+ end
48
+
49
+ end
@@ -0,0 +1,76 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test/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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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 'wiki_content/instructor-resources.html', resource.attributes['href'].value
56
+
57
+ file = resource.xpath('file[@href="wiki_content/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 = Moodle2CC::CC::WebContent.new @mod
68
+ web_content.create_html(tmp_dir)
69
+ html = Nokogiri::HTML(File.read(File.join(tmp_dir, 'wiki_content', '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,79 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test/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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::CC::WebLink.new @mod
36
+ assert_equal "http://en.wikipedia.org/wiki/Einstein", web_link.url
37
+ end
38
+
39
+ def test_it_has_an_identifier
40
+ @mod.id = 123
41
+
42
+ web_link = Moodle2CC::CC::WebLink.new @mod
43
+ assert_equal 'iecc4b622fbc1adf8b8a2085e0974ac7d', web_link.identifier
44
+ end
45
+
46
+ def test_it_creates_resource_in_imsmanifest
47
+ web_link = Moodle2CC::CC::WebLink.new @mod
48
+ node = Builder::XmlMarkup.new
49
+ xml = Nokogiri::XML(web_link.create_resource_node(node))
50
+
51
+ resource = xml.xpath('resource').first
52
+ assert resource
53
+ assert_equal 'imswl_xmlv1p1', resource.attributes['type'].value
54
+ assert_equal 'i15aaccec404aa2ad557108a689bbba8f', resource.attributes['identifier'].value
55
+
56
+ file = resource.xpath('file[@href="i15aaccec404aa2ad557108a689bbba8f.xml"]').first
57
+ assert file
58
+ end
59
+
60
+ def test_it_creates_xml
61
+ @mod.id = 123
62
+ @mod.name = "About Your Instructor"
63
+ @mod.reference = "http://en.wikipedia.org/wiki/Einstein"
64
+
65
+ tmp_dir = File.expand_path('../../../tmp', __FILE__)
66
+ web_link = Moodle2CC::CC::WebLink.new @mod
67
+ web_link.create_xml(tmp_dir)
68
+ xml = Nokogiri::XML(File.read(File.join(tmp_dir, "#{web_link.identifier}.xml")))
69
+
70
+ assert xml
71
+ 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
72
+ assert_equal "http://www.w3.org/2001/XMLSchema-instance", xml.namespaces['xmlns:xsi']
73
+ assert_equal "http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1", xml.namespaces['xmlns']
74
+ assert_equal web_link.identifier, xml.xpath('xmlns:webLink').first.attributes['identifier'].value
75
+
76
+ assert_equal "About Your Instructor", xml.xpath('xmlns:webLink/xmlns:title').text
77
+ assert xml.xpath('xmlns:webLink/xmlns:url[@href="http://en.wikipedia.org/wiki/Einstein"]').first
78
+ end
79
+ end
@@ -0,0 +1,139 @@
1
+ require 'nokogiri'
2
+ require 'minitest/autorun'
3
+ require 'test/test_helper'
4
+ require 'test/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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::CC::Wiki.new @mod
36
+ assert_equal 'My Wiki', wiki.title
37
+ end
38
+
39
+ def test_it_converts_pages
40
+ pages!
41
+ wiki = Moodle2CC::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 'wiki_content/my-wiki-my-wiki.html', wiki.pages[0].href
47
+ assert_equal 'i56eb35e2b44710c48f7aa6b6297e9c98', 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 'wiki_content/my-wiki-new-page.html', wiki.pages[1].href
52
+ assert_equal 'i56eb35e2b44710c48f7aa6b6297e9c98', 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 = Moodle2CC::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 'wiki_content/my-wiki.html', wiki.pages[0].href
66
+ assert_equal 'ib87fd4bafae6f3e3ee7dadb65b0e45a3', wiki.pages[0].identifier
67
+ end
68
+
69
+ def test_it_has_a_root_page_for_defined_pages
70
+ pages!
71
+ wiki = Moodle2CC::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 = Moodle2CC::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 = Moodle2CC::CC::Wiki.new @mod
92
+ assert_equal 'ib87fd4bafae6f3e3ee7dadb65b0e45a3', wiki.identifier
93
+ end
94
+
95
+ def test_it_creates_resource_in_imsmanifest
96
+ wiki = Moodle2CC::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 'wiki_content/my-wiki-link.html', resource.attributes['href'].value
107
+ assert_equal 'i13d1eba598141a33bd00dc38186d148a', resource.attributes['identifier'].value
108
+
109
+ file = resource.xpath('file[@href="wiki_content/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 'wiki_content/my-wiki-my-wiki.html', resource.attributes['href'].value
116
+ assert_equal 'i56eb35e2b44710c48f7aa6b6297e9c98', resource.attributes['identifier'].value
117
+
118
+ file = resource.xpath('file[@href="wiki_content/my-wiki-my-wiki.html"]').first
119
+ assert file
120
+ end
121
+
122
+ def test_it_creates_wiki_html
123
+ wiki = Moodle2CC::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, 'wiki_content/my-wiki-my-wiki.html')))
128
+ assert html
129
+ assert_equal 'i56eb35e2b44710c48f7aa6b6297e9c98', 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, 'wiki_content/my-wiki-link.html')))
134
+ assert html
135
+ assert_equal 'i13d1eba598141a33bd00dc38186d148a', 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