3 use Test::More tests => 27;
5 use Courier::AustraliaPost::Standard;
6 use Courier::AustraliaPost::Air;
7 use Courier::AustraliaPost::Sea;
14 sourcepostcode => "4350",
22 my $cfg = bless \%cfg_work, "Test::Cfg";
24 my $std = Courier::AustraliaPost::Standard->new(config => $cfg);
25 my $air = Courier::AustraliaPost::Air->new(config => $cfg);
26 my $sea = Courier::AustraliaPost::Sea->new(config => $cfg);
28 ok($std, "make standard courier object");
29 ok($std->can_deliver(country => "AU",
31 postcode => "2145"), "can deliver to australia");
32 ok(!$std->can_deliver(country => "NZ"),
33 "can't deliver to NZ");
35 my $tiny_parcel = BSE::Shipping::Parcel->new
42 my $small_parcel = BSE::Shipping::Parcel->new
50 my $medium_parcel = BSE::Shipping::Parcel->new
58 my $local_tiny_cost = $std->calculate_shipping
60 parcels => [ $tiny_parcel ],
65 ok($local_tiny_cost, "got a local tiny parcel cost")
66 or diag $std->error_message;
67 like($local_tiny_cost, qr/^\d+$/, "it's an integer");
68 print "# $local_tiny_cost\n";
70 my $local_small_cost = $std->calculate_shipping
72 parcels => [ $small_parcel ],
77 ok($local_small_cost, "got a local small parcel cost")
78 or diag $std->error_message;
79 like($local_small_cost, qr/^\d+$/, "it's an integer");
80 print "# $local_small_cost\n";
82 my $local_medium_cost = $std->calculate_shipping
84 parcels => [ $medium_parcel ],
89 ok($local_medium_cost, "got a local medium cost")
90 or diag $std->error_message;
91 like($local_medium_cost, qr/^\d+$/, "it's an integer");
92 print "# $local_medium_cost\n";
93 cmp_ok($local_tiny_cost, "<=", $local_small_cost, "tiny < small");
94 cmp_ok($local_small_cost, "<=", $local_medium_cost, "small < medium");
97 my $nsw_medium_cost = $std->calculate_shipping
99 parcels => [ $medium_parcel ],
101 suburb => "Westmead",
105 ok($nsw_medium_cost, "got a nsw medium cost");
106 like($nsw_medium_cost, qr/^\d+$/, "it's an integer");
107 print "# $nsw_medium_cost\n";
108 cmp_ok($local_medium_cost, "<=", $nsw_medium_cost, "local <= nsw");
111 my $perth_medium_cost = $std->calculate_shipping
113 parcels => [ $medium_parcel ],
119 ok($perth_medium_cost, "got a perth medium cost");
120 like($perth_medium_cost, qr/^\d+$/, "it's an integer");
121 print "# $perth_medium_cost\n";
122 cmp_ok($nsw_medium_cost, "<=", $perth_medium_cost, "nsw <= perth");
125 my $us_medium_cost_air = $air->calculate_shipping
127 parcels => [ $medium_parcel ],
133 ok($us_medium_cost_air, "got a US medium cost");
134 like($us_medium_cost_air, qr/^\d+$/, "it's an integer");
135 print "# $us_medium_cost_air\n";
136 cmp_ok($perth_medium_cost, "<=", $us_medium_cost_air, "perth <= us air");
138 my $us_medium_cost_sea = $sea->calculate_shipping
140 parcels => [ $medium_parcel ],
146 ok($us_medium_cost_sea, "got a US medium cost");
147 like($us_medium_cost_sea, qr/^\d+$/, "it's an integer");
148 print "# $us_medium_cost_sea\n";
149 cmp_ok($perth_medium_cost, "<=", $us_medium_cost_air, "perth <= us air");
152 my $too_long = BSE::Shipping::Parcel->new
159 my $too_long_cost = $std->calculate_shipping
161 parcels => [ $too_long ],
163 suburb => "Westmead",
166 is($too_long_cost, undef, "too long returns undef");
167 ok($std->error_message, "some error set");
169 my $big_girth = BSE::Shipping::Parcel->new
177 my $big_girth_cost = $std->calculate_shipping
179 parcels => [ $big_girth ],
181 suburb => "Westmead",
184 is($too_long_cost, undef, "big girth returns undef");
185 ok($std->error_message, "some error set");
190 my ($self, $section, $key, $def) = @_;
192 exists $self->{$section} or return $def;
193 exists $self->{$section}{$key} or return $def;
194 return $self->{$section}{$key};