File Coverage

inc/WebService/Cmis/Test/Object.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package WebService::Cmis::Test::Object;
2              
3 1     1   633 use strict;
  1         2  
  1         52  
4 1     1   4 use warnings;
  1         2  
  1         21  
5              
6 1     1   4 use base qw(WebService::Cmis::Test);
  1         1  
  1         536  
7             use Test::More;
8             use Test::Harness;
9              
10              
11             use WebService::Cmis qw(:collections :utils :relations :namespaces :contenttypes);
12             use WebService::Cmis::ACE;
13             use Error qw(:try);
14              
15             sub test_Object_getProperties : Tests {
16             my $this = shift;
17              
18             my $folder = $this->getTestFolder;
19              
20             my $props = $folder->getProperties;
21             note("props:\n".join("\n", map(" ".$_->toString, values %$props)));
22              
23             ok(defined $props->{"cmis:baseTypeId"}) or diag("no baseTypeId found");
24             ok(defined $props->{"cmis:objectId"}) or diag("no objectId found");
25             ok(defined $props->{"cmis:name"}) or diag("no name found");
26              
27             foreach my $key (sort keys %$props) {
28             my $val = $props->{$key}->getValue || '';
29             ok(defined $val);
30             note("$key = $val");
31             }
32             }
33              
34             sub test_Object_getProperty : Test {
35             my $this = shift;
36              
37             require WebService::Cmis::Object;
38              
39             my $folder = $this->getTestFolder;
40             my $props = $folder->getProperties;
41             my $name = $folder->getProperty("cmis:name");
42             note("name=$name");
43             is($name, $props->{"cmis:name"}->getValue);
44             }
45              
46             sub test_Object_getPropertiesFiltered : Test(8) {
47             my $this = shift;
48              
49             my $folder = $this->getTestFolder;
50             ok(defined $folder) or diag("no test folder found");
51              
52             ##### 1rst call
53             my $props1 = $folder->getProperties("lastModifiedBy");
54             note("found ".scalar(keys %$props1)." property");
55              
56             is(1, scalar(keys %$props1));
57              
58             my $prop1 = $props1->{"cmis:lastModifiedBy"}->getValue;
59             ok(defined $prop1);
60              
61             ##### 2nd call
62             my $props2 = $folder->getProperties("cmis:objectTypeId");
63             note("found ".scalar(keys %$props2)." property");
64              
65             is(1, scalar(keys %$props2));
66              
67             my $prop2 = $props2->{"cmis:objectTypeId"}->getValue;
68             ok(defined $prop2);
69              
70             ##### 3nd call
71             my $props3 = $folder->getProperties("cmis:createdBy, cmis:creationDate");
72             note("found ".scalar(keys %$props3)." property");
73             note("props3=".join(', ', keys %$props3));
74              
75             is(2, scalar(keys %$props3));
76              
77             # SMELL: fails on nuxeo
78             my $prop3 = $props3->{"cmis:createdBy"}->getValue;
79             ok(defined $prop3);
80             note("prop3=".($prop3||'undef'));
81              
82             # SMELL: fails on nuxeo
83             my $prop4 = $props3->{"cmis:creationDate"}->getValue;
84             ok(defined $prop4);
85              
86             }
87              
88             sub test_Object_getParents_root : Test(4) {
89             my $this = shift;
90              
91             my $repo = $this->getRepository;
92             my $root = $repo->getRootFolder;
93             ok(defined $root) or diag("no root folder found");
94             my $error;
95              
96             my $parents;
97             try {
98             $parents = $root->getObjectParents;
99             } catch WebService::Cmis::NotSupportedException with {
100             $error = shift;
101             isa_ok($error, "WebService::Cmis::NotSupportedException");
102             like($error, qr'^object does not support getObjectParents');
103             };
104              
105             ok(!defined $parents) or diag("root doesn't have a parent");
106             }
107              
108             sub test_Object_getParents_children : Tests {
109             my $this = shift;
110              
111             my $repo = $this->getRepository;
112             my $root = $repo->getRootFolder;
113             ok(defined $root) or diag("no root folder found");
114             note("root=".$root->getId);
115              
116             my $children = $root->getChildren;
117             note("found ".$children->getSize." children in root folder");
118              
119             while (my $obj = $children->getNext) {
120             my $parents = $obj->getObjectParents;
121             ok(defined $parents);
122              
123             my $parent;
124             if ($parents->isa("WebService::Cmis::AtomFeed")) {
125             is(1, $parents->getSize);
126             $parent = $parents->getNext;
127             } else {
128             $parent = $parents;
129             }
130              
131             note("object=".$obj->getName);
132             note("parent=".$parent->getId);
133              
134             is($root->getId, $parent->getId) or diag("child doesn't point back to its parent");
135             }
136             }
137              
138             sub test_Object_getParents_subchildren : Tests {
139             my $this = shift;
140             my $repo = $this->getRepository;
141             my $root = $repo->getRootFolder;
142              
143             ok($root) or diag("no root folder found");
144              
145             my $children = $root->getChildren;
146             note("found ".$children->getSize." children in root folder");
147              
148             # get first folder
149             my $folder;
150             while(my $obj = $children->getNext) {
151             if ($obj->getTypeId eq 'cmis:folder') {
152             $folder = $obj;
153             last;
154             }
155             }
156             return unless $folder;
157              
158             $children = $folder->getChildren;
159             note("found ".$children->getSize." children in sub folder ".$folder->getTitle.", url=".$folder->getSelfLink);
160              
161             while(my $obj = $children->getNext) {
162             my $parents = $obj->getObjectParents;
163             note("obj=$obj, name=".$obj->getName);
164             note("parents=$parents, ref=".ref($parents));
165             my $parent;
166             if ($parents->isa("WebService::Cmis::AtomFeed")) {
167             is(1, $parents->getSize);
168             $parent = $parents->getNext;
169             } else {
170             $parent = $parents;
171             }
172             isa_ok($parent, "WebService::Cmis::Folder");
173             }
174             }
175              
176             sub test_Object_getAppliedPolicies : Tests {
177             my $this = shift;
178              
179             my $repo = $this->getRepository;
180             my $rootCollection = $repo->getCollection(ROOT_COLL);
181             ok(defined $rootCollection) or diag("can't fetch root collection");
182              
183             while(my $child = $rootCollection->getNext) {
184             my $policies;
185             my $exceptionOkay = 0;
186            
187             try {
188             $policies = $child->getAppliedPolicies;
189             } catch WebService::Cmis::NotSupportedException with {
190             my $error = shift;
191             is($error, 'This object has canGetAppliedPolicies set to false');
192             $exceptionOkay = 1;
193             };
194             next if $exceptionOkay;
195              
196             ok(defined $policies);
197             note("found ".$policies->getSize." policies for".$child->getName);
198             while(my $obj = $policies->getNext) {
199             isa_ok($obj, 'WebServices::Cmis::Policy');
200             note("obj=".$obj->getName);
201             }
202             }
203             }
204              
205             sub test_Object_getRelations : Tests {
206             my $this = shift;
207              
208             my $repo = $this->getRepository;
209             my $rootCollection = $repo->getCollection(ROOT_COLL);
210             ok(defined $rootCollection) or diag("can't fetch root collection");
211              
212             while(my $child = $rootCollection->getNext) {
213             my $rels = $child->getRelationships;
214             ok(defined $rels);
215             note("found ".$rels->getSize." relations for".$child->getName);
216             while(my $obj = $rels->getNext) {
217             isa_ok($obj, 'WebServices::Cmis::Policy');
218             note("obj=".$obj->getName);
219             }
220             }
221             }
222              
223             sub test_Object_getTestFolder : Test {
224             my $this = shift;
225              
226             my $repo = $this->getRepository;
227             my $obj = $this->getTestFolder;
228             ok($obj);
229             }
230              
231             sub test_Object_getTestDocument : Test {
232             my $this = shift;
233              
234             my $obj = $this->getTestDocument;
235             ok(defined $obj);
236             }
237              
238             sub test_Object_getAllowableActions : Tests {
239             my $this = shift;
240              
241             my $repo = $this->getRepository;
242             my $obj = $this->getTestDocument;
243             ok(defined $obj);
244              
245             my $allowableActions = $obj->getAllowableActions;
246             ok(defined $allowableActions) or diag("can't get allowable actions");
247             foreach my $action (sort keys %$allowableActions) {
248             note("$action=$allowableActions->{$action}");
249             like($action, qr'^can');
250             like($allowableActions->{$action}, qr'^(0|1)$');
251             }
252             }
253              
254             sub test_Object_getObject : Test {
255             my $this = shift;
256              
257             require WebService::Cmis::Object;
258              
259             my $repo = $this->getRepository;
260              
261             my $rootFolderId = $repo->getRepositoryInfo->{'rootFolderId'};
262             my $obj = new WebService::Cmis::Object(repository=>$repo, id => $rootFolderId);
263              
264             ok(defined $obj) or diag("can't create an Object");
265             note("obj=$obj");
266             }
267              
268              
269             sub test_Object_getName : Test(2) {
270             my $this = shift;
271              
272             my $repo = $this->getRepository;
273             my $obj = $repo->getRootFolder;
274              
275             my $props = $obj->getProperties;
276             my $name = $props->{"cmis:name"}->getValue;
277             ok(defined $name);
278             note("cmis:name=$name");
279             is($name, $obj->getProperty("cmis:name"));
280             }
281              
282             sub test_Object_getSummary : Test {
283             my $this = shift;
284              
285             my $repo = $this->getRepository;
286             my $root = $repo->getRootFolder;
287              
288             my $summary = $root->getSummary;
289             ok(defined $summary);
290             note("summary=$summary");
291             }
292              
293             sub test_Object_getPublished : Test(2) {
294             my $this = shift;
295              
296             my $repo = $this->getRepository;
297             my $vendorName = $repo->getRepositoryInfo->{vendorName};
298              
299             SKIP: {
300             skip "no atom:published property in this repo", 2
301             if $vendorName =~ /nuxeo/i;
302              
303             my $folder = $this->getTestFolder;
304              
305             my $published = $folder->getPublished;
306             ok(defined $published);
307             $published = 'undef' unless defined $published;
308             like($published, qr'^\d+');
309              
310             #require WebService::Cmis::Property;
311             note("published=".WebService::Cmis::Property::formatDateTime($published)." ($published)");
312             }
313             }
314              
315             sub test_Object_getEdited : Test(2) {
316             my $this = shift;
317              
318             my $folder = $this->getTestFolder;
319              
320             my $edited = $folder->getEdited;
321             ok(defined $edited);
322             $edited = 'undef' unless defined $edited;
323             like($edited, qr'^\d+');
324              
325             #require WebService::Cmis::Property;
326             note("edited=".WebService::Cmis::Property::formatDateTime($edited)." ($edited)");
327             }
328              
329             sub test_Object_getTitle : Test {
330             my $this = shift;
331              
332             my $repo = $this->getRepository;
333             my $root = $repo->getRootFolder;
334              
335             my $title = $root->getTitle;
336             ok(defined $title);
337             note("title=$title");
338             }
339              
340              
341             sub test_Object_getLinkFirst : Test(2) {
342             my $this = shift;
343              
344             my $repo = $this->getRepository;
345             my $obj = $repo->getRootFolder;
346              
347             my $href = $obj->getLink('*');
348             ok(defined $href);
349             note("href=$href");
350              
351             $href =~ s/^(http:\/\/[^\/]+?):80\//$1\//g; # remove bogus :80 port
352             like($href, qr"^$this->{config}{url}");
353             }
354              
355             sub test_Object_getLink : Test(2) {
356             my $this = shift;
357              
358             my $repo = $this->getRepository;
359             my $obj = $repo->getRootFolder;
360              
361             my $href = $obj->getLink(FOLDER_TREE_REL);
362             ok(defined $href);
363             $href ||= 'undef';
364             note("href=$href");
365              
366             $href =~ s/^(http:\/\/[^\/]+?):80\//$1\//g; # remove bogus :80 port
367             like($href, qr"^$this->{config}{url}.*tree");
368             }
369              
370             sub test_Object_getLinkFiltered : Test(2) {
371             my $this = shift;
372              
373             my $repo = $this->getRepository;
374             my $obj = $repo->getRootFolder;
375              
376             my $href = $obj->getLink(DOWN_REL, ATOM_XML_FEED_TYPE_P);
377             ok(defined $href);
378              
379             $href =~ s/^(http:\/\/[^\/]+?):80\//$1\//g; # remove bogus :80 port
380             like($href, qr"^$this->{config}{url}.*children");
381              
382             }
383              
384             sub test_Object_getSelfLink : Test(2) {
385             my $this = shift;
386              
387             my $repo = $this->getRepository;
388             my $obj = $repo->getRootFolder;
389              
390             my $href = $obj->getSelfLink;
391             ok(defined $href);
392              
393             $href =~ s/^(http:\/\/[^\/]+?):80\//$1\//g; # remove bogus :80 port
394             like($href, qr/^$this->{config}{url}/);
395             }
396              
397             sub test_Object_getACL : Test(2) {
398             my $this = shift;
399              
400             my $repo = $this->getRepository;
401             my $canACL = $repo->getCapabilities()->{'ACL'};
402              
403             SKIP: {
404             skip "not able to manage ACLs", 2 unless $canACL eq 'manage';
405              
406             my $obj = $this->getTestFolder;
407              
408             my $acl;
409             my $exceptionOk = 0;
410             my $error;
411              
412             try {
413             $acl = $obj->getACL;
414             } catch WebService::Cmis::NotSupportedException with {
415             my $error = shift;
416             like($error, "This repository does not support ACLs");
417             $exceptionOk = 1;
418             };
419             return $error if $exceptionOk;
420              
421             ok(defined $acl);
422              
423             note($acl->{xmlDoc}->toString);
424             my $result = $acl->toString;
425             ok(defined $result);
426              
427             # SMELL: add some tests that make sense
428             }
429             }
430              
431             sub test_Object_getFolderParent : Tests {
432             my $this = shift;
433              
434             my $folder = $this->getTestFolder;
435             my $folderId = $folder->getId;
436             ok(defined $folderId);
437             note("folderId=$folderId");
438              
439             my $parentFolder = $folder->getFolderParent;
440             ok(defined $parentFolder);
441              
442             my $parentId = $parentFolder->getId;
443             ok(defined $parentId) || BAIL_OUT("why don't we get an id here sometimes?");
444              
445             note("parentFolder: id=".$parentId.", title=".$parentFolder->getTitle);
446              
447             my $found = 0;
448             my $children = $parentFolder->getChildren(types=>"folders");
449             ok(defined $children);
450             while (my $subFolder = $children->getNext) {
451             ok(defined $subFolder);
452             note("subFolder: id=".$subFolder->getId.", title=".$subFolder->getTitle);
453             isa_ok($subFolder, "WebService::Cmis::Object");
454             $found = 1 if $subFolder->getId eq $folderId;
455             }
456            
457             ok($found) || diag("folder not found in child list of its own parent");
458             }
459              
460             sub test_Object_updateProperties : Test(3) {
461             my $this = shift;
462              
463             my $obj = $this->getTestDocument;
464              
465             my $name1 = $obj->getName;
466             my $summary1 = $obj->getSummary || '';
467             my $title1 = $obj->getTitle;
468             my $updated1 = $obj->getUpdated;
469              
470             note("name=$name1, title=$title1, summary=$summary1, updated=$updated1, url=".$obj->getSelfLink);
471              
472             my $extension = $name1;
473             $extension =~ s/^.*\.(.*?)$/$1/;
474              
475             my $newName = 'SomeOtherName.'.$extension;
476              
477             sleep(1);
478              
479             $obj->updateProperties([
480             WebService::Cmis::Property::newString(
481             id => 'cmis:name',
482             value => $newName,
483             ),
484             ]);
485              
486             my $name2 = $obj->getName;
487             my $summary2 = $obj->getSummary || '';
488             my $title2 = $obj->getTitle;
489             my $updated2 = $obj->getUpdated;
490              
491             note("name=$name2, title=$title2, summary=$summary2 updated=$updated2");
492              
493             is($newName, $name2);
494             isnt($name1, $name2);
495             isnt($updated1, $updated2);
496             }
497              
498             sub test_Object_updateSummary : Test(4) {
499             my $this = shift;
500              
501             my $repo = $this->getRepository;
502             my $msg = $this->isBrokenFeature("updateSummary");
503              
504             SKIP: {
505             skip $msg, 4 if $msg;
506              
507             my $obj = $this->getTestDocument;
508              
509             my $name1 = $obj->getName;
510             my $summary1 = $obj->getSummary;
511             my $title1 = $obj->getTitle;
512             my $updated1 = $obj->getUpdated;
513              
514             #print STDERR $obj->{xmlDoc}->toString(1)."\n";
515              
516             note("name=$name1, title=$title1, summary=$summary1, updated=$updated1, url=" . $obj->getSelfLink);
517              
518             sleep(1);
519              
520             my $text = 'icon showing a red button written "free" on it';
521             $obj->updateSummary($text);
522              
523             my $name2 = $obj->getName;
524             my $summary2 = $obj->getSummary;
525             my $title2 = $obj->getTitle;
526             my $updated2 = $obj->getUpdated;
527              
528             note("name=$name2, title=$title2, summary=$summary2 updated=$updated2");
529              
530             is($name2, $name1);
531             is($summary2, $text);
532             isnt($updated2, $updated1);
533             isnt($summary2, $summary1);
534             }
535             }
536              
537             sub test_Object_updateSummary_empty : Test(2) {
538             my $this = shift;
539              
540             my $msg = $this->isBrokenFeature("updateSummary");
541              
542             SKIP: {
543             skip $msg, 2 if $msg;
544              
545             my $repo = $this->getRepository;
546             my $obj = $this->getTestDocument;
547              
548             my $summary = $obj->getSummary;
549             note("summary=$summary");
550             ok($summary);
551              
552             my $text = '';
553             $obj->updateSummary($text);
554             $summary = $obj->getSummary;
555             is($summary, '');
556             }
557             }
558              
559             sub test_Object_applyACL : Test(7) {
560             my $this = shift;
561              
562             my $repo = $this->getRepository;
563             my $canACL = $repo->getCapabilities()->{'ACL'};
564              
565             SKIP: {
566             skip "not able to manage ACLs", 7 unless $canACL eq 'manage';
567              
568             my $obj = $this->getTestFolder;
569              
570             #print STDERR "obj=$obj\n";
571              
572             my $acl = $obj->getACL;
573             ok(defined $acl);
574             my $origSize = $acl->getSize;
575              
576             note("1: our ACL has got $origSize ACEs");
577             note("1: acl=" . $acl->toString);
578              
579             my $ace = new WebService::Cmis::ACE(
580             principalId => 'jdoe',
581             permissions => 'cmis:write',
582             direct => 'true'
583             );
584             $acl->addEntry($ace);
585              
586             note("2: after adding one ACE we have " . ($origSize + 1) . " ACEs");
587             note("2: acl=" . $acl->toString);
588              
589             is($acl->getSize, $origSize + 1);
590              
591             my $returnAcl = $obj->applyACL($acl);
592             my $returnSize = $returnAcl->getSize;
593             ok(defined $returnAcl);
594              
595             note("3: applying the ACL we get $returnSize ACEs in return ... could be more than one on plus for some strange reason.");
596             note("3: acl=" . $returnAcl->toString);
597              
598             ok($returnSize > $origSize);
599              
600             my $againAcl = $obj->getACL;
601             my $againSize = $againAcl->getSize;
602              
603             note("4: getting a fresh ACL from the object has got $againSize ACEs.");
604             note("4: acl=" . $againAcl->toString);
605              
606             ok(defined $againAcl);
607              
608             # is( $againSize, $returnSize ); ... woops this isn't necessarily the same as returned when applying the acl
609              
610             $againAcl->removeEntry("jdoe");
611             $againSize = $againAcl->getSize;
612              
613             note("5: removing all ACEs for jdoe leaves us with $againSize, origSize was $origSize");
614             note("5: acl=" . $againAcl->toString);
615              
616             #is($againSize, $origSize);# basically I am not sure what alfresco is doing here behind the scene
617              
618             $returnAcl = $obj->applyACL($againAcl);
619             $returnSize = $returnAcl->getSize;
620             ok(defined $returnAcl);
621              
622             note("6: applying the ACL we get $returnSize ACEs in return");
623             note("6: acl=" . $returnAcl->toString);
624              
625             is($returnSize, $againSize);
626              
627             # is( $returnAcl->toString, $againAcl->toString ); ... woops this isn't necessarily the same as returned when applying the acl
628             }
629             }
630              
631             sub test_Object_applyACL_same : Test(6) {
632             my $this = shift;
633              
634             my $repo = $this->getRepository;
635             my $canACL = $repo->getCapabilities()->{'ACL'};
636              
637             SKIP: {
638             skip "not able to manage ACLs", 6 unless $canACL eq 'manage';
639              
640             my $obj = $this->getTestFolder;
641             my $acl = $obj->getACL;
642              
643             ok(defined $acl);
644             my $origSize = $acl->getSize;
645             note("1: our ACL has got $origSize ACEs");
646             ok($origSize > 0);
647             #note("1: acl=".$acl->toString);
648              
649             $acl->addEntry(new WebService::Cmis::ACE(
650             principalId => 'jdoe',
651             permissions => 'cmis:write',
652             direct => 'true'
653             ));
654             my $size = $acl->getSize;
655             note("2: our ACL has got $size ACEs now");
656             is($size, $origSize+1);
657             #note("2: acl=".$acl->toString);
658              
659             # adding the same again
660             $acl->addEntry(new WebService::Cmis::ACE(
661             principalId => 'jdoe',
662             permissions => 'cmis:write',
663             direct => 'true'
664             ));
665             $size = $acl->getSize;
666             note("3: our ACL has got $size ACEs now");
667             is($size, $origSize+2);
668              
669             # adding the same again
670             $acl->addEntry(new WebService::Cmis::ACE(
671             principalId => 'jdoe',
672             permissions => 'cmis:write',
673             direct => 'true'
674             ));
675             $size = $acl->getSize;
676             note("4: our ACL has got $size ACEs now");
677             is($size, $origSize+3);
678              
679             note("before acl=".$acl->toString);
680              
681             my $returnAcl = $obj->applyACL($acl);
682             my $returnSize = $returnAcl->getSize;
683             note("4: the returned ACL has got $returnSize ACEs");
684             ok($returnSize < $size);
685             note("after acl=".$returnAcl->toString);
686             note($returnAcl->getXmlDoc->toString(1));
687              
688             }
689             }
690              
691             1;