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.
Files changed (77) hide show
  1. data/CHANGES +93 -0
  2. data/LICENSE +22 -0
  3. data/README +58 -0
  4. data/Rakefile +13 -0
  5. data/VERSION +1 -0
  6. data/google4r-checkout-1.0.5-1.0.5.gem +0 -0
  7. data/google4r-checkout-1.0.5.gemspec +174 -0
  8. data/lib/google4r/checkout.rb +34 -0
  9. data/lib/google4r/checkout/commands.rb +567 -0
  10. data/lib/google4r/checkout/frontend.rb +210 -0
  11. data/lib/google4r/checkout/merchant_calculation.rb +321 -0
  12. data/lib/google4r/checkout/notifications.rb +708 -0
  13. data/lib/google4r/checkout/shared.rb +1086 -0
  14. data/lib/google4r/checkout/utils.rb +94 -0
  15. data/lib/google4r/checkout/xml_generation.rb +880 -0
  16. data/test/integration/checkout_command_test.rb +174 -0
  17. data/test/unit/add_merchant_order_number_command_test.rb +70 -0
  18. data/test/unit/add_tracking_data_command_test.rb +75 -0
  19. data/test/unit/address_test.rb +131 -0
  20. data/test/unit/anonymous_address_test.rb +75 -0
  21. data/test/unit/archive_order_command_test.rb +66 -0
  22. data/test/unit/area_test.rb +44 -0
  23. data/test/unit/authorization_amount_notification_test.rb +69 -0
  24. data/test/unit/authorize_order_command_test.rb +66 -0
  25. data/test/unit/backorder_items_command_test.rb +83 -0
  26. data/test/unit/callback_handler_test.rb +83 -0
  27. data/test/unit/cancel_items_command_test.rb +89 -0
  28. data/test/unit/cancel_order_command_test.rb +83 -0
  29. data/test/unit/carrier_calculated_shipping_test.rb +57 -0
  30. data/test/unit/charge_amount_notification_test.rb +64 -0
  31. data/test/unit/charge_order_command_test.rb +77 -0
  32. data/test/unit/chargeback_amount_notification_test.rb +65 -0
  33. data/test/unit/checkout_command_test.rb +125 -0
  34. data/test/unit/checkout_command_xml_generator_test.rb +218 -0
  35. data/test/unit/command_test.rb +116 -0
  36. data/test/unit/deliver_order_command_test.rb +70 -0
  37. data/test/unit/delivery_method_test.rb +42 -0
  38. data/test/unit/digital_content_test.rb +105 -0
  39. data/test/unit/flat_rate_shipping_test.rb +132 -0
  40. data/test/unit/frontend_test.rb +144 -0
  41. data/test/unit/item_info_test.rb +69 -0
  42. data/test/unit/item_test.rb +171 -0
  43. data/test/unit/marketing_preferences_test.rb +65 -0
  44. data/test/unit/merchant_calculated_shipping_test.rb +172 -0
  45. data/test/unit/merchant_calculation_callback_test.rb +137 -0
  46. data/test/unit/merchant_calculation_result_test.rb +78 -0
  47. data/test/unit/merchant_calculation_results_test.rb +178 -0
  48. data/test/unit/merchant_code_result_test.rb +51 -0
  49. data/test/unit/merchant_code_test.rb +122 -0
  50. data/test/unit/new_order_notification_test.rb +115 -0
  51. data/test/unit/notification_acknowledgement_test.rb +67 -0
  52. data/test/unit/notification_handler_test.rb +113 -0
  53. data/test/unit/order_adjustment_test.rb +119 -0
  54. data/test/unit/order_report_command_test.rb +111 -0
  55. data/test/unit/order_state_change_notification_test.rb +158 -0
  56. data/test/unit/pickup_shipping_test.rb +70 -0
  57. data/test/unit/postal_area_test.rb +71 -0
  58. data/test/unit/private_data_parser_test.rb +68 -0
  59. data/test/unit/refund_amount_notification_test.rb +65 -0
  60. data/test/unit/refund_order_command_test.rb +86 -0
  61. data/test/unit/reset_items_shipping_information_command_test.rb +83 -0
  62. data/test/unit/return_items_command_test.rb +83 -0
  63. data/test/unit/risk_information_notification_test.rb +98 -0
  64. data/test/unit/send_buyer_message_command_test.rb +73 -0
  65. data/test/unit/ship_items_command_test.rb +101 -0
  66. data/test/unit/shipping_adjustment_test.rb +100 -0
  67. data/test/unit/shopping_cart_test.rb +146 -0
  68. data/test/unit/tax_rule_test.rb +70 -0
  69. data/test/unit/tax_table_test.rb +82 -0
  70. data/test/unit/tracking_data_test.rb +54 -0
  71. data/test/unit/unarchive_order_command_test.rb +66 -0
  72. data/test/unit/us_country_area_test.rb +76 -0
  73. data/test/unit/us_state_area_test.rb +70 -0
  74. data/test/unit/us_zip_area_test.rb +66 -0
  75. data/test/unit/world_area_test.rb +48 -0
  76. data/var/cacert.pem +7815 -0
  77. metadata +189 -0
