ILIAS  release_7 Revision v7.30-3-g800a261c036
DirectoryNestingTest.php
Go to the documentation of this file.
1<?php
2
4
10
16{
17 private const NESTING_256 = 256; // 16^2
18 private const NESTING_4096 = 4096; // 16^3
19 private const NESTING_65536 = 65536; // 16^4
20 private const NESTING_4294967296 = 4294967296; // 16^8
21 private const NESTING_281474976710656 = 281474976710656; // 16^12
22
25 private const COMBINATIONS = 16; // 0-9a-f
26
31
32 protected function setUp() : void
33 {
34 parent::setUp();
35 $this->file_system_mock = $this->createMock(Filesystem::class);
36 }
37
38 private function withImplementation(StorageHandler $h, int $min, int $max) : void
39 {
41
42 for ($x = 0; $x < 100; $x++) {
43 $random_id = $id_generator->getUniqueResourceIdentification();
44 $path = $h->getContainerPathWithoutBase($random_id);
45 $path_elements = explode("/", $h->getContainerPathWithoutBase($random_id));
46 $first_element = end($path_elements);
47 $last_path_element = end($path_elements);
48 foreach ($path_elements as $path_element) {
49 $characters = strlen($path_element);
50 $possible_combinations = self::COMBINATIONS ** $characters;
51 if ($path_element !== $last_path_element) {
52 $this->assertLessThanOrEqual($max, $possible_combinations);
53 $this->assertGreaterThan($min, $possible_combinations);
54 }
55 }
56 }
57 }
58
59 public function testMaxNestingV1() : void
60 {
61 $storage_handler = new FileSystemStorageHandler($this->file_system_mock, 2);
62 $this->withImplementation($storage_handler, self::NESTING_256, self::NESTING_281474976710656);
63 }
64
65 public function testMaxNestingV2() : void
66 {
67 $storage_handler = new MaxNestingFileSystemStorageHandler($this->file_system_mock, 2);
68 $this->withImplementation($storage_handler, self::NESTING_4096 - 1, self::NESTING_4096);
69 }
70
71}
72
An exception for terminatinating execution or to throw for unit testing.
withImplementation(StorageHandler $h, int $min, int $max)
Interface Filesystem The filesystem interface provides the public interface for the Filesystem servic...
Definition: Filesystem.php:22
getContainerPathWithoutBase(ResourceIdentification $identification)
This is only the path of a ResourceIdentification inside the StorageLocation base path.