diff options
Diffstat (limited to 't')
-rw-r--r-- | t/Pagination.t (renamed from t/Helper.t) | 91 | ||||
-rw-r--r-- | t/ViewWebmail.t | 84 |
2 files changed, 94 insertions, 81 deletions
diff --git a/t/Helper.t b/t/Pagination.t index 4578594..e06df03 100644 --- a/t/Helper.t +++ b/t/Pagination.t @@ -1,89 +1,19 @@ use v5.22; use warnings; +use strict; use utf8; use Test::More; -use Encode 'decode'; -use MIME::Words 'decode_mimewords'; - -use JWebmail::Plugin::Helper; - - -subtest 'print_size10' => sub { - my %TESTS = ( - 1 => '1 Byte', - 10 => '10 Byte', - 100 => '100 Byte', - 1000 => '1 kByte', - 10000 => '10 kByte', - 100000 => '100 kByte', - 1000000 => '1 MByte', - 10 * 10**6 => '10 MByte', - 10 * 2**20 => '10 MByte', - 800 => '800 Byte', - 9999 => '10 kByte', - 9500 => '10 kByte', - 1024 => '1 kByte', - 1023 => '1 kByte', - ); - - plan tests => scalar keys %TESTS; - - while (my ($input, $want) = each %TESTS) { - is(JWebmail::Plugin::Helper::print_sizes10($input), $want); - } -}; - - -subtest 'vaild_mail_line' => sub { - my %TESTS = ( - 'abc@example.com' => 1, - 'ABC Ex <abc@example.com>' => 1, - '"ABC Ex" <abc@example.com>' => 1, - '"A@B.V Ex" <abc@example.com>' => 1, - '"A@B.V Ex\"" <abc@example.com>' => 1, - 'ABC Ex abc@example.com' => 0, - ); - - plan tests => scalar keys %TESTS; - - while (my ($input, $want) = each %TESTS) { - cmp_ok(JWebmail::Plugin::Helper->mail_line('', $input), '!=', $want); - } -}; - - -subtest 'mime_word_decode' => sub { - my $input = "=?utf-8?Q?Jannis=20wir=20vermissen=20dich!=20Komm=20zur=C3=BCck=20und=20spare=20mit=20uns=20beim=20shoppen=20deiner=20Lieblingsmarken?="; - my $want = "Jannis wir vermissen dich! Komm zurück und spare mit uns beim shoppen deiner Lieblingsmarken"; - my $got = scalar decode_mimewords $input; - - isnt $want, $got; - is $want, _to_perl_enc(decode_mimewords $input); - is $want, decode('MIME-Header', $input); - - done_testing 3; -}; - -sub _to_perl_enc { - my $out = ''; - for (@_) { - if ($_->[1]) { - $out .= decode($_->[1], $_->[0]); - } - else { - $out .= $_->[0]; - } - } - return $out; -} +use JWebmail::Plugin::Paginate; subtest 'pagination' => sub { my %res; - %res = JWebmail::Plugin::Helper::_paginate(first_item => 0, page_size => 10, total_items => 55)->%*; + my $p = \&JWebmail::Plugin::Paginate::_paginate; + + %res = $p->(first_item => 0, page_size => 10, total_items => 55)->%*; is $res{first_item}, 0; is $res{last_item}, 9; @@ -98,7 +28,7 @@ subtest 'pagination' => sub { is_deeply $res{next_page}, [10, 20], 'next'; is_deeply $res{last_page}, [50, 55], 'last'; - %res = JWebmail::Plugin::Helper::_paginate(first_item => 10, page_size => 10, total_items => 55)->%*; + %res = $p->(first_item => 10, page_size => 10, total_items => 55)->%*; is $res{first_item}, 10; is $res{last_item}, 19; @@ -113,7 +43,7 @@ subtest 'pagination' => sub { is_deeply $res{next_page}, [20, 30], 'next'; is_deeply $res{last_page}, [50, 55], 'last'; - %res = JWebmail::Plugin::Helper::_paginate(first_item => 20, page_size => 10, total_items => 55)->%*; + %res = $p->(first_item => 20, page_size => 10, total_items => 55)->%*; is $res{first_item}, 20; is $res{last_item}, 29; @@ -128,7 +58,7 @@ subtest 'pagination' => sub { is_deeply $res{next_page}, [30, 40], 'next'; is_deeply $res{last_page}, [50, 55], 'last'; - %res = JWebmail::Plugin::Helper::_paginate(first_item => 50, page_size => 10, total_items => 55)->%*; + %res = $p->(first_item => 50, page_size => 10, total_items => 55)->%*; is $res{first_item}, 50; is $res{last_item}, 54; @@ -143,7 +73,7 @@ subtest 'pagination' => sub { is_deeply $res{next_page}, [50, 55], 'next'; is_deeply $res{last_page}, [50, 55], 'last'; - %res = JWebmail::Plugin::Helper::_paginate(first_item => 0, page_size => 10, total_items => 0)->%*; + %res = $p->(first_item => 0, page_size => 10, total_items => 0)->%*; ok !defined $res{first_item}; ok !defined $res{last_item}; @@ -161,7 +91,7 @@ subtest 'pagination' => sub { SKIP: { skip 'The first_item does not align with page boundaries and behaiviour is not specified.'; - %res = JWebmail::Plugin::Helper::_paginate(first_item => 19, page_size => 10, total_items => 55)->%*; + %res = $p->(first_item => 19, page_size => 10, total_items => 55)->%*; is $res{first_item}, 20; is $res{last_item}, 29; @@ -180,5 +110,4 @@ subtest 'pagination' => sub { done_testing; }; - done_testing; diff --git a/t/ViewWebmail.t b/t/ViewWebmail.t new file mode 100644 index 0000000..b1dd75f --- /dev/null +++ b/t/ViewWebmail.t @@ -0,0 +1,84 @@ +use v5.22; +use warnings; +use strict; +use utf8; + +use Test::More; + +use Encode 'decode'; +use MIME::Words 'decode_mimewords'; + +use JWebmail; +use JWebmail::View::Webmail; + + +subtest 'print_size10' => sub { + my %TESTS = ( + 1 => '1 Byte', + 10 => '10 Byte', + 100 => '100 Byte', + 1000 => '1 kByte', + 10000 => '10 kByte', + 100000 => '100 kByte', + 1000000 => '1 MByte', + 10 * 10**6 => '10 MByte', + 10 * 2**20 => '10 MByte', + 800 => '800 Byte', + 9999 => '10 kByte', + 9500 => '10 kByte', + 1024 => '1 kByte', + 1023 => '1 kByte', + ); + + plan tests => scalar keys %TESTS; + + while (my ($input, $want) = each %TESTS) { + is(JWebmail::View::Webmail->print_sizes10($input), $want); + } +}; + + +subtest 'vaild_mail_line' => sub { + my %TESTS = ( + 'abc@example.com' => 1, + 'ABC Ex <abc@example.com>' => 1, + '"ABC Ex" <abc@example.com>' => 1, + '"A@B.V Ex" <abc@example.com>' => 1, + '"A@B.V Ex\"" <abc@example.com>' => 1, + 'ABC Ex abc@example.com' => 0, + ); + + plan tests => scalar keys %TESTS; + + while (my ($input, $want) = each %TESTS) { + cmp_ok(JWebmail->_mail_line('', $input), '!=', $want); + } +}; + + +subtest 'mime_word_decode' => sub { + my $input = "=?utf-8?Q?Jannis_wir_vermissen_dich!=20Komm=20zur=C3=BCck=20und=20spare=20mit=20uns=20beim=20shoppen=20deiner=20Lieblingsmarken?="; + my $want = "Jannis wir vermissen dich! Komm zurück und spare mit uns beim shoppen deiner Lieblingsmarken"; + my $got = scalar decode_mimewords $input; + + isnt $want, $got; + is $want, _to_perl_enc(decode_mimewords $input); + is $want, decode('MIME-Header', $input); + + done_testing 3; +}; + +sub _to_perl_enc { + my $out = ''; + for (@_) { + if ($_->[1]) { + $out .= decode($_->[1], $_->[0]); + } + else { + $out .= $_->[0]; + } + } + return $out; +} + +done_testing; |