google4r-checkout 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +40 -0
- data/LICENSE +22 -0
- data/README +76 -0
- data/lib/google4r/checkout.rb +33 -0
- data/lib/google4r/checkout/commands.rb +260 -0
- data/lib/google4r/checkout/frontend.rb +108 -0
- data/lib/google4r/checkout/notifications.rb +549 -0
- data/lib/google4r/checkout/shared.rb +541 -0
- data/lib/google4r/checkout/xml_generation.rb +313 -0
- data/test/integration/checkout_command_test.rb +103 -0
- data/test/unit/address_test.rb +131 -0
- data/test/unit/area_test.rb +44 -0
- data/test/unit/checkout_command_test.rb +116 -0
- data/test/unit/checkout_command_xml_generator_test.rb +203 -0
- data/test/unit/command_test.rb +115 -0
- data/test/unit/flat_rate_shipping_test.rb +114 -0
- data/test/unit/frontend_test.rb +63 -0
- data/test/unit/item_test.rb +159 -0
- data/test/unit/marketing_preferences_test.rb +65 -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 +43 -0
- data/test/unit/notification_handler_test.rb +93 -0
- data/test/unit/order_adjustment_test.rb +119 -0
- data/test/unit/order_state_change_notification_test.rb +159 -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/shipping_adjustment_test.rb +100 -0
- data/test/unit/shipping_method_test.rb +41 -0
- data/test/unit/shopping_cart_test.rb +146 -0
- data/test/unit/tax_rule_test.rb +70 -0
- data/test/unit/tax_table_test.rb +82 -0
- data/test/unit/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 +92 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/pickup_shipping_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 PickupShipping class.
|
35
|
+
class Google4R::Checkout::PickupShippingMethodTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@shipping = PickupShipping.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_initialization
|
43
|
+
assert_nil @shipping.name
|
44
|
+
assert_nil @shipping.price
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_pickup_shipping_method_behaves_correctly
|
48
|
+
[ :name, :name=, :price, :price= ].each do |sym|
|
49
|
+
assert_respond_to @shipping, sym
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_pickup_shipping_method_setting_attributes_works_correctly
|
54
|
+
@shipping.name = "Shipping Method Name"
|
55
|
+
assert_equal "Shipping Method Name", @shipping.name
|
56
|
+
|
57
|
+
@shipping.price = Money.new(100, "EUR")
|
58
|
+
assert_kind_of Money, @shipping.price
|
59
|
+
assert_equal 100, @shipping.price.cents
|
60
|
+
assert_equal "EUR", @shipping.price.currency
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_pickup_shipping_method_price_is_validated
|
64
|
+
# Test that PickupShippingMethod checks for its price attribute responding
|
65
|
+
# to cents and currency.
|
66
|
+
assert_raises(RuntimeError) { @shipping.price = nil }
|
67
|
+
assert_raises(RuntimeError) { @shipping.price = 10 }
|
68
|
+
assert_raises(RuntimeError) { @shipping.price = "str" }
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'google4r/checkout'
|
2
|
+
|
3
|
+
require 'test/frontend_configuration'
|
4
|
+
#--
|
5
|
+
# Project: google_checkout4r
|
6
|
+
# File: test/unit/area_test.rb
|
7
|
+
# Author: Manuel Holtgrewe <purestorm at ggnore dot net>
|
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 Area.
|
38
|
+
class Google4R::Checkout::PostalAreaTest < Test::Unit::TestCase
|
39
|
+
include Google4R::Checkout
|
40
|
+
|
41
|
+
def setup
|
42
|
+
@area = PostalArea.new('GB', 'S6*')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_initialization_works
|
46
|
+
assert_equal 'GB' , @area.country_code
|
47
|
+
assert_equal 'S6*', @area.postal_code_pattern
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_us_state_area_behaves_correctly
|
51
|
+
assert_respond_to @area, :country_code
|
52
|
+
assert_respond_to @area, :country_code=
|
53
|
+
assert_respond_to @area, :postal_code_pattern
|
54
|
+
assert_respond_to @area, :postal_code_pattern=
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_accessors_should_work
|
58
|
+
@area.postal_code_pattern = '100*'
|
59
|
+
assert_equal '100*', @area.postal_code_pattern
|
60
|
+
|
61
|
+
@area.country_code = 'DE'
|
62
|
+
assert_equal 'DE', @area.country_code
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_initialize_without_postcode_works
|
66
|
+
pa = PostalArea.new('DE')
|
67
|
+
assert_equal 'DE', pa.country_code
|
68
|
+
assert_nil pa.postal_code_pattern
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/private_data_parser_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 PrivateDataParser.
|
35
|
+
class Google4R::Checkout::PrivateDataParserTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str1 = %q{<merchant-private-item-data>
|
40
|
+
<item-note>Text 1</item-note>
|
41
|
+
<item-note>Text 2</item-note>
|
42
|
+
<nested>
|
43
|
+
<tags>value</tags>
|
44
|
+
</nested>
|
45
|
+
</merchant-private-item-data>}
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_responds_correctly
|
49
|
+
assert_respond_to PrivateDataParser, :element_to_value
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_parser_works_in_simple_example
|
53
|
+
element = REXML::Document.new(@xml_str1).root.elements['//tags']
|
54
|
+
|
55
|
+
assert_equal 'value', PrivateDataParser.element_to_value(element)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_parser_works_in_complex_example
|
59
|
+
doc = REXML::Document.new(@xml_str1)
|
60
|
+
|
61
|
+
hash =
|
62
|
+
{
|
63
|
+
'item-note' => [ 'Text 1', 'Text 2' ],
|
64
|
+
'nested' => { 'tags' => 'value' }
|
65
|
+
}
|
66
|
+
assert_equal hash, PrivateDataParser.element_to_value(doc.root)
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/shipping_adjustment_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 ShippingAdjustmentTest.
|
35
|
+
class Google4R::Checkout::ShippingAdjustmentTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
40
|
+
<%s>
|
41
|
+
<shipping-name>%s</shipping-name>
|
42
|
+
<shipping-cost currency="%s">%s</shipping-cost>
|
43
|
+
</%s>}
|
44
|
+
|
45
|
+
@valid_adjustment_types =
|
46
|
+
[
|
47
|
+
[ "FLAT_RATE", 'flat-rate-shipping-adjustment' ],
|
48
|
+
[ "PICKUP", 'pickup-shipping-adjustment' ],
|
49
|
+
]
|
50
|
+
|
51
|
+
@invalid_adjustment_types = [ 'merchant-calculated-shipping', 'invalid-shipping' ]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_responds_correctly
|
55
|
+
adjustment = ShippingAdjustment.new
|
56
|
+
|
57
|
+
[ :type, :type=, :name, :name=, :cost, :cost= ].each do |symbol|
|
58
|
+
assert_respond_to adjustment, symbol
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_constants_are_defined
|
63
|
+
assert defined?(ShippingAdjustment::FLAT_RATE)
|
64
|
+
assert defined?(ShippingAdjustment::PICKUP)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_create_from_element_works_with_valid_shipping_adjustment_types
|
68
|
+
@valid_adjustment_types.each do |pair|
|
69
|
+
type, tag_name = pair
|
70
|
+
|
71
|
+
xml_str = @xml_str %
|
72
|
+
[
|
73
|
+
tag_name, 'Some Name', 'USD', '10.00', tag_name
|
74
|
+
]
|
75
|
+
|
76
|
+
element = REXML::Document.new(xml_str).root
|
77
|
+
|
78
|
+
adjustment = ShippingAdjustment.create_from_element(element)
|
79
|
+
|
80
|
+
assert_equal Money.new(1000, 'USD'), adjustment.cost
|
81
|
+
assert_equal type, adjustment.type
|
82
|
+
assert_equal 'Some Name', adjustment.name
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_create_from_element_raises_exception_with_invalid_shipping_adjustment_types
|
87
|
+
@invalid_adjustment_types.each do |tag_name|
|
88
|
+
xml_str = @xml_str %
|
89
|
+
[
|
90
|
+
tag_name, 'Some Name', 'USD', '10.00', tag_name
|
91
|
+
]
|
92
|
+
|
93
|
+
element = REXML::Document.new(xml_str).root
|
94
|
+
|
95
|
+
assert_raises(RuntimeError) do
|
96
|
+
adjustment = ShippingAdjustment.create_from_element(element)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/shipping_method_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 ShippingMethod class.
|
35
|
+
class Google4R::Checkout::ShippingMethodTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def test_shipping_method_raises_runtime_error_on_initialisation
|
39
|
+
assert_raises(RuntimeError) { ShippingMethod.new }
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,146 @@
|
|
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
|
+
# Tests for the ShoppingCart class and all subclasses.
|
35
|
+
class Google4R::Checkout::ShoppingCartTest < 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
|
+
@command = @frontend.create_checkout_command
|
42
|
+
@shopping_cart = @command.shopping_cart
|
43
|
+
|
44
|
+
@xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
|
45
|
+
<shopping-cart>
|
46
|
+
<merchant-private-data>
|
47
|
+
<affiliate-code>01234</affiliate-code>
|
48
|
+
</merchant-private-data>
|
49
|
+
<cart-expiration>
|
50
|
+
<good-until-date>2007-12-31T23:59:59-05:00</good-until-date>
|
51
|
+
</cart-expiration>
|
52
|
+
<items>
|
53
|
+
<item>
|
54
|
+
<item-name>AA Rechargeable Battery Pack</item-name>
|
55
|
+
<item-description>Battery pack containing four AA rechargeable batteries</item-description>
|
56
|
+
<unit-price currency="USD">12.00</unit-price>
|
57
|
+
<quantity>1</quantity>
|
58
|
+
</item>
|
59
|
+
<item>
|
60
|
+
<item-name>MegaSound 2GB MP3 Player</item-name>
|
61
|
+
<item-description>Portable MP3 player - stores 500 songs</item-description>
|
62
|
+
<quantity>1</quantity>
|
63
|
+
<unit-price currency="USD">178.00</unit-price>
|
64
|
+
</item>
|
65
|
+
</items>
|
66
|
+
</shopping-cart>}
|
67
|
+
|
68
|
+
@optional_tags = [ 'cart-expiration', 'merchant-private-data' ]
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_behaves_correctly
|
72
|
+
[ :owner, :expires_at, :items, :owner, :private_data, :private_data= ].each do |sym|
|
73
|
+
assert_respond_to @shopping_cart, sym
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_initialized_correctly
|
78
|
+
assert_equal @command, @shopping_cart.owner
|
79
|
+
assert_equal nil, @shopping_cart.expires_at
|
80
|
+
assert_equal [], @shopping_cart.items
|
81
|
+
assert_equal @command, @shopping_cart.owner
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_accessors_work_correctly
|
85
|
+
hash = { 'foo' => [ { 'bar' => 'baz' }, "d'oh", 2 ] }
|
86
|
+
@shopping_cart.private_data = hash.dup
|
87
|
+
assert_equal hash, @shopping_cart.private_data
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_setting_private_data_only_works_with_a_hash
|
91
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 1 }
|
92
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = nil }
|
93
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = 'Foobar' }
|
94
|
+
assert_raises(RuntimeError) { @shopping_cart.private_data = [] }
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_create_item_works_correctly_with_block
|
98
|
+
the_item = nil
|
99
|
+
|
100
|
+
res =
|
101
|
+
@shopping_cart.create_item do |item|
|
102
|
+
the_item = item
|
103
|
+
|
104
|
+
assert_kind_of Item, item
|
105
|
+
end
|
106
|
+
|
107
|
+
assert_equal res, the_item
|
108
|
+
assert @shopping_cart.items.include?(the_item)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_create_item_works_correctly_without_block
|
112
|
+
item = @shopping_cart.create_item
|
113
|
+
|
114
|
+
assert @shopping_cart.items.include?(item)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_create_from_element_works
|
118
|
+
@optional_tags.power.each do |optional_tag_names|
|
119
|
+
xml_str = @xml_str
|
120
|
+
|
121
|
+
optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
|
122
|
+
|
123
|
+
element = REXML::Document.new(xml_str).root
|
124
|
+
|
125
|
+
expect = Item.stubs(:create_from_element)
|
126
|
+
expect.with do |element, shopping_cart|
|
127
|
+
element.name == 'item' and
|
128
|
+
element.elements['item-name'].text == 'AA Rechargeable Battery Pack'
|
129
|
+
end
|
130
|
+
expect.times(1).returns(:item1)
|
131
|
+
|
132
|
+
expect = Item.stubs(:create_from_element)
|
133
|
+
expect.with do |element, shopping_cart|
|
134
|
+
element.name == 'item' and
|
135
|
+
element.elements['item-name'].text == 'MegaSound 2GB MP3 Player'
|
136
|
+
end
|
137
|
+
expect.times(1).returns(:item2)
|
138
|
+
|
139
|
+
shopping_cart = ShoppingCart.create_from_element(element, nil)
|
140
|
+
|
141
|
+
assert_equal Time.parse("2007-12-31T23:59:59-05:00"), shopping_cart.expires_at unless optional_tag_names.include?('cart-expiration')
|
142
|
+
assert_equal [ :item1, :item2 ], shopping_cart.items
|
143
|
+
assert_equal({ 'affiliate-code' => '01234' }, shopping_cart.private_data) unless optional_tag_names.include?('merchant-private-data')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|