UserFeedParseTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. namespace Tests\Unit;
  17. if (!defined('INSTALLDIR')) {
  18. define('INSTALLDIR', dirname(dirname(__DIR__)));
  19. }
  20. if (!defined('PUBLICDIR')) {
  21. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  22. }
  23. if (!defined('GNUSOCIAL')) {
  24. define('GNUSOCIAL', true);
  25. }
  26. if (!defined('STATUSNET')) { // Compatibility
  27. define('STATUSNET', true);
  28. }
  29. use Activity;
  30. use ActivityObject;
  31. use DOMDocument;
  32. use PHPUnit\Framework\TestCase;
  33. require_once INSTALLDIR . '/lib/util/common.php';
  34. final class UserFeedParseTests extends TestCase
  35. {
  36. public function testFeed1()
  37. {
  38. global $_testfeed1;
  39. $dom = new DOMDocument();
  40. $dom->loadXML($_testfeed1);
  41. $this->assertFalse(empty($dom));
  42. $entries = $dom->getElementsByTagName('entry');
  43. $entry1 = $entries->item(0);
  44. $this->assertFalse(empty($entry1));
  45. $feedEl = $dom->getElementsByTagName('feed')->item(0);
  46. $this->assertFalse(empty($feedEl));
  47. // Test actor (from activity:subject)
  48. $act1 = new Activity($entry1, $feedEl);
  49. $this->assertFalse(empty($act1));
  50. $this->assertFalse(empty($act1->actor));
  51. $this->assertEquals($act1->actor->type, ActivityObject::PERSON);
  52. $this->assertEquals($act1->actor->title, 'Zach Copley');
  53. $this->assertEquals($act1->actor->id, 'http://localhost/statusnet/user/1');
  54. $this->assertEquals($act1->actor->link, 'http://localhost/statusnet/zach');
  55. $avatars = $act1->actor->avatarLinks;
  56. $this->assertEquals(
  57. $avatars[0]->url,
  58. 'http://localhost/statusnet/theme/default/default-avatar-profile.png'
  59. );
  60. $this->assertEquals(
  61. $avatars[1]->url,
  62. 'http://localhost/statusnet/theme/default/default-avatar-stream.png'
  63. );
  64. $this->assertEquals(
  65. $avatars[2]->url,
  66. 'http://localhost/statusnet/theme/default/default-avatar-mini.png'
  67. );
  68. $this->assertEquals($act1->actor->displayName, 'Zach Copley');
  69. $poco = $act1->actor->poco;
  70. $this->assertEquals($poco->preferredUsername, 'zach');
  71. $this->assertEquals($poco->address->formatted, 'El Cerrito, CA');
  72. $this->assertEquals($poco->urls[0]->type, 'homepage');
  73. $this->assertEquals($poco->urls[0]->value, 'http://zach.copley.name');
  74. $this->assertEquals($poco->urls[0]->primary, true);
  75. $this->assertEquals($poco->note, 'Zach Hack Attack');
  76. // test the post
  77. //var_export($act1);
  78. $this->assertEquals($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note');
  79. $this->assertEquals($act1->objects[0]->title, 'And now for something completely insane...');
  80. $this->assertEquals($act1->objects[0]->content, 'And now for something completely insane...');
  81. $this->assertEquals($act1->objects[0]->id, 'http://localhost/statusnet/notice/3');
  82. }
  83. }
  84. $_testfeed1 = <<<TESTFEED1
  85. <?xml version="1.0" encoding="UTF-8"?>
  86. <feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
  87. <id>http://localhost/statusnet/api/statuses/user_timeline/1.atom</id>
  88. <title>zach timeline</title>
  89. <subtitle>Updates from zach on Zach Dev!</subtitle>
  90. <logo>http://localhost/statusnet/theme/default/default-avatar-profile.png</logo>
  91. <updated>2010-03-04T01:41:14+00:00</updated>
  92. <author>
  93. <name>zach</name>
  94. <uri>http://localhost/statusnet/user/1</uri>
  95. </author>
  96. <link href="http://localhost/statusnet/zach" rel="alternate" type="text/html"/>
  97. <link href="http://localhost/statusnet/main/sup#1" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
  98. <link href="http://localhost/statusnet/main/push/hub" rel="hub"/>
  99. <link href="http://localhost/statusnet/main/salmon/user/1" rel="http://salmon-protocol.org/ns/salmon-replies"/>
  100. <link href="http://localhost/statusnet/main/salmon/user/1" rel="http://salmon-protocol.org/ns/salmon-mention"/>
  101. <link href="http://localhost/statusnet/api/statuses/user_timeline/1.atom" rel="self" type="application/atom+xml"/>
  102. <activity:subject>
  103. <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
  104. <id>http://localhost/statusnet/user/1</id>
  105. <title>Zach Copley</title>
  106. <link rel="alternate" type="text/html" href="http://localhost/statusnet/zach"/>
  107. <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://localhost/statusnet/theme/default/default-avatar-profile.png"/>
  108. <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://localhost/statusnet/theme/default/default-avatar-stream.png"/>
  109. <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://localhost/statusnet/theme/default/default-avatar-mini.png"/>
  110. <poco:preferredUsername>zach</poco:preferredUsername>
  111. <poco:displayName>Zach Copley</poco:displayName>
  112. <poco:note>Zach Hack Attack</poco:note>
  113. <poco:address>
  114. <poco:formatted>El Cerrito, CA</poco:formatted>
  115. </poco:address>
  116. <poco:urls>
  117. <poco:type>homepage</poco:type>
  118. <poco:value>http://zach.copley.name</poco:value>
  119. <poco:primary>true</poco:primary>
  120. </poco:urls>
  121. </activity:subject>
  122. <entry>
  123. <title>And now for something completely insane...</title>
  124. <link rel="alternate" type="text/html" href="http://localhost/statusnet/notice/3"/>
  125. <id>http://localhost/statusnet/notice/3</id>
  126. <published>2010-03-04T01:41:07+00:00</published>
  127. <updated>2010-03-04T01:41:07+00:00</updated>
  128. <link rel="ostatus:conversation" href="http://localhost/statusnet/conversation/3"/>
  129. <content type="html">And now for something completely insane...</content>
  130. </entry>
  131. </feed>
  132. TESTFEED1;