scorm2004-manifest 0.1.0

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 (129) hide show
  1. data/.document +5 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +36 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +94 -0
  6. data/Rakefile +39 -0
  7. data/VERSION +1 -0
  8. data/lib/scorm2004/manifest/adlseq_map_info.rb +17 -0
  9. data/lib/scorm2004/manifest/adlseq_objective.rb +14 -0
  10. data/lib/scorm2004/manifest/adlseq_objectives.rb +11 -0
  11. data/lib/scorm2004/manifest/attributes.rb +147 -0
  12. data/lib/scorm2004/manifest/children.rb +83 -0
  13. data/lib/scorm2004/manifest/completion_threshold.rb +13 -0
  14. data/lib/scorm2004/manifest/condition_rule.rb +12 -0
  15. data/lib/scorm2004/manifest/constrained_choice_considerations.rb +12 -0
  16. data/lib/scorm2004/manifest/control_mode.rb +16 -0
  17. data/lib/scorm2004/manifest/custom_error.rb +15 -0
  18. data/lib/scorm2004/manifest/data.rb +11 -0
  19. data/lib/scorm2004/manifest/data_from_lms.rb +21 -0
  20. data/lib/scorm2004/manifest/delivery_controls.rb +13 -0
  21. data/lib/scorm2004/manifest/dependency.rb +21 -0
  22. data/lib/scorm2004/manifest/error.rb +5 -0
  23. data/lib/scorm2004/manifest/file.rb +16 -0
  24. data/lib/scorm2004/manifest/hide_lmsui.rb +21 -0
  25. data/lib/scorm2004/manifest/href.rb +24 -0
  26. data/lib/scorm2004/manifest/item.rb +36 -0
  27. data/lib/scorm2004/manifest/limit_conditions.rb +12 -0
  28. data/lib/scorm2004/manifest/manifest.rb +26 -0
  29. data/lib/scorm2004/manifest/map.rb +13 -0
  30. data/lib/scorm2004/manifest/map_info.rb +15 -0
  31. data/lib/scorm2004/manifest/min_normalized_measure.rb +18 -0
  32. data/lib/scorm2004/manifest/navigation_interface.rb +10 -0
  33. data/lib/scorm2004/manifest/objective.rb +16 -0
  34. data/lib/scorm2004/manifest/objectives.rb +12 -0
  35. data/lib/scorm2004/manifest/organization.rb +20 -0
  36. data/lib/scorm2004/manifest/organizations.rb +24 -0
  37. data/lib/scorm2004/manifest/presentation.rb +10 -0
  38. data/lib/scorm2004/manifest/primary_objective.rb +24 -0
  39. data/lib/scorm2004/manifest/randomization_controls.rb +16 -0
  40. data/lib/scorm2004/manifest/resource.rb +18 -0
  41. data/lib/scorm2004/manifest/resources.rb +12 -0
  42. data/lib/scorm2004/manifest/rollup_action.rb +13 -0
  43. data/lib/scorm2004/manifest/rollup_condition.rb +24 -0
  44. data/lib/scorm2004/manifest/rollup_conditions.rb +14 -0
  45. data/lib/scorm2004/manifest/rollup_considerations.rb +17 -0
  46. data/lib/scorm2004/manifest/rollup_rule.rb +19 -0
  47. data/lib/scorm2004/manifest/rollup_rules.rb +16 -0
  48. data/lib/scorm2004/manifest/rule_action.rb +31 -0
  49. data/lib/scorm2004/manifest/rule_condition.rb +41 -0
  50. data/lib/scorm2004/manifest/rule_conditions.rb +14 -0
  51. data/lib/scorm2004/manifest/schema.rb +18 -0
  52. data/lib/scorm2004/manifest/schemaversion.rb +18 -0
  53. data/lib/scorm2004/manifest/sequencing.rb +24 -0
  54. data/lib/scorm2004/manifest/sequencing_collection.rb +11 -0
  55. data/lib/scorm2004/manifest/sequencing_rules.rb +13 -0
  56. data/lib/scorm2004/manifest/text_node.rb +11 -0
  57. data/lib/scorm2004/manifest/time_limit_action.rb +24 -0
  58. data/lib/scorm2004/manifest/title.rb +16 -0
  59. data/lib/scorm2004/manifest/visitor_pattern.rb +31 -0
  60. data/lib/scorm2004/manifest/xml_base.rb +38 -0
  61. data/lib/scorm2004/manifest.rb +76 -0
  62. data/lib/scorm2004-manifest.rb +1 -0
  63. data/test/functional_test.rb +45 -0
  64. data/test/helper.rb +18 -0
  65. data/test/mbce_test.rb +66 -0
  66. data/test/msce_test.rb +55 -0
  67. data/test/scorm2004/manifest/adlseq_map_info_test.rb +47 -0
  68. data/test/scorm2004/manifest/adlseq_objective_test.rb +44 -0
  69. data/test/scorm2004/manifest/adlseq_objectives_test.rb +29 -0
  70. data/test/scorm2004/manifest/any_uri_token_test.rb +40 -0
  71. data/test/scorm2004/manifest/attributes_test.rb +224 -0
  72. data/test/scorm2004/manifest/children_test.rb +330 -0
  73. data/test/scorm2004/manifest/completion_threshold_test.rb +80 -0
  74. data/test/scorm2004/manifest/condition_rule_test.rb +40 -0
  75. data/test/scorm2004/manifest/constrained_choice_considerations_test.rb +25 -0
  76. data/test/scorm2004/manifest/control_mode_test.rb +41 -0
  77. data/test/scorm2004/manifest/custom_error_test.rb +43 -0
  78. data/test/scorm2004/manifest/data_from_lms_test.rb +47 -0
  79. data/test/scorm2004/manifest/data_test.rb +31 -0
  80. data/test/scorm2004/manifest/delivery_controls_test.rb +27 -0
  81. data/test/scorm2004/manifest/dependency_test.rb +53 -0
  82. data/test/scorm2004/manifest/duration_attribute_test.rb +59 -0
  83. data/test/scorm2004/manifest/file_test.rb +40 -0
  84. data/test/scorm2004/manifest/hide_lmsui_test.rb +40 -0
  85. data/test/scorm2004/manifest/href_test.rb +43 -0
  86. data/test/scorm2004/manifest/item_test.rb +86 -0
  87. data/test/scorm2004/manifest/limit_conditions_test.rb +34 -0
  88. data/test/scorm2004/manifest/manifest_test.rb +152 -0
  89. data/test/scorm2004/manifest/map_info_test.rb +41 -0
  90. data/test/scorm2004/manifest/map_test.rb +32 -0
  91. data/test/scorm2004/manifest/min_normalized_measure_test.rb +28 -0
  92. data/test/scorm2004/manifest/navigation_interface_test.rb +29 -0
  93. data/test/scorm2004/manifest/non_negative_integer_attribute_test.rb +64 -0
  94. data/test/scorm2004/manifest/objective_test.rb +45 -0
  95. data/test/scorm2004/manifest/objectives_test.rb +37 -0
  96. data/test/scorm2004/manifest/organization_test.rb +115 -0
  97. data/test/scorm2004/manifest/organizations_test.rb +68 -0
  98. data/test/scorm2004/manifest/partial_manifest.rb +23 -0
  99. data/test/scorm2004/manifest/partial_manifest_test.rb +44 -0
  100. data/test/scorm2004/manifest/presentation_test.rb +26 -0
  101. data/test/scorm2004/manifest/primary_objective_test.rb +65 -0
  102. data/test/scorm2004/manifest/randomization_controls_test.rb +71 -0
  103. data/test/scorm2004/manifest/resource_test.rb +96 -0
  104. data/test/scorm2004/manifest/resources_test.rb +41 -0
  105. data/test/scorm2004/manifest/rollup_action_test.rb +33 -0
  106. data/test/scorm2004/manifest/rollup_condition_test.rb +42 -0
  107. data/test/scorm2004/manifest/rollup_conditions_test.rb +53 -0
  108. data/test/scorm2004/manifest/rollup_considerations_test.rb +42 -0
  109. data/test/scorm2004/manifest/rollup_rule_test.rb +87 -0
  110. data/test/scorm2004/manifest/rollup_rules_test.rb +60 -0
  111. data/test/scorm2004/manifest/rule_action_test.rb +79 -0
  112. data/test/scorm2004/manifest/rule_condition_test.rb +70 -0
  113. data/test/scorm2004/manifest/rule_conditions_test.rb +37 -0
  114. data/test/scorm2004/manifest/schema_test.rb +29 -0
  115. data/test/scorm2004/manifest/schemaversion_test.rb +29 -0
  116. data/test/scorm2004/manifest/sequencing_collection_test.rb +31 -0
  117. data/test/scorm2004/manifest/sequencing_rules_test.rb +36 -0
  118. data/test/scorm2004/manifest/sequencing_test.rb +42 -0
  119. data/test/scorm2004/manifest/string_attribute_test.rb +68 -0
  120. data/test/scorm2004/manifest/text_node_test.rb +37 -0
  121. data/test/scorm2004/manifest/time_limit_action_test.rb +51 -0
  122. data/test/scorm2004/manifest/title_test.rb +59 -0
  123. data/test/scorm2004/manifest/token_attribute_test.rb +53 -0
  124. data/test/scorm2004/manifest/visitor_pattern_test.rb +85 -0
  125. data/test/scorm2004/manifest/xml_base_test.rb +125 -0
  126. data/test/scorm2004/manifest_test.rb +33 -0
  127. data/test/scorm2004_test.rb +9 -0
  128. data/test/sece_test.rb +53 -0
  129. metadata +260 -0
