NoteTest.php 2.9 KB

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