summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Helper.t184
-rw-r--r--t/INI.t96
-rw-r--r--t/Webmail.t34
3 files changed, 314 insertions, 0 deletions
diff --git a/t/Helper.t b/t/Helper.t
new file mode 100644
index 0000000..99758a3
--- /dev/null
+++ b/t/Helper.t
@@ -0,0 +1,184 @@
+use v5.22;
+use warnings;
+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;
+}
+
+
+subtest 'pagination' => sub {
+ my %res;
+
+ %res = JWebmail::Plugin::Helper::_paginate(first_item => 0, page_size => 10, total_items => 55);
+
+ is $res{first_item}, 1;
+ is $res{last_item}, 10;
+ is $res{total_items}, 55;
+
+ is $res{page_size}, 10;
+ is $res{total_pages}, 6;
+ is $res{current_page}, 1;
+
+ is_deeply $res{first_page}, [1, 10], 'first';
+ is_deeply $res{prev_page}, [1, 10], 'prev';
+ is_deeply $res{next_page}, [11, 20], 'next';
+ is_deeply $res{last_page}, [51, 55], 'last';
+
+ %res = JWebmail::Plugin::Helper::_paginate(first_item => 10, page_size => 10, total_items => 55);
+
+ is $res{first_item}, 11;
+ is $res{last_item}, 20;
+ is $res{total_items}, 55;
+
+ is $res{page_size}, 10;
+ is $res{total_pages}, 6;
+ is $res{current_page}, 2;
+
+ is_deeply $res{first_page}, [1, 10], 'first';
+ is_deeply $res{prev_page}, [1, 10], 'prev';
+ is_deeply $res{next_page}, [21, 30], 'next';
+ is_deeply $res{last_page}, [51, 55], 'last';
+
+ %res = JWebmail::Plugin::Helper::_paginate(first_item => 20, page_size => 10, total_items => 55);
+
+ is $res{first_item}, 21;
+ is $res{last_item}, 30;
+ is $res{total_items}, 55;
+
+ is $res{page_size}, 10;
+ is $res{total_pages}, 6;
+ is $res{current_page}, 3;
+
+ is_deeply $res{first_page}, [1, 10], 'first';
+ is_deeply $res{prev_page}, [11, 20], 'prev';
+ is_deeply $res{next_page}, [31, 40], 'next';
+ is_deeply $res{last_page}, [51, 55], 'last';
+
+ %res = JWebmail::Plugin::Helper::_paginate(first_item => 50, page_size => 10, total_items => 55);
+
+ is $res{first_item}, 51;
+ is $res{last_item}, 55;
+ is $res{total_items}, 55;
+
+ is $res{page_size}, 10;
+ is $res{total_pages}, 6;
+ is $res{current_page}, 6;
+
+ is_deeply $res{first_page}, [1, 10], 'first';
+ is_deeply $res{prev_page}, [41, 50], 'prev';
+ is_deeply $res{next_page}, [51, 55], 'next';
+ is_deeply $res{last_page}, [51, 55], 'last';
+
+ %res = JWebmail::Plugin::Helper::_paginate(first_item => 0, page_size => 10, total_items => 0);
+
+ is $res{first_item}, 0;
+ is $res{last_item}, 0;
+ is $res{total_items}, 0;
+
+ is $res{page_size}, 10;
+ is $res{total_pages}, 0;
+ is $res{current_page}, 1;
+
+ is_deeply $res{first_page}, [0, 0], 'first';
+ is_deeply $res{prev_page}, [0, 0], 'prev';
+ is_deeply $res{next_page}, [0, 0], 'next';
+ is_deeply $res{last_page}, [0, 0], 'last';
+
+ 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);
+
+ is $res{first_item}, 20;
+ is $res{last_item}, 29;
+ is $res{total_items}, 55;
+
+ is $res{page_size}, 10;
+ is $res{total_pages}, 6;
+ is $res{current_page}, 3;
+
+ is_deeply $res{first_page}, [1, 10], 'first';
+ is_deeply $res{prev_page}, [11, 20], 'prev';
+ is_deeply $res{next_page}, [31, 40], 'next';
+ is_deeply $res{last_page}, [51, 55], 'last';
+ }
+
+ done_testing;
+};
+
+
+done_testing; \ No newline at end of file
diff --git a/t/INI.t b/t/INI.t
new file mode 100644
index 0000000..469589e
--- /dev/null
+++ b/t/INI.t
@@ -0,0 +1,96 @@
+package JWebmail::Test::INI;
+
+use v5.22;
+use warnings;
+use utf8;
+
+use Config::Tiny;
+use JWebmail::Plugin::INIConfig;
+use Data::Dumper;
+
+use Test2::Bundle::More;
+#use Test2::V0;
+#use Test::More;
+
+
+local $/;
+my $data = <DATA>;
+close DATA;
+
+my $ct = Config::Tiny->new;
+my $conf = $ct->read_string($data);
+
+ok(not $ct->errstr) or diag $ct->errstr;
+
+SKIP: {
+ skip 'only for debuging';
+
+ diag explain $conf;
+}
+
+
+subtest 'flat' => sub {
+ is $conf->{'_'}{a}, 'b';
+ is $conf->{section}{d}, 'e';
+ is $conf->{section}{1}, 'a';
+ is $conf->{'nested::section'}{a}, 'info';
+ is $conf->{array_section}{0}, 'a';
+ is $conf->{'nested::array_section'}{0}, 'a';
+};
+
+
+subtest 'processed' => sub {
+ my $conf2 = JWebmail::Plugin::INIConfig::_process_config($conf);
+
+ is $conf2->{a}, 'b';
+ is $conf2->{section}{d}, 'e';
+ is $conf2->{section}{1}, 'a';
+ is $conf2->{nested}{section}{a}, 'info';
+ is $conf2->{nested}{section}{deeply}{x}, 'deeply';
+ is $conf2->{array_section}[0], 'a';
+ is $conf2->{nested}{array_section}[0], 'a';
+};
+
+
+done_testing;
+
+
+__DATA__
+
+# example file
+# [global_section alias _]
+a = b ; line comment
+
+[section]
+d = e
+f = e # not a comment
+
+"ha llo , = &f" = 'nic a = %& xa'
+
+1 = a
+2 = b
+
+x =
+y =
+
+[othersection]
+long = my very long value
+
+[nested::section]
+a = info
+
+[nested::section::deeply]
+x = deeply
+
+[array_section]
+0 = a
+1 = b
+2 = c
+3 = d
+4 = e
+
+[nested::array_section]
+0 = a
+
+#[nested::array_section::1::deeply]
+#key = val \ No newline at end of file
diff --git a/t/Webmail.t b/t/Webmail.t
new file mode 100644
index 0000000..48406b9
--- /dev/null
+++ b/t/Webmail.t
@@ -0,0 +1,34 @@
+use v5.22;
+use warnings;
+use utf8;
+
+use Test::More;
+use Test::Mojo;
+
+use JWebmail::Model::Driver::Mock;
+
+my $user = JWebmail::Model::Driver::Mock::VALID_USER;
+my $pw = JWebmail::Model::Driver::Mock::VALID_PW;
+
+my $t = Test::Mojo->new('JWebmail', {
+ development => { use_read_mock => 1, block_writes => 1 },
+});
+
+$t->get_ok('/')->status_is(200);
+
+$t->post_ok('/login', form => {userid => $user, password => 'x'})
+ ->status_is(400);
+
+$t->post_ok('/login', form => {userid => $user, password => 'abcde'})
+ ->status_is(401);
+
+$t->post_ok('/login', form => {userid => $user, password => $pw})
+ ->status_is(303);
+
+done_testing();
+
+
+#$r->get('/123' => sub { my $c = shift; $c->render(inline => $c->stash->{lang}) });
+#my $x = $self->build_controller;
+#$x->match->find($self, {method => 'GET', path => '//write'});
+#print $self->dumper($x->match->stack); \ No newline at end of file