ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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\AbstractTestBase
 getDummyStream ()
 

Protected Member Functions

 getResourceBuilder (string $denied_ending)
 
 getFileNamePolicy (string $denied_ending)
 
- Protected Member Functions inherited from ILIAS\ResourceStorage\AbstractBaseResourceBuilderTestCase
 setUp ()
 
 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\AbstractTestBase
 setUp ()
 
 getDummyUploadResult (string $file_name, string $mime_type, int $size)
 
 getDummyFileRevision (ResourceIdentification $id)
 

Additional Inherited Members

- Data Fields inherited from ILIAS\ResourceStorage\AbstractBaseResourceBuilderTestCase
 $flavour_repository
 
- Protected Attributes inherited from ILIAS\ResourceStorage\AbstractBaseResourceBuilderTestCase
 $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\AbstractTestBase
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.

References ILIAS\__construct(), and ILIAS\Refinery\check().

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

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

References ILIAS\ResourceStorage\Policy\FileNamePolicyTest\getFileNamePolicy().

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

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  }
+ 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 78 of file FileNamePolicyTest.php.

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

78  : void
79  {
80  $denied_ending = 'xml';
81  $resource_builder = $this->getResourceBuilder($denied_ending);
82 
83  // EXPECTED VALUES
84  $expected_file_name = 'info.' . $denied_ending;
85 
86  // MOCK
87  [$upload_result, $info_resolver, $identification] = $this->mockResourceAndRevision(
88  $expected_file_name,
89  "",
90  0,
91  1,
92  0
93  );
94 
95  // RUN
96  $resource = $resource_builder->new(
98  $info_resolver
99  );
100 
101  $this->expectException(FileNamePolicyException::class);
102  $resource_builder->store($resource);
103  }
mockResourceAndRevision(string $expected_file_name, string $expected_mime_type, int $expected_size, int $expected_version_number, int $expected_owner_id)
+ Here is the call graph for this function:

◆ testValidFileEnding()

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

Definition at line 105 of file FileNamePolicyTest.php.

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

105  : void
106  {
107  $denied_ending = 'xml';
108  $resource_builder = $this->getResourceBuilder($denied_ending);
109 
110  // EXPECTED VALUES
111  $expected_file_name = 'info.pdf';
112 
113  // MOCK
114  [$upload_result, $info_resolver, $identification] = $this->mockResourceAndRevision(
115  $expected_file_name,
116  "",
117  0,
118  1,
119  0
120  );
121 
122  // RUN
123  $resource = $resource_builder->new(
125  $info_resolver
126  );
127 
128  $resource_builder->store($resource);
129  }
mockResourceAndRevision(string $expected_file_name, string $expected_mime_type, int $expected_size, int $expected_version_number, int $expected_owner_id)
+ Here is the call graph for this function:

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