2021-05-23 20:56:45 +01:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-05-23 20:56:45 +01:00
|
|
|
// {{{ 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/>.
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2021-11-15 19:27:39 +00:00
|
|
|
namespace App\Tests\Controller;
|
2021-05-23 20:56:45 +01:00
|
|
|
|
|
|
|
use App\Controller\Network;
|
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Core\Security;
|
|
|
|
use App\Core\VisibilityScope;
|
|
|
|
use App\Entity\Note;
|
|
|
|
use App\Util\Common;
|
|
|
|
use App\Util\Exception\ClientException;
|
|
|
|
use App\Util\GNUsocialTestCase;
|
|
|
|
use Jchook\AssertThrows\AssertThrows;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
|
|
use Symfony\Component\Security\Core\Security as SSecurity;
|
|
|
|
|
|
|
|
class NetworkTest extends GNUsocialTestCase
|
|
|
|
{
|
|
|
|
use AssertThrows;
|
|
|
|
|
|
|
|
public function testPublic()
|
|
|
|
{
|
|
|
|
$this->testRoute('public', fn ($vis) => $vis->public || $vis->site);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHome()
|
|
|
|
{
|
|
|
|
$this->testRoute('home', fn ($vis) => !$vis->message, ['taken_user']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNetwork()
|
|
|
|
{
|
|
|
|
$this->testRoute('network', fn ($vis) => $vis->public);
|
|
|
|
}
|
|
|
|
|
2021-11-15 19:27:39 +00:00
|
|
|
// TODO replies, re-enable
|
|
|
|
// public function testReplies()
|
|
|
|
// {
|
|
|
|
// $this->testRoute('replies', fn ($vis) => $vis->public, [], function () {
|
|
|
|
// $user = DB::findOneBy('local_user', ['nickname' => 'taken_user']);
|
|
|
|
// $sec = $this->getMockBuilder(SSecurity::class)->setConstructorArgs([self::$kernel->getContainer()])->getMock();
|
|
|
|
// $sec->method('getUser')->willReturn($user);
|
|
|
|
// Security::setHelper($sec, null);
|
|
|
|
// });
|
|
|
|
// }
|
2021-05-23 20:56:45 +01:00
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
private function testRoute(string $route, callable $visibility, array $extra_args = [], ?callable $setup_login = null)
|
2021-05-23 20:56:45 +01:00
|
|
|
{
|
|
|
|
parent::bootKernel();
|
2021-10-10 09:26:18 +01:00
|
|
|
if (!\is_null($setup_login)) {
|
2021-05-23 20:56:45 +01:00
|
|
|
$setup_login();
|
|
|
|
}
|
|
|
|
$req = $this->createMock(Request::class);
|
|
|
|
$req_stack = $this->createMock(RequestStack::class);
|
|
|
|
$network = new Network($req_stack);
|
|
|
|
if ($route == 'home') {
|
|
|
|
static::assertThrows(ClientException::class, fn () => $network->home($req, 'username_not_taken'));
|
|
|
|
}
|
|
|
|
$result = $network->{$route}($req, ...$extra_args);
|
2021-11-15 19:27:39 +00:00
|
|
|
static::assertSame($result['_template'], 'network/feed.html.twig');
|
2021-05-23 20:56:45 +01:00
|
|
|
foreach ($result['notes'] as $n) {
|
2021-10-10 09:26:18 +01:00
|
|
|
static::assertIsArray($n['replies']);
|
2021-05-23 20:56:45 +01:00
|
|
|
}
|
|
|
|
$notes = Common::flattenNoteArray($result['notes']);
|
|
|
|
foreach ($notes as $n) {
|
2021-10-10 09:26:18 +01:00
|
|
|
static::assertTrue(\get_class($n) == Note::class);
|
2021-05-23 20:56:45 +01:00
|
|
|
$vis = VisibilityScope::create($n->getScope());
|
|
|
|
static::assertTrue($visibility($vis));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|