UserFeedParseTest.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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('GNUSOCIAL')) {
  21. define('GNUSOCIAL', true);
  22. }
  23. if (!defined('STATUSNET')) { // Compatibility
  24. define('STATUSNET', true);
  25. }
  26. use Activity;
  27. use ActivityObject;
  28. use DOMDocument;
  29. use PHPUnit\Framework\TestCase;
  30. require_once INSTALLDIR . '/lib/common.php';
  31. final class UserFeedParseTests extends TestCase
  32. {
  33. public function testFeed1()
  34. {
  35. global $_testfeed1;
  36. $dom = new DOMDocument();
  37. $dom->loadXML($_testfeed1);
  38. $this->assertFalse(empty($dom));
  39. $entries = $dom->getElementsByTagName('entry');
  40. $entry1 = $entries->item(0);
  41. $this->assertFalse(empty($entry1));
  42. $feedEl = $dom->getElementsByTagName('feed')->item(0);
  43. $this->assertFalse(empty($feedEl));
  44. // Test actor (from activity:subject)
  45. $act1 = new Activity($entry1, $feedEl);
  46. $this->assertFalse(empty($act1));
  47. $this->assertFalse(empty($act1->actor));
  48. $this->assertEquals($act1->actor->type, ActivityObject::PERSON);
  49. $this->assertEquals($act1->actor->title, 'Zach Copley');
  50. $this->assertEquals($act1->actor->id, 'http://localhost/statusnet/user/1');
  51. $this->assertEquals($act1->actor->link, 'http://localhost/statusnet/zach');
  52. $avatars = $act1->actor->avatarLinks;
  53. $this->assertEquals(
  54. $avatars[0]->url,
  55. 'http://localhost/statusnet/theme/default/default-avatar-profile.png'
  56. );
  57. $this->assertEquals(
  58. $avatars[1]->url,
  59. 'http://localhost/statusnet/theme/default/default-avatar-stream.png'
  60. );
  61. $this->assertEquals(
  62. $avatars[2]->url,
  63. 'http://localhost/statusnet/theme/default/default-avatar-mini.png'
  64. );
  65. $this->assertEquals($act1->actor->displayName, 'Zach Copley');
  66. $poco = $act1->actor->poco;
  67. $this->assertEquals($poco->preferredUsername, 'zach');
  68. $this->assertEquals($poco->address->formatted, 'El Cerrito, CA');
  69. $this->assertEquals($poco->urls[0]->type, 'homepage');
  70. $this->assertEquals($poco->urls[0]->value, 'http://zach.copley.name');
  71. $this->assertEquals($poco->urls[0]->primary, true);
  72. $this->assertEquals($poco->note, 'Zach Hack Attack');
  73. // test the post
  74. //var_export($act1);
  75. $this->assertEquals($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note');
  76. $this->assertEquals($act1->objects[0]->title, 'And now for something completely insane...');
  77. $this->assertEquals($act1->objects[0]->content, 'And now for something completely insane...');
  78. $this->assertEquals($act1->objects[0]->id, 'http://localhost/statusnet/notice/3');
  79. }
  80. }
  81. $_testfeed1 = <<<TESTFEED1
  82. <?xml version="1.0" encoding="UTF-8"?>
  83. <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">
  84. <id>http://localhost/statusnet/api/statuses/user_timeline/1.atom</id>
  85. <title>zach timeline</title>
  86. <subtitle>Updates from zach on Zach Dev!</subtitle>
  87. <logo>http://localhost/statusnet/theme/default/default-avatar-profile.png</logo>
  88. <updated>2010-03-04T01:41:14+00:00</updated>
  89. <author>
  90. <name>zach</name>
  91. <uri>http://localhost/statusnet/user/1</uri>
  92. </author>
  93. <link href="http://localhost/statusnet/zach" rel="alternate" type="text/html"/>
  94. <link href="http://localhost/statusnet/main/sup#1" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
  95. <link href="http://localhost/statusnet/main/push/hub" rel="hub"/>
  96. <link href="http://localhost/statusnet/main/salmon/user/1" rel="http://salmon-protocol.org/ns/salmon-replies"/>
  97. <link href="http://localhost/statusnet/main/salmon/user/1" rel="http://salmon-protocol.org/ns/salmon-mention"/>
  98. <link href="http://localhost/statusnet/api/statuses/user_timeline/1.atom" rel="self" type="application/atom+xml"/>
  99. <activity:subject>
  100. <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
  101. <id>http://localhost/statusnet/user/1</id>
  102. <title>Zach Copley</title>
  103. <link rel="alternate" type="text/html" href="http://localhost/statusnet/zach"/>
  104. <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://localhost/statusnet/theme/default/default-avatar-profile.png"/>
  105. <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://localhost/statusnet/theme/default/default-avatar-stream.png"/>
  106. <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://localhost/statusnet/theme/default/default-avatar-mini.png"/>
  107. <poco:preferredUsername>zach</poco:preferredUsername>
  108. <poco:displayName>Zach Copley</poco:displayName>
  109. <poco:note>Zach Hack Attack</poco:note>
  110. <poco:address>
  111. <poco:formatted>El Cerrito, CA</poco:formatted>
  112. </poco:address>
  113. <poco:urls>
  114. <poco:type>homepage</poco:type>
  115. <poco:value>http://zach.copley.name</poco:value>
  116. <poco:primary>true</poco:primary>
  117. </poco:urls>
  118. </activity:subject>
  119. <entry>
  120. <title>And now for something completely insane...</title>
  121. <link rel="alternate" type="text/html" href="http://localhost/statusnet/notice/3"/>
  122. <id>http://localhost/statusnet/notice/3</id>
  123. <published>2010-03-04T01:41:07+00:00</published>
  124. <updated>2010-03-04T01:41:07+00:00</updated>
  125. <link rel="ostatus:conversation" href="http://localhost/statusnet/conversation/3"/>
  126. <content type="html">And now for something completely insane...</content>
  127. </entry>
  128. </feed>
  129. TESTFEED1;