2021-08-19 01:28:26 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-08-19 01:28:26 +09: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/>.
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
namespace App\Tests\Entity;
|
|
|
|
|
2022-03-27 23:19:09 +09:00
|
|
|
use App\Core\DB;
|
2021-08-19 01:28:26 +09:00
|
|
|
use App\Core\VisibilityScope;
|
2022-03-08 10:46:50 +09:00
|
|
|
use App\Entity\Actor;
|
|
|
|
use App\Entity\Note;
|
2021-08-19 01:28:26 +09:00
|
|
|
use App\Util\GNUsocialTestCase;
|
2021-10-29 02:05:28 +09:00
|
|
|
use Functional as F;
|
2021-08-19 01:28:26 +09:00
|
|
|
use Jchook\AssertThrows\AssertThrows;
|
|
|
|
|
|
|
|
class NoteTest extends GNUsocialTestCase
|
|
|
|
{
|
|
|
|
use AssertThrows;
|
|
|
|
|
2021-10-29 02:05:28 +09:00
|
|
|
// public function testGetReplies()
|
|
|
|
// {
|
|
|
|
// $user = DB::findOneBy('local_user', ['nickname' => 'taken_user']);
|
|
|
|
// $notes = DB::findBy('note', ['actor_id' => $user->getId(), 'content' => 'some content', 'reply_to' => null]);
|
|
|
|
// dd($notes, F\map($notes, fn ($n) => $n->getReplies()), DB::dql('select n from note n'));
|
|
|
|
// $note = DB::findOneBy('note', ['actor_id' => $user->getId(), 'content' => 'some content', 'reply_to' => null]);
|
|
|
|
// $replies = $note->getReplies();
|
|
|
|
// // dd($note, $replies);
|
|
|
|
// static::assertSame('some other content', $replies[0]->getContent());
|
|
|
|
// static::assertSame($user->getId(), $replies[0]->getActorId());
|
|
|
|
// static::assertSame($note->getId(), $replies[0]->getReplyTo());
|
|
|
|
|
|
|
|
// static::assertSame($user->getNickname(), $replies[0]->getReplyToNickname());
|
|
|
|
// }
|
2021-08-19 01:28:26 +09:00
|
|
|
|
|
|
|
public function testIsVisibleTo()
|
|
|
|
{
|
2022-03-14 00:03:03 +09:00
|
|
|
static::bootKernel();
|
2022-10-29 02:49:03 +09:00
|
|
|
$actor = DB::findOneBy(Actor::class, ['nickname' => 'local_user_note_test']);
|
2022-03-08 10:46:50 +09:00
|
|
|
$private_group = DB::findOneBy(Actor::class, ['nickname' => 'taken_private_group']);
|
|
|
|
$private_group_member = DB::findOneBy(Actor::class, ['nickname' => 'some_user']);
|
|
|
|
$public_group = DB::findOneBy(Actor::class, ['nickname' => 'taken_public_group']);
|
2021-08-19 01:28:26 +09:00
|
|
|
|
2022-10-29 02:49:03 +09:00
|
|
|
$note_visible_to_1 = DB::findOneBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'message', 'scope' => VisibilityScope::MESSAGE->value]);
|
2022-03-14 00:03:03 +09:00
|
|
|
static::assertTrue($note_visible_to_1->isVisibleTo($actor));
|
2022-03-08 10:46:50 +09:00
|
|
|
static::assertFalse($note_visible_to_1->isVisibleTo($private_group));
|
|
|
|
static::assertFalse($note_visible_to_1->isVisibleTo($private_group_member));
|
2021-08-19 01:28:26 +09:00
|
|
|
|
2022-10-29 02:49:03 +09:00
|
|
|
$note_public = DB::findOneBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'some other content']);
|
2022-03-14 00:03:03 +09:00
|
|
|
static::assertTrue($note_public->isVisibleTo($actor));
|
2022-03-08 10:46:50 +09:00
|
|
|
static::assertTrue($note_public->isVisibleTo($private_group));
|
|
|
|
static::assertTrue($note_public->isVisibleTo($private_group_member));
|
2021-08-19 01:28:26 +09:00
|
|
|
|
2022-10-29 02:49:03 +09:00
|
|
|
$group_note = DB::findOneBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'group note private', 'scope' => VisibilityScope::GROUP->value]);
|
2022-03-14 00:03:03 +09:00
|
|
|
static::assertTrue($group_note->isVisibleTo($private_group_member, in: $private_group));
|
|
|
|
static::assertFalse($group_note->isVisibleTo($actor, in: $private_group));
|
2022-03-08 10:46:50 +09:00
|
|
|
static::assertFalse($group_note->isVisibleTo($private_group, in: $private_group));
|
2021-08-19 01:28:26 +09:00
|
|
|
}
|
|
|
|
}
|