google4r-checkout-jn 1.1.jniziol
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.
- data/CHANGES +136 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/lib/google4r/checkout.rb +34 -0
- data/lib/google4r/checkout/commands.rb +665 -0
- data/lib/google4r/checkout/frontend.rb +222 -0
- data/lib/google4r/checkout/merchant_calculation.rb +323 -0
- data/lib/google4r/checkout/notifications.rb +774 -0
- data/lib/google4r/checkout/shared.rb +1386 -0
- data/lib/google4r/checkout/utils.rb +94 -0
- data/lib/google4r/checkout/xml_generation.rb +1023 -0
- data/test/frontend_configuration_example.rb +13 -0
- data/test/integration/checkout_command_test.rb +261 -0
- data/test/test_helper.rb +105 -0
- data/test/unit/add_merchant_order_number_command_test.rb +65 -0
- data/test/unit/add_tracking_data_command_test.rb +68 -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 +63 -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 +63 -0
- data/test/unit/backorder_items_command_test.rb +69 -0
- data/test/unit/callback_handler_test.rb +83 -0
- data/test/unit/cancel_items_command_test.rb +76 -0
- data/test/unit/cancel_order_command_test.rb +74 -0
- data/test/unit/carrier_calculated_shipping_test.rb +57 -0
- data/test/unit/charge_amount_notification_test.rb +72 -0
- data/test/unit/charge_and_ship_order_command_test.rb +69 -0
- data/test/unit/charge_fee_test.rb +53 -0
- data/test/unit/charge_order_command_test.rb +69 -0
- data/test/unit/chargeback_amount_notification_test.rb +69 -0
- data/test/unit/checkout_command_test.rb +149 -0
- data/test/unit/checkout_command_xml_generator_test.rb +216 -0
- data/test/unit/command_test.rb +116 -0
- data/test/unit/deliver_order_command_test.rb +65 -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 +133 -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 +173 -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 +203 -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 +109 -0
- data/test/unit/order_state_change_notification_test.rb +158 -0
- data/test/unit/parameterized_url_test.rb +57 -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 +67 -0
- data/test/unit/refund_order_command_test.rb +79 -0
- data/test/unit/reset_items_shipping_information_command_test.rb +69 -0
- data/test/unit/return_items_command_test.rb +69 -0
- data/test/unit/risk_information_notification_test.rb +98 -0
- data/test/unit/send_buyer_message_command_test.rb +68 -0
- data/test/unit/ship_items_command_test.rb +81 -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 +88 -0
- data/test/unit/tracking_data_test.rb +54 -0
- data/test/unit/unarchive_order_command_test.rb +63 -0
- data/test/unit/url_parameter_test.rb +55 -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 +230 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
# Uncomment the following line if you are using Google Checkout in Great Britain
|
2
|
+
# and adjust it if you want to test google4r-checkout against any other (future)
|
3
|
+
# Google Checkout service.
|
4
|
+
|
5
|
+
# Money.default_currency = 'GBP'
|
6
|
+
|
7
|
+
# The test configuration for the Google4R::Checkout::Frontend class.
|
8
|
+
FRONTEND_CONFIGURATION =
|
9
|
+
{
|
10
|
+
:merchant_id => '',
|
11
|
+
:merchant_key => '',
|
12
|
+
:use_sandbox => true
|
13
|
+
}
|
@@ -0,0 +1,261 @@
|
|
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
|
+
|
66
|
+
assert_kind_of CheckoutRedirectResponse, result
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_sending_to_google_works_with_google_handled_subscription
|
70
|
+
setup_command(@command)
|
71
|
+
|
72
|
+
@command.shopping_cart.create_item do |item|
|
73
|
+
item.name = "Test subscription"
|
74
|
+
item.description = "12 month subscription"
|
75
|
+
item.unit_price = Money.us_dollar(0)
|
76
|
+
item.quantity = 1
|
77
|
+
item.private_data = { :id => 123456 }
|
78
|
+
|
79
|
+
item.create_subscription do |subscription|
|
80
|
+
subscription.type = "google"
|
81
|
+
subscription.period = "MONTHLY"
|
82
|
+
|
83
|
+
subscription.add_payment do |payment|
|
84
|
+
payment.times = 12
|
85
|
+
payment.maximum_charge = Money.us_dollar(1200)
|
86
|
+
end
|
87
|
+
|
88
|
+
subscription.add_recurrent_item do |rec_item|
|
89
|
+
rec_item.name = "Usage of My Awesome Website for One Month"
|
90
|
+
rec_item.description = "Your flat charge for accessing my web site"
|
91
|
+
rec_item.quantity = 1
|
92
|
+
rec_item.unit_price = Money.us_dollar(1200)
|
93
|
+
|
94
|
+
rec_item.create_digital_content do |content|
|
95
|
+
content.display_disposition = "OPTIMISTIC"
|
96
|
+
content.url = "http://mywebsite.example.com"
|
97
|
+
content.description = "Pie is found at this web site!"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
item.create_digital_content do |content|
|
102
|
+
content.display_disposition = "OPTIMISTIC"
|
103
|
+
content.description = "Congratulations! Your subscription is being set up. Feel free to log onto" +
|
104
|
+
"<a href=\"http://mywebsite.example.com\">My website</a>."
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
result = @command.send_to_google_checkout
|
110
|
+
assert_kind_of CheckoutRedirectResponse, result
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_sending_to_google_works_with_merchant_handled_subscription
|
114
|
+
setup_command(@command)
|
115
|
+
|
116
|
+
@command.shopping_cart.create_item do |item|
|
117
|
+
item.name = "Test subscription"
|
118
|
+
item.description = "12 month subscription"
|
119
|
+
item.unit_price = Money.us_dollar(0)
|
120
|
+
item.quantity = 1
|
121
|
+
item.private_data = { :id => 123456 }
|
122
|
+
|
123
|
+
item.create_subscription do |subscription|
|
124
|
+
subscription.type = "merchant"
|
125
|
+
subscription.period = "MONTHLY"
|
126
|
+
subscription.start_date = Time.new
|
127
|
+
subscription.start_date += (60 * 60 * 24 * 30)
|
128
|
+
subscription.no_charge_after = subscription.start_date + (60 * 60 * 24 * 365)
|
129
|
+
|
130
|
+
subscription.add_payment do |payment|
|
131
|
+
payment.times = 12
|
132
|
+
payment.maximum_charge = Money.us_dollar(1200)
|
133
|
+
end
|
134
|
+
|
135
|
+
item.create_digital_content do |content|
|
136
|
+
content.display_disposition = "OPTIMISTIC"
|
137
|
+
content.description = "Congratulations! Your subscription is being set up. Feel free to log onto" +
|
138
|
+
"<a href=\"http://mywebsite.example.com\">My website</a>."
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
result = @command.send_to_google_checkout
|
144
|
+
assert_kind_of CheckoutRedirectResponse, result
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_using_invalid_credentials_raise_google_checkout_error
|
148
|
+
invalid_patches = [ [ :merchant_id, 'invalid' ], [ :merchant_key, 'invalid' ] ]
|
149
|
+
|
150
|
+
invalid_patches.each do |patch|
|
151
|
+
config = FRONTEND_CONFIGURATION.dup
|
152
|
+
config[patch[0]] = patch[1]
|
153
|
+
@frontend = Frontend.new(config)
|
154
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
155
|
+
@command = @frontend.create_checkout_command
|
156
|
+
|
157
|
+
setup_command(@command)
|
158
|
+
assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_invalid_xml_raises_google_checkout_error
|
163
|
+
class << @command
|
164
|
+
def to_xml
|
165
|
+
''
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
setup_command(@command)
|
170
|
+
assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
|
171
|
+
end
|
172
|
+
|
173
|
+
protected
|
174
|
+
|
175
|
+
# Sets up the given CheckoutCommand so it contains some
|
176
|
+
# shipping methods and its cart contains some items.
|
177
|
+
def setup_command(command, shipping_type=FlatRateShipping)
|
178
|
+
|
179
|
+
if shipping_type == FlatRateShipping
|
180
|
+
# Add shipping methods.
|
181
|
+
command.create_shipping_method(FlatRateShipping) do |shipping|
|
182
|
+
shipping.name = 'UPS Ground Shipping'
|
183
|
+
shipping.price = Money.new(2000) # USD 20, GPB 20, etc.
|
184
|
+
shipping.create_allowed_area(UsCountryArea) do |area|
|
185
|
+
area.area = UsCountryArea::ALL
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
if shipping_type == MerchantCalculatedShipping
|
191
|
+
command.merchant_calculations_url = 'http://www.example.com'
|
192
|
+
|
193
|
+
command.create_shipping_method(MerchantCalculatedShipping) do |shipping|
|
194
|
+
shipping.name = 'International Shipping'
|
195
|
+
shipping.price = Money.new(2000)
|
196
|
+
shipping.create_address_filters_allowed_area(PostalArea) do |area|
|
197
|
+
area.country_code = 'US'
|
198
|
+
area.postal_code_pattern = '12*'
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
if shipping_type == CarrierCalculatedShipping
|
204
|
+
command.create_shipping_method(CarrierCalculatedShipping) do |shipping|
|
205
|
+
shipping.create_carrier_calculated_shipping_option do | option |
|
206
|
+
option.shipping_company =
|
207
|
+
CarrierCalculatedShipping::CarrierCalculatedShippingOption::FEDEX
|
208
|
+
option.price = Money.new(3000)
|
209
|
+
option.shipping_type = 'Priority Overnight'
|
210
|
+
option.carrier_pickup = 'REGULAR_PICKUP'
|
211
|
+
option.additional_fixed_charge = Money.new(500)
|
212
|
+
option.additional_variable_charge_percent = 15.5
|
213
|
+
end
|
214
|
+
shipping.create_shipping_package do | package |
|
215
|
+
ship_from = AnonymousAddress.new
|
216
|
+
ship_from.address_id = 'ABC'
|
217
|
+
ship_from.city = 'Ann Arbor'
|
218
|
+
ship_from.region = 'MI'
|
219
|
+
ship_from.country_code = 'US'
|
220
|
+
ship_from.postal_code = '48104'
|
221
|
+
package.ship_from = ship_from
|
222
|
+
package.delivery_address_category =
|
223
|
+
CarrierCalculatedShipping::ShippingPackage::COMMERCIAL
|
224
|
+
package.height = Dimension.new(1)
|
225
|
+
package.length = Dimension.new(2)
|
226
|
+
package.width = Dimension.new(3)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
# Add a paramterized URL with url parameters
|
232
|
+
command.create_parameterized_url(:url => "http://google.ca") do |parameterized_url|
|
233
|
+
parameterized_url.create_url_parameter(:name => "order", :type => 'order-id')
|
234
|
+
end
|
235
|
+
|
236
|
+
# Add a parameterized URL without URL parameters
|
237
|
+
command.create_parameterized_url(:url => "http://www.google.com")
|
238
|
+
|
239
|
+
# Add items to the cart.
|
240
|
+
1.upto(5) do |i|
|
241
|
+
command.shopping_cart.create_item do |item|
|
242
|
+
item.name = "Test Item #{i}"
|
243
|
+
item.description = "This is a test item (#{i})"
|
244
|
+
item.unit_price = Money.new(350)
|
245
|
+
item.quantity = i * 3
|
246
|
+
item.id = "test-#{i}-123456789"
|
247
|
+
item.weight = Weight.new(2.2)
|
248
|
+
if (i == 5)
|
249
|
+
item.create_digital_content do |dc|
|
250
|
+
dc.display_disposition =
|
251
|
+
Google4R::Checkout::Item::DigitalContent::OPTIMISTIC
|
252
|
+
dc.description = "Information on how to get your content"
|
253
|
+
dc.url = "http://my.domain.com/downloads"
|
254
|
+
dc.key = "abcde12345"
|
255
|
+
dc.email_delivery = false
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Project: google4r
|
2
|
+
# File: /test/test_helper.rb
|
3
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
4
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
5
|
+
# License: MIT License as follows:
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
# a copy of this software and associated documentation files (the
|
9
|
+
# "Software"), to deal in the Software without restriction, including
|
10
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
12
|
+
# persons to whom the Software is furnished to do so, subject to the
|
13
|
+
# following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be included
|
16
|
+
# in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
19
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
21
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
22
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
23
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
24
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
|
26
|
+
# setup load path
|
27
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..')
|
28
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
29
|
+
|
30
|
+
# require dependencies
|
31
|
+
|
32
|
+
require 'test/unit'
|
33
|
+
|
34
|
+
require 'rubygems'
|
35
|
+
require 'bundler'
|
36
|
+
Bundler.setup(:default, :test)
|
37
|
+
|
38
|
+
require 'mocha'
|
39
|
+
require 'nokogiri'
|
40
|
+
|
41
|
+
class Array
|
42
|
+
# Returns the "power set" for this Array. This means that an array with all
|
43
|
+
# subsets of the array's elements will be returned.
|
44
|
+
def power
|
45
|
+
# the power set line is stolen from http://johncarrino.net/blog/2006/08/11/powerset-in-ruby/
|
46
|
+
inject([[]]){|c,y|r=[];c.each{|i|r<<i;r<<i+[y]};r}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# A helper class for the tests that require TaxTable objects.
|
51
|
+
class TestTaxTableFactory
|
52
|
+
def effective_tax_tables_at(time)
|
53
|
+
table = Google4R::Checkout::TaxTable.new(false)
|
54
|
+
table.name = "Some Table"
|
55
|
+
|
56
|
+
[ table ]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Test::Unit::TestCase
|
61
|
+
def assert_nospace_equal(expected, actual)
|
62
|
+
return assert_equal(expected.gsub(/\s/, ''), actual.gsub(/\s/, ''))
|
63
|
+
end
|
64
|
+
|
65
|
+
def command_selector(command)
|
66
|
+
"#{Google4R::Checkout::CommandXmlGenerator::COMMAND_TO_TAG[command.class]}" +
|
67
|
+
"[google-order-number='#{command.google_order_number}']"
|
68
|
+
end
|
69
|
+
|
70
|
+
def find_elements(selector, xml)
|
71
|
+
Nokogiri.parse(xml).css(selector)
|
72
|
+
end
|
73
|
+
|
74
|
+
def assert_element_exists(selector, xml, msg=nil)
|
75
|
+
found = find_elements(selector, xml)
|
76
|
+
assert_not_equal 0, found.size, (msg || "Expected to find #{selector} in #{xml}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def assert_no_element_exists(selector, xml, msg=nil)
|
80
|
+
found = find_elements(selector, xml)
|
81
|
+
assert_equal 0, found.size, (msg || "Expected to find #{selector} in #{xml}")
|
82
|
+
end
|
83
|
+
|
84
|
+
def assert_element_text_equals(text, selector, xml, msg=nil)
|
85
|
+
found = find_elements(selector, xml)
|
86
|
+
assert_equal 1, found.size, "Expected to find one #{selector} in #{xml} but found #{found.size}"
|
87
|
+
assert_equal text, found.text, msg
|
88
|
+
end
|
89
|
+
|
90
|
+
def find_command_elements(selector, command)
|
91
|
+
find_elements("#{command_selector(command)} #{selector}", command.to_xml)
|
92
|
+
end
|
93
|
+
|
94
|
+
def assert_command_element_text_equals(text, selector, command, msg=nil)
|
95
|
+
assert_element_text_equals(text, "#{command_selector(command)} #{selector}", command.to_xml, msg)
|
96
|
+
end
|
97
|
+
|
98
|
+
def assert_command_element_exists(selector, command, msg=nil)
|
99
|
+
assert_element_exists("#{command_selector(command)} #{selector}", command.to_xml, msg)
|
100
|
+
end
|
101
|
+
|
102
|
+
def assert_no_command_element_exists(selector, command, msg=nil)
|
103
|
+
assert_no_element_exists("#{command_selector(command)} #{selector}", command.to_xml, msg)
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
+
end
|
45
|
+
|
46
|
+
def test_behaves_correctly
|
47
|
+
[ :google_order_number, :merchant_order_number ].each do |symbol|
|
48
|
+
assert_respond_to @command, symbol
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_xml
|
53
|
+
assert_command_element_text_equals(@command.merchant_order_number, "> merchant-order-number", @command)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_accessors
|
57
|
+
assert_equal('841171949013218', @command.google_order_number)
|
58
|
+
assert_equal('P6502-53-7861SBJD', @command.merchant_order_number)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_to_xml_does_not_raise_exception
|
62
|
+
assert_nothing_raised { @command.to_xml }
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,68 @@
|
|
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
|
+
end
|
46
|
+
|
47
|
+
def test_behaves_correctly
|
48
|
+
[ :google_order_number, :carrier, :tracking_number ].each do |symbol|
|
49
|
+
assert_respond_to @command, symbol
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_xml
|
54
|
+
assert_command_element_text_equals(@command.carrier, "> tracking-data > carrier", @command)
|
55
|
+
assert_command_element_text_equals(@command.tracking_number, "> tracking-data > tracking-number", @command)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_accessors
|
59
|
+
assert_equal('841171949013218', @command.google_order_number)
|
60
|
+
assert_equal('Z9842W69871281267', @command.tracking_number)
|
61
|
+
assert_equal('UPS', @command.carrier)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_to_xml_does_not_raise_exception
|
65
|
+
assert_nothing_raised { @command.to_xml }
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|