Skip to content

Commit

Permalink
added more tests for different plugin options
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 4, 2011
1 parent ecbebe6 commit 811e4d8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Changes
Expand Up @@ -5,7 +5,8 @@ This file documents the revision history for Perl extension Mojolicious.
- Increased Perl version requirement to 5.10.1.
- Improved message parser performance slightly.
- Improved Mojo::IOLoop to die if started twice.
- Improved resolver tests.
- Improved documentation.
- Improved tests.
- Fixed small formatting bug in Mojo::Headers.
- Fixed small proxy message generation bug.
- Fixed many portability issues.
Expand Down
23 changes: 5 additions & 18 deletions lib/Mojolicious/Plugin/Charset.pm
Expand Up @@ -8,24 +8,11 @@ sub register {
my ($self, $app, $conf) = @_;
$conf ||= {};

# Got a charset
if (my $charset = $conf->{charset}) {

# Add charset to text/html content type
$app->types->type(html => "text/html;charset=$charset");

# Allow defined but blank encoding to suppress unwanted
# conversion
my $encoding =
defined $conf->{encoding}
? $conf->{encoding}
: $conf->{charset};
$app->renderer->encoding($encoding) if $encoding;

# This has to be done before params are cloned
$app->hook(after_build_tx => sub { shift->req->default_charset($charset) }
);
}
# Change default charset on all layers
return unless my $charset = $conf->{charset};
$app->types->type(html => "text/html;charset=$charset");
$app->renderer->encoding($charset);
$app->hook(after_build_tx => sub { shift->req->default_charset($charset) });
}

1;
Expand Down
9 changes: 6 additions & 3 deletions t/mojo/loader.t
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use Mojo::Base -strict;

use Test::More tests => 38;
use Test::More tests => 41;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand Down Expand Up @@ -70,5 +70,8 @@ ok !!LoaderTest::C->can('new'), 'loaded successfully';
ok !!$loader->load('LoaderTest'), 'nothing to load';

# Invalid class
ok !!$loader->load('Mojolicious/Lite'), 'nothing to load';
ok !$loader->load('Mojolicious::Lite'), 'loaded successfully';
ok !!$loader->load('Mojolicious/Lite'), 'nothing to load';
ok !!$loader->load('Mojolicious/Lite.pm'), 'nothing to load';
ok !!$loader->load('Mojolicious\Lite'), 'nothing to load';
ok !!$loader->load('Mojolicious\Lite.pm'), 'nothing to load';
ok !$loader->load('Mojolicious::Lite'), 'loaded successfully';
4 changes: 2 additions & 2 deletions t/mojolicious/i18n_shortcut_lite_app.t
Expand Up @@ -28,7 +28,7 @@ use Mojolicious::Lite;
use Test::Mojo;

# I18N plugin
plugin I18N => {namespace => 'MyTestApp::I18N'};
plugin I18N => {default => 'de', namespace => 'MyTestApp::I18N'};

# GET /
get '/' => 'index';
Expand Down Expand Up @@ -71,7 +71,7 @@ $t->get_ok('/mixed' => {'Accept-Language' => 'de, en-US'})->status_is(200)
->content_is("Hallo Weltde\nHello Worlden\n");

# Nothing
$t->get_ok('/nothing')->status_is(200)->content_is("Hello Worlden\n");
$t->get_ok('/nothing')->status_is(200)->content_is("Hallo Weltde\n");

# Unknown (manual)
$t->get_ok('/unknown')->status_is(200)->content_is("unknownde\nunknownen\n");
Expand Down
10 changes: 7 additions & 3 deletions t/mojolicious/twinkle_lite_app.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
}

use Test::More tests => 17;
use Test::More tests => 19;

# "Pizza delivery for...
# I. C. Weiner. Aww... I always thought by this stage in my life I'd be the
Expand All @@ -29,8 +29,9 @@ my $twinkle = {

# Plugins
plugin EPRenderer => {name => 'twinkle', template => $twinkle};
plugin 'PODRenderer';
plugin PODRenderer => {name => 'teapod', preprocess => 'twinkle'};
plugin PODRenderer => {no_perldoc => 1};
plugin PODRenderer =>
{name => 'teapod', preprocess => 'twinkle', no_perldoc => 1};
my $config = plugin JSONConfig =>
{default => {foo => 'bar'}, ext => 'conf', template => $twinkle};
is $config->{foo}, 'bar', 'right value';
Expand Down Expand Up @@ -69,6 +70,9 @@ $t->get_ok('/docs2')->status_is(200)->content_like(qr/<h2>snowman<\/h2>/);
# GET /docs3
$t->get_ok('/docs3')->status_is(200)->content_like(qr/<h3><\/h3>/);

# GET /perldoc (disabled)
$t->get_ok('/perldoc')->status_is(404);

__DATA__
@@ index.html.twinkle
. layout 'twinkle';
Expand Down

0 comments on commit 811e4d8

Please sign in to comment.