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,144 @@
|
|
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
|
+
[ :configuration, :tax_table_factory, :tax_table_factory=,
|
50
|
+
:create_notification_handler, :create_callback_handler,
|
51
|
+
:create_deliver_order_command, :create_charge_order_command,
|
52
|
+
:create_checkout_command, :create_cancel_order_command,
|
53
|
+
:create_refund_order_command, :create_send_buyer_message_command,
|
54
|
+
:create_authorize_order_command, :create_add_merchant_order_number_command,
|
55
|
+
:create_add_tracking_data_command, :create_archive_order_command,
|
56
|
+
:create_unarchive_order_command, :create_ship_items_command,
|
57
|
+
:create_backorder_items_command, :create_return_items_command,
|
58
|
+
:create_cancel_items_command, :create_reset_items_shipping_information_command,
|
59
|
+
:create_order_report_command
|
60
|
+
].each do |symbol|
|
61
|
+
assert_respond_to @frontend, symbol
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create_notification_handler_works_correctly
|
66
|
+
assert_kind_of NotificationHandler, @frontend.create_notification_handler
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_create_callback_handler_works_correctly
|
70
|
+
assert_kind_of CallbackHandler, @frontend.create_callback_handler
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_create_deliver_order_command_works_correctly
|
74
|
+
assert_kind_of DeliverOrderCommand, @frontend.create_deliver_order_command
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_create_charge_order_command_works_correctly
|
78
|
+
assert_kind_of ChargeOrderCommand, @frontend.create_charge_order_command
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_create_checkout_command_works_correctly
|
82
|
+
assert_kind_of CheckoutCommand, @frontend.create_checkout_command
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_create_cancel_order_command_works_correctly
|
86
|
+
assert_kind_of CancelOrderCommand, @frontend.create_cancel_order_command
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_create_refund_order_command_works_correctly
|
90
|
+
assert_kind_of RefundOrderCommand, @frontend.create_refund_order_command
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_create_send_buyer_message_command_works_correctly
|
94
|
+
assert_kind_of SendBuyerMessageCommand, @frontend.create_send_buyer_message_command
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_create_authorize_order_command_works_correctly
|
98
|
+
assert_kind_of AuthorizeOrderCommand, @frontend.create_authorize_order_command
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_create_add_merchant_order_number_command_works_correctly
|
102
|
+
assert_kind_of AddMerchantOrderNumberCommand, @frontend.create_add_merchant_order_number_command
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_create_add_tracking_data_command_works_correctly
|
106
|
+
assert_kind_of AddTrackingDataCommand, @frontend.create_add_tracking_data_command
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_create_archive_order_command_works_correctly
|
110
|
+
assert_kind_of ArchiveOrderCommand, @frontend.create_archive_order_command
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_create_unarchive_order_command_works_correctly
|
114
|
+
assert_kind_of UnarchiveOrderCommand, @frontend.create_unarchive_order_command
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_create_ship_items_command_works_correctly
|
118
|
+
assert_kind_of ShipItemsCommand, @frontend.create_ship_items_command
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_create_backorder_items_command_works_correctly
|
122
|
+
assert_kind_of BackorderItemsCommand, @frontend.create_backorder_items_command
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_create_return_items_command_works_correctly
|
126
|
+
assert_kind_of ReturnItemsCommand, @frontend.create_return_items_command
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_create_cancel_items_command_works_correctly
|
130
|
+
assert_kind_of CancelItemsCommand, @frontend.create_cancel_items_command
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_create_reset_items_shipping_information_command_works_correctly
|
134
|
+
assert_kind_of ResetItemsShippingInformationCommand,
|
135
|
+
@frontend.create_reset_items_shipping_information_command
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_create_order_report_command_works_correctly
|
139
|
+
assert_kind_of OrderReportCommand,
|
140
|
+
@frontend.create_order_report_command(
|
141
|
+
Time.utc(2007, 9, 1, 0, 0, 0),
|
142
|
+
Time.utc(2007, 9, 30, 23, 59, 59))
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'google4r/checkout'
|
2
|
+
|
3
|
+
require 'test/frontend_configuration'
|
4
|
+
#--
|
5
|
+
# Project: google_checkout4r
|
6
|
+
# File: test/unit/item_info_test.rb
|
7
|
+
# Author: Tony Chan <api.htchan at gmail dot com>
|
8
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
9
|
+
# License: MIT License as follows:
|
10
|
+
#
|
11
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
12
|
+
# a copy of this software and associated documentation files (the
|
13
|
+
# "Software"), to deal in the Software without restriction, including
|
14
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
15
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
16
|
+
# persons to whom the Software is furnished to do so, subject to the
|
17
|
+
# following conditions:
|
18
|
+
#
|
19
|
+
# The above copyright notice and this permission notice shall be included
|
20
|
+
# in all copies or substantial portions of the Software.
|
21
|
+
#
|
22
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
23
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
24
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
25
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
26
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
27
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
28
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
29
|
+
#++
|
30
|
+
|
31
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
32
|
+
|
33
|
+
require 'google4r/checkout'
|
34
|
+
|
35
|
+
require 'test/frontend_configuration'
|
36
|
+
|
37
|
+
# Test for the class ItemInfo.
|
38
|
+
class Google4R::Checkout::ItemInfoTest < Test::Unit::TestCase
|
39
|
+
include Google4R::Checkout
|
40
|
+
|
41
|
+
def setup
|
42
|
+
@item_info = ItemInfo.new('A1')
|
43
|
+
@item_info.create_tracking_data('UPS', '55555555')
|
44
|
+
@item_info.create_tracking_data('FedEx', '12345678')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_initialization_works
|
48
|
+
assert_kind_of ItemInfo, @item_info
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_responds_correctly
|
52
|
+
[ :merchant_item_id, :tracking_data_arr].each do |sym|
|
53
|
+
assert_respond_to @item_info, sym
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_merchant_item_id
|
58
|
+
assert_equal('A1', @item_info.merchant_item_id)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_tracking_data_arr
|
62
|
+
tracking_data = @item_info.tracking_data_arr[0]
|
63
|
+
assert_equal('UPS', tracking_data.carrier)
|
64
|
+
assert_equal('55555555', tracking_data.tracking_number)
|
65
|
+
tracking_data = @item_info.tracking_data_arr[1]
|
66
|
+
assert_equal('FedEx', tracking_data.carrier)
|
67
|
+
assert_equal('12345678', tracking_data.tracking_number)
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,171 @@
|
|
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
|
+
<item-weight unit='LB' value='2.2'/>
|
47
|
+
<unit-price currency="USD">178.00</unit-price>
|
48
|
+
<quantity>1</quantity>
|
49
|
+
<merchant-item-id>MGS2GBMP3</merchant-item-id>
|
50
|
+
<merchant-private-item-data>
|
51
|
+
<item-note>Text 1</item-note>
|
52
|
+
<item-note>Text 2</item-note>
|
53
|
+
<nested>
|
54
|
+
<tags>value</tags>
|
55
|
+
</nested>
|
56
|
+
</merchant-private-item-data>
|
57
|
+
<tax-table-selector>Some Table</tax-table-selector>
|
58
|
+
<digital-content>
|
59
|
+
<display-disposition>OPTIMISTIC</display-disposition>
|
60
|
+
<email-delivery>true</email-delivery>
|
61
|
+
</digital-content>
|
62
|
+
</item>}
|
63
|
+
|
64
|
+
@optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
|
65
|
+
|
66
|
+
@command = @frontend.create_checkout_command
|
67
|
+
@shopping_cart = @command.shopping_cart
|
68
|
+
@item = @shopping_cart.create_item
|
69
|
+
@digital_content = @item.digital_content
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_item_behaves_correctly
|
73
|
+
[ :shopping_cart, :name, :name=, :description, :description=, :unit_price, :unit_price=,
|
74
|
+
:quantity, :quantity=, :id, :id=, :private_data, :private_data=,
|
75
|
+
:tax_table, :tax_table=, :digital_content, :weight, :weight=
|
76
|
+
].each do |symbol|
|
77
|
+
assert_respond_to @item, symbol
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_item_gets_initialized_correctly
|
82
|
+
assert_equal @shopping_cart, @item.shopping_cart
|
83
|
+
assert_nil @item.name
|
84
|
+
assert_nil @item.description
|
85
|
+
assert_nil @item.unit_price
|
86
|
+
assert_nil @item.quantity
|
87
|
+
assert_nil @item.private_data
|
88
|
+
assert_nil @item.id
|
89
|
+
assert_nil @item.tax_table
|
90
|
+
assert_nil @item.digital_content
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_item_setters_work
|
94
|
+
@item.name = "name"
|
95
|
+
assert_equal "name", @item.name
|
96
|
+
|
97
|
+
@item.description = "description"
|
98
|
+
assert_equal "description", @item.description
|
99
|
+
|
100
|
+
@item.unit_price = Money.new(100, "EUR")
|
101
|
+
assert_equal Money.new(100, "EUR"), @item.unit_price
|
102
|
+
|
103
|
+
@item.quantity = 10
|
104
|
+
assert_equal 10, @item.quantity
|
105
|
+
|
106
|
+
@item.id = "id"
|
107
|
+
assert_equal "id", @item.id
|
108
|
+
|
109
|
+
@item.private_data = Hash.new
|
110
|
+
assert_equal Hash.new, @item.private_data
|
111
|
+
|
112
|
+
@item.weight = Weight.new(2.2)
|
113
|
+
assert_equal Weight, @item.weight.class
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_set_tax_table_works
|
117
|
+
table = @command.tax_tables.first
|
118
|
+
@item.tax_table = table
|
119
|
+
assert_equal table, @item.tax_table
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_set_tax_table_raises_if_table_is_unknown_in_command
|
123
|
+
assert_raises(RuntimeError) { @item.tax_table = TaxTable.new(false) }
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_set_private_data_only_works_with_hashes
|
127
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 1 }
|
128
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = nil }
|
129
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 'Foobar' }
|
130
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = [] }
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_item_price_must_be_money_instance
|
134
|
+
assert_raises(RuntimeError) { @item.unit_price = nil }
|
135
|
+
assert_raises(RuntimeError) { @item.unit_price = "String" }
|
136
|
+
assert_raises(RuntimeError) { @item.unit_price = 10 }
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_create_from_element_works
|
140
|
+
@optional_tags.power.each do |optional_tag_names|
|
141
|
+
xml_str = @xml_str
|
142
|
+
|
143
|
+
optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
|
144
|
+
|
145
|
+
command = @frontend.create_checkout_command
|
146
|
+
tax_table = TaxTable.new(false)
|
147
|
+
tax_table.name = 'Some Table'
|
148
|
+
command.tax_tables << tax_table
|
149
|
+
item = Item.create_from_element(REXML::Document.new(xml_str).root, command.shopping_cart)
|
150
|
+
|
151
|
+
assert_equal command.shopping_cart, item.shopping_cart
|
152
|
+
|
153
|
+
assert_equal 'MegaSound 2GB MP3 Player', item.name
|
154
|
+
assert_equal 'Portable MP3 player - stores 500 songs', item.description
|
155
|
+
assert_equal Money.new(17800, 'USD'), item.unit_price
|
156
|
+
assert_equal 1, item.quantity
|
157
|
+
assert_equal 'MGS2GBMP3', item.id unless item.id.nil?
|
158
|
+
assert_equal 2.2, item.weight.value
|
159
|
+
assert_equal 'LB', item.weight.unit
|
160
|
+
|
161
|
+
hash =
|
162
|
+
{
|
163
|
+
'item-note' => [ 'Text 1', 'Text 2' ],
|
164
|
+
'nested' => { 'tags' => 'value' }
|
165
|
+
}
|
166
|
+
assert_equal hash, item.private_data unless optional_tag_names.include?('merchant-private-item-data')
|
167
|
+
|
168
|
+
assert_equal 'Some Table', item.tax_table.name unless optional_tag_names.include?('tax-table-selector')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
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
|