ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
RootFolderTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\App\tests;
22 
24 
29 final class RootFolderTest extends TestCase
30 {
31  private const ALLOWED_ROOT_FOLDER_FILES = [
32  '.eslintrc.json',
33  '.gitignore',
34  '.htaccess',
35  '.phpunit.result.cache',
36  'captainhook.local.json',
37  'phpstan.local.neon',
38  'phpstan-baseline.neon',
39  '.php_cs.cache',
40  '.php-cs-fixer.cache',
41  'captainhook.json',
42  'composer.json',
43  'composer_new.json',
44  'composer.lock',
45  'ilias.ini.php',
46  'ilias_version.php',
47  'LICENSE',
48  'package-lock.json',
49  'package.json',
50  'README.md',
51  'unzip_test_file.zip',
52  '.DS_Store',
53  '.buildpath',
54  '.project'
55  ];
56 
57  private const ALLOWED_ROOT_FOLDER_DIRS = [
58  '.git',
59  '.github',
60  '.idea',
61  'artifacts',
62  'cli',
63  'components',
64  'docs',
65  'extern',
66  'lang',
67  'node_modules',
68  'public',
69  'scripts',
70  'templates',
71  'vendor',
72  '.settings'
73  ];
74 
75  protected array $ALLOWED_ROOT_FOLDER_DIRS = [];
76  protected array $ALLOWED_ROOT_FOLDER_FILES = [];
77 
78  protected function setUp(): void
79  {
80  $this->ALLOWED_ROOT_FOLDER_DIRS = array_merge(
81  self::ALLOWED_ROOT_FOLDER_DIRS,
82  explode(",", (string) getenv('ALLOWED_ROOT_FOLDER_DIRS'))
83  );
84  $this->ALLOWED_ROOT_FOLDER_FILES = array_merge(
85  self::ALLOWED_ROOT_FOLDER_FILES,
86  explode(",", (string) getenv('ALLOWED_ROOT_FOLDER_FILES'))
87  );
88  }
89 
90  private function getAppRootFolderOrFail(): string
91  {
92  $app_root_folder = __DIR__ . "/../../../../";
93 
94  if (!is_file($app_root_folder . '/ilias_version.php')) {
95  $this->fail('Could not determine ILIAS root folder');
96  }
97 
98  return $app_root_folder;
99  }
100 
101  public function testAppRootFolderOnlyContainsDefinedFiles(): void
102  {
103  $found_files = [];
104  $iter = new \CallbackFilterIterator(
106  static function (\DirectoryIterator $file): bool {
107  return $file->isFile();
108  }
109  );
110  foreach ($iter as $file) {
112  $found_files[] = $file->getBasename();
113  }
114  sort($found_files);
115 
116  $unexpected_files = array_diff($found_files, $this->ALLOWED_ROOT_FOLDER_FILES);
117 
118  $this->assertEmpty(
119  $unexpected_files,
120  sprintf(
121  'The following files are not expected in the ILIAS root folder: %s',
122  implode(', ', $unexpected_files)
123  )
124  );
125  }
126 
127  public function testAppRootFolderOnlyContainsDefinedFolders(): void
128  {
129  $found_directories = [];
130  $iter = new \CallbackFilterIterator(
132  static function (\DirectoryIterator $file): bool {
133  return $file->isDir() && !$file->isDot();
134  }
135  );
136  foreach ($iter as $file) {
138  $found_directories[] = $file->getBasename();
139  }
140 
141  $unexpected_directories = array_diff($found_directories, $this->ALLOWED_ROOT_FOLDER_DIRS);
142  sort($unexpected_directories);
143 
144  $this->assertEmpty(
145  $unexpected_directories,
146  sprintf(
147  'The following directories are not expected in the ILIAS root folder: %s',
148  implode(', ', $unexpected_directories)
149  )
150  );
151  }
152 }
sort()
description: > Example for rendering a Sort Glyph.
Definition: sort.php:25
Class RootFolderTest.