You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
6.5 KiB

  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class ActivityStreamsTest extends PHPUnit_Framework_TestCase {
  5. private $http;
  6. public function setUp() {
  7. $this->client = new Parse();
  8. $this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
  9. $this->client->mc = null;
  10. }
  11. private function parse($params) {
  12. $request = new Request($params);
  13. $response = new Response();
  14. return $this->client->parse($request, $response);
  15. }
  16. public function testAuthorProfile() {
  17. $url = 'http://activitystreams.example/aaronpk';
  18. $response = $this->parse(['url' => $url]);
  19. $body = $response->getContent();
  20. $this->assertEquals(200, $response->getStatusCode());
  21. $data = json_decode($body, true);
  22. $this->assertEquals('activity+json', $data['source-format']);
  23. $this->assertEquals('card', $data['data']['type']);
  24. $this->assertEquals('aaronpk', $data['data']['name']);
  25. $this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['photo']);
  26. $this->assertEquals('https://aaronparecki.com/', $data['data']['url']);
  27. }
  28. public function testNoteWithTags() {
  29. $url = 'http://activitystreams.example/note.json';
  30. $response = $this->parse(['url' => $url]);
  31. $body = $response->getContent();
  32. $this->assertEquals(200, $response->getStatusCode());
  33. $data = json_decode($body, true);
  34. $this->assertEquals('activity+json', $data['source-format']);
  35. $this->assertEquals('note', $data['data']['post-type']);
  36. $this->assertEquals($url, $data['data']['url']);
  37. $this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
  38. $this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['content']['text']);
  39. $this->assertArrayNotHasKey('html', $data['data']['content']);
  40. $this->assertSame(['activitystreams'], $data['data']['category']);
  41. $this->assertEquals('aaronpk', $data['data']['author']['name']);
  42. $this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['author']['photo']);
  43. $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
  44. }
  45. public function testPhoto() {
  46. $url = 'http://activitystreams.example/photo.json';
  47. $response = $this->parse(['url' => $url]);
  48. $body = $response->getContent();
  49. $this->assertEquals(200, $response->getStatusCode());
  50. $data = json_decode($body, true);
  51. $this->assertEquals('activity+json', $data['source-format']);
  52. $this->assertEquals($url, $data['data']['url']);
  53. $this->assertEquals('photo', $data['data']['post-type']);
  54. $this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
  55. $this->assertEquals('This is the text content of an ActivityStreams photo', $data['data']['content']['text']);
  56. $this->assertArrayNotHasKey('html', $data['data']['content']);
  57. $this->assertSame(['activitystreams'], $data['data']['category']);
  58. $this->assertSame(['https://aaronparecki.com/2018/06/28/26/photo.jpg'], $data['data']['photo']);
  59. }
  60. public function testVideo() {
  61. $url = 'http://activitystreams.example/video.json';
  62. $response = $this->parse(['url' => $url]);
  63. $body = $response->getContent();
  64. $this->assertEquals(200, $response->getStatusCode());
  65. $data = json_decode($body, true);
  66. $this->assertEquals('activity+json', $data['source-format']);
  67. $this->assertEquals('video', $data['data']['post-type']);
  68. $this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
  69. $this->assertSame(['https://aaronparecki.com/2018/07/21/19/video.mp4'], $data['data']['video']);
  70. }
  71. public function testReply() {
  72. $url = 'http://activitystreams.example/reply.json';
  73. $response = $this->parse(['url' => $url]);
  74. $body = $response->getContent();
  75. $this->assertEquals(200, $response->getStatusCode());
  76. $data = json_decode($body, true);
  77. $this->assertEquals('activity+json', $data['source-format']);
  78. $this->assertEquals('reply', $data['data']['post-type']);
  79. $this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
  80. $this->assertArrayNotHasKey('category', $data['data']); // should not include the person-tag
  81. // For now, don't fetch the reply context
  82. $this->assertEquals(['http://activitystreams.example/note.json'], $data['data']['in-reply-to']);
  83. }
  84. public function testCustomEmoji() {
  85. $url = 'http://activitystreams.example/custom-emoji.json';
  86. $response = $this->parse(['url' => $url]);
  87. $body = $response->getContent();
  88. $this->assertEquals(200, $response->getStatusCode());
  89. $data = json_decode($body, true);
  90. $this->assertEquals('activity+json', $data['source-format']);
  91. $this->assertEquals('note', $data['data']['post-type']);
  92. $this->assertEquals("https://mastodon.social/@Gargron/100465999501820229", $data['data']['url']);
  93. $this->assertEquals('2018-07-30T22:24:54+00:00', $data['data']['published']);
  94. $this->assertEquals(':yikes:', $data['data']['content']['text']);
  95. $this->assertEquals('<p><img src="https://files.mastodon.social/custom_emojis/images/000/031/275/original/yikes.png" alt=":yikes:" title=":yikes:" height="24" class="xray-custom-emoji"></p>', $data['data']['content']['html']);
  96. $this->assertEquals('Eugen', $data['data']['author']['name']);
  97. $this->assertEquals('Gargron', $data['data']['author']['nickname']);
  98. $this->assertEquals('https://files.mastodon.social/accounts/avatars/000/000/001/original/eb9e00274b135808.png', $data['data']['author']['photo']);
  99. $this->assertEquals('https://mastodon.social/@Gargron', $data['data']['author']['url']);
  100. }
  101. public function testRelAlternatePriority() {
  102. $url = 'http://source.example.com/rel-alternate-as2';
  103. $response = $this->parse(['url' => $url]);
  104. $body = $response->getContent();
  105. $this->assertEquals(200, $response->getStatusCode());
  106. $data = json_decode($body, true);
  107. $this->assertEquals('activity+json', $data['source-format']);
  108. $this->assertEquals('http://activitystreams.example/note.json', $data['parsed-url']);
  109. $this->assertEquals('http://source.example.com/rel-alternate-as2', $data['url']);
  110. $this->assertEquals('note', $data['data']['post-type']);
  111. $this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
  112. $this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['content']['text']);
  113. $this->assertArrayNotHasKey('html', $data['data']['content']);
  114. $this->assertSame(['activitystreams'], $data['data']['category']);
  115. }
  116. }