APAnnounceStrategyTest.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Tests\Unit;
  3. use Tests\TestCase;
  4. use Illuminate\Foundation\Testing\WithFaker;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use App\Util\ActivityPub\Helpers;
  7. class APAnnounceStrategyTest extends TestCase
  8. {
  9. public function setUp(): void
  10. {
  11. parent::setUp();
  12. $this->invalid = [
  13. 'id' => 'test',
  14. 'type' => 'Announce',
  15. 'actor' => null,
  16. 'published' => '',
  17. 'to' => ['test'],
  18. 'cc' => 'test',
  19. 'object' => 'test'
  20. ];
  21. $this->mastodon = json_decode('{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":{"@id":"as:movedTo","@type":"@id"},"Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"featured":{"@id":"toot:featured","@type":"@id"},"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value"}],"id":"https://mastodon.social/users/dansup/statuses/100784657480587830/activity","type":"Announce","actor":"https://mastodon.social/users/dansup","published":"2018-09-25T05:03:49Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://pleroma.site/users/pixeldev","https://mastodon.social/users/dansup/followers"],"object":"https://pleroma.site/objects/68b5c876-f52b-4819-8d81-de6839d73fbc","atomUri":"https://mastodon.social/users/dansup/statuses/100784657480587830/activity"}', true);
  22. $this->pleroma = json_decode('{"@context":"https://www.w3.org/ns/activitystreams","actor":"https://pleroma.site/users/pixeldev","cc":["https://www.w3.org/ns/activitystreams#Public"],"context":"tag:mastodon.social,2018-10-14:objectId=59146153:objectType=Conversation","context_id":12325955,"id":"https://pleroma.site/activities/db2273eb-d504-4e3a-8f74-c343d069755a","object":"https://mastodon.social/users/dansup/statuses/100891324792793720","published":"2018-10-14T01:22:18.554227Z","to":["https://pleroma.site/users/pixeldev/followers","https://mastodon.social/users/dansup"],"type":"Announce"}', true);
  23. }
  24. public function testBasicValidation()
  25. {
  26. $this->assertFalse(Helpers::validateObject($this->invalid));
  27. }
  28. public function testMastodonValidation()
  29. {
  30. $this->assertTrue(Helpers::validateObject($this->mastodon));
  31. }
  32. public function testPleromaValidation()
  33. {
  34. $this->assertTrue(Helpers::validateObject($this->pleroma));
  35. }
  36. public function testMastodonAudienceScope()
  37. {
  38. $scope = Helpers::normalizeAudience($this->mastodon, false);
  39. $actual = [
  40. "to" => [],
  41. "cc" => [
  42. "https://pleroma.site/users/pixeldev",
  43. "https://mastodon.social/users/dansup/followers",
  44. ],
  45. "scope" => "public",
  46. ];
  47. $this->assertEquals($scope, $actual);
  48. }
  49. public function testPleromaAudienceScope()
  50. {
  51. $scope = Helpers::normalizeAudience($this->pleroma, false);
  52. $actual = [
  53. "to" => [
  54. "https://pleroma.site/users/pixeldev/followers",
  55. "https://mastodon.social/users/dansup",
  56. ],
  57. "cc" => [],
  58. "scope" => "unlisted",
  59. ];
  60. $this->assertEquals($scope, $actual);
  61. }
  62. public function testInvalidAudienceScope()
  63. {
  64. $scope = Helpers::normalizeAudience($this->invalid, false);
  65. $actual = [
  66. 'to' => [],
  67. 'cc' => [],
  68. 'scope' => 'private'
  69. ];
  70. $this->assertEquals($scope, $actual);
  71. }
  72. }