PageRenderTime 85ms CodeModel.GetById 77ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/xt/locale_data_localize.t

http://github.com/gshank/html-formhandler
Unknown | 56 lines | 49 code | 7 blank | 0 comment | 0 complexity | ca52d4d37991471723ee83d6ee45e612 MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4use Test::Exception;
 5use HTML::FormHandler::Field::Text;
 6
 7BEGIN {
 8    eval "use Data::Localize";
 9    if ($@) {
10        plan skip_all => "Data::Localize is not installed";
11    }
12}
13
14{
15    package MyApp::Test::I18N::en_US;
16    our %Lexicon = (
17        'You lost, insert coin' => 'Not won, coin needed',
18        'Test field' => 'Grfg svryq',
19    );
20}
21
22{
23    package MyApp::Test::Form;
24    use HTML::FormHandler::Moose;
25    extends 'HTML::FormHandler';
26
27    sub _build_language_handle {
28        my $class = Moose::Meta::Class->create_anon_class(
29            superclasses => [ 'Data::Localize' ],
30            methods => {
31                maketext => sub { shift->localize(@_) }
32            }
33        );
34        my $loc = $class->new_object();
35        $loc->set_languages('en_US');
36        $loc->add_localizer(
37            class => "Namespace",
38            namespaces => [ "MyApp::Test::I18N" ],
39        );
40        return $loc;
41    }
42
43    has_field 'foo';
44    has_field 'bar';
45    sub validate_foo {
46        my ( $self, $field ) = @_;
47        $field->add_error('You lost, insert coin');
48    }
49}
50
51my $form = MyApp::Test::Form->new;
52ok( $form, 'form built' );
53$form->process( params => { foo => 'test' } );
54is( $form->field('foo')->errors->[0], 'Not won, coin needed', 'right message' );
55
56done_testing;