Skip to content

Commit 3f6d0c4

Browse files
authored
Merge pull request #59462 from Keeper-of-the-Keys/config-header-attempt-2
feat: add config header and tests.
2 parents c61b17f + 3f539d7 commit 3f6d0c4

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

lib/private/Config.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@
1616
*/
1717
class Config {
1818
public const ENV_PREFIX = 'NC_';
19+
public const CONF_WARNING = "
20+
/*
21+
* WARNING
22+
*
23+
* This file gets modified by automatic processes and all lines that are not
24+
* active code (ie. comments) are lost during that process.
25+
*
26+
* If you want to document things with comments or use constants add your settings
27+
* in a '<NAME>.config.php' file which will be included and rendered into this file.
28+
*
29+
* Example:
30+
* <?php
31+
* \$CONFIG = [];
32+
*
33+
* See also: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-merged-configuration-files
34+
*/
35+
";
1936

2037
protected array $cache = [];
2138
protected array $envCache = [];
@@ -269,6 +286,7 @@ private function writeData(): void {
269286

270287
// Create a php file ...
271288
$content = "<?php\n";
289+
$content .= self::CONF_WARNING;
272290
$content .= '$CONFIG = ';
273291
$content .= var_export(self::trustSystemConfig($this->cache), true);
274292
$content .= ";\n";

tests/lib/ConfigTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ 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\n";
101+
$expected .= \OC\Config::CONF_WARNING;
102+
$expected .= "\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
101103
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n);\n";
102104
$this->assertEquals($expected, $content);
103105

@@ -108,7 +110,9 @@ public function testSetValue(): void {
108110

109111
$content = file_get_contents($this->configFile);
110112

111-
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
113+
$expected = "<?php\n";
114+
$expected .= \OC\Config::CONF_WARNING;
115+
$expected .= "\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
112116
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n 'bar' => 'red',\n 'apps' => \n "
113117
. " array (\n 0 => 'files',\n 1 => 'gallery',\n ),\n);\n";
114118
$this->assertEquals($expected, $content);
@@ -139,7 +143,9 @@ public function testSetValues(): void {
139143
$this->assertSame(null, $config->getValue('not_exists'));
140144

141145
$content = file_get_contents($this->configFile);
142-
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
146+
$expected = "<?php\n";
147+
$expected .= \OC\Config::CONF_WARNING;
148+
$expected .= "\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
143149
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n);\n";
144150
$this->assertEquals($expected, $content);
145151
}
@@ -150,7 +156,9 @@ public function testDeleteKey(): void {
150156
$this->assertSame('this_was_clearly_not_set_before', $config->getValue('foo', 'this_was_clearly_not_set_before'));
151157
$content = file_get_contents($this->configFile);
152158

153-
$expected = "<?php\n\$CONFIG = array (\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
159+
$expected = "<?php\n";
160+
$expected .= \OC\Config::CONF_WARNING;
161+
$expected .= "\$CONFIG = array (\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
154162
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n);\n";
155163
$this->assertEquals($expected, $content);
156164
}
@@ -170,7 +178,9 @@ public function testConfigMerge(): void {
170178

171179
// Write a new value to the config
172180
$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 "
181+
$expected = "<?php\n";
182+
$expected .= \OC\Config::CONF_WARNING;
183+
$expected .= "\$CONFIG = array (\n 'foo' => 'bar',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n "
174184
. " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n 'php53' => 'totallyOutdated',\n 'CoolWebsites' => \n array (\n "
175185
. " 0 => 'demo.owncloud.org',\n 1 => 'owncloud.org',\n 2 => 'owncloud.com',\n ),\n);\n";
176186
$this->assertEquals($expected, file_get_contents($this->configFile));

0 commit comments

Comments
 (0)