google4r-checkout 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +40 -0
- data/LICENSE +22 -0
- data/README +76 -0
- data/lib/google4r/checkout.rb +33 -0
- data/lib/google4r/checkout/commands.rb +260 -0
- data/lib/google4r/checkout/frontend.rb +108 -0
- data/lib/google4r/checkout/notifications.rb +549 -0
- data/lib/google4r/checkout/shared.rb +541 -0
- data/lib/google4r/checkout/xml_generation.rb +313 -0
- data/test/integration/checkout_command_test.rb +103 -0
- data/test/unit/address_test.rb +131 -0
- data/test/unit/area_test.rb +44 -0
- data/test/unit/checkout_command_test.rb +116 -0
- data/test/unit/checkout_command_xml_generator_test.rb +203 -0
- data/test/unit/command_test.rb +115 -0
- data/test/unit/flat_rate_shipping_test.rb +114 -0
- data/test/unit/frontend_test.rb +63 -0
- data/test/unit/item_test.rb +159 -0
- data/test/unit/marketing_preferences_test.rb +65 -0
- data/test/unit/merchant_code_test.rb +122 -0
- data/test/unit/new_order_notification_test.rb +115 -0
- data/test/unit/notification_acknowledgement_test.rb +43 -0
- data/test/unit/notification_handler_test.rb +93 -0
- data/test/unit/order_adjustment_test.rb +119 -0
- data/test/unit/order_state_change_notification_test.rb +159 -0
- data/test/unit/pickup_shipping_test.rb +70 -0
- data/test/unit/postal_area_test.rb +71 -0
- data/test/unit/private_data_parser_test.rb +68 -0
- data/test/unit/shipping_adjustment_test.rb +100 -0
- data/test/unit/shipping_method_test.rb +41 -0
- data/test/unit/shopping_cart_test.rb +146 -0
- data/test/unit/tax_rule_test.rb +70 -0
- data/test/unit/tax_table_test.rb +82 -0
- data/test/unit/us_country_area_test.rb +76 -0
- data/test/unit/us_state_area_test.rb +70 -0
- data/test/unit/us_zip_area_test.rb +66 -0
- data/test/unit/world_area_test.rb +48 -0
- data/var/cacert.pem +7815 -0
- metadata +92 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
6
|
+
# License: MIT License as follows:
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
13
|
+
# persons to whom the Software is furnished to do so, subject to the
|
14
|
+
# following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be included
|
17
|
+
# in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
20
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
22
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
23
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
24
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
25
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
#++
|
27
|
+
|
28
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
29
|
+
|
30
|
+
require 'google4r/checkout'
|
31
|
+
|
32
|
+
require 'test/frontend_configuration'
|
33
|
+
|
34
|
+
# Test for the FlatRateShipping class.
|
35
|
+
class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@shipping = FlatRateShipping.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_flat_rate_shipping_method_behaves_correctly
|
43
|
+
[ :name, :name=, :price, :price=,
|
44
|
+
:allowed_areas, :create_allowed_area, :excluded_areas, :create_excluded_area
|
45
|
+
].each do |symbol|
|
46
|
+
assert_respond_to @shipping, symbol
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_initialization
|
51
|
+
assert_nil @shipping.name
|
52
|
+
assert_nil @shipping.price
|
53
|
+
assert_equal [], @shipping.allowed_areas
|
54
|
+
assert_equal [], @shipping.excluded_areas
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_flat_rate_shipping_method_setting_attributes_works_correctly
|
58
|
+
@shipping.name = "Shipping Method Name"
|
59
|
+
assert_equal "Shipping Method Name", @shipping.name
|
60
|
+
|
61
|
+
@shipping.price = Money.new(100, "EUR")
|
62
|
+
assert_kind_of Money, @shipping.price
|
63
|
+
assert_equal 100, @shipping.price.cents
|
64
|
+
assert_equal "EUR", @shipping.price.currency
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_flat_rate_shipping_method_price_is_validated
|
68
|
+
# Test that FlatRateShippingMethod checks for its price attribute responding
|
69
|
+
# to cents and currency.
|
70
|
+
assert_raises(RuntimeError) { @shipping.price = nil }
|
71
|
+
assert_raises(RuntimeError) { @shipping.price = 10 }
|
72
|
+
assert_raises(RuntimeError) { @shipping.price = "str" }
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_create_create_allowed_excluded_areas_works_with_block
|
76
|
+
[ [ :allowed_areas, :create_allowed_area], [ :excluded_areas, :create_excluded_area ] ].each do |pair|
|
77
|
+
read_sym, create_sym = pair
|
78
|
+
|
79
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
80
|
+
|
81
|
+
the_area = nil
|
82
|
+
|
83
|
+
res =
|
84
|
+
@shipping.send(create_sym, clazz) do |area|
|
85
|
+
the_area = area
|
86
|
+
assert_kind_of clazz, area
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_equal res, the_area
|
90
|
+
assert @shipping.send(read_sym).include?(the_area)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_create_create_allowed_excluded_areas_works_without_block
|
96
|
+
[ [ :allowed_areas, :create_allowed_area], [ :excluded_areas, :create_excluded_area ] ].each do |pair|
|
97
|
+
read_sym, create_sym = pair
|
98
|
+
|
99
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
100
|
+
area = @shipping.send(create_sym, clazz)
|
101
|
+
|
102
|
+
assert_kind_of clazz, area
|
103
|
+
|
104
|
+
assert @shipping.send(read_sym).include?(area)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_create_create_allowed_excluded_areas_validates_parameter
|
110
|
+
[ :create_allowed_area, :create_excluded_area ].each do |sym|
|
111
|
+
assert_raises(RuntimeError) { @shipping.send(sym, String) }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/frontend_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
6
|
+
# License: MIT License as follows:
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
13
|
+
# persons to whom the Software is furnished to do so, subject to the
|
14
|
+
# following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be included
|
17
|
+
# in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
20
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
22
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
23
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
24
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
25
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
#++
|
27
|
+
|
28
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
29
|
+
|
30
|
+
require 'google4r/checkout'
|
31
|
+
|
32
|
+
require 'test/frontend_configuration'
|
33
|
+
|
34
|
+
# Test for the class Area and all of its subclasses.
|
35
|
+
class Google4R::Checkout::FrontendTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
40
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_initialized_correctly
|
44
|
+
assert_equal FRONTEND_CONFIGURATION.dup, @frontend.configuration
|
45
|
+
assert @frontend.configuration.frozen?
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_frontend_behaves_correctly
|
49
|
+
[ :create_checkout_command, :configuration, :tax_table_factory,
|
50
|
+
:tax_table_factory=
|
51
|
+
].each do |symbol|
|
52
|
+
assert_respond_to @frontend, symbol
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_create_checkout_command_works_correctly
|
57
|
+
assert_kind_of CheckoutCommand, @frontend.create_checkout_command
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_create_notification_handler_works_correctly
|
61
|
+
assert_kind_of NotificationHandler, @frontend.create_notification_handler
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/area_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
6
|
+
# License: MIT License as follows:
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
13
|
+
# persons to whom the Software is furnished to do so, subject to the
|
14
|
+
# following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be included
|
17
|
+
# in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
20
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
22
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
23
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
24
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
25
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
#++
|
27
|
+
|
28
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
29
|
+
|
30
|
+
require 'google4r/checkout'
|
31
|
+
|
32
|
+
require 'test/frontend_configuration'
|
33
|
+
|
34
|
+
# Test for the Item class.
|
35
|
+
class Google4R::Checkout::ItemTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
40
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
41
|
+
|
42
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
43
|
+
<item>
|
44
|
+
<item-name>MegaSound 2GB MP3 Player</item-name>
|
45
|
+
<item-description>Portable MP3 player - stores 500 songs</item-description>
|
46
|
+
<unit-price currency="USD">178.00</unit-price>
|
47
|
+
<quantity>1</quantity>
|
48
|
+
<merchant-item-id>MGS2GBMP3</merchant-item-id>
|
49
|
+
<merchant-private-item-data>
|
50
|
+
<item-note>Text 1</item-note>
|
51
|
+
<item-note>Text 2</item-note>
|
52
|
+
<nested>
|
53
|
+
<tags>value</tags>
|
54
|
+
</nested>
|
55
|
+
</merchant-private-item-data>
|
56
|
+
<tax-table-selector>Some Table</tax-table-selector>
|
57
|
+
</item>}
|
58
|
+
|
59
|
+
@optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
|
60
|
+
|
61
|
+
@command = @frontend.create_checkout_command
|
62
|
+
@shopping_cart = @command.shopping_cart
|
63
|
+
@item = @shopping_cart.create_item
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_item_behaves_correctly
|
67
|
+
[ :shopping_cart, :name, :name=, :description, :description=, :unit_price, :unit_price=,
|
68
|
+
:quantity, :quantity=, :id, :id=, :private_data, :private_data=,
|
69
|
+
:tax_table, :tax_table=
|
70
|
+
].each do |symbol|
|
71
|
+
assert_respond_to @item, symbol
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_item_gets_initialized_correctly
|
76
|
+
assert_equal @shopping_cart, @item.shopping_cart
|
77
|
+
assert_nil @item.name
|
78
|
+
assert_nil @item.description
|
79
|
+
assert_nil @item.unit_price
|
80
|
+
assert_nil @item.quantity
|
81
|
+
assert_nil @item.private_data
|
82
|
+
assert_nil @item.id
|
83
|
+
assert_nil @item.tax_table
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_item_setters_work
|
87
|
+
@item.name = "name"
|
88
|
+
assert_equal "name", @item.name
|
89
|
+
|
90
|
+
@item.description = "description"
|
91
|
+
assert_equal "description", @item.description
|
92
|
+
|
93
|
+
@item.unit_price = Money.new(100, "EUR")
|
94
|
+
assert_equal Money.new(100, "EUR"), @item.unit_price
|
95
|
+
|
96
|
+
@item.quantity = 10
|
97
|
+
assert_equal 10, @item.quantity
|
98
|
+
|
99
|
+
@item.id = "id"
|
100
|
+
assert_equal "id", @item.id
|
101
|
+
|
102
|
+
@item.private_data = Hash.new
|
103
|
+
assert_equal Hash.new, @item.private_data
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_set_tax_table_works
|
107
|
+
table = @command.tax_tables.first
|
108
|
+
@item.tax_table = table
|
109
|
+
assert_equal table, @item.tax_table
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_set_tax_table_raises_if_table_is_unknown_in_command
|
113
|
+
assert_raises(RuntimeError) { @item.tax_table = TaxTable.new(false) }
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_set_private_data_only_works_with_hashes
|
117
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 1 }
|
118
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = nil }
|
119
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 'Foobar' }
|
120
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = [] }
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_item_price_must_be_money_instance
|
124
|
+
assert_raises(RuntimeError) { @item.unit_price = nil }
|
125
|
+
assert_raises(RuntimeError) { @item.unit_price = "String" }
|
126
|
+
assert_raises(RuntimeError) { @item.unit_price = 10 }
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_create_from_element_works
|
130
|
+
@optional_tags.power.each do |optional_tag_names|
|
131
|
+
xml_str = @xml_str
|
132
|
+
|
133
|
+
optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
|
134
|
+
|
135
|
+
command = @frontend.create_checkout_command
|
136
|
+
tax_table = TaxTable.new(false)
|
137
|
+
tax_table.name = 'Some Table'
|
138
|
+
command.tax_tables << tax_table
|
139
|
+
item = Item.create_from_element(REXML::Document.new(xml_str).root, command.shopping_cart)
|
140
|
+
|
141
|
+
assert_equal command.shopping_cart, item.shopping_cart
|
142
|
+
|
143
|
+
assert_equal 'MegaSound 2GB MP3 Player', item.name
|
144
|
+
assert_equal 'Portable MP3 player - stores 500 songs', item.description
|
145
|
+
assert_equal Money.new(17800, 'USD'), item.unit_price
|
146
|
+
assert_equal 1, item.quantity
|
147
|
+
assert_equal 'MGS2GBMP3', item.id unless item.id.nil?
|
148
|
+
|
149
|
+
hash =
|
150
|
+
{
|
151
|
+
'item-note' => [ 'Text 1', 'Text 2' ],
|
152
|
+
'nested' => { 'tags' => 'value' }
|
153
|
+
}
|
154
|
+
assert_equal hash, item.private_data unless optional_tag_names.include?('merchant-private-item-data')
|
155
|
+
|
156
|
+
assert_equal 'Some Table', item.tax_table.name unless optional_tag_names.include?('tax-table-selector')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/marketing_preferences_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
6
|
+
# License: MIT License as follows:
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
13
|
+
# persons to whom the Software is furnished to do so, subject to the
|
14
|
+
# following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be included
|
17
|
+
# in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
20
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
22
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
23
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
24
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
25
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
#++
|
27
|
+
|
28
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
29
|
+
|
30
|
+
require 'google4r/checkout'
|
31
|
+
|
32
|
+
require 'test/frontend_configuration'
|
33
|
+
|
34
|
+
# Test for the class MarketingPreferences.
|
35
|
+
class Google4R::Checkout::MarketingPreferencesTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
40
|
+
<marketing-preferences>
|
41
|
+
<email-allowed>%s</email-allowed>
|
42
|
+
</marketing-preferences>
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_responds_correctly
|
47
|
+
@preferences = MarketingPreferences.new
|
48
|
+
|
49
|
+
[ :email_allowed, :email_allowed= ].each do |symbol|
|
50
|
+
assert_respond_to @preferences, symbol
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_create_from_element_works_correctly
|
55
|
+
{ 'true' => true, 'True' => true, 'TRUE' => true, 'false' => false, 'Frue' => false,
|
56
|
+
'FALSE' => false }.each do |str, bool|
|
57
|
+
xml_str = @xml_str % str
|
58
|
+
|
59
|
+
element = REXML::Document.new(xml_str).root
|
60
|
+
pref = MarketingPreferences.create_from_element(element)
|
61
|
+
|
62
|
+
assert_equal bool, pref.email_allowed
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/merchant_code_test.rb
|
4
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
6
|
+
# License: MIT License as follows:
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
13
|
+
# persons to whom the Software is furnished to do so, subject to the
|
14
|
+
# following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be included
|
17
|
+
# in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
20
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
22
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
23
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
24
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
25
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
#++
|
27
|
+
|
28
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
29
|
+
|
30
|
+
require 'google4r/checkout'
|
31
|
+
|
32
|
+
require 'test/frontend_configuration'
|
33
|
+
|
34
|
+
# Test for the class MerchantCode.
|
35
|
+
class Google4R::Checkout::MerchantCodeTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@valid_adjustment_types =
|
40
|
+
[
|
41
|
+
[ "GIFT_CERTIFICATE", 'gift-certificate-adjustment' ],
|
42
|
+
[ "COUPON", 'coupon-adjustment' ],
|
43
|
+
]
|
44
|
+
|
45
|
+
@optional_tag_names = [ 'calculated-amount', 'message' ]
|
46
|
+
|
47
|
+
@invalid_adjustment_types = [ 'invalid-adjustment' ]
|
48
|
+
|
49
|
+
@xml_str = %q{<?xml version="1.0" encodig="UTF-8"?>
|
50
|
+
<%s>
|
51
|
+
<applied-amount currency="%s">%s</applied-amount>
|
52
|
+
<code>%s</code>
|
53
|
+
<calculated-amount currency="%s">%s</calculated-amount>
|
54
|
+
<message>%s</message>
|
55
|
+
</%s>}
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_constants_are_defined
|
59
|
+
assert defined?(MerchantCode::GIFT_CERTIFICATE)
|
60
|
+
assert defined?(MerchantCode::COUPON)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_responds_correctly
|
64
|
+
adjustment = MerchantCode.new
|
65
|
+
|
66
|
+
[ :applied_amount, :applied_amount=, :code, :code=, :calculated_amount,
|
67
|
+
:calculated_amount=, :message, :message=,
|
68
|
+
].each do |sym|
|
69
|
+
assert_respond_to adjustment, sym
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_create_from_element_works_with_valid_adjustment_types
|
74
|
+
@valid_adjustment_types.each do |pair|
|
75
|
+
type, tag_name = pair
|
76
|
+
|
77
|
+
@optional_tag_names.power.each do |optional_tag_names|
|
78
|
+
xml_str = @xml_str %
|
79
|
+
[
|
80
|
+
tag_name, 'USD', '10.00', 'some-code', 'USD', '20.00', 'Message!', tag_name
|
81
|
+
]
|
82
|
+
|
83
|
+
optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
|
84
|
+
|
85
|
+
xml_doc = REXML::Document.new(xml_str)
|
86
|
+
xml_element = xml_doc.root.elements["/#{tag_name}"]
|
87
|
+
|
88
|
+
adjustment = MerchantCode.create_from_element(xml_element)
|
89
|
+
|
90
|
+
assert_equal Money.new(1000, 'USD'), adjustment.applied_amount
|
91
|
+
assert_equal type, adjustment.type
|
92
|
+
assert_equal 'some-code', adjustment.code
|
93
|
+
|
94
|
+
if not optional_tag_names.include?('calculated-amount') then
|
95
|
+
assert_equal Money.new(2000, 'USD'), adjustment.calculated_amount
|
96
|
+
else
|
97
|
+
assert_nil adjustment.calculated_amount
|
98
|
+
end
|
99
|
+
if not optional_tag_names.include?('message') then
|
100
|
+
assert_equal 'Message!', adjustment.message
|
101
|
+
else
|
102
|
+
assert_nil adjustment.message
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_create_from_element_raises_argument_error_with_invalid_shipping_adjustment_types
|
109
|
+
@invalid_adjustment_types.each do |tag_name|
|
110
|
+
xml_str = @xml_str %
|
111
|
+
[
|
112
|
+
tag_name, 'USD', '10.00', 'some-code', 'USD', '20.00', 'Message!', tag_name
|
113
|
+
]
|
114
|
+
|
115
|
+
xml_element = REXML::Document.new(xml_str).root
|
116
|
+
|
117
|
+
assert_raises(ArgumentError) do
|
118
|
+
adjustment = MerchantCode.create_from_element(xml_element)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|