From ffddb5c07960091a33cfd6f91b6a3245efdcccf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 1 Aug 2018 16:50:20 +0200 Subject: [PATCH] =?utf8?q?Tests=20f=C3=BCr=20access-String-Auswertung=20de?= =?utf8?q?s=20Men=C3=BCs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- t/menu/parse_access_string.t | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 t/menu/parse_access_string.t diff --git a/t/menu/parse_access_string.t b/t/menu/parse_access_string.t new file mode 100644 index 000000000..f1cbd4289 --- /dev/null +++ b/t/menu/parse_access_string.t @@ -0,0 +1,62 @@ +use strict; + +use Test::More; + +use lib 't'; +use Support::TestSetup; + +Support::TestSetup::login(); + +use_ok 'SL::Menu'; + +#my $menu = SL::Menu->new('user'); +my $menu = 'SL::Menu'; + +my %node; +$node{id} = 'test_node'; + +$node{access} = 'sales_quotation_edit'; +ok($menu->parse_access_string(\%node), 'simple parse granted'); + +$node{access} = 'no such right'; +ok(!$menu->parse_access_string(\%node), 'simple parse not granted'); + +$node{access} = 'sales_quotation_edit)'; +eval {$menu->parse_access_string(\%node); ok(0, 'detect missing opening parenthesis'); 1} or do { ok(1, 'detect missing opening parenthesis'); }; + +$node{access} = '(sales_quotation_edit'; +eval {$menu->parse_access_string(\%node); ok(0, 'detect missing closing parenthesis'); 1} or do { ok(1, 'detect missing closing parenthesis'); }; + +$node{access} = 'sales_quotation_edit-'; +eval {$menu->parse_access_string(\%node); ok(0, 'detect unrecognized token'); 1} or do { ok(1, 'detect unrecognized token'); }; + +$node{access} = 'sales_order_edit & sales_quotation_edit'; +ok($menu->parse_access_string(\%node), 'grant and grant'); + +$node{access} = 'no_such_right & sales_quotation_edit'; +ok(!$menu->parse_access_string(\%node), 'not grant and grant'); + +$node{access} = 'no_such_right & no_such_right'; +ok(!$menu->parse_access_string(\%node), 'not grant and not grant'); + +$node{access} = 'sales_order_edit|sales_quotation_edit'; +ok($menu->parse_access_string(\%node), 'grant or grant'); + +$node{access} = 'no_such_right | sales_quotation_edit'; +ok($menu->parse_access_string(\%node), 'not grant or grant'); + +$node{access} = 'no_such_right | no_such_right'; +ok(!$menu->parse_access_string(\%node), 'not grant or not grant'); + +$node{access} = '(sales_quotation_edit & sales_order_edit | (no_such_right & sales_order_edit))'; +ok($menu->parse_access_string(\%node), 'parenthesis 1'); + +$node{access} = '(no_such_right & sales_order_edit | (no_such_right & sales_order_edit))'; +ok(!$menu->parse_access_string(\%node), 'parenthesis 2'); + +$node{access} = 'sales_quotation_edit & client/feature_experimental'; +ok($menu->parse_access_string(\%node), 'client'); + +done_testing; + +1; -- 2.20.1