ControllerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\GNUsocialTestCase;
  20. use Jchook\AssertThrows\AssertThrows;
  21. class ControllerTest extends GNUsocialTestCase
  22. {
  23. use AssertThrows;
  24. public function testJSONRequest()
  25. {
  26. // `server` will populate $_SERVER on the other side
  27. $client = static::createClient(options: [], server: ['HTTP_ACCEPT' => 'application/json']);
  28. $client->request('GET', '/main/all');
  29. $this->assertResponseIsSuccessful();
  30. $response = $client->getResponse();
  31. static::assertTrue($response->headers->contains('Content-Type', 'application/json'));
  32. static::assertJson($response->getContent());
  33. $json = json_decode($response->getContent(), associative: true);
  34. static::assertTrue(isset($json['notes']));
  35. static::assertTrue(isset($json['notes'][0]['note']));
  36. static::assertSame($json['notes'][0]['note']['content'], 'some content');
  37. }
  38. public function testUnsupported()
  39. {
  40. $client = static::createClient(options: [], server: ['HTTP_ACCEPT' => 'application/xml']);
  41. $client->request('GET', '/main/all');
  42. // $this->assertResponseStatusCodeSame(406);
  43. $this->assertSelectorTextContains('.stacktrace', 'ClientException');
  44. }
  45. }