ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
DirectoryNestingTest.php
Go to the documentation of this file.
1 <?php
2 
20 
21 require_once(__DIR__ . "/../AbstractTestBase.php");
22 
28 
34 {
35  private const NESTING_256 = 256; // 16^2
36  private const NESTING_4096 = 4096; // 16^3
37  private const NESTING_65536 = 65536; // 16^4
38  private const NESTING_4294967296 = 4_294_967_296; // 16^8
39  private const NESTING_281474976710656 = 281_474_976_710_656; // 16^12
40 
41  private const MAX_NESTING = self::NESTING_65536;
42  private const MIN_NESTING = self::NESTING_256;
43  private const COMBINATIONS = 16; // 0-9a-f
44 
48  protected $file_system_mock;
49 
50  protected function setUp(): void
51  {
52  parent::setUp();
53  $this->file_system_mock = $this->createMock(Filesystem::class);
54  }
55 
56  private function withImplementation(StorageHandler $h, int $min, int $max): void
57  {
59 
60  for ($x = 0; $x < 100; $x++) {
61  $random_id = $id_generator->getUniqueResourceIdentification();
62  $path = $h->getContainerPathWithoutBase($random_id);
63  $path_elements = explode("/", $h->getContainerPathWithoutBase($random_id));
64  $first_element = end($path_elements);
65  $last_path_element = end($path_elements);
66  foreach ($path_elements as $path_element) {
67  $characters = strlen($path_element);
68  $possible_combinations = self::COMBINATIONS ** $characters;
69  if ($path_element !== $last_path_element) {
70  $this->assertLessThanOrEqual($max, $possible_combinations);
71  $this->assertGreaterThan($min, $possible_combinations);
72  }
73  }
74  }
75  }
76 
77  public function testMaxNestingV1(): void
78  {
79  $storage_handler = new FileSystemStorageHandler($this->file_system_mock, 2);
80  $this->withImplementation($storage_handler, self::NESTING_256, self::NESTING_281474976710656);
81  }
82 
83  public function testMaxNestingV2(): void
84  {
85  $storage_handler = new MaxNestingFileSystemStorageHandler($this->file_system_mock, 2);
86  $this->withImplementation($storage_handler, self::NESTING_4096 - 1, self::NESTING_4096);
87  }
88 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getContainerPathWithoutBase(ResourceIdentification $identification)
This is only the path of a ResourceIdentification inside the StorageLocation base path...
$path
Definition: ltiservices.php:30
withImplementation(StorageHandler $h, int $min, int $max)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS ResourceStorage DummyIDGenerator $id_generator