6 use Test::More tests => 11;
8 use_ok('MojoX::FilterChain::DetectLang');
10 use Mojo::Transaction;
11 use MojoX::Dispatcher::FilterChain;
12 use MojoX::Dispatcher::FilterChain::Context;
14 my $c = MojoX::Dispatcher::FilterChain::Context->new();
16 my $chain = MojoX::Dispatcher::FilterChain->new();
18 $chain->add(MojoX::FilterChain::DetectLang->new(languages => [qw/ en de /]));
20 # no language specified
21 $c->tx(Mojo::Transaction->new_get('http://example.com'));
23 ok(not defined $c->stash->{language});
24 is($c->tx->req->url, 'http://example.com');
27 $c->tx(Mojo::Transaction->new_get('http://example.com/stuff'));
29 ok(not defined $c->stash->{language});
30 is($c->tx->req->url, 'http://example.com/stuff');
33 $c->tx(Mojo::Transaction->new_get('http://example.com/de'));
35 is($c->stash->{language}, 'de');
36 is($c->tx->req->url, 'http://example.com/');
39 $c->tx(Mojo::Transaction->new_get('http://example.com/de/'));
41 is($c->stash->{language}, 'de');
42 is($c->tx->req->url, 'http://example.com/');
44 # language followed by path
45 $c->tx(Mojo::Transaction->new_get('http://example.com/de/stuff'));
47 is($c->stash->{language}, 'de');
48 is($c->tx->req->url, 'http://example.com/stuff');