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\Core\DB\DB;
|
|
|
|
use App\Core\Security;
|
|
|
|
use App\Entity\Note;
|
|
|
|
use App\Util\Common;
|
|
|
|
use App\Util\Exception\ClientException;
|
|
|
|
use App\Util\GNUsocialTestCase;
|
2021-12-29 13:34:20 +00:00
|
|
|
use Component\Feed\Controller\Feeds;
|
2021-05-23 20:56:45 +01:00
|
|
|
use Jchook\AssertThrows\AssertThrows;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
|
|
use Symfony\Component\Security\Core\Security as SSecurity;
|
|
|
|
|
2021-11-26 20:37:17 +00:00
|
|
|
class FeedsTest extends GNUsocialTestCase
|
2021-05-23 20:56:45 +01:00
|
|
|
{
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
|
2021-11-26 20:37:17 +00:00
|
|
|
public function testFeeds()
|
2021-05-23 20:56:45 +01:00
|
|
|
{
|
|
|
|
$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);
|
2021-11-26 20:37:17 +00:00
|
|
|
$feeds = new Feeds($req_stack);
|
2021-05-23 20:56:45 +01:00
|
|
|
if ($route == 'home') {
|
2021-12-23 13:27:31 +00:00
|
|
|
static::assertThrows(ClientException::class, fn () => $feeds->home($req));
|
2021-05-23 20:56:45 +01:00
|
|
|
}
|
2021-11-26 20:37:17 +00:00
|
|
|
$result = $feeds->{$route}($req, ...$extra_args);
|
2022-01-02 20:04:52 +00:00
|
|
|
static::assertSame($result['_template'], 'collection/notes.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-12-26 22:17:26 +00:00
|
|
|
$vis = $n->getScope();
|
2021-05-23 20:56:45 +01:00
|
|
|
static::assertTrue($visibility($vis));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|