@@ -0,0 +1,79 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class RuleActionTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = RuleAction.new
10
+ end
11
+
12
+ test 'an empty element causes error' do
13
+ assert_error do
14
+ el('<dummy />').accept(@v)
15
+ end
16
+ end
17
+
18
+ Scorm2004::Manifest::RuleAction::PRE.each do |token|
19
+ tag = "<imsss:ruleAction action='#{token}' />"
20
+ context tag do
21
+ should 'be accepted if it is within <preConditionRule>.' do
22
+ assert pre_el(tag).accept(@v)
23
+ end
24
+
25
+ should 'cause error if it is within either <postConditionRule> or <exitConditionRule>' do
26
+ assert_error { post_el(tag).accept(@v) }
27
+ assert_error { exit_el(tag).accept(@v) }
28
+ end
29
+ end
30
+ end
31
+
32
+ Scorm2004::Manifest::RuleAction::POST.each do |token|
33
+ tag = "<imsss:ruleAction action='#{token}' />"
34
+ context tag do
35
+ should 'be accepted if it is within <postConditionRule>.' do
36
+ assert post_el(tag).accept(@v)
37
+ end
38
+
39
+ should 'cause error if it is within either <preConditionRule> or <exitConditionRule>' do
40
+ assert_error { pre_el(tag).accept(@v) }
41
+ assert_error { exit_el(tag).accept(@v) }
42
+ end
43
+ end
44
+ end
45
+
46
+ Scorm2004::Manifest::RuleAction::EXIT.each do |token|
47
+ tag = "<imsss:ruleAction action='#{token}' />"
48
+ context tag do
49
+ should 'be accepted if it is within <exitConditionRule>.' do
50
+ assert exit_el(tag).accept(@v)
51
+ end
52
+
53
+ should 'cause error if it is within either <preConditionRule> or <postConditionRule>' do
54
+ assert_error { pre_el(tag).accept(@v) }
55
+ assert_error { post_el(tag).accept(@v) }
56
+ end
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def assert_error(&block)
63
+ assert_raise RuleAction::Error, &block
64
+ end
65
+
66
+ def pre_el(xml)
67
+ el("<imsss:preConditionRule>#{xml}</imsss:preConditionRule").at('./*')
68
+ end
69
+
70
+ def post_el(xml)
71
+ el("<imsss:postConditionRule>#{xml}</imsss:postConditionRule").at('./*')
72
+ end
73
+
74
+ def exit_el(xml)
75
+ el("<imsss:exitConditionRule>#{xml}</imsss:exitConditionRule").at('./*')
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,70 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class RuleConditionTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = RuleCondition.new
10
+ end
11
+
12
+ test 'an empty element causes error' do
13
+ assert_error do
14
+ el('<dummy />').accept(@v)
15
+ end
16
+ end
17
+
18
+ test 'a visitor sets default operator value' do
19
+ el('<dummy condition="always" />').accept(@v)
20
+ assert_equal 'noOp', @v.operator
21
+ end
22
+
23
+ [-1.0, 0.0, 1.0].each do |valid_measure_threshold|
24
+ test "valid measure threshold: #{valid_measure_threshold}" do
25
+ el("<dummy measureThreshold='#{valid_measure_threshold}' condition='always' />").accept(@v)
26
+ assert_equal valid_measure_threshold, @v.measure_threshold
27
+ end
28
+ end
29
+
30
+ [-1.0001, 1.0001].each do |invalid_measure_threshold|
31
+ test "invalid measure threshold: #{invalid_measure_threshold}" do
32
+ assert_error do
33
+ el("<dummy measureThreshold='#{invalid_measure_threshold}' condition='always' />").accept(@v)
34
+ end
35
+ end
36
+ end
37
+
38
+ Scorm2004::Manifest::RuleCondition::CONDITIONS.each do |token|
39
+ test "valid condition token: #{token}" do
40
+ el("<dummy condition='#{token}' />").accept(@v)
41
+ assert_equal token, @v.condition
42
+ end
43
+ end
44
+
45
+ test 'invalid condition token causes error' do
46
+ assert_error do
47
+ el('<dummy condition="invalid" />').accept(@v)
48
+ end
49
+ end
50
+
51
+ test 'The referencedObjective attribute cannot be an empty string' do
52
+ assert_error do
53
+ el('<dummy referencedObjective="" condition="always" />').accept(@v)
54
+ end
55
+ end
56
+
57
+ [" ", "\t", "\n", "\r" ].each do |whitespace|
58
+ test "The referencedObjective cannot contain #{whitespace.dump}" do
59
+ assert_error do
60
+ el("<dummy referencedObjective='foo#{whitespace}bar' condition='always' />").accept(@v)
61
+ end
62
+ end
63
+ end
64
+
65
+ def assert_error(&block)
66
+ assert_raise RuleCondition::Error, &block
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class RuleConditionsTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = RuleConditions.new
10
+ @v.stubs(:rule_condition_visitor).returns(stub(:visit))
11
+ end
12
+
13
+ test 'a visitor set the default value as its attribute' do
14
+ el('<dummy><imsss:ruleCondition /></dummy>').accept(@v)
15
+ assert_equal 'all', @v.condition_combination
16
+ end
17
+
18
+ test 'a visitor visits its children' do
19
+ rule_condition_visitor = mock()
20
+ rule_condition_visitor.expects(:visit).twice
21
+ @v.expects(:rule_condition_visitor).twice.returns(rule_condition_visitor)
22
+ assert el(<<-XML).accept(@v)
23
+ <dummy>
24
+ <imsss:ruleCondition />
25
+ <imsss:ruleCondition />
26
+ </dummy>
27
+ XML
28
+ end
29
+
30
+ test 'an element without any <ruleCondition>s causes error' do
31
+ assert_raise RuleConditions::Error do
32
+ el('<dummy />').accept(@v)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class SchemaTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = Schema.new
10
+ end
11
+
12
+ context 'a schema visitor visiting a valid element' do
13
+ should 'not raise exception' do
14
+ assert_nothing_raised do
15
+ el('<dummy>ADL SCORM</dummy>').accept(@v)
16
+ end
17
+ end
18
+ end
19
+
20
+ context 'a schema visitor visiting an element with invalid schema' do
21
+ should 'raise exception' do
22
+ assert_raise Schema::Error do
23
+ el('<dummy>SCORM</dummy>').accept(@v)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class SchemaversionTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = Schemaversion.new
10
+ end
11
+
12
+ context 'a schemaversion visitor visiting a valid element' do
13
+ should 'not raise exceptoin' do
14
+ assert_nothing_raised do
15
+ el('<dummy>2004 4th Edition</dummy>').accept(@v)
16
+ end
17
+ end
18
+ end
19
+
20
+ context 'a schemaversion visitor visiting an element with invalid schemaversion' do
21
+ should 'raise exception' do
22
+ assert_raise Schemaversion::Error do
23
+ el('<dummy>2004 3rd Edition</dummy>').accept(@v)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class SequencingCollectionTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = SequencingCollection.new
10
+ end
11
+
12
+ test 'an empety element' do
13
+ assert_raise SequencingCollection::Error do
14
+ el('<dummy />').accept(@v)
15
+ end
16
+ end
17
+
18
+ test 'an elemeent with two sequencings' do
19
+ sequencing_visitor = mock()
20
+ sequencing_visitor.expects(:visit).twice
21
+ @v.expects(:sequencing_visitor).twice.returns(sequencing_visitor)
22
+ assert el(<<-XML).accept(@v)
23
+ <dummy>
24
+ <imsss:sequencing />
25
+ <imsss:sequencing />
26
+ </dummy>
27
+ XML
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class SequencingRulesTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = SequencingRules.new
10
+ end
11
+
12
+ test 'an empty element' do
13
+ assert el('<dummy />').accept(@v)
14
+ end
15
+
16
+ test 'an element with children' do
17
+ condition_rule_visitor = mock()
18
+ condition_rule_visitor.expects(:visit).times(6)
19
+ @v.expects(:condition_rule_visitor).times(6).returns(condition_rule_visitor)
20
+ el(<<-XML).accept(@v)
21
+ <dummy>
22
+ <imsss:preConditionRule /><imsss:preConditionRule />
23
+ <imsss:postConditionRule /><imsss:postConditionRule />
24
+ <imsss:exitConditionRule /><imsss:exitConditionRule />
25
+ </dummy>
26
+ XML
27
+ end
28
+
29
+ %w( pre_condition_rules post_condition_rules exit_condition_rules ).each do |children|
30
+ test "a visitor responds to :#{children}" do
31
+ assert @v.respond_to? children.intern
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,42 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class SequencingTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = Sequencing.new
10
+ end
11
+
12
+ test 'an empty element' do
13
+ assert el('<dummy />').accept(@v)
14
+ end
15
+
16
+ test 'ID attribute' do
17
+ el('<dummy ID="foo" />').accept(@v)
18
+ assert_equal 'foo', @v.id
19
+ end
20
+
21
+ test 'an element with children' do
22
+ %w( control_mode sequencing_rules limit_conditions rollup_rules objectives randomization_controls delivery_controls constrained_choice_considerations rollup_considerations adlseq_objectives ).each do |child|
23
+ @v.expects("#{child}_visitor".intern).once.returns(mock(:visit))
24
+ end
25
+ assert el(<<-XML).accept(@v)
26
+ <dummy>
27
+ <imsss:controlMode />
28
+ <imsss:sequencingRules />
29
+ <imsss:limitConditions />
30
+ <imsss:rollupRules />
31
+ <imsss:objectives />
32
+ <imsss:randomizationControls />
33
+ <imsss:deliveryControls />
34
+ <adlseq:constrainedChoiceConsiderations />
35
+ <adlseq:rollupConsiderations />
36
+ <adlseq:objectives />
37
+ </dummy>
38
+ XML
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,68 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class StringAttributeTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ context 'a visitor for an element with a string attribute' do
9
+ class SimpleVisitor
10
+ include VisitorPattern
11
+ include CustomError
12
+ include Attributes
13
+
14
+ attribute :string, 'foo'
15
+ end
16
+
17
+ setup do
18
+ @v = SimpleVisitor.new
19
+ end
20
+
21
+ should 'set the string value as its attribute' do
22
+ el('<dummy foo="bar baz" />').accept(@v)
23
+ assert_equal 'bar baz', @v.foo
24
+ end
25
+
26
+ should 'raise exception if the attribute does not exist' do
27
+ assert_raise SimpleVisitor::Error do
28
+ el('<dummy />').accept(@v)
29
+ end
30
+ end
31
+ end
32
+
33
+ context 'a visitor having SPM' do
34
+ class SpmVisitor
35
+ include VisitorPattern
36
+ include CustomError
37
+ include Attributes
38
+
39
+ attribute :string, 'foo', spm: 10
40
+ end
41
+
42
+ should 'raise exception if the value exceeds the SPM' do
43
+ @v = SpmVisitor.new
44
+ assert_raise SpmVisitor::Error do
45
+ el('<dummy foo="' + 'x' * 11 + '" />').accept(@v)
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'a visitor for an element with a string attribute optional' do
51
+ class OptionalVisitor
52
+ include VisitorPattern
53
+ include CustomError
54
+ include Attributes
55
+
56
+ attribute :string, 'foo', allow_nil: true
57
+ end
58
+
59
+ should 'not raise exception' do
60
+ @v = OptionalVisitor.new
61
+ assert_nothing_raised do
62
+ el('<dummy />').accept(@v)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class TextNodeTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ class Visitor
9
+ include VisitorPattern
10
+ include TextNode
11
+ end
12
+
13
+ setup do
14
+ @v = Visitor.new
15
+ el('<dummy>hello world</dummy>').accept(@v)
16
+ end
17
+
18
+ context 'a visitor that includes the TextNode module' do
19
+ should 'respond_to :content' do
20
+ assert @v.respond_to? :content
21
+ end
22
+
23
+ should 'respond_to :to_s' do
24
+ assert @v.respond_to? :to_s
25
+ end
26
+
27
+ should 'alias :to_s :content' do
28
+ assert_equal @v.to_s, @v.content
29
+ end
30
+
31
+ should 'alias :to_str :content'do
32
+ assert_equal @v.to_str, @v.content
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class TimeLimitActionTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = TimeLimitAction.new
10
+ end
11
+
12
+ context 'a <adlcp:timeLimitAction> visitor' do
13
+ should 'respond to :content' do
14
+ @v.respond_to? :content
15
+ end
16
+
17
+ should 'respond to :to_s' do
18
+ @v.respond_to? :to_s
19
+ end
20
+ end
21
+
22
+ TimeLimitAction.vocabulary.each do |token|
23
+ test "<adlcp:timeLimitAction>#{token}</adlcp:timieLimitAction>" do
24
+ assert_nothing_raised do
25
+ el("<dummy>#{token}</dummy").accept(@v)
26
+ end
27
+ assert_equal token, @v.content
28
+ assert_equal @v.content, @v.to_s
29
+ end
30
+ end
31
+
32
+ test 'an empty element causes error' do
33
+ assert_error do
34
+ el('<dummy />').accept(@v)
35
+ end
36
+ end
37
+
38
+ test 'an invalid token causes error' do
39
+ assert_error do
40
+ el('<dummy>invalid token, error</dummy>').accept(@v)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def assert_error(&block)
47
+ assert_raise TimeLimitAction::Error, &block
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class TitleTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ context 'a title visitor' do
9
+ setup do
10
+ @v = Title.new
11
+ end
12
+
13
+ context 'visiting a title' do
14
+ setup do
15
+ @title_content = 'a sample title'
16
+ el("<title>#{@title_content}</title>").accept(@v)
17
+ end
18
+
19
+ should 'respond to content' do
20
+ assert @v.respond_to? :content
21
+ end
22
+
23
+ should 'also respond to to_s that aliases content' do
24
+ assert @v.respond_to? :to_s
25
+ assert_equal @v.content, @v.to_s
26
+ end
27
+
28
+ should 'set a content as its attribute' do
29
+ assert_equal @title_content, @v.content
30
+ end
31
+ end
32
+
33
+ context 'visiting a too long title' do
34
+ should 'raise exception' do
35
+ assert_error do
36
+ el('<title>' + 'x' * 201 + '</title').accept(@v)
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'visiting an empty title element' do
42
+ should 'raise exception' do
43
+ assert_error do
44
+ el('<title />').accept(@v)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def assert_error(&block)
53
+ assert_raise Title::Error, &block
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ # LocalWords: TitleTest PartialManifest el
@@ -0,0 +1,53 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class TokenAttributeTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ context 'visitor having a token attribute' do
9
+ class VisitorHavingTokenAttribute
10
+ include VisitorPattern
11
+ include CustomError
12
+ include Attributes
13
+
14
+ attribute :token, 'foo', vocabulary: ['foo', 'bar', 'foo bar']
15
+ end
16
+
17
+ setup do
18
+ @v = VisitorHavingTokenAttribute.new
19
+ end
20
+
21
+ context 'visiting an element without the attribute' do
22
+ should 'raise exception' do
23
+ assert_raise VisitorHavingTokenAttribute::Error do
24
+ el('<dummy />').accept(@v)
25
+ end
26
+ end
27
+ end
28
+
29
+ context 'visiting an element with a valid token attribute' do
30
+ should 'set the token as the value of the attribute' do
31
+ el('<dummy foo="bar" />').accept(@v)
32
+ assert_equal 'bar', @v.foo
33
+ end
34
+ end
35
+
36
+ context 'visiting an element with an invalid token attribute' do
37
+ should 'raise exception' do
38
+ assert_raise VisitorHavingTokenAttribute::Error do
39
+ el('<dummy foo="hoge" />').accept(@v)
40
+ end
41
+ end
42
+ end
43
+
44
+ context 'visiting an element with token attribute having leading and trailing spaces' do
45
+ should 'remove these spaces' do
46
+ el('<dummy foo=" foo bar " />').accept(@v)
47
+ assert_equal 'foo bar', @v.foo
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end