AdminTest.php 3.4 KB

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