ILIAS  release_7 Revision v7.30-3-g800a261c036
ILIAS\ResourceStorage\Policy\FileNamePolicyTest Class Reference

Class FileNamePolicyTest. More...

+ Inheritance diagram for ILIAS\ResourceStorage\Policy\FileNamePolicyTest:
+ Collaboration diagram for ILIAS\ResourceStorage\Policy\FileNamePolicyTest:

Public Member Functions

 testDeniedFileEnding ()
 
 testValidFileEnding ()
 
- Public Member Functions inherited from ILIAS\ResourceStorage\AbstractBaseTest
 getDummyStream ()
 

Protected Member Functions

 getResourceBuilder (string $denied_ending)
 
 getFileNamePolicy (string $denied_ending)
 
- Protected Member Functions inherited from ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest
 setUp ()
 @inheritDoc More...
 
 mockResourceAndRevision (string $expected_file_name, string $expected_mime_type, int $expected_size, int $expected_version_number, int $expected_owner_id)
 
- Protected Member Functions inherited from ILIAS\ResourceStorage\AbstractBaseTest
 setUp ()
 @inheritDoc More...
 
 getDummyUploadResult (string $file_name, string $mime_type, int $size)
 
 getDummyFileRevision (ResourceIdentification $id)
 

Additional Inherited Members

- Protected Attributes inherited from ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest
 $revision
 
 $information
 
 $upload_result
 
 $information_repository
 
 $resource_repository
 
 $revision_repository
 
 $storage_handler
 
 $resource_builder
 
 $stakeholder_repository
 
 $locking
 
 $storage_handler_factory
 
- Protected Attributes inherited from ILIAS\ResourceStorage\AbstractBaseTest
 $id_generator
 
 $db_mock
 

Detailed Description

Member Function Documentation

◆ getFileNamePolicy()

ILIAS\ResourceStorage\Policy\FileNamePolicyTest::getFileNamePolicy ( string  $denied_ending)
protected
Returns
FileNamePolicy

Definition at line 37 of file FileNamePolicyTest.php.

38 {
39 return new class($denied_ending) implements FileNamePolicy {
40 public function __construct(string $denied_ending)
41 {
42 $this->denied_ending = $denied_ending;
43 }
44
45 public function check(string $extension) : bool
46 {
47 if ($this->denied_ending === $extension) {
48 throw new FileNamePolicyException('ERROR');
49 }
50 return true;
51 }
52
53 public function isValidExtension(string $extension) : bool
54 {
55 return $this->denied_ending !== $extension;
56 }
57
58 public function isBlockedExtension(string $extension) : bool
59 {
60 return $this->denied_ending === $extension;
61 }
62
63 public function prepareFileNameForConsumer(string $filename_with_extension) : string
64 {
65 return $filename_with_extension;
66 }
67
68 };
69 }
__construct($a_client_id=0)
Constructor setup ILIAS global object @access public.

References ILIAS\__construct().

Referenced by ILIAS\ResourceStorage\Policy\FileNamePolicyTest\getResourceBuilder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getResourceBuilder()

ILIAS\ResourceStorage\Policy\FileNamePolicyTest::getResourceBuilder ( string  $denied_ending)
protected
Parameters
string$denied_ending
Returns
ResourceBuilder

Definition at line 19 of file FileNamePolicyTest.php.

19 : ResourceBuilder
20 {
21 $policy = $this->getFileNamePolicy($denied_ending);
22 $resource_builder = new ResourceBuilder(
23 $this->storage_handler_factory,
24 $this->revision_repository,
25 $this->resource_repository,
26 $this->information_repository,
27 $this->stakeholder_repository,
28 $this->locking,
29 $policy
30 );
31 return $resource_builder;
32 }

References ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest\$resource_builder, and ILIAS\ResourceStorage\Policy\FileNamePolicyTest\getFileNamePolicy().

Referenced by ILIAS\ResourceStorage\Policy\FileNamePolicyTest\testDeniedFileEnding(), and ILIAS\ResourceStorage\Policy\FileNamePolicyTest\testValidFileEnding().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDeniedFileEnding()

ILIAS\ResourceStorage\Policy\FileNamePolicyTest::testDeniedFileEnding ( )

Definition at line 71 of file FileNamePolicyTest.php.

71 : void
72 {
73 $denied_ending = 'xml';
74 $resource_builder = $this->getResourceBuilder($denied_ending);
75
76 // EXPECTED VALUES
77 $expected_file_name = 'info.' . $denied_ending;
78
79 // MOCK
80 list($upload_result, $info_resolver, $identification) = $this->mockResourceAndRevision(
81 $expected_file_name,
82 "",
83 0, 1, 0
84 );
85
86 // RUN
87 $resource = $resource_builder->new(
89 $info_resolver
90 );
91
92 $this->expectException(FileNamePolicyException::class);
93 $resource_builder->store($resource);
94 }
mockResourceAndRevision(string $expected_file_name, string $expected_mime_type, int $expected_size, int $expected_version_number, int $expected_owner_id)

References ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest\$resource_builder, ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest\$upload_result, ILIAS\ResourceStorage\Policy\FileNamePolicyTest\getResourceBuilder(), and ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest\mockResourceAndRevision().

+ Here is the call graph for this function:

◆ testValidFileEnding()

ILIAS\ResourceStorage\Policy\FileNamePolicyTest::testValidFileEnding ( )

Definition at line 96 of file FileNamePolicyTest.php.

96 : void
97 {
98 $denied_ending = 'xml';
99 $resource_builder = $this->getResourceBuilder($denied_ending);
100
101 // EXPECTED VALUES
102 $expected_file_name = 'info.pdf';
103
104 // MOCK
105 list($upload_result, $info_resolver, $identification) = $this->mockResourceAndRevision(
106 $expected_file_name,
107 "",
108 0, 1, 0
109 );
110
111 // RUN
112 $resource = $resource_builder->new(
114 $info_resolver
115 );
116
117 $resource_builder->store($resource);
118 }

References ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest\$resource_builder, ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest\$upload_result, ILIAS\ResourceStorage\Policy\FileNamePolicyTest\getResourceBuilder(), and ILIAS\ResourceStorage\AbstractBaseResourceBuilderTest\mockResourceAndRevision().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: