scorm2004-manifest 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +94 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/lib/scorm2004/manifest/adlseq_map_info.rb +17 -0
- data/lib/scorm2004/manifest/adlseq_objective.rb +14 -0
- data/lib/scorm2004/manifest/adlseq_objectives.rb +11 -0
- data/lib/scorm2004/manifest/attributes.rb +147 -0
- data/lib/scorm2004/manifest/children.rb +83 -0
- data/lib/scorm2004/manifest/completion_threshold.rb +13 -0
- data/lib/scorm2004/manifest/condition_rule.rb +12 -0
- data/lib/scorm2004/manifest/constrained_choice_considerations.rb +12 -0
- data/lib/scorm2004/manifest/control_mode.rb +16 -0
- data/lib/scorm2004/manifest/custom_error.rb +15 -0
- data/lib/scorm2004/manifest/data.rb +11 -0
- data/lib/scorm2004/manifest/data_from_lms.rb +21 -0
- data/lib/scorm2004/manifest/delivery_controls.rb +13 -0
- data/lib/scorm2004/manifest/dependency.rb +21 -0
- data/lib/scorm2004/manifest/error.rb +5 -0
- data/lib/scorm2004/manifest/file.rb +16 -0
- data/lib/scorm2004/manifest/hide_lmsui.rb +21 -0
- data/lib/scorm2004/manifest/href.rb +24 -0
- data/lib/scorm2004/manifest/item.rb +36 -0
- data/lib/scorm2004/manifest/limit_conditions.rb +12 -0
- data/lib/scorm2004/manifest/manifest.rb +26 -0
- data/lib/scorm2004/manifest/map.rb +13 -0
- data/lib/scorm2004/manifest/map_info.rb +15 -0
- data/lib/scorm2004/manifest/min_normalized_measure.rb +18 -0
- data/lib/scorm2004/manifest/navigation_interface.rb +10 -0
- data/lib/scorm2004/manifest/objective.rb +16 -0
- data/lib/scorm2004/manifest/objectives.rb +12 -0
- data/lib/scorm2004/manifest/organization.rb +20 -0
- data/lib/scorm2004/manifest/organizations.rb +24 -0
- data/lib/scorm2004/manifest/presentation.rb +10 -0
- data/lib/scorm2004/manifest/primary_objective.rb +24 -0
- data/lib/scorm2004/manifest/randomization_controls.rb +16 -0
- data/lib/scorm2004/manifest/resource.rb +18 -0
- data/lib/scorm2004/manifest/resources.rb +12 -0
- data/lib/scorm2004/manifest/rollup_action.rb +13 -0
- data/lib/scorm2004/manifest/rollup_condition.rb +24 -0
- data/lib/scorm2004/manifest/rollup_conditions.rb +14 -0
- data/lib/scorm2004/manifest/rollup_considerations.rb +17 -0
- data/lib/scorm2004/manifest/rollup_rule.rb +19 -0
- data/lib/scorm2004/manifest/rollup_rules.rb +16 -0
- data/lib/scorm2004/manifest/rule_action.rb +31 -0
- data/lib/scorm2004/manifest/rule_condition.rb +41 -0
- data/lib/scorm2004/manifest/rule_conditions.rb +14 -0
- data/lib/scorm2004/manifest/schema.rb +18 -0
- data/lib/scorm2004/manifest/schemaversion.rb +18 -0
- data/lib/scorm2004/manifest/sequencing.rb +24 -0
- data/lib/scorm2004/manifest/sequencing_collection.rb +11 -0
- data/lib/scorm2004/manifest/sequencing_rules.rb +13 -0
- data/lib/scorm2004/manifest/text_node.rb +11 -0
- data/lib/scorm2004/manifest/time_limit_action.rb +24 -0
- data/lib/scorm2004/manifest/title.rb +16 -0
- data/lib/scorm2004/manifest/visitor_pattern.rb +31 -0
- data/lib/scorm2004/manifest/xml_base.rb +38 -0
- data/lib/scorm2004/manifest.rb +76 -0
- data/lib/scorm2004-manifest.rb +1 -0
- data/test/functional_test.rb +45 -0
- data/test/helper.rb +18 -0
- data/test/mbce_test.rb +66 -0
- data/test/msce_test.rb +55 -0
- data/test/scorm2004/manifest/adlseq_map_info_test.rb +47 -0
- data/test/scorm2004/manifest/adlseq_objective_test.rb +44 -0
- data/test/scorm2004/manifest/adlseq_objectives_test.rb +29 -0
- data/test/scorm2004/manifest/any_uri_token_test.rb +40 -0
- data/test/scorm2004/manifest/attributes_test.rb +224 -0
- data/test/scorm2004/manifest/children_test.rb +330 -0
- data/test/scorm2004/manifest/completion_threshold_test.rb +80 -0
- data/test/scorm2004/manifest/condition_rule_test.rb +40 -0
- data/test/scorm2004/manifest/constrained_choice_considerations_test.rb +25 -0
- data/test/scorm2004/manifest/control_mode_test.rb +41 -0
- data/test/scorm2004/manifest/custom_error_test.rb +43 -0
- data/test/scorm2004/manifest/data_from_lms_test.rb +47 -0
- data/test/scorm2004/manifest/data_test.rb +31 -0
- data/test/scorm2004/manifest/delivery_controls_test.rb +27 -0
- data/test/scorm2004/manifest/dependency_test.rb +53 -0
- data/test/scorm2004/manifest/duration_attribute_test.rb +59 -0
- data/test/scorm2004/manifest/file_test.rb +40 -0
- data/test/scorm2004/manifest/hide_lmsui_test.rb +40 -0
- data/test/scorm2004/manifest/href_test.rb +43 -0
- data/test/scorm2004/manifest/item_test.rb +86 -0
- data/test/scorm2004/manifest/limit_conditions_test.rb +34 -0
- data/test/scorm2004/manifest/manifest_test.rb +152 -0
- data/test/scorm2004/manifest/map_info_test.rb +41 -0
- data/test/scorm2004/manifest/map_test.rb +32 -0
- data/test/scorm2004/manifest/min_normalized_measure_test.rb +28 -0
- data/test/scorm2004/manifest/navigation_interface_test.rb +29 -0
- data/test/scorm2004/manifest/non_negative_integer_attribute_test.rb +64 -0
- data/test/scorm2004/manifest/objective_test.rb +45 -0
- data/test/scorm2004/manifest/objectives_test.rb +37 -0
- data/test/scorm2004/manifest/organization_test.rb +115 -0
- data/test/scorm2004/manifest/organizations_test.rb +68 -0
- data/test/scorm2004/manifest/partial_manifest.rb +23 -0
- data/test/scorm2004/manifest/partial_manifest_test.rb +44 -0
- data/test/scorm2004/manifest/presentation_test.rb +26 -0
- data/test/scorm2004/manifest/primary_objective_test.rb +65 -0
- data/test/scorm2004/manifest/randomization_controls_test.rb +71 -0
- data/test/scorm2004/manifest/resource_test.rb +96 -0
- data/test/scorm2004/manifest/resources_test.rb +41 -0
- data/test/scorm2004/manifest/rollup_action_test.rb +33 -0
- data/test/scorm2004/manifest/rollup_condition_test.rb +42 -0
- data/test/scorm2004/manifest/rollup_conditions_test.rb +53 -0
- data/test/scorm2004/manifest/rollup_considerations_test.rb +42 -0
- data/test/scorm2004/manifest/rollup_rule_test.rb +87 -0
- data/test/scorm2004/manifest/rollup_rules_test.rb +60 -0
- data/test/scorm2004/manifest/rule_action_test.rb +79 -0
- data/test/scorm2004/manifest/rule_condition_test.rb +70 -0
- data/test/scorm2004/manifest/rule_conditions_test.rb +37 -0
- data/test/scorm2004/manifest/schema_test.rb +29 -0
- data/test/scorm2004/manifest/schemaversion_test.rb +29 -0
- data/test/scorm2004/manifest/sequencing_collection_test.rb +31 -0
- data/test/scorm2004/manifest/sequencing_rules_test.rb +36 -0
- data/test/scorm2004/manifest/sequencing_test.rb +42 -0
- data/test/scorm2004/manifest/string_attribute_test.rb +68 -0
- data/test/scorm2004/manifest/text_node_test.rb +37 -0
- data/test/scorm2004/manifest/time_limit_action_test.rb +51 -0
- data/test/scorm2004/manifest/title_test.rb +59 -0
- data/test/scorm2004/manifest/token_attribute_test.rb +53 -0
- data/test/scorm2004/manifest/visitor_pattern_test.rb +85 -0
- data/test/scorm2004/manifest/xml_base_test.rb +125 -0
- data/test/scorm2004/manifest_test.rb +33 -0
- data/test/scorm2004_test.rb +9 -0
- data/test/sece_test.rb +53 -0
- metadata +260 -0
@@ -0,0 +1,224 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
module Scorm2004
|
4
|
+
module Manifest
|
5
|
+
class AttributesTest < ActiveSupport::TestCase
|
6
|
+
include PartialManifest
|
7
|
+
|
8
|
+
class Visitor
|
9
|
+
include VisitorPattern
|
10
|
+
include Attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'visitor having binary attributes with default values' do
|
14
|
+
class VisitorHavingBinaryAttributesWithDefaultValues < Visitor
|
15
|
+
attribute(:boolean, 'defaultsTrue', default: true)
|
16
|
+
attribute(:boolean, 'defaultsFalse', default: false)
|
17
|
+
end
|
18
|
+
|
19
|
+
setup do
|
20
|
+
@v = VisitorHavingBinaryAttributesWithDefaultValues.new
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'set default values' do
|
24
|
+
el('<dummy />').accept(@v)
|
25
|
+
assert_equal true, @v.defaults_true
|
26
|
+
assert_equal false, @v.defaults_false
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'set boolean values' do
|
30
|
+
el('<dummy defaultsTrue="false" defaultsFalse="true" />').accept(@v)
|
31
|
+
assert_equal false, @v.defaults_true
|
32
|
+
assert_equal true, @v.defaults_false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'visitor having binary attributes without default values' do
|
37
|
+
class VisitorHavingBinaryAttributesWithoutDefaultValues < Visitor
|
38
|
+
include CustomError
|
39
|
+
|
40
|
+
attribute(:boolean, 'foo')
|
41
|
+
attribute(:boolean, 'bar')
|
42
|
+
end
|
43
|
+
|
44
|
+
setup do
|
45
|
+
@v = VisitorHavingBinaryAttributesWithoutDefaultValues.new
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'raise exception if the attribute not found' do
|
49
|
+
assert_raise VisitorHavingBinaryAttributesWithoutDefaultValues::Error do
|
50
|
+
el('<dummy foo="true" />').accept(@v)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'visitor having a attribute with namespace prefix' do
|
56
|
+
class VisitorHavingNamespacedAttribute < Visitor
|
57
|
+
attribute(:boolean, 'adlcp:foo')
|
58
|
+
end
|
59
|
+
|
60
|
+
setup do
|
61
|
+
@v = VisitorHavingNamespacedAttribute.new
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'create an unnamespaced attribute' do
|
65
|
+
el('<dummy adlcp:foo="false" />').accept(@v)
|
66
|
+
assert_equal false, @v.foo
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'visitor with an id attribute' do
|
71
|
+
class VisitorWithIdAttribute < Visitor
|
72
|
+
include CustomError
|
73
|
+
|
74
|
+
attribute(:id, 'foo')
|
75
|
+
end
|
76
|
+
|
77
|
+
setup do
|
78
|
+
@v = VisitorWithIdAttribute.new
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'set a string value as the attribute' do
|
82
|
+
el('<dummy foo="bar" />').accept(@v)
|
83
|
+
assert_equal 'bar', @v.foo
|
84
|
+
end
|
85
|
+
|
86
|
+
should 'raise exception unless the attribute exists' do
|
87
|
+
assert_raise VisitorWithIdAttribute::Error do
|
88
|
+
el('<dummy />').accept(@v)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
whitespaces = {
|
93
|
+
'space' => ' ',
|
94
|
+
'tab' => "\t",
|
95
|
+
'newline' => "\n",
|
96
|
+
'return' => "\r"
|
97
|
+
}
|
98
|
+
whitespaces.each do |k, v|
|
99
|
+
should "raise exception if the attribute value contains a #{k}" do
|
100
|
+
assert_raise VisitorWithIdAttribute::Error do
|
101
|
+
el("<dummy foo='bar#{v}baz' />").accept(@v)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
should 'raise exception if the attribute value consists of digits' do
|
107
|
+
assert_nothing_raised do
|
108
|
+
el('<dummy foo="4bar2baz6" />').accept(@v)
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_raise VisitorWithIdAttribute::Error do
|
112
|
+
el('<dummy foo="123456789" />').accept(@v)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'visitor having a decimal attribute without a default value' do
|
118
|
+
class VisitorHavingDecimalAttributeWithoutDefaultValue < Visitor
|
119
|
+
include CustomError
|
120
|
+
|
121
|
+
attribute(:decimal, 'foo')
|
122
|
+
end
|
123
|
+
|
124
|
+
setup do
|
125
|
+
@v = VisitorHavingDecimalAttributeWithoutDefaultValue.new
|
126
|
+
end
|
127
|
+
|
128
|
+
should 'raise exception unless the attribute exists' do
|
129
|
+
assert_raise VisitorHavingDecimalAttributeWithoutDefaultValue::Error do
|
130
|
+
el('<dummy />').accept(@v)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
should 'set a float value' do
|
135
|
+
el('<dummy foo="6.789" />').accept(@v)
|
136
|
+
assert_equal 6.789, @v.foo
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'visitor having a decimal attribute with a default value' do
|
141
|
+
class VisitorHavingDecimalAttributeWithDefaultValue < Visitor
|
142
|
+
attribute(:decimal, 'foo', default: -1.234)
|
143
|
+
end
|
144
|
+
|
145
|
+
setup do
|
146
|
+
@v = VisitorHavingDecimalAttributeWithDefaultValue.new
|
147
|
+
end
|
148
|
+
|
149
|
+
should 'set a default value' do
|
150
|
+
el('<dummy />').accept(@v)
|
151
|
+
assert_equal -1.234, @v.foo
|
152
|
+
end
|
153
|
+
|
154
|
+
should 'set a float value' do
|
155
|
+
el('<dummy foo="45.67" />').accept(@v)
|
156
|
+
assert_equal 45.67, @v.foo
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'visitor having a decimal attribute with a range' do
|
161
|
+
class VisitorHavingDecimalAttributeWithRange < Visitor
|
162
|
+
include CustomError
|
163
|
+
|
164
|
+
attribute(:decimal, 'foo', range: -1.0..1.0)
|
165
|
+
end
|
166
|
+
|
167
|
+
setup do
|
168
|
+
@v = VisitorHavingDecimalAttributeWithRange.new
|
169
|
+
end
|
170
|
+
|
171
|
+
should 'set a float value if the value is within the range' do
|
172
|
+
[-1.0, 0.0, 1.0].each do |v|
|
173
|
+
el("<dummy foo='#{v}' />").accept(@v)
|
174
|
+
assert_equal v, @v.foo, v
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
should 'raise exception if the value is out of the range' do
|
179
|
+
[-1.0001, 1.0001].each do |v|
|
180
|
+
assert_raise VisitorHavingDecimalAttributeWithRange::Error do
|
181
|
+
el("<dummy foo='#{v}' />").accept(@v)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'visitor having an idref attribute' do
|
188
|
+
class VisitorHavingIdrefAttribute < Visitor
|
189
|
+
include CustomError
|
190
|
+
|
191
|
+
attribute :idref, 'foo'
|
192
|
+
end
|
193
|
+
|
194
|
+
setup do
|
195
|
+
@v = VisitorHavingIdrefAttribute.new
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'visitng an element with an idref attribute' do
|
199
|
+
should 'set the idref value ast its attribute' do
|
200
|
+
el('<dummy foo="bar" />').accept(@v)
|
201
|
+
assert_equal 'bar', @v.foo
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'visiting an element without an idref attribute' do
|
206
|
+
should 'raise exception' do
|
207
|
+
assert_raise VisitorHavingIdrefAttribute::Error do
|
208
|
+
el('<dummy />').accept(@v)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# LocalWords: AttributesTest PartialManifest VisitorPattern defaultsTrue el
|
218
|
+
# LocalWords: VisitorHavingBinaryAttributesWithDefaultValues defaultsFalse
|
219
|
+
# LocalWords: VisitorHavingBinaryAttributesWithoutDefaultValues CustomError
|
220
|
+
# LocalWords: VisitorHavingNamespacedAttribute adlcp unnamespaced spm baz
|
221
|
+
# LocalWords: VisitorWithStringAttribute VisitorWithIdAttribute whitespaces
|
222
|
+
# LocalWords: VisitorHavingDecimalAttributeWithDefaultValue
|
223
|
+
# LocalWords: VisitorHavingDecimalAttributeWithoutDefaultValue
|
224
|
+
# LocalWords: VisitorHavingDecimalAttributeWithRange
|
@@ -0,0 +1,330 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
module Scorm2004
|
4
|
+
module Manifest
|
5
|
+
class Son
|
6
|
+
include VisitorPattern
|
7
|
+
end
|
8
|
+
|
9
|
+
class Grandson
|
10
|
+
include VisitorPattern
|
11
|
+
end
|
12
|
+
|
13
|
+
class ChildrenTest < ActiveSupport::TestCase
|
14
|
+
include PartialManifest
|
15
|
+
|
16
|
+
context 'visitor that has one and only one child' do
|
17
|
+
class VisitorHasOneAndOnlyOneChild
|
18
|
+
include VisitorPattern
|
19
|
+
include CustomError
|
20
|
+
include Children
|
21
|
+
|
22
|
+
has_one_and_only_one('imscp:son')
|
23
|
+
end
|
24
|
+
|
25
|
+
setup do
|
26
|
+
@v = VisitorHasOneAndOnlyOneChild.new
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'visiting an element with one child' do
|
30
|
+
should 'visit the only one child' do
|
31
|
+
@v.expects(:visit_son).once
|
32
|
+
assert el('<dummy><son /></dummy>').accept(@v)
|
33
|
+
end
|
34
|
+
|
35
|
+
should 'provide an accessor method for the child' do
|
36
|
+
el('<dummy><son /></dummy>').accept(@v)
|
37
|
+
assert @v.respond_to?(:son)
|
38
|
+
assert_kind_of Son, @v.son
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'call a visitor factory method during the visit' do
|
42
|
+
@v.expects(:son_visitor).once.returns(mock(:visit))
|
43
|
+
el('<dummy><son /></dummy>').accept(@v)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'visiting an element without the child' do
|
48
|
+
should 'raise exception' do
|
49
|
+
assert_raise VisitorHasOneAndOnlyOneChild::Error do
|
50
|
+
el('<dummy />').accept(@v)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'visiting an element with two children' do
|
56
|
+
should 'raise exception' do
|
57
|
+
assert_raise VisitorHasOneAndOnlyOneChild::Error do
|
58
|
+
el(<<XML).accept(@v)
|
59
|
+
<dummy>
|
60
|
+
<son />
|
61
|
+
<son />
|
62
|
+
</dummy>
|
63
|
+
XML
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'visitor that has zero or one child' do
|
70
|
+
class VisitorHasZeroOrOneChild
|
71
|
+
include VisitorPattern
|
72
|
+
include CustomError
|
73
|
+
include Children
|
74
|
+
|
75
|
+
has_zero_or_one('imscp:son')
|
76
|
+
end
|
77
|
+
|
78
|
+
setup do
|
79
|
+
@v = VisitorHasZeroOrOneChild.new
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'visiting an element with one child' do
|
83
|
+
should 'visit the only one child' do
|
84
|
+
@v.expects(:visit_son).once
|
85
|
+
assert el('<dummy><son /></dummy>').accept(@v)
|
86
|
+
end
|
87
|
+
|
88
|
+
should 'provide an accessor method for the child' do
|
89
|
+
el('<dummy><son /></dummy>').accept(@v)
|
90
|
+
assert @v.respond_to?(:son)
|
91
|
+
assert_kind_of Son, @v.son
|
92
|
+
end
|
93
|
+
|
94
|
+
should 'call a visitor factory method during the visit' do
|
95
|
+
@v.expects(:son_visitor).once.returns(mock(:visit))
|
96
|
+
el('<dummy><son /></dummy>').accept(@v)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'visiting an element without the child' do
|
101
|
+
should 'raise nothing' do
|
102
|
+
assert_nothing_raised do
|
103
|
+
el('<dummy />').accept(@v)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'visiting an element with two children' do
|
109
|
+
should 'raise exception' do
|
110
|
+
assert_raise VisitorHasZeroOrOneChild::Error do
|
111
|
+
el(<<XML).accept(@v)
|
112
|
+
<dummy>
|
113
|
+
<son />
|
114
|
+
<son />
|
115
|
+
</dummy>
|
116
|
+
XML
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'visitor that has one or more children' do
|
123
|
+
class VisitorHasOneOrMoreChildren
|
124
|
+
include VisitorPattern
|
125
|
+
include CustomError
|
126
|
+
include Children
|
127
|
+
|
128
|
+
has_one_or_more('imscp:son')
|
129
|
+
end
|
130
|
+
|
131
|
+
setup do
|
132
|
+
@v = VisitorHasOneOrMoreChildren.new
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'visiting an element without a child' do
|
136
|
+
should 'raise exception' do
|
137
|
+
assert_raise VisitorHasOneOrMoreChildren::Error do
|
138
|
+
el('<dummy />').accept(@v)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'visiting an element with a child' do
|
144
|
+
should 'visit the child' do
|
145
|
+
@v.expects(:visit_sons)
|
146
|
+
assert el('<dummy><son /></dummy>').accept(@v)
|
147
|
+
end
|
148
|
+
|
149
|
+
should 'provide an accessor method for children' do
|
150
|
+
el('<dummy><son /></dummy>').accept(@v)
|
151
|
+
assert_kind_of Array, @v.sons
|
152
|
+
assert_equal 1, @v.sons.size
|
153
|
+
end
|
154
|
+
|
155
|
+
should 'call a visitor factory method during the visit' do
|
156
|
+
@v.expects(:son_visitor).once.returns(mock(:visit))
|
157
|
+
el('<dummy><son /></dummy>').accept(@v)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'visiting an element with two children' do
|
162
|
+
should 'visit the children' do
|
163
|
+
@v.expects(:visit_sons)
|
164
|
+
assert el(<<XML).accept(@v)
|
165
|
+
<dummy>
|
166
|
+
<son />
|
167
|
+
<son />
|
168
|
+
</dummy>
|
169
|
+
XML
|
170
|
+
end
|
171
|
+
|
172
|
+
should 'provide an accessor method for children' do
|
173
|
+
assert el(<<XML).accept(@v)
|
174
|
+
<dummy>
|
175
|
+
<son />
|
176
|
+
<son />
|
177
|
+
</dummy>
|
178
|
+
XML
|
179
|
+
assert_kind_of Array, @v.sons
|
180
|
+
assert_equal 2, @v.sons.size
|
181
|
+
end
|
182
|
+
|
183
|
+
should 'call a visitor factory method during the visit' do
|
184
|
+
@v.expects(:son_visitor).twice.returns(stub(:visit))
|
185
|
+
assert el(<<XML).accept(@v)
|
186
|
+
<dummy>
|
187
|
+
<son />
|
188
|
+
<son />
|
189
|
+
</dummy>
|
190
|
+
XML
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'visitor that has zero or more children' do
|
196
|
+
class VisitorHasZeroOrMoreChildren
|
197
|
+
include VisitorPattern
|
198
|
+
include CustomError
|
199
|
+
include Children
|
200
|
+
|
201
|
+
has_zero_or_more('imscp:son')
|
202
|
+
end
|
203
|
+
|
204
|
+
setup do
|
205
|
+
@v = VisitorHasZeroOrMoreChildren.new
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'visiting an element without a child' do
|
209
|
+
should 'not raise exception' do
|
210
|
+
assert_nothing_raised do
|
211
|
+
el('<dummy />').accept(@v)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'visiting an element with a child' do
|
217
|
+
should 'visit the child' do
|
218
|
+
@v.expects(:visit_sons)
|
219
|
+
assert el('<dummy><son /></dummy>').accept(@v)
|
220
|
+
end
|
221
|
+
|
222
|
+
should 'provide an accessor method for children' do
|
223
|
+
el('<dummy><son /></dummy>').accept(@v)
|
224
|
+
assert_kind_of Array, @v.sons
|
225
|
+
assert_equal 1, @v.sons.size
|
226
|
+
end
|
227
|
+
|
228
|
+
should 'call a visitor factory method during the visit' do
|
229
|
+
@v.expects(:son_visitor).once.returns(mock(:visit))
|
230
|
+
el('<dummy><son /></dummy>').accept(@v)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'visiting an element with two children' do
|
235
|
+
should 'visit the children' do
|
236
|
+
@v.expects(:visit_sons)
|
237
|
+
assert el(<<XML).accept(@v)
|
238
|
+
<dummy>
|
239
|
+
<son />
|
240
|
+
<son />
|
241
|
+
</dummy>
|
242
|
+
XML
|
243
|
+
end
|
244
|
+
|
245
|
+
should 'provide an accessor method for children' do
|
246
|
+
assert el(<<XML).accept(@v)
|
247
|
+
<dummy>
|
248
|
+
<son />
|
249
|
+
<son />
|
250
|
+
</dummy>
|
251
|
+
XML
|
252
|
+
assert_kind_of Array, @v.sons
|
253
|
+
assert_equal 2, @v.sons.size
|
254
|
+
end
|
255
|
+
|
256
|
+
should 'call a visitor factory method during the visit' do
|
257
|
+
@v.expects(:son_visitor).twice.returns(stub(:visit))
|
258
|
+
assert el(<<XML).accept(@v)
|
259
|
+
<dummy>
|
260
|
+
<son />
|
261
|
+
<son />
|
262
|
+
</dummy>
|
263
|
+
XML
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context 'visitor has one grandson' do
|
269
|
+
class VisitorHasOneGrandson
|
270
|
+
include VisitorPattern
|
271
|
+
include CustomError
|
272
|
+
include Children
|
273
|
+
|
274
|
+
has_one_and_only_one './imscp:son/imscp:grandson'
|
275
|
+
end
|
276
|
+
|
277
|
+
setup do
|
278
|
+
@v = VisitorHasOneGrandson.new
|
279
|
+
end
|
280
|
+
|
281
|
+
should 'raise exception if the grandson does not exist' do
|
282
|
+
assert_raise VisitorHasOneGrandson::Error do
|
283
|
+
el('<dummy><grandson /></dummy>').accept(@v)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
should 'visit the grandson' do
|
288
|
+
el(<<-XML).accept(@v)
|
289
|
+
<dummy>
|
290
|
+
<son>
|
291
|
+
<grandson />
|
292
|
+
</son>
|
293
|
+
</dummy>
|
294
|
+
XML
|
295
|
+
assert_kind_of Grandson, @v.grandson
|
296
|
+
end
|
297
|
+
|
298
|
+
should 'call the grandson_visitor method during the visit' do
|
299
|
+
@v.expects(:grandson_visitor).once.returns(mock(:visit))
|
300
|
+
el(<<-XML).accept(@v)
|
301
|
+
<dummy>
|
302
|
+
<son>
|
303
|
+
<grandson />
|
304
|
+
</son>
|
305
|
+
</dummy>
|
306
|
+
XML
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
context 'a visitor with the visitor option' do
|
311
|
+
class NamespacedVisitor
|
312
|
+
include VisitorPattern
|
313
|
+
include CustomError
|
314
|
+
include Children
|
315
|
+
|
316
|
+
has_one_and_only_one 'imscp:foo', visitor: :foo_bar
|
317
|
+
end
|
318
|
+
|
319
|
+
setup do
|
320
|
+
@v = NamespacedVisitor.new
|
321
|
+
@v.expects(:foo_bar_visitor).once.returns(mock(:visit))
|
322
|
+
end
|
323
|
+
|
324
|
+
should 'visits a child element using the visitor' do
|
325
|
+
el('<dummy><foo /></dummy>').accept(@v)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
module Scorm2004
|
4
|
+
module Manifest
|
5
|
+
class CompletionThresholdTest < ActiveSupport::TestCase
|
6
|
+
include PartialManifest
|
7
|
+
|
8
|
+
|
9
|
+
context 'an <adlcp:completionThreshold> visitor' do
|
10
|
+
setup do
|
11
|
+
@v = CompletionThreshold.new
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'visiting an <adlcp:completionThreshold> element' do
|
15
|
+
setup do
|
16
|
+
el(<<-XML).accept(@v)
|
17
|
+
<adlcp:completionThreshold
|
18
|
+
completedByMeasure = "true"
|
19
|
+
minProgressMeasure = "0.75"
|
20
|
+
progressWeight = "0.3" />
|
21
|
+
XML
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'set completedByMeasure value as its attribute' do
|
25
|
+
assert_equal true, @v.completed_by_measure
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'set minProgressMeasure value as its attribute' do
|
29
|
+
assert_equal 0.75, @v.min_progress_measure
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'set progressWeight value as its attribute' do
|
33
|
+
assert_equal 0.3, @v.progress_weight
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'visiting an empty <adlcp:completionThreshold> element' do
|
38
|
+
should 'set default values' do
|
39
|
+
el('<adlcp:completionThreshold />').accept(@v)
|
40
|
+
assert_equal false, @v.completed_by_measure
|
41
|
+
assert_equal 1.0, @v.min_progress_measure
|
42
|
+
assert_equal 1.0, @v.progress_weight
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'visiting an <adlcp:completionThreshold> element with its attribute value out of range' do
|
47
|
+
should 'raise exception for too small minProgressMeasure' do
|
48
|
+
assert_error do
|
49
|
+
el('<adlcp:completionThreshold minProgressMeasure="-0.0001" />').accept(@v)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
should 'raise exception for too large minProgressMeasure' do
|
54
|
+
assert_error do
|
55
|
+
el('<adlcp:completionThreshold minProgressMeasure="1.0001" />').accept(@v)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
should 'raise exception for too small progressWeight' do
|
60
|
+
assert_error do
|
61
|
+
el('<adlcp:completionThreshold progressWeight="-0.0001" />').accept(@v)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
should 'raise exception for too large progressWeight' do
|
66
|
+
assert_error do
|
67
|
+
el('<adlcp:completionThreshold progressWeight="1.0001" />').accept(@v)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def assert_error(&block)
|
76
|
+
assert_raise CompletionThreshold::Error, &block
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
module Scorm2004
|
4
|
+
module Manifest
|
5
|
+
class ConditionRuleTest < ActiveSupport::TestCase
|
6
|
+
include PartialManifest
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@v = ConditionRule.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'a visitor visits children' do
|
13
|
+
@v.expects(:rule_conditions_visitor).once.returns(mock(:visit))
|
14
|
+
@v.expects(:rule_action_visitor).once.returns(mock(:visit))
|
15
|
+
el(<<-XML).accept(@v)
|
16
|
+
<dummy>
|
17
|
+
<imsss:ruleConditions />
|
18
|
+
<imsss:ruleAction />
|
19
|
+
</dummy>
|
20
|
+
XML
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'an element without <ruleConditions> causes error' do
|
24
|
+
assert_error do
|
25
|
+
el('<dummy><imsss:ruleAction /></dummy>').accept(@v)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'an element without <ruleAction> causes error' do
|
30
|
+
assert_error do
|
31
|
+
el('<dummy><imsss:ruleCondition></dummy>').accept(@v)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def assert_error(&block)
|
36
|
+
assert_raise ConditionRule::Error, &block
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
module Scorm2004
|
4
|
+
module Manifest
|
5
|
+
class ConstrainedChoiceConsiderationsTest < ActiveSupport::TestCase
|
6
|
+
include PartialManifest
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@v = ConstrainedChoiceConsiderations.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'default values' do
|
13
|
+
el.accept @v
|
14
|
+
assert_equal false, @v.prevent_activation
|
15
|
+
assert_equal false, @v.constrain_choice
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'attributes' do
|
19
|
+
el('<dummy preventActivation="1" constrainChoice="1" />').accept @v
|
20
|
+
assert_equal true, @v.prevent_activation
|
21
|
+
assert_equal true, @v.constrain_choice
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|