Files
timebank-cc-public/tests/Feature/PlatformConfigTemplatesTest.php
T

61 lines
2.1 KiB
PHP

<?php
namespace Tests\Feature;
use Tests\TestCase;
/**
* The platform config templates must offer the same settings.
*
* timebank-default.php.example is the starting point for a new installation. It once fell 53 keys
* behind timebank_cc.php.example, among them account_info.*_self / *_privileged: an installation
* set up from it hid balances from their own owners and from admins. New settings must be added
* to both templates.
*/
class PlatformConfigTemplatesTest extends TestCase
{
private function keys(string $file): array
{
return $this->flatten(require base_path("config/{$file}"));
}
/**
* Dotted paths of all leaves. A list (e.g. [1, 2, 3]) or an empty array is a value, not a branch.
*/
private function flatten(array $config, string $prefix = ''): array
{
$keys = [];
foreach ($config as $key => $value) {
$path = $prefix === '' ? (string) $key : "{$prefix}.{$key}";
if (is_array($value) && $value !== [] && !array_is_list($value)) {
$keys = array_merge($keys, $this->flatten($value, $path));
} else {
$keys[] = $path;
}
}
return $keys;
}
public function test_the_default_template_has_every_setting_of_the_timebank_cc_template(): void
{
$missing = array_diff($this->keys('timebank_cc.php.example'), $this->keys('timebank-default.php.example'));
$this->assertSame([], array_values($missing), 'Add these keys to config/timebank-default.php.example');
}
public function test_the_timebank_cc_template_has_every_setting_of_the_default_template(): void
{
$missing = array_diff($this->keys('timebank-default.php.example'), $this->keys('timebank_cc.php.example'));
$this->assertSame([], array_values($missing), 'Add these keys to config/timebank_cc.php.example');
}
public function test_the_default_template_does_not_carry_the_timebank_cc_brand(): void
{
$source = file_get_contents(base_path('config/timebank-default.php.example'));
$this->assertDoesNotMatchRegularExpression('/timebank\.cc/i', $source);
}
}