ILIAS  release_8 Revision v8.24
RootFolderTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
22
27final class RootFolderTest extends TestCase
28{
29 private const ALLOWED_ROOT_FOLDER_FILES = [
30 '.babelrc.json',
31 '.eslintrc.json',
32 '.gitignore',
33 '.htaccess',
34 '.phpunit.result.cache',
35 'captainhook.local.json',
36 'phpstan.local.neon',
37 'phpstan-baseline.neon',
38 '.php_cs.cache',
39 'calendar.php',
40 'captainhook.json',
41 'composer.json',
42 'composer.lock',
43 'confirmReg.php',
44 'error.php',
45 'favicon.ico',
46 'feed.php',
47 'goto.php',
48 'gs_content.php',
49 'ilias.ini.php',
50 'ilias.php',
51 'index.php',
52 'LICENSE',
53 'login.php',
54 'logout.php',
55 'lti.php',
56 'openidconnect.php',
57 'package-lock.json',
58 'package.json',
59 'privfeed.php',
60 'pwassist.php',
61 'README.md',
62 'register.php',
63 'rootindex.php',
64 'saml.php',
65 'sessioncheck.php',
66 'shib_login.php',
67 'shib_logout.php',
68 'storeScorm.php',
69 'storeScorm2004.php',
70 'studip_referrer.php',
71 'unzip_test_file.zip',
72 'webdav.php',
73 '.DS_Store',
74 '.buildpath',
75 '.project'
76 ];
77
78 private const ALLOWED_ROOT_FOLDER_DIRS = [
79 '.git',
80 '.github',
81 '.idea',
82 'CI',
83 'Customizing',
84 'Modules',
85 'Services',
86 'cron',
87 'data',
88 'dicto',
89 'docs',
90 'extern',
91 'include',
92 'lang',
93 'libs',
94 'node_modules',
95 'setup',
96 'src',
97 'sso',
98 'templates',
99 'test',
100 'tests',
101 'webservice',
102 'xml',
103 '.settings'
104 ];
105
106 protected array $ALLOWED_ROOT_FOLDER_DIRS = [];
107 protected array $ALLOWED_ROOT_FOLDER_FILES = [];
108
109 protected function setUp(): void
110 {
111 $this->ALLOWED_ROOT_FOLDER_DIRS = array_merge(
112 self::ALLOWED_ROOT_FOLDER_DIRS,
113 explode(",", (string) getenv('ALLOWED_ROOT_FOLDER_DIRS'))
114 );
115 $this->ALLOWED_ROOT_FOLDER_FILES = array_merge(
116 self::ALLOWED_ROOT_FOLDER_FILES,
117 explode(",", (string) getenv('ALLOWED_ROOT_FOLDER_FILES'))
118 );
119 }
120
121 private function getAppRootFolderOrFail(): string
122 {
123 $app_root_folder = getcwd();
124
125 for ($i = 0; $i < 20 && !is_file($app_root_folder . '/index.php'); $i++) {
126 $app_root_folder .= '/..';
127 }
128
129 if (!is_file($app_root_folder . '/index.php')) {
130 $this->fail('Could not determine ILIAS root folder');
131 }
132
133 return $app_root_folder;
134 }
135
136 public function testAppRootFolderOnlyContainsDefinedFiles(): void
137 {
138 $found_files = [];
139 $iter = new CallbackFilterIterator(
140 new DirectoryIterator($this->getAppRootFolderOrFail()),
141 static function (DirectoryIterator $file): bool {
142 return $file->isFile();
143 }
144 );
145 foreach ($iter as $file) {
147 $found_files[] = $file->getBasename();
148 }
149 sort($found_files);
150
151 $unexpected_files = array_diff($found_files, $this->ALLOWED_ROOT_FOLDER_FILES);
152
153 $this->assertEmpty(
154 $unexpected_files,
155 sprintf(
156 'The following files are not expected in the ILIAS root folder: %s',
157 implode(', ', $unexpected_files)
158 )
159 );
160 }
161
162 public function testAppRootFolderOnlyContainsDefinedFolders(): void
163 {
164 $found_directories = [];
165 $iter = new CallbackFilterIterator(
166 new DirectoryIterator($this->getAppRootFolderOrFail()),
167 static function (DirectoryIterator $file): bool {
168 return $file->isDir() && !$file->isDot();
169 }
170 );
171 foreach ($iter as $file) {
173 $found_directories[] = $file->getBasename();
174 }
175
176 $unexpected_directories = array_diff($found_directories, $this->ALLOWED_ROOT_FOLDER_DIRS);
177 sort($unexpected_directories);
178
179 $this->assertEmpty(
180 $unexpected_directories,
181 sprintf(
182 'The following directories are not expected in the ILIAS root folder: %s',
183 implode(', ', $unexpected_directories)
184 )
185 );
186 }
187}
Class RootFolderTest.
const ALLOWED_ROOT_FOLDER_DIRS
array $ALLOWED_ROOT_FOLDER_FILES
array $ALLOWED_ROOT_FOLDER_DIRS
const ALLOWED_ROOT_FOLDER_FILES
$i
Definition: metadata.php:41