archerfinley-google4r-checkout-1.0.5 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +93 -0
- data/LICENSE +22 -0
- data/README +58 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/google4r-checkout-1.0.5-1.0.5.gem +0 -0
- data/google4r-checkout-1.0.5.gemspec +174 -0
- data/lib/google4r/checkout.rb +34 -0
- data/lib/google4r/checkout/commands.rb +567 -0
- data/lib/google4r/checkout/frontend.rb +210 -0
- data/lib/google4r/checkout/merchant_calculation.rb +321 -0
- data/lib/google4r/checkout/notifications.rb +708 -0
- data/lib/google4r/checkout/shared.rb +1086 -0
- data/lib/google4r/checkout/utils.rb +94 -0
- data/lib/google4r/checkout/xml_generation.rb +880 -0
- data/test/integration/checkout_command_test.rb +174 -0
- data/test/unit/add_merchant_order_number_command_test.rb +70 -0
- data/test/unit/add_tracking_data_command_test.rb +75 -0
- data/test/unit/address_test.rb +131 -0
- data/test/unit/anonymous_address_test.rb +75 -0
- data/test/unit/archive_order_command_test.rb +66 -0
- data/test/unit/area_test.rb +44 -0
- data/test/unit/authorization_amount_notification_test.rb +69 -0
- data/test/unit/authorize_order_command_test.rb +66 -0
- data/test/unit/backorder_items_command_test.rb +83 -0
- data/test/unit/callback_handler_test.rb +83 -0
- data/test/unit/cancel_items_command_test.rb +89 -0
- data/test/unit/cancel_order_command_test.rb +83 -0
- data/test/unit/carrier_calculated_shipping_test.rb +57 -0
- data/test/unit/charge_amount_notification_test.rb +64 -0
- data/test/unit/charge_order_command_test.rb +77 -0
- data/test/unit/chargeback_amount_notification_test.rb +65 -0
- data/test/unit/checkout_command_test.rb +125 -0
- data/test/unit/checkout_command_xml_generator_test.rb +218 -0
- data/test/unit/command_test.rb +116 -0
- data/test/unit/deliver_order_command_test.rb +70 -0
- data/test/unit/delivery_method_test.rb +42 -0
- data/test/unit/digital_content_test.rb +105 -0
- data/test/unit/flat_rate_shipping_test.rb +132 -0
- data/test/unit/frontend_test.rb +144 -0
- data/test/unit/item_info_test.rb +69 -0
- data/test/unit/item_test.rb +171 -0
- data/test/unit/marketing_preferences_test.rb +65 -0
- data/test/unit/merchant_calculated_shipping_test.rb +172 -0
- data/test/unit/merchant_calculation_callback_test.rb +137 -0
- data/test/unit/merchant_calculation_result_test.rb +78 -0
- data/test/unit/merchant_calculation_results_test.rb +178 -0
- data/test/unit/merchant_code_result_test.rb +51 -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 +67 -0
- data/test/unit/notification_handler_test.rb +113 -0
- data/test/unit/order_adjustment_test.rb +119 -0
- data/test/unit/order_report_command_test.rb +111 -0
- data/test/unit/order_state_change_notification_test.rb +158 -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/refund_amount_notification_test.rb +65 -0
- data/test/unit/refund_order_command_test.rb +86 -0
- data/test/unit/reset_items_shipping_information_command_test.rb +83 -0
- data/test/unit/return_items_command_test.rb +83 -0
- data/test/unit/risk_information_notification_test.rb +98 -0
- data/test/unit/send_buyer_message_command_test.rb +73 -0
- data/test/unit/ship_items_command_test.rb +101 -0
- data/test/unit/shipping_adjustment_test.rb +100 -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/tracking_data_test.rb +54 -0
- data/test/unit/unarchive_order_command_test.rb +66 -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 +189 -0
@@ -0,0 +1,174 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/checkout/integration/checkout_command.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
|
+
# Integration tests for the CheckoutCommand class.
|
35
|
+
#
|
36
|
+
# Tests the CheckoutCommand class against the Google Checkout Web Service.
|
37
|
+
class Google4R::Checkout::CheckoutCommandIntegrationTest < Test::Unit::TestCase
|
38
|
+
include Google4R::Checkout
|
39
|
+
|
40
|
+
def setup
|
41
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
42
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
43
|
+
@command = @frontend.create_checkout_command
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_sending_to_google_works_with_valid_request
|
47
|
+
setup_command(@command)
|
48
|
+
result = @command.send_to_google_checkout
|
49
|
+
assert_kind_of CheckoutRedirectResponse, result
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_sending_to_google_works_with_merchant_calculated_shipping
|
53
|
+
setup_command(@command, MerchantCalculatedShipping)
|
54
|
+
result = @command.send_to_google_checkout
|
55
|
+
assert_kind_of CheckoutRedirectResponse, result
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_sending_to_google_works_with_carrier_calculated_shipping
|
59
|
+
setup_command(@command, CarrierCalculatedShipping)
|
60
|
+
result = @command.send_to_google_checkout
|
61
|
+
# Uncomment the two lines below to see the shopping cart xml and
|
62
|
+
# the redirect URL
|
63
|
+
#puts @command.to_xml
|
64
|
+
#puts result
|
65
|
+
assert_kind_of CheckoutRedirectResponse, result
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_using_invalid_credentials_raise_google_checkout_error
|
69
|
+
invalid_patches = [ [ :merchant_id, 'invalid' ], [ :merchant_key, 'invalid' ] ]
|
70
|
+
|
71
|
+
invalid_patches.each do |patch|
|
72
|
+
config = FRONTEND_CONFIGURATION.dup
|
73
|
+
config[patch[0]] = patch[1]
|
74
|
+
@frontend = Frontend.new(config)
|
75
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
76
|
+
@command = @frontend.create_checkout_command
|
77
|
+
|
78
|
+
setup_command(@command)
|
79
|
+
assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_invalid_xml_raises_google_checkout_error
|
84
|
+
class << @command
|
85
|
+
def to_xml
|
86
|
+
''
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
setup_command(@command)
|
91
|
+
assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
|
92
|
+
end
|
93
|
+
|
94
|
+
protected
|
95
|
+
|
96
|
+
# Sets up the given CheckoutCommand so it contains some
|
97
|
+
# shipping methods and its cart contains some items.
|
98
|
+
def setup_command(command, shipping_type=FlatRateShipping)
|
99
|
+
|
100
|
+
if shipping_type == FlatRateShipping
|
101
|
+
# Add shipping methods.
|
102
|
+
command.create_shipping_method(FlatRateShipping) do |shipping|
|
103
|
+
shipping.name = 'UPS Ground Shipping'
|
104
|
+
shipping.price = Money.new(2000) # USD 20, GPB 20, etc.
|
105
|
+
shipping.create_allowed_area(UsCountryArea) do |area|
|
106
|
+
area.area = UsCountryArea::ALL
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
if shipping_type == MerchantCalculatedShipping
|
112
|
+
command.merchant_calculations_url = 'http://www.example.com'
|
113
|
+
|
114
|
+
command.create_shipping_method(MerchantCalculatedShipping) do |shipping|
|
115
|
+
shipping.name = 'International Shipping'
|
116
|
+
shipping.price = Money.new(2000)
|
117
|
+
shipping.create_address_filters_allowed_area(PostalArea) do |area|
|
118
|
+
area.country_code = 'US'
|
119
|
+
area.postal_code_pattern = '12*'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
if shipping_type == CarrierCalculatedShipping
|
125
|
+
command.create_shipping_method(CarrierCalculatedShipping) do |shipping|
|
126
|
+
shipping.create_carrier_calculated_shipping_option do | option |
|
127
|
+
option.shipping_company =
|
128
|
+
CarrierCalculatedShipping::CarrierCalculatedShippingOption::FEDEX
|
129
|
+
option.price = Money.new(3000)
|
130
|
+
option.shipping_type = 'Priority Overnight'
|
131
|
+
option.carrier_pickup = 'REGULAR_PICKUP'
|
132
|
+
option.additional_fixed_charge = Money.new(500)
|
133
|
+
option.additional_variable_charge_percent = 15.5
|
134
|
+
end
|
135
|
+
shipping.create_shipping_package do | package |
|
136
|
+
ship_from = AnonymousAddress.new
|
137
|
+
ship_from.address_id = 'ABC'
|
138
|
+
ship_from.city = 'Ann Arbor'
|
139
|
+
ship_from.region = 'MI'
|
140
|
+
ship_from.country_code = 'US'
|
141
|
+
ship_from.postal_code = '48104'
|
142
|
+
package.ship_from = ship_from
|
143
|
+
package.delivery_address_category =
|
144
|
+
CarrierCalculatedShipping::ShippingPackage::COMMERCIAL
|
145
|
+
package.height = Dimension.new(1)
|
146
|
+
package.length = Dimension.new(2)
|
147
|
+
package.width = Dimension.new(3)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Add items to the cart.
|
153
|
+
1.upto(5) do |i|
|
154
|
+
command.shopping_cart.create_item do |item|
|
155
|
+
item.name = "Test Item #{i}"
|
156
|
+
item.description = "This is a test item (#{i})"
|
157
|
+
item.unit_price = Money.new(350)
|
158
|
+
item.quantity = i * 3
|
159
|
+
item.id = "test-#{i}-123456789"
|
160
|
+
item.weight = Weight.new(2.2)
|
161
|
+
if (i == 5)
|
162
|
+
item.create_digital_content do |dc|
|
163
|
+
dc.display_disposition =
|
164
|
+
Google4R::Checkout::Item::DigitalContent::OPTIMISTIC
|
165
|
+
dc.description = "Information on how to get your content"
|
166
|
+
dc.url = "http://my.domain.com/downloads"
|
167
|
+
dc.key = "abcde12345"
|
168
|
+
dc.email_delivery = false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/add_merchant_order_number_command_test.rb
|
4
|
+
# Author: Tony Chan <api.htchan at gmail dot com>
|
5
|
+
# Copyright: (c) 2007 by Tony Chan
|
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
|
+
# Tests for the AddMerchantOrderNumberCommand class.
|
35
|
+
class Google4R::Checkout::AddMerchantOrderNumberCommandTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
40
|
+
@command = @frontend.create_add_merchant_order_number_command
|
41
|
+
|
42
|
+
@command.google_order_number = '841171949013218'
|
43
|
+
@command.merchant_order_number = 'P6502-53-7861SBJD'
|
44
|
+
|
45
|
+
@sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
|
46
|
+
<add-merchant-order-number xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
|
47
|
+
<merchant-order-number>P6502-53-7861SBJD</merchant-order-number>
|
48
|
+
</add-merchant-order-number>}
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_behaves_correctly
|
52
|
+
[ :google_order_number, :merchant_order_number ].each do |symbol|
|
53
|
+
assert_respond_to @command, symbol
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_xml
|
58
|
+
assert_strings_equal(@sample_xml, @command.to_xml)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_accessors
|
62
|
+
assert_equal('841171949013218', @command.google_order_number)
|
63
|
+
assert_equal('P6502-53-7861SBJD', @command.merchant_order_number)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_to_xml_does_not_raise_exception
|
67
|
+
assert_nothing_raised { @command.to_xml }
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/add_tracking_data_command_test.rb
|
4
|
+
# Author: Tony Chan <api.htchan at gmail dot com>
|
5
|
+
# Copyright: (c) 2007 by Tony Chan
|
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
|
+
# Tests for the AddTrackingDataCommand class.
|
35
|
+
class Google4R::Checkout::AddTrackingDataCommandTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
40
|
+
@command = @frontend.create_add_tracking_data_command
|
41
|
+
|
42
|
+
@command.google_order_number = '841171949013218'
|
43
|
+
@command.carrier = 'UPS'
|
44
|
+
@command.tracking_number = 'Z9842W69871281267'
|
45
|
+
|
46
|
+
@sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
|
47
|
+
<add-tracking-data xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
|
48
|
+
<tracking-data>
|
49
|
+
<carrier>UPS</carrier>
|
50
|
+
<tracking-number>Z9842W69871281267</tracking-number>
|
51
|
+
</tracking-data>
|
52
|
+
</add-tracking-data>}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_behaves_correctly
|
56
|
+
[ :google_order_number, :carrier, :tracking_number ].each do |symbol|
|
57
|
+
assert_respond_to @command, symbol
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_xml
|
62
|
+
assert_strings_equal(@sample_xml, @command.to_xml)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_accessors
|
66
|
+
assert_equal('841171949013218', @command.google_order_number)
|
67
|
+
assert_equal('Z9842W69871281267', @command.tracking_number)
|
68
|
+
assert_equal('UPS', @command.carrier)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_to_xml_does_not_raise_exception
|
72
|
+
assert_nothing_raised { @command.to_xml }
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/address_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 Address.
|
35
|
+
class Google4R::Checkout::AddressTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@data =
|
40
|
+
{
|
41
|
+
:contact_name => 'John Smith',
|
42
|
+
:email => 'johnsmith@example.com',
|
43
|
+
:fax => '+01123456789',
|
44
|
+
:phone => '+01123456789',
|
45
|
+
:address1 => '10 Example Road',
|
46
|
+
:address2 => 'Bar',
|
47
|
+
:city => 'Sampleville',
|
48
|
+
:company_name => 'Company Name',
|
49
|
+
:region => 'CA',
|
50
|
+
:postal_code => '94141',
|
51
|
+
:country_code => 'US',
|
52
|
+
}
|
53
|
+
|
54
|
+
@optional_fields = [ :fax, :phone, :address2, :company_name, :contact_name ]
|
55
|
+
|
56
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
57
|
+
<root>
|
58
|
+
<some-address>
|
59
|
+
<contact-name>%s</contact-name>
|
60
|
+
<email>%s</email>
|
61
|
+
<fax>%s</fax>
|
62
|
+
<phone>%s</phone>
|
63
|
+
<address1>%s</address1>
|
64
|
+
<address2>%s</address2>
|
65
|
+
<city>%s</city>
|
66
|
+
<company-name>%s</company-name>
|
67
|
+
<region>%s</region>
|
68
|
+
<postal-code>%s</postal-code>
|
69
|
+
<country-code>%s</country-code>
|
70
|
+
</some-address>
|
71
|
+
</root>}
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_responds_correctly
|
75
|
+
@address = Address.new
|
76
|
+
|
77
|
+
@data.each do |key, value|
|
78
|
+
assert_respond_to @address, key, "key == #{key}"
|
79
|
+
assert_respond_to @address, "#{key}=".to_sym, "key == #{key}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_creating_address_with_full_fields_works
|
84
|
+
xml_str = @xml_str %
|
85
|
+
[
|
86
|
+
@data[:contact_name], @data[:email], @data[:fax], @data[:phone], @data[:address1],
|
87
|
+
@data[:address2], @data[:city], @data[:company_name], @data[:region],
|
88
|
+
@data[:postal_code], @data[:country_code]
|
89
|
+
]
|
90
|
+
|
91
|
+
document = REXML::Document.new(xml_str)
|
92
|
+
|
93
|
+
the_element = document.elements['/root/some-address']
|
94
|
+
|
95
|
+
address = Address.create_from_element(the_element)
|
96
|
+
|
97
|
+
@data.each do |key, value|
|
98
|
+
assert_equal value, address.send(key)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_creating_address_works_when_removing_optional_fields
|
103
|
+
@optional_fields.power.each do |optional_symbols|
|
104
|
+
xml_str = @xml_str %
|
105
|
+
[
|
106
|
+
@data[:contact_name], @data[:email], @data[:fax], @data[:phone], @data[:address1],
|
107
|
+
@data[:address2], @data[:city], @data[:company_name], @data[:region],
|
108
|
+
@data[:postal_code], @data[:country_code]
|
109
|
+
]
|
110
|
+
|
111
|
+
# Remove all optional symbols in this run.
|
112
|
+
optional_symbols.each do |symbol|
|
113
|
+
xml_str = xml_str.gsub(%r{<#{symbol.to_s.gsub('_', '-')}>.*?</#{symbol.to_s.gsub('_', '-')}>}, '')
|
114
|
+
end
|
115
|
+
|
116
|
+
document = REXML::Document.new(xml_str)
|
117
|
+
|
118
|
+
the_element = document.elements['/root/some-address']
|
119
|
+
|
120
|
+
address = Address.create_from_element(the_element)
|
121
|
+
|
122
|
+
@data.each do |key, value|
|
123
|
+
if optional_symbols.include?(key) then
|
124
|
+
assert_nil address.send(key)
|
125
|
+
else
|
126
|
+
assert_equal value, address.send(key)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|