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,41 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class ControlModeTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = ControlMode.new
10
+ end
11
+
12
+ test 'default values' do
13
+ el('<dummy />').accept(@v)
14
+ assert_equal true, @v.choice
15
+ assert_equal true, @v.choice_exit
16
+ assert_equal false, @v.flow
17
+ assert_equal false, @v.forward_only
18
+ assert_equal true, @v.use_current_attempt_objective_info
19
+ assert_equal true, @v.use_current_attempt_progress_info
20
+ end
21
+
22
+ test 'attributes' do
23
+ el(<<-XML).accept(@v)
24
+ <dummy
25
+ choice="0"
26
+ choiceExit="0"
27
+ flow="1"
28
+ forwardOnly="1"
29
+ useCurrentAttemptProgressInfo="0"
30
+ useCurrentAttemptObjectiveInfo="0" />
31
+ XML
32
+ assert_equal false, @v.choice
33
+ assert_equal false, @v.choice_exit
34
+ assert_equal true, @v.flow
35
+ assert_equal true, @v.forward_only
36
+ assert_equal false, @v.use_current_attempt_objective_info
37
+ assert_equal false, @v.use_current_attempt_progress_info
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class CustomErrorTest < ActiveSupport::TestCase
6
+ context 'Visitor including the CustomError module' do
7
+ class Visitor
8
+ include VisitorPattern
9
+ include CustomError
10
+ end
11
+
12
+ setup do
13
+ @v = Visitor.new
14
+ end
15
+
16
+ should 'have its own error class' do
17
+ assert_kind_of Scorm2004::Manifest::Error, "#{@v.class}::Error".constantize.new
18
+ end
19
+
20
+ should 'have its own error method' do
21
+ assert @v.respond_to? :error
22
+ end
23
+
24
+ context 'error method' do
25
+ should 'raise its own exceptoin' do
26
+ assert_raise "#{@v.class}::Error".constantize do
27
+ @v.error('dummy message')
28
+ end
29
+ end
30
+
31
+ should 'set message' do
32
+ begin
33
+ message = 'something wrong'
34
+ @v.error(message)
35
+ rescue "#{@v.class}::Error".constantize => e
36
+ assert_equal message, e.message
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class DataFromLmsTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = DataFromLms.new
10
+ end
11
+
12
+ context 'an <adlcp:dataFromLMS> visitor' do
13
+ should 'respond to :content' do
14
+ assert @v.respond_to? :content
15
+ end
16
+
17
+ should 'respond to :to_s' do
18
+ assert @v.respond_to? :to_s
19
+ end
20
+
21
+ context 'visiting an empty element' do
22
+ should 'return a blank string as its content' do
23
+ el('<dummy />').accept(@v)
24
+ assert_equal '', @v.content
25
+ assert_equal @v.to_s, @v.content
26
+ end
27
+ end
28
+
29
+ context 'visiting an element' do
30
+ should 'return the content as its content' do
31
+ el('<dummy>a sample content</dummy>').accept(@v)
32
+ assert_equal 'a sample content', @v.content
33
+ assert_equal @v.to_s, @v.content
34
+ end
35
+ end
36
+
37
+ context 'visitng an element whose content is too large' do
38
+ should 'raise exception' do
39
+ assert_raise DataFromLms::Error do
40
+ el('<dummy>' + 'x' * (DataFromLms.spm + 1) + '</dummy>').accept(@v)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class DataTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = Scorm2004::Manifest::Data.new
10
+ end
11
+
12
+ test 'an empty element' do
13
+ assert_raise Data::Error do
14
+ el('<dummy />').accept(@v)
15
+ end
16
+ end
17
+
18
+ test 'an element with children' do
19
+ map_visitor = mock()
20
+ map_visitor.expects(:visit).twice
21
+ @v.expects(:map_visitor).twice.returns(map_visitor)
22
+ assert el(<<-XML).accept(@v)
23
+ <dummy>
24
+ <adlcp:map />
25
+ <adlcp:map />
26
+ </dummy>
27
+ XML
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class DeliveryControlsTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = DeliveryControls.new
10
+ end
11
+
12
+ test 'default values' do
13
+ el.accept @v
14
+ assert_equal true, @v.tracked
15
+ assert_equal false, @v.completion_set_by_content
16
+ assert_equal false, @v.objective_set_by_content
17
+ end
18
+
19
+ test 'attributes' do
20
+ el('<dummy tracked="0" completionSetByContent="1" objectiveSetByContent="1" />').accept @v
21
+ assert_equal false, @v.tracked
22
+ assert_equal true, @v.completion_set_by_content
23
+ assert_equal true, @v.objective_set_by_content
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,53 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class DependencyTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = Dependency.new
10
+ end
11
+
12
+ context 'a dependency visitor' do
13
+ setup do
14
+ @v = Dependency.new
15
+ end
16
+
17
+ context 'visiting a dependency element' do
18
+ should 'set an identifierref value as its attribute' do
19
+ el(<<-XML).accept(@v)
20
+ <dependency identifierref="k22" />
21
+ <resources>
22
+ <resource identifier="k22" />
23
+ </resources>
24
+ XML
25
+ assert_equal 'k22', @v.identifierref
26
+ end
27
+ end
28
+
29
+ context 'visiting a dependency element without an identifierref attribute' do
30
+ should 'raise exception' do
31
+ assert_error do
32
+ el('<dependency />').accept(@v)
33
+ end
34
+ end
35
+ end
36
+
37
+ context 'visiting a dependency element with its referencing resource nonexistent' do
38
+ should 'raise exceptoin' do
39
+ assert_error do
40
+ el('<dependency identifierref="k22" />').accept(@v)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def assert_error(&block)
49
+ assert_raise(Dependency::Error, &block)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class DurationAttributeTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ context 'an visitor with a duration attribute' do
9
+ class Visitor
10
+ include VisitorPattern
11
+ include CustomError
12
+ include Attributes
13
+
14
+ attribute :duration, 'foo'
15
+ end
16
+
17
+ setup do
18
+ @v = Visitor.new
19
+ end
20
+
21
+ should 'raise exception when visiting an empty element' do
22
+ assert_error { el('<dummy />').accept(@v) }
23
+ end
24
+
25
+ %w( PT1004199059S PT130S PT2M10S P1DT2S -P1Y P1Y2M3DT5H20M30.123S ).each do |valid_duration|
26
+ tag = "<dummy foo='#{valid_duration}' />"
27
+ should "accept #{tag}" do
28
+ el(tag).accept(@v)
29
+ assert_equal valid_duration, @v.foo
30
+ end
31
+ end
32
+
33
+ %w( 1Y P1S P-1Y P1M2Y P1Y-1M ).each do |invalid_duration|
34
+ tag = "<dumm foo='#{invalid_duration}' />"
35
+ should "reject #{tag}" do
36
+ assert_error { el(tag).accept(@v )}
37
+ end
38
+ end
39
+
40
+ def assert_error(&block)
41
+ assert_raise Visitor::Error, &block
42
+ end
43
+ end
44
+
45
+ context 'an visitor with a duration attribute optional' do
46
+ class VisitorWithOptionalAttribute
47
+ include VisitorPattern
48
+ include Attributes
49
+
50
+ attribute :duration, 'bar', allow_nil: true
51
+ end
52
+
53
+ should 'raise nothing' do
54
+ assert_nothing_raised { el('<dummy />').accept(VisitorWithOptionalAttribute.new) }
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,40 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class FileTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ context 'a file visitor with its parent no XML Base' do
9
+ setup do
10
+ @v = Scorm2004::Manifest::File.new
11
+ end
12
+
13
+ context 'visiting a file element' do
14
+ should 'set an href value as its attribute' do
15
+ el('<file href="path/to/file" />').accept(@v)
16
+ assert_equal 'path/to/file', @v.href
17
+ end
18
+ end
19
+
20
+ context 'visiting a file element without an href attribute' do
21
+ should 'raise exception' do
22
+ assert_raise Scorm2004::Manifest::File::Error do
23
+ el('<file />').accept(@v)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ context 'a file visitor with its parent a path base' do
30
+ context 'visiting a file element' do
31
+ should 'set a resolved href value as its attribute' do
32
+ @v = Scorm2004::Manifest::File.new(base: Pathname('path/to/base'))
33
+ el('<file href="path/to/file" />').accept(@v)
34
+ assert_equal 'path/to/base/path/to/file', @v.href
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class HideLmsuiTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = HideLmsui.new
10
+ end
11
+
12
+ HideLmsui.vocabulary.each do |token|
13
+ tag ="<adlnav:hideLMSUI>#{token}</adlnav:hideLMSUI>"
14
+ test tag do
15
+ el(tag).accept(@v)
16
+ assert_equal token, @v.content
17
+ assert_equal @v.content, @v.to_s
18
+ end
19
+ end
20
+
21
+ test 'an empty element' do
22
+ assert_error do
23
+ el('<dummy />').accept(@v)
24
+ end
25
+ end
26
+
27
+ test 'an element with an invalid token' do
28
+ assert_error do
29
+ el('<dummy>invalidToken</dummy').accept(@v)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def assert_error(&block)
36
+ assert_raise HideLmsui::Error, &block
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class HrefTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ class Visitor
9
+ include VisitorPattern
10
+ include CustomError
11
+ include XmlBase
12
+ include Href
13
+ end
14
+
15
+ context 'a visitor with its own base value' do
16
+ setup do
17
+ @v = Visitor.new(base: Pathname('a/b/c'))
18
+ end
19
+
20
+ context 'visiting an element with xml:base and href' do
21
+ should 'calculate the resolved href properly' do
22
+ el('<dummy xml:base="../../d/e/f/" href="x/y/z.html').accept(@v)
23
+ assert_equal 'a/d/e/f/x/y/z.html', @v.href
24
+ end
25
+ end
26
+
27
+ context 'visiting an element without href' do
28
+ should 'return nil for href' do
29
+ el('<dummy xml:base="../../d/e/f/" />').accept(@v)
30
+ assert_nil @v.href
31
+ end
32
+ end
33
+
34
+ context 'visiting an element with href' do
35
+ should 'calculate the resolved href properly' do
36
+ el('<dummy href="../../x/y/z.html" />').accept(@v)
37
+ assert_equal 'a/x/y/z.html', @v.href
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,86 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class ItemTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ context 'an <item> visitor' do
9
+ setup do
10
+ @v = Item.new
11
+ stubify(@v)
12
+ end
13
+
14
+ context 'with expectations visiting a fully-equipped <item> element' do
15
+ setup do
16
+ %w( title time_limit_action data_from_lms completion_threshold
17
+ sequencing presentation data ).each do |singular|
18
+ @v.expects("#{singular}_visitor".intern).once.returns(mock(:visit))
19
+ end
20
+ item_visitor = mock()
21
+ item_visitor.expects(:visit).twice
22
+ @v.expects(:item_visitor).twice.returns(item_visitor)
23
+ el(<<-XML).accept(@v)
24
+ <item identifier="i92"
25
+ identifierref="r25"
26
+ isvisible="false"
27
+ parameters="?foo=bar#baz">
28
+ <title />
29
+ <item />
30
+ <item />
31
+ <adlcp:timeLimitAction />
32
+ <adlcp:dataFromLMS />
33
+ <adlcp:completionThreshold />
34
+ <imsss:sequencing />
35
+ <adlnav:presentation />
36
+ <adlcp:data />
37
+ </item>
38
+ <resources>
39
+ <resource identifier="r25" />
40
+ </resources>
41
+ XML
42
+ end
43
+
44
+ should 'satisfy expectations' do
45
+ assert @v
46
+ end
47
+
48
+ should 'set an identifier value as its attribute' do
49
+ assert_equal 'i92', @v.identifier
50
+ end
51
+
52
+ should 'set an identifierref value as its attribute' do
53
+ assert_equal 'r25', @v.identifierref
54
+ end
55
+
56
+ should 'set an isvisible value as its attribute' do
57
+ assert_equal false, @v.isvisible
58
+ end
59
+
60
+ should 'set a paramters value as its attribute' do
61
+ assert_equal '?foo=bar#baz', @v.parameters
62
+ end
63
+ end
64
+
65
+ context 'visiting a bare <item> element' do
66
+ should 'set default values as its attributes' do
67
+ el('<item identifier="r26"><title /><item /></item>').accept(@v)
68
+ assert_equal "r26", @v.identifier
69
+ assert_equal nil, @v.identifierref
70
+ assert_equal true, @v.isvisible
71
+ assert_equal nil, @v.parameters
72
+ end
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def stubify(visitor)
79
+ %w( title item time_limit_action data_from_lms completion_thoreshold
80
+ sequencing presentation data ).each do |child|
81
+ visitor.stubs("#{child}_visitor".intern).returns(stub(:visit))
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,34 @@
1
+ require_relative '../../helper'
2
+
3
+ module Scorm2004
4
+ module Manifest
5
+ class LimitConditionsTest < ActiveSupport::TestCase
6
+ include PartialManifest
7
+
8
+ setup do
9
+ @v = LimitConditions.new
10
+ end
11
+
12
+ test 'an empty element' do
13
+ assert el('<dummy />').accept(@v)
14
+ end
15
+
16
+ %w( 0 1 001 +41 001002 ).each do |valid_number|
17
+ tag = "<dummy attemptLimit='#{valid_number}' />"
18
+ test tag do
19
+ el(tag).accept(@v)
20
+ assert_equal Integer(valid_number, 10), @v.attempt_limit
21
+ end
22
+ end
23
+
24
+ %w( -1 +0.1 1.000 ).each do |invalid_number|
25
+ tag = "<dummy attemptLimit='#{invalid_number}' />"
26
+ test tag do
27
+ assert_raise LimitConditions::Error do
28
+ el(tag).accept(@v)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end