Added unit tests to test all of get_amazon_tld in Amazon.pm.
authorZach Sim <joseph.zachariah.sim@gmail.com>
Tue, 18 Jan 2011 23:07:25 +0000 (12:07 +1300)
committerChris Nighswonger <chris.nighswonger@gmail.com>
Thu, 20 Jan 2011 22:59:43 +0000 (17:59 -0500)
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
(cherry picked from commit b56121db026837e3d6d6e7e7f3800d7a5b92923c)

Signed-off-by: Chris Nighswonger <chris.nighswonger@gmail.com>
t/Amazon.t

index a0ca21b..f8352c8 100755 (executable)
@@ -6,9 +6,44 @@
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 8;
+use C4::Context;
 
 BEGIN {
         use_ok('C4::External::Amazon');
 }
 
+my $context = C4::Context->new();
+
+my $locale = $context->preference('AmazonLocale');
+
+$context->set_preference('AmazonLocale','CA');
+$context->clear_syspref_cache();
+is(get_amazon_tld,'.ca','Changes locale to CA and tests get_amazon_tld');
+
+$context->set_preference('AmazonLocale','DE');
+$context->clear_syspref_cache();
+is(get_amazon_tld,'.de','Changes locale to DE and tests get_amazon_tld');
+
+$context->set_preference('AmazonLocale','FR');
+$context->clear_syspref_cache();
+is(get_amazon_tld,'.fr','Changes locale to FR and tests get_amazon_tld');
+
+$context->set_preference('AmazonLocale','JP');
+$context->clear_syspref_cache();
+is(get_amazon_tld,'.jp','Changes locale to JP and tests get_amazon_tld');
+
+$context->set_preference('AmazonLocale','UK');
+$context->clear_syspref_cache();
+is(get_amazon_tld,'.co.uk','Changes locale to UK and tests get_amazon_tld');
+
+$context->set_preference('AmazonLocale','US');
+$context->clear_syspref_cache();
+is(get_amazon_tld,'.com','Changes locale to US and tests get_amazon_tld');
+
+$context->set_preference('AmazonLocale','NZ');
+$context->clear_syspref_cache();
+is(get_amazon_tld,'.com','Changes locale to one not in the array and tests get_amazon_tld');
+
+$context->set_preference('AmazonLocale',$locale);
+$context->clear_syspref_cache();