diff --git a/plugins/Favourite/Controller/Favourite.php b/plugins/Favourite/Controller/Favourite.php index a7b8e0b5ee..b842bc1f8f 100644 --- a/plugins/Favourite/Controller/Favourite.php +++ b/plugins/Favourite/Controller/Favourite.php @@ -35,11 +35,11 @@ class Favourite 'where f.gsactor_id = :id ' . 'order by f.created DESC', ['id' => $actor_id]); - Event::handle('FormatNoteList', [&$notes]); + Event::handle('FormatNoteList', [$notes, &$note_out]); return [ '_template' => 'network/public.html.twig', - 'notes' => $notes, + 'notes' => $notes_out, ]; } @@ -62,7 +62,7 @@ class Favourite 'order by f.created DESC' , ['id' => $actor_id]); - Event::handle('FormatNoteList', [&$notes]); + Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/reversefavs.html.twig', diff --git a/plugins/TreeNotes/TreeNotes.php b/plugins/TreeNotes/TreeNotes.php index 1d8c1aba93..249a36b1d7 100644 --- a/plugins/TreeNotes/TreeNotes.php +++ b/plugins/TreeNotes/TreeNotes.php @@ -27,10 +27,10 @@ class TreeNotes extends Plugin /** * Format the given $notes_in_trees_out in a list of reply trees */ - public function onFormatNoteList(array &$notes_in_trees_out) + public function onFormatNoteList(array $notes_in, ?array &$notes_out) { - $roots = array_filter($notes_in_trees_out, function (Note $note) { return $note->getReplyTo() == null; }, ARRAY_FILTER_USE_BOTH); - $notes_in_trees_out = $this->build_tree($roots, $notes_in_trees_out); + $roots = array_filter($notes_in, function (Note $note) { return $note->getReplyTo() == null; }); + $notes_out = $this->build_tree($roots, $notes_in); } private function build_tree(array $parents, array $notes) @@ -44,7 +44,7 @@ class TreeNotes extends Plugin private function build_subtree(Note $parent, array $notes) { - $children = array_filter($notes, function (Note $n) use ($parent) { return $parent->getId() == $n->getReplyTo(); }, ARRAY_FILTER_USE_BOTH); + $children = array_filter($notes, function (Note $n) use ($parent) { return $parent->getId() == $n->getReplyTo(); }); return ['note' => $parent, 'replies' => $this->build_tree($children, $notes)]; } } diff --git a/src/Controller/Network.php b/src/Controller/Network.php index e16c0fa34b..7f4adecccc 100644 --- a/src/Controller/Network.php +++ b/src/Controller/Network.php @@ -56,11 +56,11 @@ class Network extends Controller { $notes = Note::getAllNotes($this->instance_scope); - Event::handle('FormatNoteList', [&$notes]); + Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/public.html.twig', - 'notes' => $notes, + 'notes' => $notes_out, ]; } @@ -98,11 +98,11 @@ class Network extends Controller END; $notes = DB::sql($query, ['note' => 'App\Entity\Note'], ['target_actor_id' => $target->getId()]); - Event::handle('FormatNoteList', [&$notes]); + Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/public.html.twig', - 'notes' => $notes, + 'notes' => $notes_out, ]; } @@ -110,11 +110,11 @@ END; { $notes = Note::getAllNotes($this->public_scope); - Event::handle('FormatNoteList', [&$notes]); + Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/public.html.twig', - 'notes' => $notes, + 'notes' => $notes_out, ]; } @@ -125,11 +125,11 @@ END; 'where n.reply_to is not null and n.gsactor_id = :id ' . 'order by n.created DESC', ['id' => $actor_id]); - Event::handle('FormatNoteList', [&$notes]); + Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'network/public.html.twig', - 'notes' => $notes, + 'notes' => $notes_out, ]; } } diff --git a/tests/Core/ControllerTest.php b/tests/Core/ControllerTest.php new file mode 100644 index 0000000000..1d34550a76 --- /dev/null +++ b/tests/Core/ControllerTest.php @@ -0,0 +1,43 @@ +. + +// }}} + +namespace App\Tests\Core; + +use App\Util\GNUsocialTestCase; +use Jchook\AssertThrows\AssertThrows; + +class ControllerTest extends GNUsocialTestCase +{ + use AssertThrows; + + public function testJSONRequest() + { + // `server` will populate $_SERVER on the other side + $client = static::createClient(options: [], server: ['HTTP_ACCEPT' => 'application/json']); + $client->request('GET', '/main/all'); + $this->assertResponseIsSuccessful(); + $response = $client->getResponse(); + static::assertTrue($response->headers->contains('Content-Type', 'application/json')); + static::assertJson($response->getContent()); + $json = json_decode($response->getContent(), associative: true); + dd($json); + } +}