ILIAS  release_8 Revision v8.24
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
 
 $collection_repository
 
 $revision_repository
 
 $storage_handler
 
ILIAS ResourceStorage Resource ResourceBuilder $resource_builder
 
 $stakeholder_repository
 
 $locking
 
 $storage_handler_factory
 
 $stream_access
 
Repositories $repositories
 
- Protected Attributes inherited from ILIAS\ResourceStorage\AbstractBaseTest
ILIAS ResourceStorage DummyIDGenerator $id_generator
 
 $db_mock
 

Detailed Description

Member Function Documentation

◆ getFileNamePolicy()

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

Definition at line 43 of file FileNamePolicyTest.php.

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

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

Definition at line 31 of file FileNamePolicyTest.php.

31 : ResourceBuilder
32 {
33 $policy = $this->getFileNamePolicy($denied_ending);
34 return new ResourceBuilder(
35 $this->storage_handler_factory,
36 $this->repositories,
37 $this->locking,
38 $this->stream_access,
39 $policy
40 );
41 }

References 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 76 of file FileNamePolicyTest.php.

76 : void
77 {
78 $denied_ending = 'xml';
79 $resource_builder = $this->getResourceBuilder($denied_ending);
80
81 // EXPECTED VALUES
82 $expected_file_name = 'info.' . $denied_ending;
83
84 // MOCK
85 [$upload_result, $info_resolver, $identification] = $this->mockResourceAndRevision(
86 $expected_file_name,
87 "",
88 0,
89 1,
90 0
91 );
92
93 // RUN
94 $resource = $resource_builder->new(
96 $info_resolver
97 );
98
99 $this->expectException(FileNamePolicyException::class);
100 $resource_builder->store($resource);
101 }
mockResourceAndRevision(string $expected_file_name, string $expected_mime_type, int $expected_size, int $expected_version_number, int $expected_owner_id)
ILIAS ResourceStorage Resource ResourceBuilder $resource_builder

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 103 of file FileNamePolicyTest.php.

103 : void
104 {
105 $denied_ending = 'xml';
106 $resource_builder = $this->getResourceBuilder($denied_ending);
107
108 // EXPECTED VALUES
109 $expected_file_name = 'info.pdf';
110
111 // MOCK
112 [$upload_result, $info_resolver, $identification] = $this->mockResourceAndRevision(
113 $expected_file_name,
114 "",
115 0,
116 1,
117 0
118 );
119
120 // RUN
121 $resource = $resource_builder->new(
123 $info_resolver
124 );
125
126 $resource_builder->store($resource);
127 }

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: