X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FApp-EzPz.git;a=blobdiff_plain;f=t%2Fusers.t;fp=t%2Fusers.t;h=18cba49c7f48a802589fd937aa1b70e7cbfa4087;hp=0000000000000000000000000000000000000000;hb=8dbc46889fe504dede2f94e854254e919ce68416;hpb=6b4ac75f6057d5775e1380ac845b602bef755cba diff --git a/t/users.t b/t/users.t new file mode 100644 index 0000000..18cba49 --- /dev/null +++ b/t/users.t @@ -0,0 +1,61 @@ +use strictures 1; +use Test::More; +use App::EzPz::UserStore; +use File::Temp qw(tempfile); + +my $us = App::EzPz::UserStore->new(htpasswd_file => (tempfile)[1]); + +my $mst = $us->add({ username => 'mst', password => 'boromir' }); + +is($mst->username, 'mst', 'username ok'); +ok($mst->check_password('boromir'), 'right pw ok on user'); +ok(!$mst->check_password('gimli'), 'wrong pw not ok on user'); + +ok($us->check_password('mst', 'boromir'), 'right pw ok on user store'); +ok(!$us->check_password('mst', 'gimli'), 'wrong pw not ok on user store'); + +ok(!$us->check_password('genehack', 'boromir'), 'nonexistent user fails ok'); + +my $mst_clone = $us->add({ username => 'an_mst_clone', password => 'dnatank' }); + +is( + join(',', sort map $_->username, $us->all), + 'an_mst_clone,mst', + 'user list ok with 2 users' +); + +$us->remove($mst_clone); + +is( + join(',', sort map $_->username, $us->all), + 'mst', + 'user list ok after delete' +); + +is( + join(',', $mst->list_names), '', + 'No lists yet' +); + +$mst->add_list_name($_) for qw(list1 list2 list3); + +is( + join(',', $mst->list_names), 'list1,list2,list3', + 'Three lists after add', +); + +$mst->remove_list_name('list2'); + +is( + join(',', $mst->list_names), 'list1,list3', + 'Two lists after move', +); + +$mst->add_list_name('list2'); + +is( + join(',', $mst->list_names), 'list1,list3,list2', + 'Re-add appends', +); + +done_testing;