521269995c9e4cd38c3659779f3acd8facf67e3a
[kivitendo-erp.git] / t / menu / parse_access_string.t
1 use strict;
2
3 use Test::More;
4
5 use lib 't';
6 use Support::TestSetup;
7
8 Support::TestSetup::login();
9
10 use_ok 'SL::Menu';
11
12 #my $menu = SL::Menu->new('user');
13 my $menu = 'SL::Menu';
14
15 my %node;
16 $node{id} = 'test_node';
17
18 $node{access} = 'sales_quotation_edit';
19 ok($menu->parse_access_string(\%node), 'simple parse granted');
20
21 $node{access} = 'no such right';
22 ok(!$menu->parse_access_string(\%node), 'simple parse not granted');
23
24 $node{access} = 'sales_quotation_edit)';
25 eval {$menu->parse_access_string(\%node); ok(0, 'detect missing opening parenthesis'); 1} or do { ok(1, 'detect missing opening parenthesis'); };
26
27 $node{access} = '(sales_quotation_edit';
28 eval {$menu->parse_access_string(\%node); ok(0, 'detect missing closing parenthesis'); 1} or do { ok(1, 'detect missing closing parenthesis'); };
29
30 $node{access} = 'sales_quotation_edit-';
31 eval {$menu->parse_access_string(\%node); ok(0, 'detect unrecognized token'); 1} or do { ok(1, 'detect unrecognized token'); };
32
33 $node{access} = 'sales_order_edit & sales_quotation_edit';
34 ok($menu->parse_access_string(\%node), 'grant and grant');
35
36 $node{access} = 'no_such_right & sales_quotation_edit';
37 ok(!$menu->parse_access_string(\%node), 'not grant and grant');
38
39 $node{access} = 'no_such_right & no_such_right';
40 ok(!$menu->parse_access_string(\%node), 'not grant and not grant');
41
42 $node{access} = 'sales_order_edit|sales_quotation_edit';
43 ok($menu->parse_access_string(\%node), 'grant or grant');
44
45 $node{access} = 'no_such_right | sales_quotation_edit';
46 ok($menu->parse_access_string(\%node), 'not grant or grant');
47
48 $node{access} = 'no_such_right | no_such_right';
49 ok(!$menu->parse_access_string(\%node), 'not grant or not grant');
50
51 $node{access} = '(sales_quotation_edit & sales_order_edit | (no_such_right & sales_order_edit))';
52 ok($menu->parse_access_string(\%node), 'parenthesis 1');
53
54 $node{access} = '(no_such_right & sales_order_edit | (no_such_right & sales_order_edit))';
55 ok(!$menu->parse_access_string(\%node), 'parenthesis 2');
56
57 $node{access} = 'sales_quotation_edit & client/feature_experimental_order';
58 ok($menu->parse_access_string(\%node), 'client');
59
60 $node{access} = '!no_such_right';
61 ok($menu->parse_access_string(\%node), 'simple negation 1');
62
63 $node{access} = '!sales_order_edit';
64 ok(!$menu->parse_access_string(\%node), 'simple negation 2');
65
66 $node{access} = '!!sales_order_edit';
67 ok($menu->parse_access_string(\%node), 'double negation');
68
69 $node{access} = '(no_such_right & sales_order_edit | !(no_such_right & sales_order_edit))';
70 ok($menu->parse_access_string(\%node), 'parenthesis with negation 1');
71
72 $node{access} = '(no_such_right & sales_order_edit | (!no_such_right | !sales_order_edit))';
73 ok($menu->parse_access_string(\%node), 'parenthesis with negation 2');
74
75 $node{access} = 'sales_quotation_edit & !client/feature_experimental_order';
76 ok(!$menu->parse_access_string(\%node), 'client negation');
77
78 done_testing;
79
80 1;