Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maros committed Oct 7, 2011
1 parent 567c4de commit ea212a1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
9 changes: 8 additions & 1 deletion t/02_base.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use strict;
use warnings;

use Test::Most tests=>56+1;
use Test::Most tests=>59+1;
use Test::NoWarnings;

use lib qw(t/);
Expand Down Expand Up @@ -91,6 +91,13 @@ $mech->{catalyst_debug} = 1;
is($response->{translation}{6},'string6','String 6 for fr ok');
}

# Test 4e - invalid locale
{
my $response = request($mech,'/base/test4/xx');
is($response->{locale},'de_AT','Locale');
}


# Test 5 - locale set
{
my $response = request($mech,'/base/test5');
Expand Down
35 changes: 31 additions & 4 deletions t/03_get_locale.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use strict;
use warnings;

use Test::Most tests=>8;
use Test::Most tests=>22;
#use Test::NoWarnings;
# Cannot run with NoWarnings since we get a warning from HTTP::BrowserDetect
# wen running under make test
Expand All @@ -14,44 +14,60 @@ use Catalyst::Test 'TestApp';
{
my($res, $c) = ctx_request('/base/test6');
my $request = $c->request;
$request->header('Accept-Language','zh, fr_CH; q=0.8, fr; q=0.6');
$request->header('Accept-Language','zh, fr_CH; q=0.8, sk; q=0.6');
cmp_deeply($c->request->accept_language,['zh','fr_CH','sk','fr'],'Accept language');
is($c->get_locale_from_browser,'fr_CH','Locale from accept-language');
}

{
my($res, $c) = ctx_request('/base/test6');
my $request = $c->request;
$request->header('Accept-Language','zh, FR; q=0.8, fr_CH; q=0.6');
cmp_deeply($c->request->accept_language,['zh','fr','fr_CH'],'Accept language');
is($c->get_locale_from_browser,'fr','Locale from accept-language');
}

{
my($res, $c) = ctx_request('/base/test6');
my $request = $c->request;
$request->header('Accept-Language','zh, de-at; q=0.8, de; q=0.6');
cmp_deeply($c->request->accept_language,['zh','de_AT','de'],'Accept language');
is($c->get_locale_from_browser,'de_AT','Locale from accept-language');
}

{
my($res, $c) = ctx_request('/base/test6');
my $request = $c->request;
$request->header('Accept-Language','zh, de; q=0.8, de_at; q=0.6');
$request->header('Accept-Language','zh, de; q=0.8, de-at; q=0.6');
cmp_deeply($c->request->accept_language,['zh','de','de_AT'],'Accept language');
is($c->get_locale_from_browser,'de_AT','Locale from accept-language');
}

{
my($res, $c) = ctx_request('/base/test6');
my $request = $c->request;
$request->header('Accept-Language','xx, de-ch; q=0.8, de-at; q=0.6');
cmp_deeply($c->request->accept_language,['xx','de_CH','de_AT','de'],'Accept language');
is($c->get_locale_from_browser,'de_CH','Locale from accept-language');
}

{
my($res, $c) = ctx_request('/base/test6');
my $request = $c->request;
$request->header('Accept-Language','zh, sk, fr-ca');
$request->header('User-Agent',"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.2) Gecko/20100115 Firefox/3.6");
cmp_deeply($c->request->accept_language,['zh','sk','fr_CA','fr'],'Accept language');
is($c->request->browser_language,'de','Browser language');
is($c->get_locale_from_browser,'fr','Locale from accept-language');
}

{
my($res, $c) = ctx_request('/base/test6');
my $request = $c->request;
$request->header('Accept-Language','zh, sk, cz');
$request->header('Accept-Language','zh, sk, cz, gibe-rsih');
$request->header('User-Agent',"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2) Gecko/20100115 Firefox/3.6");
cmp_deeply($c->request->accept_language,['zh','sk','cz'],'Accept language');
is($c->request->browser_language,'fr','Browser language');
is($c->get_locale_from_browser,'fr','Locale from browser');
}

Expand All @@ -60,6 +76,17 @@ use Catalyst::Test 'TestApp';
my $request = $c->request;
$request->header('Accept-Language','zh, sk, cz');
$request->address('84.20.181.0');
cmp_deeply($c->request->accept_language,['zh','sk','cz'],'Accept language');
is($c->request->client_country,'AT','Browser territory');
is($c->get_locale_from_browser,'de_AT','Locale from IP');
}

{
my($res, $c) = ctx_request('/base/test6');
my $request = $c->request;
$request->header('Accept-Language','giberish');
$request->address('84.20.181.0');
is($c->request->client_country,'AT','Browser territory');
is($c->get_locale_from_browser,'de_AT','Locale from IP');
}

Expand Down
5 changes: 4 additions & 1 deletion t/testlib.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ sub import {
}

sub init {
return Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'TestApp');
return Test::WWW::Mechanize::Catalyst->new(
catalyst_app => 'TestApp',
cookie_jar => {},
);
}

sub request {
Expand Down

0 comments on commit ea212a1

Please # to comment.