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