From f3e699e9a746901fce150a67510d23395e7bf362 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 17 Nov 2009 09:37:05 -0800 Subject: [PATCH] Retrofit UPS to use Locales instead of Locales::Country. Fixes bug #11221 Updated tests, module, gotcha.txt, and testEnvironment.pl --- docs/changelog/7.x.x.txt | 1 + docs/gotcha.txt | 35 +++++++++++++------------ lib/WebGUI/Shop/ShipDriver/UPS.pm | 14 +++++----- sbin/testEnvironment.pl | 2 +- t/Shop/ShipDriver/UPS.t | 43 ++++++++++--------------------- 5 files changed, 41 insertions(+), 54 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 28137d40e..320bc9840 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -24,6 +24,7 @@ - fixed #11245: send stats - fixed #11247: Survey edit screen broken - fixed #11246: Image.pm - Validation error + - fixed #11221: wrong version of Locales::Country in testEnvironment 7.8.4 - Fixed a compatibility problem between WRE and new Spectre code. diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 24271457b..335a93344 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -9,30 +9,33 @@ save you many hours of grief. 7.8.5 -------------------------------------------------------------------- + * WebGUI now requires Locales 0.10 or higher, to replace the deprecated + modules Locales::Country. + * Users, no matter if they are created via anonymous registration, via the Admin Console Users screen, or via code, now always get their default values from the Profile Fields instead of via the Visitor account. Previously, based on how the user was created, they would get default values from different places. -* The following style templates have been cleaned up by the TWG: - - WebGUI 6 Blank Style, Style 01; Style 02, Style 03: - - no structural changes - - Fail safe: - - added new CSS that is more robust and validates (in external file: style.css); - - it was also necessary to update the css to work with the new navigation templates - - changed the markup and the order of the home/login/user/admin controls at the bottom - - All of the above templates: - - added a link tag to wg-base.css - - added conditional comments at the top and bottom of the body tag to be able to target - IE versions easily with css + * The following style templates have been cleaned up by the TWG: + - WebGUI 6 Blank Style, Style 01; Style 02, Style 03: + - no structural changes + - Fail safe: + - added new CSS that is more robust and validates (in external file: style.css); + - it was also necessary to update the css to work with the new navigation templates + - changed the markup and the order of the home/login/user/admin controls at the bottom + - All of the above templates: + - added a link tag to wg-base.css + - added conditional comments at the top and bottom of the body tag to be able to target + IE versions easily with css -* Added wg-base.css, which is linked to in each style template. This stylesheet is for css that - is used in more than one tempalte, like pagination inline icons etc. Inline styles that are - removed from templates, will be replaced with styles in wg-base.css (and example is RFE 11182). - Elements that are styled in wg-base.css have a classname that starts with "wg-". + * Added wg-base.css, which is linked to in each style template. This stylesheet is for css that + is used in more than one tempalte, like pagination inline icons etc. Inline styles that are + removed from templates, will be replaced with styles in wg-base.css (and example is RFE 11182). + Elements that are styled in wg-base.css have a classname that starts with "wg-". - wg-base.css replaces webgui.css, which will be removed from the site. + wg-base.css replaces webgui.css, which will be removed from the site. 7.8.4 -------------------------------------------------------------------- diff --git a/lib/WebGUI/Shop/ShipDriver/UPS.pm b/lib/WebGUI/Shop/ShipDriver/UPS.pm index c58e2ef4f..26b92bb29 100644 --- a/lib/WebGUI/Shop/ShipDriver/UPS.pm +++ b/lib/WebGUI/Shop/ShipDriver/UPS.pm @@ -7,7 +7,7 @@ use WebGUI::Exception::Shop; use XML::Simple; use LWP; use Tie::IxHash; -use Locales::Country qw/ en /; +use Locales; use Class::InsideOut qw/ :std /; use Data::Dumper; @@ -64,7 +64,7 @@ sub buildXML { $xmlAcc->{AccessLicenseNumber} = [ $self->get('licenseNo') ]; $xmlAcc->{UserId} = [ $self->get('userId') ]; $xmlAcc->{Password} = [ $self->get('password') ]; - my $localizedCountry = Locales::Country->new('en'); + my $localizedCountry = Locales->new('en'); my $xml = XMLout(\%xmlHash, KeepRoot => 1, NoSort => 1, @@ -95,14 +95,14 @@ sub buildXML { $xmlRate->{Shipment} = { Shipper => { Address => [ { - PostalCode => [ $self->get('sourceZip' ) ], - CountryCode => [ $localizedCountry->country2code($self->get('sourceCountry'), 'alpha2') ], + PostalCode => [ $self->get('sourceZip') ], + CountryCode => [ $localizedCountry->get_code_from_territory($self->get('sourceCountry')) ], }, ], }, ShipTo => { Address => [ { PostalCode => [ $destination->get('code') ], - CountryCode => [ $localizedCountry->country2code($destination->get('country'), 'alpha2') ], + CountryCode => [ $localizedCountry->get_code_from_territory($destination->get('country')) ], } ], }, Service => { @@ -301,9 +301,9 @@ sub definition { $customerClassification{'03'} = $i18n->get('customer classification 03'); $customerClassification{'04'} = $i18n->get('customer classification 04'); - my $localizedCountries = Locales::Country->new('en'); ##Note, for future i18n change the locale + my $localizedCountries = Locales->new('en'); ##Note, for future i18n change the locale tie my %localizedCountries, 'Tie::IxHash'; - %localizedCountries = map { $_ => $_ } grep { !ref $_ } $localizedCountries->all_country_names(); + %localizedCountries = map { $_ => $_ } grep { !ref $_ } $localizedCountries->get_territory_names(); tie my %fields, 'Tie::IxHash'; %fields = ( diff --git a/sbin/testEnvironment.pl b/sbin/testEnvironment.pl index 9bb2e3fd8..d3962ea6c 100755 --- a/sbin/testEnvironment.pl +++ b/sbin/testEnvironment.pl @@ -135,7 +135,7 @@ checkModule("CSS::Minifier::XS", "0.03" ); checkModule("JavaScript::Minifier::XS", "0.05" ); checkModule("Readonly", "1.03" ); checkModule("Business::PayPal::API", "0.62" ); -checkModule("Locales::Country", "0.05" ); +checkModule("Locales", "0.10" ); failAndExit("Required modules are missing, running no more checks.") if $missingModule; diff --git a/t/Shop/ShipDriver/UPS.t b/t/Shop/ShipDriver/UPS.t index 5aeab8a00..9a04dbfab 100644 --- a/t/Shop/ShipDriver/UPS.t +++ b/t/Shop/ShipDriver/UPS.t @@ -20,10 +20,14 @@ use Test::More; use Test::Deep; use XML::Simple; use Data::Dumper; -use Locales::Country qw/en/; use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; +use WebGUI::Shop::ShipDriver::UPS; +use Locales; +#my $locales = Locales->new('en'); +#diag Dumper [ $locales->get_territory_names() ]; +#diag $locales->get_code_from_territory('United States'); #---------------------------------------------------------------------------- # Init @@ -35,16 +39,13 @@ $session->user({user => $user}); #---------------------------------------------------------------------------- # Tests -my $tests = 41; -plan tests => 1 + $tests; +plan tests => 41; #---------------------------------------------------------------------------- # put your tests here -my $loaded = use_ok('WebGUI::Shop::ShipDriver::UPS'); - my $storage; -my ($driver, $cart); +my ($driver); my $versionTag = WebGUI::VersionTag->getWorking($session); my $home = WebGUI::Asset->getDefault($session); @@ -108,11 +109,7 @@ my $blueFeather = $feather->setCollateral('variantsJSON', 'variantId', 'new', ); $versionTag->commit; -WebGUI::Test->tagsToRollback($versionTag); - -SKIP: { - -skip 'Unable to load module WebGUI::Shop::ShipDriver::UPS', $tests unless $loaded; +addToCleanup($versionTag); ####################################################################### # @@ -190,6 +187,7 @@ $driver = WebGUI::Shop::ShipDriver::UPS->create($session, { enabled => 1, shipType => 'PARCEL', }); +addToCleanup($driver); eval { $driver->calculate() }; $e = Exception::Class->caught(); @@ -258,21 +256,22 @@ cmp_deeply( '... checking error message', ); -$cart = WebGUI::Shop::Cart->newBySession($session); +my $cart = WebGUI::Shop::Cart->newBySession($session); +addToCleanup($cart); my $addressBook = $cart->getAddressBook; my $workAddress = $addressBook->addAddress({ label => 'work', organization => 'Plain Black Corporation', address1 => '1360 Regent St. #145', city => 'Madison', state => 'WI', code => '53715', - country => 'USA', + country => 'United States', }); my $wucAddress = $addressBook->addAddress({ label => 'wuc', organization => 'Madison Concourse Hotel', address1 => '1 W Dayton St', city => 'Madison', state => 'WI', code => '53703', - country => 'USA', + country => 'United States', }); $cart->update({shippingAddressId => $workAddress->getId}); @@ -517,8 +516,6 @@ SKIP: { my $xmlData = XMLin($response->content, ForceArray => [qw/RatedPackage/],); ok($xmlData->{Response}->{ResponseStatusCode}, '... responseCode is successful'); ok($xmlData->{RatedShipment}->{TotalCharges}->{MonetaryValue}, '... total charges returned'); - #diag $xmlData->{RatedShipment}->{TotalCharges}->{MonetaryValue}; - } ok($driver->getEditForm(), 'getEditForm'); @@ -540,17 +537,3 @@ is ( ); $cart->empty; -} - -#---------------------------------------------------------------------------- -# Cleanup -END { - if (defined $driver && $driver->isa('WebGUI::Shop::ShipDriver')) { - $driver->delete; - } - if (defined $cart && $cart->isa('WebGUI::Shop::Cart')) { - my $addressBook = $cart->getAddressBook(); - $addressBook->delete if $addressBook; - $cart->delete; - } -}