Skip to content

Commit 52d092d

Browse files
feat: add config header and tests.
Signed-off-by: E.S. Rosenberg a.k.a. Keeper of the Keys <es-github@rosenberg.org.il>
1 parent 1afeb1c commit 52d092d

2 files changed

Lines changed: 119 additions & 7 deletions

File tree

lib/private/Config.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,25 @@ private function writeData(): void {
268268
}
269269

270270
// Create a php file ...
271-
$content = "<?php\n";
272-
$content .= '$CONFIG = ';
271+
$content = "<?php
272+
273+
/*
274+
* WARNING
275+
*
276+
* This file gets modified by automatic processes and all lines that are not
277+
* active code (ie. comments) are lost during that process.
278+
*
279+
* If you want to document things with comments or use constants add your settings
280+
* in a '<NAME>.config.php' file which will be included and rendered into this file.
281+
*
282+
* Example:
283+
* <?php
284+
* \$CONFIG = [];
285+
*
286+
* See also: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-merged-configuration-files
287+
*/
288+
289+
\$CONFIG = ";
273290
$content .= var_export(self::trustSystemConfig($this->cache), true);
274291
$content .= ";\n";
275292

tests/lib/ConfigTest.php

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,26 @@ public function testSetValue(): void {
9797
$this->assertSame('moo', $config->getValue('foo'));
9898

9999
$content = file_get_contents($this->configFile);
100-
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
100+
$expected = "<?php
101+
102+
/*
103+
* WARNING
104+
*
105+
* This file gets modified by automatic processes and all lines that are not
106+
* active code (ie. comments) are lost during that process.
107+
*
108+
* If you want to document things with comments or use constants add your settings
109+
* in a '<NAME>.config.php' file which will be included and rendered into this file.
110+
*
111+
* Example:
112+
* <?php
113+
* \$CONFIG = [];
114+
*
115+
* See also: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-merged-configuration-files
116+
*/
117+
118+
";
119+
$expected .= "\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
101120
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n);\n";
102121
$this->assertEquals($expected, $content);
103122

@@ -108,7 +127,26 @@ public function testSetValue(): void {
108127

109128
$content = file_get_contents($this->configFile);
110129

111-
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
130+
$expected = "<?php
131+
132+
/*
133+
* WARNING
134+
*
135+
* This file gets modified by automatic processes and all lines that are not
136+
* active code (ie. comments) are lost during that process.
137+
*
138+
* If you want to document things with comments or use constants add your settings
139+
* in a '<NAME>.config.php' file which will be included and rendered into this file.
140+
*
141+
* Example:
142+
* <?php
143+
* \$CONFIG = [];
144+
*
145+
* See also: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-merged-configuration-files
146+
*/
147+
148+
";
149+
$expected .= "\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
112150
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n 'bar' => 'red',\n 'apps' => \n "
113151
. " array (\n 0 => 'files',\n 1 => 'gallery',\n ),\n);\n";
114152
$this->assertEquals($expected, $content);
@@ -139,7 +177,26 @@ public function testSetValues(): void {
139177
$this->assertSame(null, $config->getValue('not_exists'));
140178

141179
$content = file_get_contents($this->configFile);
142-
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
180+
$expected = "<?php
181+
182+
/*
183+
* WARNING
184+
*
185+
* This file gets modified by automatic processes and all lines that are not
186+
* active code (ie. comments) are lost during that process.
187+
*
188+
* If you want to document things with comments or use constants add your settings
189+
* in a '<NAME>.config.php' file which will be included and rendered into this file.
190+
*
191+
* Example:
192+
* <?php
193+
* \$CONFIG = [];
194+
*
195+
* See also: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-merged-configuration-files
196+
*/
197+
198+
";
199+
$expected .= "\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
143200
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n);\n";
144201
$this->assertEquals($expected, $content);
145202
}
@@ -150,7 +207,26 @@ public function testDeleteKey(): void {
150207
$this->assertSame('this_was_clearly_not_set_before', $config->getValue('foo', 'this_was_clearly_not_set_before'));
151208
$content = file_get_contents($this->configFile);
152209

153-
$expected = "<?php\n\$CONFIG = array (\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
210+
$expected = "<?php
211+
212+
/*
213+
* WARNING
214+
*
215+
* This file gets modified by automatic processes and all lines that are not
216+
* active code (ie. comments) are lost during that process.
217+
*
218+
* If you want to document things with comments or use constants add your settings
219+
* in a '<NAME>.config.php' file which will be included and rendered into this file.
220+
*
221+
* Example:
222+
* <?php
223+
* \$CONFIG = [];
224+
*
225+
* See also: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-merged-configuration-files
226+
*/
227+
228+
";
229+
$expected .= "\$CONFIG = array (\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
154230
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n);\n";
155231
$this->assertEquals($expected, $content);
156232
}
@@ -170,7 +246,26 @@ public function testConfigMerge(): void {
170246

171247
// Write a new value to the config
172248
$config->setValue('CoolWebsites', ['demo.owncloud.org', 'owncloud.org', 'owncloud.com']);
173-
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'bar',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
249+
$expected = "<?php
250+
251+
/*
252+
* WARNING
253+
*
254+
* This file gets modified by automatic processes and all lines that are not
255+
* active code (ie. comments) are lost during that process.
256+
*
257+
* If you want to document things with comments or use constants add your settings
258+
* in a '<NAME>.config.php' file which will be included and rendered into this file.
259+
*
260+
* Example:
261+
* <?php
262+
* \$CONFIG = [];
263+
*
264+
* See also: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-merged-configuration-files
265+
*/
266+
267+
";
268+
$expected .= "\$CONFIG = array (\n 'foo' => 'bar',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
174269
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n 'php53' => 'totallyOutdated',\n 'CoolWebsites' => \n array (\n "
175270
. " 0 => 'demo.owncloud.org',\n 1 => 'owncloud.org',\n 2 => 'owncloud.com',\n ),\n);\n";
176271
$this->assertEquals($expected, file_get_contents($this->configFile));

0 commit comments

Comments
 (0)