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,116 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/command_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
|
+
require 'net/http'
|
35
|
+
|
36
|
+
require 'base64'
|
37
|
+
|
38
|
+
class TestCommand < Google4R::Checkout::Command
|
39
|
+
XML_REPRESENTATION = "<?xml version='1.0' ?><root />"
|
40
|
+
|
41
|
+
def to_xml
|
42
|
+
XML_REPRESENTATION
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Test for the class Command.
|
47
|
+
class Google4R::Checkout::CommandTest < Test::Unit::TestCase
|
48
|
+
include Google4R::Checkout
|
49
|
+
|
50
|
+
def setup
|
51
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
52
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
53
|
+
@command = TestCommand.new(@frontend)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_sending_fails_if_certificate_validation_fails
|
57
|
+
OpenSSL::SSL::SSLSocket.any_instance.stubs(:connect).raises(OpenSSL::SSL::SSLError, 'certificate verify failed')
|
58
|
+
|
59
|
+
assert_raises(OpenSSL::SSL::SSLError) { @command.send_to_google_checkout }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_instantiate_abstract_class
|
63
|
+
assert_raises(RuntimeError) { Command.new(Frontend.new(FRONTEND_CONFIGURATION)) }
|
64
|
+
assert_raises(RuntimeError) { ItemsCommand.new(Frontend.new(FRONTEND_CONFIGURATION)) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_unknown_xml_response_in_body_raises_runtime_error
|
68
|
+
mock_body = '<?xml version="1.0" ?><unexpected-tag />'
|
69
|
+
|
70
|
+
success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
|
71
|
+
success_response.expects(:body).returns(mock_body)
|
72
|
+
|
73
|
+
Net::HTTP.any_instance.stubs(:request).returns(success_response)
|
74
|
+
|
75
|
+
assert_raises(RuntimeError) { @command.send_to_google_checkout }
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_invalid_response_code_raises_runtime_error
|
79
|
+
unknown_response = mock()
|
80
|
+
unknown_response.expects(:code)
|
81
|
+
unknown_response.expects(:message)
|
82
|
+
|
83
|
+
Net::HTTP.any_instance.stubs(:request).returns(unknown_response)
|
84
|
+
|
85
|
+
assert_raises(RuntimeError) { @command.send_to_google_checkout }
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_error_tag_in_response_code_raises_google_checkout_error
|
89
|
+
mock_body = '<?xml version="1.0" encoding="UTF-8"?><error xmlns="http://checkout.google.com/schema/2" serial-number="foo-bar"><error-message>Malformed URL component: expected id: (\d{10})|(\d{15}), but got something-different</error-message></error>'
|
90
|
+
|
91
|
+
error_response = Net::HTTPClientError.new(Net::HTTP.version_1_2, 400, "Bad Request")
|
92
|
+
error_response.expects(:body).returns(mock_body)
|
93
|
+
|
94
|
+
Net::HTTP.any_instance.stubs(:request).returns(error_response)
|
95
|
+
|
96
|
+
assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_send_to_google_checkout_works_correctly_if_200_is_returned
|
100
|
+
mock_body = '<?xml version="1.0" encoding="UTF-8"?><checkout-redirect xmlns="http://checkout.google.com/schema/2" serial-number="foo-bar"><redirect-url>https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=foo-bar</redirect-url></checkout-redirect>'
|
101
|
+
|
102
|
+
success_response = Net::HTTPSuccess.new(Net::HTTP.version_1_2, 200, "OK")
|
103
|
+
success_response.expects(:body).returns(mock_body)
|
104
|
+
|
105
|
+
Net::HTTP.any_instance.stubs(:request).returns(success_response)
|
106
|
+
|
107
|
+
Net::HTTP::Post.any_instance.expects(:basic_auth).with(FRONTEND_CONFIGURATION[:merchant_id],
|
108
|
+
FRONTEND_CONFIGURATION[:merchant_key])
|
109
|
+
|
110
|
+
result = @command.send_to_google_checkout
|
111
|
+
|
112
|
+
assert_kind_of CheckoutRedirectResponse, result
|
113
|
+
assert_equal 'foo-bar', result.serial_number
|
114
|
+
assert_equal 'https://sandbox.google.com/checkout/view/buy?o=shoppingcart&shoppingcart=foo-bar', result.redirect_url
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/deliver_order_command_test.rb
|
4
|
+
# Author: Dan Dukeson <dandukeson at gmail dot com>
|
5
|
+
# Copyright: (c) 2007 by Dan Dukeson
|
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 DeliverOrderCommand class.
|
35
|
+
class Google4R::Checkout::DeliverOrderCommandTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
40
|
+
@command = @frontend.create_deliver_order_command
|
41
|
+
|
42
|
+
@command.google_order_number = '841171949013218'
|
43
|
+
@command.send_email = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_behaves_correctly
|
47
|
+
[ :google_order_number, :send_email ].each do |symbol|
|
48
|
+
assert_respond_to @command, symbol
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_xml_send_email
|
53
|
+
assert_command_element_text_equals("true", "> send-email", @command)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_accessors
|
57
|
+
assert_equal('841171949013218', @command.google_order_number)
|
58
|
+
assert @command.send_email
|
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,42 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/shipping_method_test.rb
|
4
|
+
# Authors: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Tony Chan <api.htchan at gmail dot com>
|
6
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
7
|
+
# License: MIT License as follows:
|
8
|
+
#
|
9
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
# a copy of this software and associated documentation files (the
|
11
|
+
# "Software"), to deal in the Software without restriction, including
|
12
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
14
|
+
# persons to whom the Software is furnished to do so, subject to the
|
15
|
+
# following conditions:
|
16
|
+
#
|
17
|
+
# The above copyright notice and this permission notice shall be included
|
18
|
+
# in all copies or substantial portions of the Software.
|
19
|
+
#
|
20
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
23
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
24
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
25
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
26
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
30
|
+
|
31
|
+
require 'google4r/checkout'
|
32
|
+
|
33
|
+
require 'test/frontend_configuration'
|
34
|
+
|
35
|
+
# Test for the ShippingMethod class.
|
36
|
+
class Google4R::Checkout::DeliveryMethodTest < Test::Unit::TestCase
|
37
|
+
include Google4R::Checkout
|
38
|
+
|
39
|
+
def test_shipping_method_raises_runtime_error_on_initialisation
|
40
|
+
assert_raises(RuntimeError) { DeliveryMethod.new }
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/digital_content_test.rb
|
4
|
+
# Author: Tony Chan <api.htchan at gmail dot com>
|
5
|
+
# Copyright: (c) 2007 by Dan Dukeson
|
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 ShipItemsCommand class.
|
35
|
+
class Google4R::Checkout::DigitalContentTest < 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
|
+
@email_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
43
|
+
<digital-content>
|
44
|
+
<display-disposition>OPTIMISTIC</display-disposition>
|
45
|
+
<email-delivery>true</email-delivery>
|
46
|
+
</digital-content>}
|
47
|
+
|
48
|
+
@key_url_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
49
|
+
<digital-content>
|
50
|
+
<display-disposition>PESSIMISTIC</display-disposition>
|
51
|
+
<description>
|
52
|
+
Please go to &lt;a href="http://supersoft.example.com"&gt;our website&lt;/a&gt;,
|
53
|
+
and enter your access key so that you can download our software.
|
54
|
+
</description>
|
55
|
+
<key>1456-1514-3657-2198</key>
|
56
|
+
<url>http://supersoft.example.com</url>
|
57
|
+
</digital-content>}
|
58
|
+
|
59
|
+
@description_delivery_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
60
|
+
<digital-content>
|
61
|
+
<display-disposition>OPTIMISTIC</display-disposition>
|
62
|
+
<description>
|
63
|
+
It may take up to 24 hours to process your new storage. You will
|
64
|
+
be able to see your increased storage on your
|
65
|
+
&lt;a href="http://login.example.com"&gt;account page&lt;/a&gt;.
|
66
|
+
</description>
|
67
|
+
</digital-content>}
|
68
|
+
|
69
|
+
|
70
|
+
@optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
|
71
|
+
|
72
|
+
@command = @frontend.create_checkout_command
|
73
|
+
@shopping_cart = @command.shopping_cart
|
74
|
+
@item = @shopping_cart.create_item
|
75
|
+
@item.create_digital_content
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_behaves_correctly
|
79
|
+
[ :description, :description=, :display_disposition,
|
80
|
+
:display_disposition=, :email_delivery,
|
81
|
+
:email_delivery=, :key, :key=, :url, :url= ].each do |symbol|
|
82
|
+
assert_respond_to @item.digital_content, symbol
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_create_from_element_works
|
87
|
+
digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@email_delivery_str).root)
|
88
|
+
assert_equal 'OPTIMISTIC', digital_content.display_disposition
|
89
|
+
assert_equal "true", digital_content.email_delivery
|
90
|
+
|
91
|
+
digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@key_url_delivery_str).root)
|
92
|
+
assert_equal 'PESSIMISTIC', digital_content.display_disposition
|
93
|
+
assert_nil digital_content.email_delivery
|
94
|
+
assert_equal '1456-1514-3657-2198', digital_content.key
|
95
|
+
assert_equal 'http://supersoft.example.com', digital_content.url
|
96
|
+
|
97
|
+
digital_content = Item::DigitalContent.create_from_element(REXML::Document.new(@description_delivery_str).root)
|
98
|
+
assert_equal 'OPTIMISTIC', digital_content.display_disposition
|
99
|
+
assert_nospace_equal %q{It may take up to 24 hours to process your new
|
100
|
+
storage. You will be able to see your increased storage on your &lt;a
|
101
|
+
href="http://login.example.com"&gt;account page&lt;/a&gt;.},
|
102
|
+
REXML::Text.new(digital_content.description).to_s
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/flat_rate_shipping_test.rb
|
4
|
+
# Authors: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Tony Chan <api.htchan at gmail dot com>
|
6
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
7
|
+
# License: MIT License as follows:
|
8
|
+
#
|
9
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
# a copy of this software and associated documentation files (the
|
11
|
+
# "Software"), to deal in the Software without restriction, including
|
12
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
14
|
+
# persons to whom the Software is furnished to do so, subject to the
|
15
|
+
# following conditions:
|
16
|
+
#
|
17
|
+
# The above copyright notice and this permission notice shall be included
|
18
|
+
# in all copies or substantial portions of the Software.
|
19
|
+
#
|
20
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
23
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
24
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
25
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
26
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
30
|
+
|
31
|
+
require 'google4r/checkout'
|
32
|
+
|
33
|
+
require 'test/frontend_configuration'
|
34
|
+
|
35
|
+
# Test for the FlatRateShipping class.
|
36
|
+
class Google4R::Checkout::FlatRateShippingMethodTest < Test::Unit::TestCase
|
37
|
+
include Google4R::Checkout
|
38
|
+
|
39
|
+
def setup
|
40
|
+
@shipping = FlatRateShipping.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_flat_rate_shipping_method_behaves_correctly
|
44
|
+
[ :name, :name=, :price, :price=,
|
45
|
+
:shipping_restrictions_allowed_areas, :shipping_restrictions_excluded_areas,
|
46
|
+
:create_allowed_area, :create_excluded_area, :create_area,
|
47
|
+
:shipping_restrictions_allow_us_po_box
|
48
|
+
].each do |symbol|
|
49
|
+
assert_respond_to @shipping, symbol
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_initialization
|
54
|
+
assert_nil @shipping.name
|
55
|
+
assert_nil @shipping.price
|
56
|
+
assert_equal [], @shipping.shipping_restrictions_allowed_areas
|
57
|
+
assert_equal [], @shipping.shipping_restrictions_excluded_areas
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_flat_rate_shipping_method_setting_attributes_works_correctly
|
61
|
+
@shipping.name = "Shipping Method Name"
|
62
|
+
assert_equal "Shipping Method Name", @shipping.name
|
63
|
+
|
64
|
+
@shipping.price = Money.new(100, "EUR")
|
65
|
+
assert_kind_of Money, @shipping.price
|
66
|
+
assert_equal 100, @shipping.price.cents
|
67
|
+
assert_equal "EUR", @shipping.price.currency.iso_code
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_flat_rate_shipping_method_price_is_validated
|
71
|
+
# Test that FlatRateShippingMethod checks for its price attribute responding
|
72
|
+
# to cents and currency.
|
73
|
+
assert_raises(RuntimeError) { @shipping.price = nil }
|
74
|
+
assert_raises(RuntimeError) { @shipping.price = 10 }
|
75
|
+
assert_raises(RuntimeError) { @shipping.price = "str" }
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_create_allowed_excluded_areas_works_with_block
|
79
|
+
[ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
|
80
|
+
[ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
|
81
|
+
read_sym, create_sym = pair
|
82
|
+
|
83
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
84
|
+
|
85
|
+
the_area = nil
|
86
|
+
|
87
|
+
res =
|
88
|
+
@shipping.send(create_sym, clazz) do |area|
|
89
|
+
the_area = area
|
90
|
+
assert_kind_of clazz, area
|
91
|
+
end
|
92
|
+
|
93
|
+
assert_equal res, the_area
|
94
|
+
assert @shipping.send(read_sym).include?(the_area)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_create_allowed_excluded_areas_works_without_block
|
100
|
+
[ [ :shipping_restrictions_allowed_areas, :create_allowed_area],
|
101
|
+
[ :shipping_restrictions_excluded_areas, :create_excluded_area ] ].each do |pair|
|
102
|
+
read_sym, create_sym = pair
|
103
|
+
|
104
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
105
|
+
area = @shipping.send(create_sym, clazz)
|
106
|
+
|
107
|
+
assert_kind_of clazz, area
|
108
|
+
|
109
|
+
assert @shipping.send(read_sym).include?(area)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_create_allowed_excluded_areas_validates_parameter
|
115
|
+
[ :create_allowed_area, :create_excluded_area ].each do |sym|
|
116
|
+
assert_raises(RuntimeError) { @shipping.send(sym, String) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_new_create_area_with_flat_rate_shipping
|
121
|
+
[ [ :shipping_restrictions, :allowed_areas ],
|
122
|
+
[ :shipping_restrictions, :excluded_areas ] ].each do |pair|
|
123
|
+
type_sym, area_sym = pair
|
124
|
+
[ UsZipArea, UsStateArea, UsCountryArea ].each do |clazz|
|
125
|
+
area = @shipping.send(:create_area, type_sym, area_sym, clazz)
|
126
|
+
|
127
|
+
assert_kind_of clazz, area
|
128
|
+
|
129
|
+
assert @shipping.send((type_sym.to_s + '_' + area_sym.to_s).to_sym).include?(area)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|