| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  | use Activity; | 
					
						
							|  |  |  | use ActivityObject; | 
					
						
							|  |  |  | use ActivityUtils; | 
					
						
							|  |  |  | use ActivityVerb; | 
					
						
							|  |  |  | use Conversation; | 
					
						
							|  |  |  | use DOMDocument; | 
					
						
							|  |  |  | use Exception; | 
					
						
							|  |  |  | use Notice; | 
					
						
							|  |  |  | use PHPUnit\Framework\TestCase; | 
					
						
							|  |  |  | use User; | 
					
						
							|  |  |  | use User_group; | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | require_once INSTALLDIR . '/lib/common.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  | final class ActivityGenerationTests extends TestCase | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |     static $author1 = null; | 
					
						
							|  |  |  |     static $author2 = null; | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |     static $targetUser1 = null; | 
					
						
							|  |  |  |     static $targetUser2 = null; | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |     static $targetGroup1 = null; | 
					
						
							|  |  |  |     static $targetGroup2 = null; | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 01:29:20 +01:00
										 |  |  |     public static function setUpBeforeClass(): void | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-10-21 13:20:30 +02:00
										 |  |  |         $authorNick1 = 'activitygenerationtestsuser' . common_random_hexstr(4); | 
					
						
							|  |  |  |         $authorNick2 = 'activitygenerationtestsuser' . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 13:20:30 +02:00
										 |  |  |         $targetNick1 = 'activitygenerationteststarget' . common_random_hexstr(4); | 
					
						
							|  |  |  |         $targetNick2 = 'activitygenerationteststarget' . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 13:20:30 +02:00
										 |  |  |         $groupNick1 = 'activitygenerationtestsgroup' . common_random_hexstr(4); | 
					
						
							|  |  |  |         $groupNick2 = 'activitygenerationtestsgroup' . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |         try { | 
					
						
							|  |  |  |             self::$author1 = User::register(array('nickname' => $authorNick1, | 
					
						
							|  |  |  |                 'email' => $authorNick1 . '@example.net', | 
					
						
							|  |  |  |                 'email_confirmed' => true)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             self::$author2 = User::register(array('nickname' => $authorNick2, | 
					
						
							|  |  |  |                 'email' => $authorNick2 . '@example.net', | 
					
						
							|  |  |  |                 'email_confirmed' => true)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             self::$targetUser1 = User::register(array('nickname' => $targetNick1, | 
					
						
							|  |  |  |                 'email' => $targetNick1 . '@example.net', | 
					
						
							|  |  |  |                 'email_confirmed' => true)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             self::$targetUser2 = User::register(array('nickname' => $targetNick2, | 
					
						
							|  |  |  |                 'email' => $targetNick2 . '@example.net', | 
					
						
							|  |  |  |                 'email_confirmed' => true)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             self::$targetGroup1 = User_group::register(array('nickname' => $groupNick1, | 
					
						
							|  |  |  |                 'userid' => self::$author1->id, | 
					
						
							|  |  |  |                 'aliases' => array(), | 
					
						
							|  |  |  |                 'local' => true, | 
					
						
							|  |  |  |                 'location' => null, | 
					
						
							|  |  |  |                 'description' => null, | 
					
						
							|  |  |  |                 'fullname' => null, | 
					
						
							|  |  |  |                 'homepage' => null, | 
					
						
							|  |  |  |                 'mainpage' => null)); | 
					
						
							|  |  |  |             self::$targetGroup2 = User_group::register(array('nickname' => $groupNick2, | 
					
						
							|  |  |  |                 'userid' => self::$author1->id, | 
					
						
							|  |  |  |                 'aliases' => array(), | 
					
						
							|  |  |  |                 'local' => true, | 
					
						
							|  |  |  |                 'location' => null, | 
					
						
							|  |  |  |                 'description' => null, | 
					
						
							|  |  |  |                 'fullname' => null, | 
					
						
							|  |  |  |                 'homepage' => null, | 
					
						
							|  |  |  |                 'mainpage' => null)); | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         } catch (Exception $e) { | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             self::tearDownAfterClass(); | 
					
						
							|  |  |  |             throw $e; | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testBasicNoticeActivity() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-28 14:08:42 +02:00
										 |  |  |         $this->assertEquals($notice->getUri(), ActivityUtils::childContent($element, 'id')); | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |         $this->assertEquals('New note by ' . self::$author1->nickname, ActivityUtils::childContent($element, 'title')); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |         $this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content')); | 
					
						
							|  |  |  |         $this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published'))); | 
					
						
							|  |  |  |         $this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated'))); | 
					
						
							|  |  |  |         $this->assertEquals(ActivityVerb::POST, ActivityUtils::childContent($element, 'verb', Activity::SPEC)); | 
					
						
							|  |  |  |         $this->assertEquals(ActivityObject::NOTE, ActivityUtils::childContent($element, 'object-type', Activity::SPEC)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testNamespaceFlag() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertTrue($element->hasAttribute('xmlns')); | 
					
						
							|  |  |  |         $this->assertTrue($element->hasAttribute('xmlns:thr')); | 
					
						
							|  |  |  |         $this->assertTrue($element->hasAttribute('xmlns:georss')); | 
					
						
							|  |  |  |         $this->assertTrue($element->hasAttribute('xmlns:activity')); | 
					
						
							|  |  |  |         $this->assertTrue($element->hasAttribute('xmlns:media')); | 
					
						
							|  |  |  |         $this->assertTrue($element->hasAttribute('xmlns:poco')); | 
					
						
							|  |  |  |         $this->assertTrue($element->hasAttribute('xmlns:ostatus')); | 
					
						
							|  |  |  |         $this->assertTrue($element->hasAttribute('xmlns:statusnet')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertFalse($element->hasAttribute('xmlns')); | 
					
						
							|  |  |  |         $this->assertFalse($element->hasAttribute('xmlns:thr')); | 
					
						
							|  |  |  |         $this->assertFalse($element->hasAttribute('xmlns:georss')); | 
					
						
							|  |  |  |         $this->assertFalse($element->hasAttribute('xmlns:activity')); | 
					
						
							|  |  |  |         $this->assertFalse($element->hasAttribute('xmlns:media')); | 
					
						
							|  |  |  |         $this->assertFalse($element->hasAttribute('xmlns:poco')); | 
					
						
							|  |  |  |         $this->assertFalse($element->hasAttribute('xmlns:ostatus')); | 
					
						
							|  |  |  |         $this->assertFalse($element->hasAttribute('xmlns:statusnet')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     public function testSourceFlag() | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Test with no source
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(false, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $source = ActivityUtils::child($element, 'source'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertNull($source); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Test with source
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(false, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $source = ActivityUtils::child($element, 'source'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertNotNull($source); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     public function testSourceContent() | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  |         // make a time difference!
 | 
					
						
							|  |  |  |         sleep(2); | 
					
						
							|  |  |  |         $notice2 = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(false, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $source = ActivityUtils::child($element, 'source'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $atomUrl = common_local_url('ApiTimelineUser', array('id' => self::$author1->id, 'format' => 'atom')); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $profile = self::$author1->getProfile(); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->assertEquals($atomUrl, ActivityUtils::childContent($source, 'id')); | 
					
						
							|  |  |  |         $this->assertEquals($atomUrl, ActivityUtils::getLink($source, 'self', 'application/atom+xml')); | 
					
						
							|  |  |  |         $this->assertEquals($profile->profileurl, ActivityUtils::getPermalink($source)); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:49:49 -07:00
										 |  |  |         $this->assertEquals(strtotime($notice2->created), strtotime(ActivityUtils::childContent($source, 'updated'))); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         // XXX: do we care here?
 | 
					
						
							|  |  |  |         $this->assertFalse(is_null(ActivityUtils::childContent($source, 'title'))); | 
					
						
							|  |  |  |         $this->assertEquals(common_config('license', 'url'), ActivityUtils::getLink($source, 'license')); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     public function testAuthorFlag() | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Test with no author
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(false, false, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertNull(ActivityUtils::child($element, 'author')); | 
					
						
							|  |  |  |         $this->assertNull(ActivityUtils::child($element, 'actor', Activity::SPEC)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Test with source
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(false, false, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $author = ActivityUtils::child($element, 'author'); | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |         $actor = ActivityUtils::child($element, 'actor', Activity::SPEC); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->assertFalse(is_null($author)); | 
					
						
							| 
									
										
										
										
											2010-12-30 13:21:59 -08:00
										 |  |  |         $this->assertTrue(is_null($actor)); // <activity:actor> is obsolete, no longer added
 | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  |     public function testAuthorContent() | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Test with author
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(false, false, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $author = ActivityUtils::child($element, 'author'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $this->assertEquals(self::$author1->getNickname(), ActivityUtils::childContent($author, 'name')); | 
					
						
							|  |  |  |         $this->assertEquals(self::$author1->getUri(), ActivityUtils::childContent($author, 'uri')); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-30 13:21:59 -08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * We no longer create <activity:actor> entries, they have merged to <atom:author> | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-08-03 15:49:49 -07:00
										 |  |  |     public function testActorContent() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Test with author
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(false, false, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $actor = ActivityUtils::child($element, 'actor', Activity::SPEC); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-30 13:21:59 -08:00
										 |  |  |         $this->assertEquals($actor, null); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:49:49 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     public function testReplyLink() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $orig = $this->_fakeNotice(self::$targetUser1); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id)); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $reply->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $irt = ActivityUtils::child($element, 'in-reply-to', 'http://purl.org/syndication/thread/1.0'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertNotNull($irt); | 
					
						
							| 
									
										
										
										
											2014-04-28 14:08:42 +02:00
										 |  |  |         $this->assertEquals($orig->getUri(), $irt->getAttribute('ref')); | 
					
						
							|  |  |  |         $this->assertEquals($orig->getUrl(), $irt->getAttribute('href')); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testReplyAttention() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $orig = $this->_fakeNotice(self::$targetUser1); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id)); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $reply->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $this->assertEquals(self::$targetUser1->getUri(), ActivityUtils::getLink($element, 'mentioned')); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testMultipleReplyAttention() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $orig = $this->_fakeNotice(self::$targetUser1); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $reply = Notice::saveNew(self::$targetUser2->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id)); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $text = "@" . self::$targetUser1->nickname . " @" . self::$targetUser2->nickname . " reply text " . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $reply2 = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $reply->id)); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $reply2->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 18:42:15 +02:00
										 |  |  |         $links = ActivityUtils::getLinks($element, 'mentioned'); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 16:04:19 -07:00
										 |  |  |         $hrefs = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach ($links as $link) { | 
					
						
							|  |  |  |             $hrefs[] = $link->getAttribute('href'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $this->assertTrue(in_array(self::$targetUser1->getUri(), $hrefs)); | 
					
						
							|  |  |  |         $this->assertTrue(in_array(self::$targetUser2->getUri(), $hrefs)); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGroupPostAttention() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $text = "!" . self::$targetGroup1->nickname . " reply text " . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $notice = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null)); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $this->assertEquals(self::$targetGroup1->getUri(), ActivityUtils::getLink($element, 'mentioned')); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testMultipleGroupPostAttention() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $text = "!" . self::$targetGroup1->nickname . " !" . self::$targetGroup2->nickname . " reply text " . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $notice = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null)); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 18:42:15 +02:00
										 |  |  |         $links = ActivityUtils::getLinks($element, 'mentioned'); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $hrefs = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach ($links as $link) { | 
					
						
							|  |  |  |             $hrefs[] = $link->getAttribute('href'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $this->assertTrue(in_array(self::$targetGroup1->getUri(), $hrefs)); | 
					
						
							|  |  |  |         $this->assertTrue(in_array(self::$targetGroup2->getUri(), $hrefs)); | 
					
						
							| 
									
										
										
										
											2010-08-03 16:04:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testRepeatLink() | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $notice = $this->_fakeNotice(self::$author1); | 
					
						
							|  |  |  |         $repeat = $notice->repeat(self::$author2->getProfile(), 'test'); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $repeat->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/'); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $this->assertNotNull($noticeInfo); | 
					
						
							|  |  |  |         $this->assertEquals($notice->id, $noticeInfo->getAttribute('repeat_of')); | 
					
						
							|  |  |  |         $this->assertEquals($repeat->id, $noticeInfo->getAttribute('local_id')); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testTag() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-10-21 13:20:30 +02:00
										 |  |  |         $tag1 = common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $notice = $this->_fakeNotice(self::$author1, '#' . $tag1); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $category = ActivityUtils::child($element, 'category'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertNotNull($category); | 
					
						
							|  |  |  |         $this->assertEquals($tag1, $category->getAttribute('term')); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  |     public function testMultiTag() | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-10-21 13:20:30 +02:00
										 |  |  |         $tag1 = common_random_hexstr(4); | 
					
						
							|  |  |  |         $tag2 = common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $notice = $this->_fakeNotice(self::$author1, '#' . $tag1 . ' #' . $tag2); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $categories = $element->getElementsByTagName('category'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertNotNull($categories); | 
					
						
							|  |  |  |         $this->assertEquals(2, $categories->length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $terms = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for ($i = 0; $i < $categories->length; $i++) { | 
					
						
							|  |  |  |             $cat = $categories->item($i); | 
					
						
							|  |  |  |             $terms[] = $cat->getAttribute('term'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertTrue(in_array($tag1, $terms)); | 
					
						
							|  |  |  |         $this->assertTrue(in_array($tag2, $terms)); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGeotaggedActivity() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $notice = Notice::saveNew(self::$author1->id, common_random_hexstr(4), 'test', array('uri' => null, 'lat' => 45.5, 'lon' => -73.6)); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $this->assertEquals('45.5000000 -73.6000000', ActivityUtils::childContent($element, 'point', "http://www.georss.org/georss")); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     public function testNoticeInfo() | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $entry = $notice->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertEquals($notice->id, $noticeInfo->getAttribute('local_id')); | 
					
						
							|  |  |  |         $this->assertEquals($notice->source, $noticeInfo->getAttribute('source')); | 
					
						
							|  |  |  |         $this->assertEquals('', $noticeInfo->getAttribute('repeat_of')); | 
					
						
							|  |  |  |         $this->assertEquals('', $noticeInfo->getAttribute('repeated')); | 
					
						
							| 
									
										
										
										
											2014-06-28 13:11:03 +02:00
										 |  |  | //        $this->assertEquals('', $noticeInfo->getAttribute('favorite'));
 | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  |         $this->assertEquals('', $noticeInfo->getAttribute('source_link')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testNoticeInfoRepeatOf() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $repeat = $notice->repeat(self::$author2->getProfile(), 'test'); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $repeat->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertEquals($notice->id, $noticeInfo->getAttribute('repeat_of')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testNoticeInfoRepeated() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $notice = $this->_fakeNotice(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $repeat = $notice->repeat(self::$author2->getProfile(), 'test'); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $entry = $notice->asAtomEntry(false, false, false, self::$author2->getProfile()); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertEquals('true', $noticeInfo->getAttribute('repeated')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $entry = $notice->asAtomEntry(false, false, false, self::$targetUser1->getProfile()); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->assertEquals('false', $noticeInfo->getAttribute('repeated')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |     /*    public function testNoticeInfoFave() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             $notice = $this->_fakeNotice(); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $fave = Fave::addNew(self::$author2->getProfile(), $notice); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             // Should be set if user has faved
 | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $entry = $notice->asAtomEntry(false, false, false, self::$author2); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $element = $this->_entryToElement($entry, true); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $this->assertEquals('true', $noticeInfo->getAttribute('favorite')); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             // Shouldn't be set if user has not faved
 | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $entry = $notice->asAtomEntry(false, false, false, self::$targetUser1); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $element = $this->_entryToElement($entry, true); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |             $this->assertEquals('false', $noticeInfo->getAttribute('favorite')); | 
					
						
							|  |  |  |         }*/ | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function testConversationLink() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $orig = $this->_fakeNotice(self::$targetUser1); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id)); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |         $conv = Conversation::getKV('id', $reply->conversation); | 
					
						
							| 
									
										
										
										
											2010-08-03 15:26:19 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $entry = $reply->asAtomEntry(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $element = $this->_entryToElement($entry, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         $this->assertEquals($conv->getUrl(), ActivityUtils::getLink($element, 'ostatus:conversation')); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 01:29:20 +01:00
										 |  |  |     public static function tearDownAfterClass(): void | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         if (!is_null(self::$author1)) { | 
					
						
							|  |  |  |             self::$author1->getProfile()->delete(); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         if (!is_null(self::$author2)) { | 
					
						
							|  |  |  |             self::$author2->getProfile()->delete(); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         if (!is_null(self::$targetUser1)) { | 
					
						
							|  |  |  |             self::$targetUser1->getProfile()->delete(); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         if (!is_null(self::$targetUser2)) { | 
					
						
							|  |  |  |             self::$targetUser2->getProfile()->delete(); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         if (!is_null(self::$targetGroup1)) { | 
					
						
							|  |  |  |             self::$targetGroup1->delete(); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |         if (!is_null(self::$targetGroup2)) { | 
					
						
							|  |  |  |             self::$targetGroup2->delete(); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:17:36 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private function _fakeNotice($user = null, $text = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (empty($user)) { | 
					
						
							| 
									
										
										
										
											2016-08-09 09:42:25 +05:30
										 |  |  |             $user = self::$author1; | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($text)) { | 
					
						
							| 
									
										
										
										
											2013-10-21 13:20:30 +02:00
										 |  |  |             $text = "fake-o text-o " . common_random_hexstr(32); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return Notice::saveNew($user->id, $text, 'test', array('uri' => null)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private function _entryToElement($entry, $namespace = false) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |         $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n\n"; | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |         $xml .= '<feed'; | 
					
						
							|  |  |  |         if ($namespace) { | 
					
						
							|  |  |  |             $xml .= ' xmlns="http://www.w3.org/2005/Atom"'; | 
					
						
							|  |  |  |             $xml .= ' xmlns:thr="http://purl.org/syndication/thread/1.0"'; | 
					
						
							|  |  |  |             $xml .= ' xmlns:georss="http://www.georss.org/georss"'; | 
					
						
							|  |  |  |             $xml .= ' xmlns:activity="http://activitystrea.ms/spec/1.0/"'; | 
					
						
							|  |  |  |             $xml .= ' xmlns:media="http://purl.org/syndication/atommedia"'; | 
					
						
							|  |  |  |             $xml .= ' xmlns:poco="http://portablecontacts.net/spec/1.0"'; | 
					
						
							|  |  |  |             $xml .= ' xmlns:ostatus="http://ostatus.org/schema/1.0"'; | 
					
						
							|  |  |  |             $xml .= ' xmlns:statusnet="http://status.net/schema/api/1/"'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $xml .= '>' . "\n" . $entry . "\n" . '</feed>' . "\n"; | 
					
						
							| 
									
										
										
										
											2019-07-12 16:31:14 +01:00
										 |  |  |         $doc = new DOMDocument(); | 
					
						
							|  |  |  |         $doc->loadXML($xml); | 
					
						
							| 
									
										
										
										
											2010-08-03 13:41:44 -07:00
										 |  |  |         $feed = $doc->documentElement; | 
					
						
							|  |  |  |         $entries = $feed->getElementsByTagName('entry'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $entries->item(0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |