AdminTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // {{{ License
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. // }}}
  18. namespace App\Tests\Core;
  19. use App\Util\Common;
  20. use App\Util\Formatting;
  21. use App\Util\GNUsocialTestCase;
  22. use Jchook\AssertThrows\AssertThrows;
  23. class AdminTest extends GNUsocialTestCase
  24. {
  25. use AssertThrows;
  26. private function test(array $setting, callable $get_value)
  27. {
  28. $client = static::createClient();
  29. copy(INSTALLDIR . '/social.local.yaml', INSTALLDIR . '/social.local.yaml.back');
  30. $old = Common::config(...$setting);
  31. $value = $get_value();
  32. $client->request('GET', '/panel');
  33. $crawler = $client->submitForm('Set site setting', [
  34. 'save_admin[setting]' => implode(':', $setting),
  35. // False gets converted to "", which HTTP doesn't send, so we get null on the other side
  36. 'save_admin[value]' => $value == false ? 'false' : Formatting::toString($value),
  37. ]);
  38. static::assertSame($value, Common::config(...$setting));
  39. // $client->request('GET', '/panel');
  40. $crawler = $client->submitForm('Set site setting', [
  41. 'save_admin[setting]' => implode(':', $setting),
  42. 'save_admin[value]' => Formatting::toString($old),
  43. ]);
  44. static::assertSame($old, Common::config(...$setting));
  45. rename(INSTALLDIR . '/social.local.yaml.back', INSTALLDIR . '/social.local.yaml');
  46. }
  47. public function testSiteString()
  48. {
  49. $this->test(['attachments', 'dir'], fn () => Common::config('storage', 'dir') . 'foo' . DIRECTORY_SEPARATOR);
  50. }
  51. public function testSiteInt()
  52. {
  53. $this->test(['attachments', 'file_quota'], fn () => 8388608); // 1MB in bits
  54. }
  55. public function testSiteArray()
  56. {
  57. $this->test(['plugins', 'core'], fn () => ['some plugin', 'some other']);
  58. }
  59. public function testSiteBoolTrue()
  60. {
  61. $this->test(['attachments', 'uploads'], fn () => true);
  62. }
  63. public function testSiteBoolFalse()
  64. {
  65. $this->test(['attachments', 'uploads'], fn () => false);
  66. }
  67. public function testSiteInvalidSection()
  68. {
  69. $client = static::createClient();
  70. $client->request('GET', '/panel');
  71. $this->assertThrows(\InvalidArgumentException::class,
  72. fn () => $client->submitForm('Set site setting', [
  73. 'save_admin[setting]' => 'invalid:section',
  74. 'save_admin[value]' => 'false',
  75. ]));
  76. }
  77. }