UserFeedParseTest.php 5.6 KB

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