. // }}} namespace App\Tests\Core; use App\Util\Common; use App\Util\Formatting; use App\Util\GNUsocialTestCase; use Jchook\AssertThrows\AssertThrows; class AdminTest extends GNUsocialTestCase { use AssertThrows; private function test(array $setting, callable $get_value) { $client = static::createClient(); copy(INSTALLDIR . '/social.local.yaml', INSTALLDIR . '/social.local.yaml.back'); $old = Common::config(...$setting); $value = $get_value(); $client->request('GET', '/panel'); $crawler = $client->submitForm('Set site setting', [ 'save_admin[setting]' => implode(':', $setting), // False gets converted to "", which HTTP doesn't send, so we get null on the other side 'save_admin[value]' => $value == false ? 'false' : Formatting::toString($value), ]); static::assertSame($value, Common::config(...$setting)); // $client->request('GET', '/panel'); $crawler = $client->submitForm('Set site setting', [ 'save_admin[setting]' => implode(':', $setting), 'save_admin[value]' => Formatting::toString($old), ]); static::assertSame($old, Common::config(...$setting)); rename(INSTALLDIR . '/social.local.yaml.back', INSTALLDIR . '/social.local.yaml'); } public function testSiteString() { $this->test(['attachments', 'dir'], fn () => Common::config('storage', 'dir') . 'foo' . DIRECTORY_SEPARATOR); } public function testSiteInt() { $this->test(['attachments', 'file_quota'], fn () => 8388608); // 1MB in bits } public function testSiteArray() { $this->test(['plugins', 'core'], fn () => ['some plugin', 'some other']); } public function testSiteBoolTrue() { $this->test(['attachments', 'uploads'], fn () => true); } public function testSiteBoolFalse() { $this->test(['attachments', 'uploads'], fn () => false); } public function testSiteInvalidSection() { $client = static::createClient(); $client->request('GET', '/panel'); $this->assertThrows(\InvalidArgumentException::class, fn () => $client->submitForm('Set site setting', [ 'save_admin[setting]' => 'invalid:section', 'save_admin[value]' => 'false', ])); } }