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