NoteTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. namespace App\Tests\Entity;
  20. use App\Core\DB\DB;
  21. use App\Core\VisibilityScope;
  22. use App\Entity\Actor;
  23. use App\Entity\Note;
  24. use App\Util\GNUsocialTestCase;
  25. use Functional as F;
  26. use Jchook\AssertThrows\AssertThrows;
  27. class NoteTest extends GNUsocialTestCase
  28. {
  29. use AssertThrows;
  30. // public function testGetReplies()
  31. // {
  32. // $user = DB::findOneBy('local_user', ['nickname' => 'taken_user']);
  33. // $notes = DB::findBy('note', ['actor_id' => $user->getId(), 'content' => 'some content', 'reply_to' => null]);
  34. // dd($notes, F\map($notes, fn ($n) => $n->getReplies()), DB::dql('select n from note n'));
  35. // $note = DB::findOneBy('note', ['actor_id' => $user->getId(), 'content' => 'some content', 'reply_to' => null]);
  36. // $replies = $note->getReplies();
  37. // // dd($note, $replies);
  38. // static::assertSame('some other content', $replies[0]->getContent());
  39. // static::assertSame($user->getId(), $replies[0]->getActorId());
  40. // static::assertSame($note->getId(), $replies[0]->getReplyTo());
  41. // static::assertSame($user->getNickname(), $replies[0]->getReplyToNickname());
  42. // }
  43. public function testIsVisibleTo()
  44. {
  45. static::bootKernel();
  46. $actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']);
  47. $private_group = DB::findOneBy(Actor::class, ['nickname' => 'taken_private_group']);
  48. $private_group_member = DB::findOneBy(Actor::class, ['nickname' => 'some_user']);
  49. $public_group = DB::findOneBy(Actor::class, ['nickname' => 'taken_public_group']);
  50. $note_visible_to_1 = DB::findBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'private note', 'scope' => VisibilityScope::MESSAGE->value], limit: 1)[0];
  51. static::assertTrue($note_visible_to_1->isVisibleTo($actor));
  52. static::assertFalse($note_visible_to_1->isVisibleTo($private_group));
  53. static::assertFalse($note_visible_to_1->isVisibleTo($private_group_member));
  54. $note_public = DB::findBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'some other content'], limit: 1)[0];
  55. static::assertTrue($note_public->isVisibleTo($actor));
  56. static::assertTrue($note_public->isVisibleTo($private_group));
  57. static::assertTrue($note_public->isVisibleTo($private_group_member));
  58. $group_note = DB::findBy(Note::class, ['actor_id' => $actor->getId(), 'content' => 'group note private', 'scope' => VisibilityScope::GROUP->value], limit: 1)[0];
  59. static::assertTrue($group_note->isVisibleTo($private_group_member, in: $private_group));
  60. static::assertFalse($group_note->isVisibleTo($actor, in: $private_group));
  61. static::assertFalse($group_note->isVisibleTo($private_group, in: $private_group));
  62. }
  63. }