[EVENTS] Change FormatNoteList do separate in and out arguments
This is necessary due to some weird problem which I wasn't able to figure out (but which doesn't matter) that somehow causes the event to be called twice during testing, and thus the function was exploding
This commit is contained in:
parent
57f43108bb
commit
061a85d6b3
|
@ -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',
|
||||
|
|
|
@ -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)];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
43
tests/Core/ControllerTest.php
Normal file
43
tests/Core/ControllerTest.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
// {{{ License
|
||||
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// GNU social is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// }}}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user