@@ -0,0 +1,218 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/checkout_command_xml_generator_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
+ require 'tempfile'
36
+
37
+ require 'open3' rescue require 'win32/open3'
38
+
39
+ require 'rexml/document'
40
+
41
+ # Test for the class UsZipArea.
42
+ #
43
+ # TODO: Make the tests querying Google Checkout's diagnose service and the XSD validation optional.
44
+ class Google4R::Checkout::CheckoutCommandXmlGeneratorTest < Test::Unit::TestCase
45
+ include Google4R::Checkout
46
+
47
+ def setup
48
+ @schema_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'xml', 'apiv2.xsd'))
49
+ @expected_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'xml', 'test_check_persisting_works_expected.xml'))
50
+
51
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
52
+ @frontend.tax_table_factory = TestTaxTableFactory.new
53
+ @command = @frontend.create_checkout_command
54
+ @generator = CheckoutCommandXmlGenerator.new(@command)
55
+ end
56
+
57
+ # Note that this is not really a good test. We do not actually compare anything.
58
+ # Instead, we simply generate some XML, validate it using XSD via xmllint and then
59
+ # compare it to the output that we validated by reading it earlier.
60
+ def test_check_persisting_works
61
+ tax_tables = Array.new
62
+ table = TaxTable.new(false)
63
+ table.name = 'Default Table'
64
+ table.create_rule do |rule|
65
+ rule.rate = 0.04
66
+ rule.area = UsCountryArea.new
67
+ rule.area.area = UsCountryArea::ALL
68
+ end
69
+ table.create_rule do |rule|
70
+ rule.area=Google4R::Checkout::PostalArea.new('GB', 'S6*')
71
+ rule.shipping_taxed=true
72
+ rule.rate=0.03
73
+ end
74
+ table.create_rule do |rule|
75
+ rule.area=Google4R::Checkout::PostalArea.new('GB')
76
+ rule.shipping_taxed=false
77
+ rule.rate=0.07
78
+ end
79
+ table.create_rule do |rule|
80
+ rule.area=Google4R::Checkout::WorldArea.new
81
+ rule.shipping_taxed=true
82
+ rule.rate=0.10
83
+ end
84
+ tax_tables << table
85
+ nondefault_table = TaxTable.new(false)
86
+ nondefault_table.name = 'Special Table'
87
+ nondefault_table.create_rule do |rule|
88
+ rule.rate = 0.02
89
+ rule.area = UsCountryArea.new
90
+ rule.area.area = UsCountryArea::ALL
91
+ end
92
+ tax_tables << nondefault_table
93
+
94
+ TestTaxTableFactory.any_instance.stubs(:effective_tax_tables_at).returns(tax_tables)
95
+ @frontend.tax_table_factory = TestTaxTableFactory.new
96
+ @command = @frontend.create_checkout_command
97
+
98
+ @command.continue_shopping_url = 'http://wwww.example.com/continue_shopping'
99
+ @command.edit_cart_url = 'http://wwww.example.com/edit_cart'
100
+ @command.request_buyer_phone_number = false
101
+ @command.merchant_calculations_url = 'http://www.example.com/merchant_calcuations'
102
+ @command.accept_merchant_coupons = true
103
+ @command.accept_gift_certificates = true
104
+ @command.platform_id = '1234567890'
105
+ @command.analytics_data = 'abcd1234defgh5678ijklmn'
106
+
107
+ @generator = CheckoutCommandXmlGenerator.new(@command)
108
+
109
+ @command.shopping_cart.expires_at = Time.parse('2007-11-29T15:33:20 UTC')
110
+
111
+ @command.create_shipping_method(PickupShipping) do |shipping|
112
+ shipping.name = 'Pickup Test Shipping'
113
+ shipping.price = Money.new(100, 'USD')
114
+ end
115
+
116
+ @command.create_shipping_method(FlatRateShipping) do |shipping|
117
+ shipping.name = 'State Test Shipping'
118
+ shipping.price = Money.new(100, 'USD')
119
+
120
+ shipping.create_allowed_area(UsStateArea) { |area| area.state = 'CA' }
121
+ shipping.create_excluded_area(UsStateArea) { |area| area.state = 'TX' }
122
+ end
123
+
124
+ @command.create_shipping_method(FlatRateShipping) do |shipping|
125
+ shipping.name = 'Country Area Test Shipping'
126
+ shipping.price = Money.new(100, 'USD')
127
+
128
+ shipping.create_allowed_area(UsCountryArea) { |area| area.area = UsCountryArea::FULL_50_STATES }
129
+ shipping.create_excluded_area(UsCountryArea) { |area| area.area = UsCountryArea::CONTINENTAL_48 }
130
+ end
131
+
132
+ @command.create_shipping_method(FlatRateShipping) do |shipping|
133
+ shipping.name = 'Zip Test Shipping'
134
+ shipping.price = Money.new(100, 'USD')
135
+
136
+ shipping.create_allowed_area(UsZipArea) { |area| area.pattern = '1*' }
137
+ shipping.create_excluded_area(UsZipArea) { |area| area.pattern = '12*' }
138
+ end
139
+
140
+ @command.shopping_cart.private_data = { 'we' => 'can pass in some data here'.split }
141
+
142
+ 1.upto(10) do |i|
143
+ @command.shopping_cart.create_item do |item|
144
+ item.name = "Item Name #{i}"
145
+ item.description = "Description #{i}"
146
+ item.unit_price = Money.new(i * 1000, 'USD')
147
+ item.quantity = i * 2
148
+ item.id = "Merchant ID #{i}"
149
+ if i == 1 then
150
+ item.private_data = { 'some' => { 'data' => 'Yeah, Yeah!' }, 'bars' => { 'bar' => [ 1, 2 ] } }
151
+ end
152
+
153
+ item.tax_table = nondefault_table if i % 2 == 1
154
+ end
155
+ end
156
+
157
+ xml_str = @generator.generate
158
+ assert_xml_validates_against_xml_schema(@schema_path, xml_str)
159
+ assert_string_equals_file_contents(@expected_path, xml_str)
160
+ assert_google_checkout_diagnose_returns_no_warnings(xml_str)
161
+ end
162
+
163
+ # Test that values within hashes are persisted correctly.
164
+ def test_process_hash_processes_hash_values_correctly
165
+ element = REXML::Element.new('root')
166
+ @generator.instance_eval { process_hash(element, { 'key' => 'value' }) }
167
+ assert_equal "<root><key>value</key></root>", element.to_s
168
+ end
169
+
170
+ protected
171
+
172
+ def assert_google_checkout_diagnose_returns_no_warnings(xml_str)
173
+ tmpfile = Tempfile.new('xml_output')
174
+ tmpfile << xml_str
175
+ tmpfile.flush
176
+
177
+ url = "https://%s:%s@sandbox.google.com/checkout/cws/v2/Merchant/%s/request/diagnose" %
178
+ [ FRONTEND_CONFIGURATION[:merchant_id], FRONTEND_CONFIGURATION[:merchant_key],
179
+ FRONTEND_CONFIGURATION[:merchant_id] ]
180
+
181
+ stdin, stdout, stderr = Open3.popen3("curl -d @#{tmpfile.path} #{url}")
182
+ outstr = stdout.read
183
+ errstr = stderr.read
184
+
185
+ assert (outstr != ''), 'curl command not available'
186
+
187
+ # Check that there is no <warnings> tag in the XML.
188
+ xml_document = REXML::Document.new(outstr)
189
+ assert 0, xml_document.root.elements.to_a('//warnings').size
190
+
191
+ tmpfile.close!
192
+ end
193
+
194
+ def assert_xml_validates_against_xml_schema(schema_path, xml_str)
195
+ tmpfile = Tempfile.new('xml_output')
196
+ tmpfile << xml_str
197
+ tmpfile.flush
198
+
199
+ #puts "---\n#{xml_str}\n---"
200
+
201
+ stdin, stdout, stderr = Open3.popen3("xmllint --schema #{schema_path} #{tmpfile.path}")
202
+
203
+ outstr = stdout.read
204
+ errstr = stderr.read
205
+ if errstr !~ /validates$/ then
206
+ assert false, "The document did not validate: ---\nOUT:#{outstr}\nERR:#{errstr}\n---"
207
+ else
208
+ assert true
209
+ end
210
+
211
+ tmpfile.close!
212
+ end
213
+
214
+ def assert_string_equals_file_contents(expected_path, xml_str)
215
+ file_contents = File.open(expected_path, 'r') { |f| f.read }
216
+ assert_strings_equal file_contents, xml_str
217
+ end
218
+ end
@@ -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&amp;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,70 @@
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
+
45
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
46
+ <deliver-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
47
+ <send-email>true</send-email>
48
+ </deliver-order>}
49
+ end
50
+
51
+ def test_behaves_correctly
52
+ [ :google_order_number, :send_email ].each do |symbol|
53
+ assert_respond_to @command, symbol
54
+ end
55
+ end
56
+
57
+ def test_xml_send_email
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 @command.send_email
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,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 &amp;lt;a href=&quot;http://supersoft.example.com&quot;&amp;gt;our website&amp;lt;/a&amp;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
+ &amp;lt;a href=&quot;http://login.example.com&quot;&amp;gt;account page&amp;lt;/a&amp;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 &amp;lt;a
101
+ href=&quot;http://login.example.com&quot;&amp;gt;account page&amp;lt;/a&amp;gt;.},
102
+ REXML::Text.new(digital_content.description).to_s
103
+ end
104
+
105
+ end