File Coverage

inc/WebService/Cmis/Test/ACL.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package WebService::Cmis::Test::ACL;
2 1     1   640 use base qw(WebService::Cmis::Test);
  1         2  
  1         532  
3              
4             use strict;
5             use warnings;
6              
7             use Test::More;
8             use Error qw(:try);
9             use WebService::Cmis qw(:collections :utils :relations :namespaces :contenttypes);
10             use WebService::Cmis::ACL;
11              
12             use XML::LibXML qw(:libxml);
13              
14             sub test_ACL_getXmlDoc : Test {
15             my $this = shift;
16              
17             # SMELL: there might be either separate cmis:permission paragraphs for the
18             # same principal, or just one with all permissions listed within.
19             my $origString = <<'HERE';
20            
21            
22            
23            
24             jdoe
25            
26             false
27             cmis:read
28            
29            
30            
31             jdoe
32            
33             false
34             cmis:write
35            
36            
37             HERE
38              
39             my $xmlDoc = XML::LibXML->load_xml(string => $origString);
40              
41             my $acl = new WebService::Cmis::ACL(xmlDoc=>$xmlDoc);
42             my $newString = $acl->getXmlDoc->toString(1);
43              
44             #note("orig:\n$origString");
45             note("new:\n$newString\n");
46              
47             is($newString, $origString) or $this->reportXmlDiff($newString, $origString);
48             }
49              
50             sub test_ACL_empty : Test(4) {
51             my $this = shift;
52              
53             my $acl = new WebService::Cmis::ACL();
54             ok(defined $acl);
55             isa_ok($acl, 'WebService::Cmis::ACL');
56              
57             is($acl->getSize, 0);
58             ok(!defined $acl->{xmlDoc});
59             }
60              
61             sub test_ACL_addEntry_separate : Test(3) {
62             my $this = shift;
63              
64             my $writeAccess = new WebService::Cmis::ACE(
65             principalId => 'jdoe',
66             direct => 'true',
67             permissions => 'cmis:write'
68             );
69              
70             my $readAccess = new WebService::Cmis::ACE(
71             principalId => 'jdoe',
72             direct => 'true',
73             permissions => 'cmis:read'
74             );
75              
76             my $acl = new WebService::Cmis::ACL();
77              
78             $acl->addEntry($writeAccess);
79             $acl->addEntry($readAccess);
80             is($acl->getSize, 2);
81              
82             my $string = $acl->getXmlDoc->toString(1);
83             ok(defined $string);
84              
85             my $expected = <<'HERE';
86            
87            
88            
89            
90             jdoe
91            
92             true
93             cmis:write
94            
95            
96            
97             jdoe
98            
99             true
100             cmis:read
101            
102            
103             HERE
104              
105             is($string, $expected) or $this->reportXmlDiff($string, $expected)
106             }
107              
108             sub test_ACL_addEntry_joined : Test(3) {
109             my $this = shift;
110              
111             my $ace = new WebService::Cmis::ACE(
112             principalId => 'jdoe',
113             direct => 'true',
114             permissions => ['cmis:write', 'cmis:read']
115             );
116              
117             my $acl = new WebService::Cmis::ACL();
118             $acl->addEntry($ace);
119             is($acl->getSize, 1);
120              
121             my $string = $acl->getXmlDoc->toString(1);
122             ok(defined $string);
123              
124             my $expected = <<'HERE';
125            
126            
127            
128            
129             jdoe
130            
131             true
132             cmis:write
133             cmis:read
134            
135            
136             HERE
137              
138             is($string, $expected) or $this->reportXmlDiff($string, $expected)
139             }
140              
141             sub test_ACL_addEntry_chained : Tests {
142             my $this = shift;
143              
144             my $acl = new WebService::Cmis::ACL()->addEntry(
145             new WebService::Cmis::ACE(
146             principalId => 'jdoe',
147             direct => 'true',
148             permissions => ['cmis:write', 'cmis:read']
149             )
150             );
151              
152             my $string = $acl->getXmlDoc->toString(1);
153             ok(defined $string);
154              
155             my $expected = <<'HERE';
156            
157            
158            
159            
160             jdoe
161            
162             true
163             cmis:write
164             cmis:read
165            
166            
167             HERE
168              
169             is($string, $expected) or $this->reportXmlDiff($string, $expected)
170             }
171              
172             sub test_ACL_removeEntry : Test(5) {
173             my $this = shift;
174              
175             my $writeAccess = new WebService::Cmis::ACE(
176             principalId => 'jdoe',
177             direct => 'true',
178             permissions => 'cmis:write'
179             );
180              
181             my $readAccess = new WebService::Cmis::ACE(
182             principalId => 'jdoe',
183             direct => 'true',
184             permissions => 'cmis:read'
185             );
186              
187             my $acl = new WebService::Cmis::ACL();
188              
189             $acl->addEntry($writeAccess);
190             note("1: acl=\n".$acl->toString);
191             is($acl->getSize, 1);
192              
193             $acl->addEntry($readAccess);
194             note("2: acl=\n".$acl->toString);
195             is($acl->getSize, 2);
196              
197             $acl->removeEntry($writeAccess);
198             note("3:acl=\n".$acl->toString);
199             is($acl->getSize, 1);
200              
201             $acl->addEntry($writeAccess);
202             is($acl->getSize, 2);
203              
204             $acl->removeEntry("jdoe");
205             is($acl->getSize, 0);
206             }
207              
208             1;