. namespace Tests\Unit; if (!defined('INSTALLDIR')) { define('INSTALLDIR', dirname(dirname(__DIR__))); } if (!defined('PUBLICDIR')) { define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public'); } if (!defined('GNUSOCIAL')) { define('GNUSOCIAL', true); } if (!defined('STATUSNET')) { // Compatibility define('STATUSNET', true); } use Activity; use ActivityObject; use DOMDocument; use PHPUnit\Framework\TestCase; require_once INSTALLDIR . '/lib/util/common.php'; final class UserFeedParseTest extends TestCase { public function testFeed1() { global $_testfeed1; $dom = new DOMDocument(); $dom->loadXML($_testfeed1); static::assertFalse(empty($dom)); $entries = $dom->getElementsByTagName('entry'); $entry1 = $entries->item(0); static::assertFalse(empty($entry1)); $feedEl = $dom->getElementsByTagName('feed')->item(0); static::assertFalse(empty($feedEl)); // Test actor (from activity:subject) $act1 = new Activity($entry1, $feedEl); static::assertFalse(empty($act1)); static::assertFalse(empty($act1->actor)); static::assertSame($act1->actor->type, ActivityObject::PERSON); static::assertSame($act1->actor->title, 'Zach Copley'); static::assertSame($act1->actor->id, 'http://localhost/statusnet/user/1'); static::assertSame($act1->actor->link, 'http://localhost/statusnet/zach'); $avatars = $act1->actor->avatarLinks; static::assertSame( $avatars[0]->url, 'http://localhost/statusnet/theme/default/default-avatar-profile.png' ); static::assertSame( $avatars[1]->url, 'http://localhost/statusnet/theme/default/default-avatar-stream.png' ); static::assertSame( $avatars[2]->url, 'http://localhost/statusnet/theme/default/default-avatar-mini.png' ); static::assertSame($act1->actor->displayName, 'Zach Copley'); $poco = $act1->actor->poco; static::assertSame($poco->preferredUsername, 'zach'); static::assertSame($poco->address->formatted, 'El Cerrito, CA'); static::assertSame($poco->urls[0]->type, 'homepage'); static::assertSame($poco->urls[0]->value, 'http://zach.copley.name'); static::assertSame($poco->urls[0]->primary, true); static::assertSame($poco->note, 'Zach Hack Attack'); // test the post //var_export($act1); static::assertSame($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note'); static::assertSame($act1->objects[0]->title, 'And now for something completely insane...'); static::assertSame($act1->objects[0]->content, 'And now for something completely insane...'); static::assertSame($act1->objects[0]->id, 'http://localhost/statusnet/notice/3'); } } $_testfeed1 = << http://localhost/statusnet/api/statuses/user_timeline/1.atom zach timeline Updates from zach on Zach Dev! http://localhost/statusnet/theme/default/default-avatar-profile.png 2010-03-04T01:41:14+00:00 zach http://localhost/statusnet/user/1 http://activitystrea.ms/schema/1.0/person http://localhost/statusnet/user/1 Zach Copley zach Zach Copley Zach Hack Attack El Cerrito, CA homepage http://zach.copley.name true And now for something completely insane... http://localhost/statusnet/notice/3 2010-03-04T01:41:07+00:00 2010-03-04T01:41:07+00:00 And now for something completely insane... TESTFEED1;