- public function testApiStatusesUpdateWithoutAuthenticatedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- $_SESSION['authenticated'] = false;
- api_statuses_update('json');
- }
-
- /**
- * Test the api_statuses_update() function with a parent status.
- *
- * @return void
- */
- public function testApiStatusesUpdateWithParent()
- {
- $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
- }
-
- /**
- * Test the api_statuses_update() function with a media_ids parameter.
- *
- * @return void
- */
- public function testApiStatusesUpdateWithMediaIds()
- {
- $this->markTestIncomplete();
- }
-
- /**
- * Test the api_statuses_update() function with the throttle limit reached.
- *
- * @return void
- */
- public function testApiStatusesUpdateWithDayThrottleReached()
- {
- $this->markTestIncomplete();
- }
-
- /**
- * Test the api_media_upload() function.
- * @runInSeparateProcess
- * @preserveGlobalState disabled
- */
- public function testApiMediaUpload()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- api_media_upload();
- }
-
- /**
- * Test the api_media_upload() function without an authenticated user.
- *
- * @return void
- */
- public function testApiMediaUploadWithoutAuthenticatedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- $_SESSION['authenticated'] = false;
- api_media_upload();
- }
-
- /**
- * Test the api_media_upload() function with an invalid uploaded media.
- *
- * @return void
- */
- public function testApiMediaUploadWithMedia()
- {
- $this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
- $_FILES = [
- 'media' => [
- 'id' => 666,
- 'tmp_name' => 'tmp_name'
- ]
- ];
- api_media_upload();
- }
-
- /**
- * Test the api_media_upload() function with an valid uploaded media.
- *
- * @return void
- */
- public function testApiMediaUploadWithValidMedia()
- {
- $_FILES = [
- 'media' => [
- 'id' => 666,
- 'size' => 666,
- 'width' => 666,
- 'height' => 666,
- 'tmp_name' => $this->getTempImage(),
- 'name' => 'spacer.png',
- 'type' => 'image/png'
- ]
- ];
- $app = DI::app();
- DI::args()->setArgc(2);
-
- $result = api_media_upload();
- self::assertEquals('image/png', $result['media']['image']['image_type']);
- self::assertEquals(1, $result['media']['image']['w']);
- self::assertEquals(1, $result['media']['image']['h']);
- self::assertNotEmpty($result['media']['image']['friendica_preview_url']);
- }
-
- /**
- * Test the api_status_show() function.
- */
- public function testApiStatusShowWithJson()
- {
- $result = api_status_show('json', 1);
- self::assertStatus($result['status']);
- }
-
- /**
- * Test the api_status_show() function with an XML result.
- */
- public function testApiStatusShowWithXml()
- {
- $result = api_status_show('xml', 1);
- self::assertXml($result, 'statuses');
- }
-
- /**
- * Test the api_get_last_status() function
- */
- public function testApiGetLastStatus()
- {
- $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
-
- self::assertNotNull($item);
- }
-
- /**
- * Test the api_users_show() function.
- *
- * @return void
- */
- public function testApiUsersShow()
- {
- $result = api_users_show('json');
- // We can't use assertSelfUser() here because the user object is missing some properties.
- self::assertEquals($this->selfUser['id'], $result['user']['cid']);
- self::assertEquals('DFRN', $result['user']['location']);
- self::assertEquals($this->selfUser['name'], $result['user']['name']);
- self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
- self::assertTrue($result['user']['verified']);
- }
-
- /**
- * Test the api_users_show() function with an XML result.
- *
- * @return void
- */
- public function testApiUsersShowWithXml()
- {
- $result = api_users_show('xml');
- self::assertXml($result, 'statuses');
- }
-
- /**
- * Test the api_users_search() function.
- *
- * @return void
- */
- public function testApiUsersSearch()
- {
- $_GET['q'] = 'othercontact';
- $result = api_users_search('json');
- self::assertOtherUser($result['users'][0]);
- }
-
- /**
- * Test the api_users_search() function with an XML result.
- *
- * @return void
- */
- public function testApiUsersSearchWithXml()
- {
- $_GET['q'] = 'othercontact';
- $result = api_users_search('xml');
- self::assertXml($result, 'users');
- }
-
- /**
- * Test the api_users_search() function without a GET q parameter.
- *
- * @return void
- */
- public function testApiUsersSearchWithoutQuery()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- api_users_search('json');
- }
-
- /**
- * Test the api_users_lookup() function.
- *
- * @return void
- */
- public function testApiUsersLookup()
- {
- $this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
- api_users_lookup('json');
- }
-
- /**
- * Test the api_users_lookup() function with an user ID.
- *
- * @return void
- */
- public function testApiUsersLookupWithUserId()
- {
- $_REQUEST['user_id'] = $this->otherUser['id'];
- $result = api_users_lookup('json');
- self::assertOtherUser($result['users'][0]);
- }
-
- /**
- * Test the api_search() function.
- *
- * @return void
- */
- public function testApiSearch()
- {
- $_REQUEST['q'] = 'reply';
- $_REQUEST['max_id'] = 10;
- $result = api_search('json');
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
- }
- }
-
- /**
- * Test the api_search() function a count parameter.
- *
- * @return void
- */
- public function testApiSearchWithCount()
- {
- $_REQUEST['q'] = 'reply';
- $_REQUEST['count'] = 20;
- $result = api_search('json');
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
- }
- }
-
- /**
- * Test the api_search() function with an rpp parameter.
- *
- * @return void
- */
- public function testApiSearchWithRpp()
- {
- $_REQUEST['q'] = 'reply';
- $_REQUEST['rpp'] = 20;
- $result = api_search('json');
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- self::assertStringContainsStringIgnoringCase('reply', $status['text'], '', true);
- }
- }
-
- /**
- * Test the api_search() function with an q parameter contains hashtag.
- * @doesNotPerformAssertions
- */
- public function testApiSearchWithHashtag()
- {
- $_REQUEST['q'] = '%23friendica';
- $result = api_search('json');
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- self::assertStringContainsStringIgnoringCase('#friendica', $status['text'], '', true);
- }
- }
-
- /**
- * Test the api_search() function with an exclude_replies parameter.
- * @doesNotPerformAssertions
- */
- public function testApiSearchWithExcludeReplies()
- {
- $_REQUEST['max_id'] = 10;
- $_REQUEST['exclude_replies'] = true;
- $_REQUEST['q'] = 'friendica';
- $result = api_search('json');
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_search() function without an authenticated user.
- *
- * @return void
- */
- public function testApiSearchWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- api_search('json');
- }
-
- /**
- * Test the api_search() function without any GET query parameter.
- *
- * @return void
- */
- public function testApiSearchWithoutQuery()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- api_search('json');
- }
-
- /**
- * Test the api_statuses_home_timeline() function.
- *
- * @return void
- */
- public function testApiStatusesHomeTimeline()
- {
- $_REQUEST['max_id'] = 10;
- $_REQUEST['exclude_replies'] = true;
- $_REQUEST['conversation_id'] = 1;
- $result = api_statuses_home_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_home_timeline() function with a negative page parameter.
- *
- * @return void
- */
- public function testApiStatusesHomeTimelineWithNegativePage()
- {
- $_REQUEST['page'] = -2;
- $result = api_statuses_home_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_home_timeline() with an unallowed user.
- *
- * @return void
- */
- public function testApiStatusesHomeTimelineWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- api_statuses_home_timeline('json');
- }
-
- /**
- * Test the api_statuses_home_timeline() function with an RSS result.
- *
- * @return void
- */
- public function testApiStatusesHomeTimelineWithRss()
- {
- $result = api_statuses_home_timeline('rss');
- self::assertXml($result, 'statuses');
- }
-
- /**
- * Test the api_statuses_public_timeline() function.
- *
- * @return void
- */
- public function testApiStatusesPublicTimeline()
- {
- $_REQUEST['max_id'] = 10;
- $_REQUEST['conversation_id'] = 1;
- $result = api_statuses_public_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
- *
- * @return void
- */
- public function testApiStatusesPublicTimelineWithExcludeReplies()
- {
- $_REQUEST['max_id'] = 10;
- $_REQUEST['exclude_replies'] = true;
- $result = api_statuses_public_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_public_timeline() function with a negative page parameter.
- *
- * @return void
- */
- public function testApiStatusesPublicTimelineWithNegativePage()
- {
- $_REQUEST['page'] = -2;
- $result = api_statuses_public_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_public_timeline() function with an unallowed user.
- *
- * @return void
- */
- public function testApiStatusesPublicTimelineWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- api_statuses_public_timeline('json');
- }
-
- /**
- * Test the api_statuses_public_timeline() function with an RSS result.
- *
- * @return void
- */
- public function testApiStatusesPublicTimelineWithRss()
- {
- $result = api_statuses_public_timeline('rss');
- self::assertXml($result, 'statuses');
- }
-
- /**
- * Test the api_statuses_networkpublic_timeline() function.
- *
- * @return void
- */
- public function testApiStatusesNetworkpublicTimeline()
- {
- $_REQUEST['max_id'] = 10;
- $result = api_statuses_networkpublic_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
- *
- * @return void
- */
- public function testApiStatusesNetworkpublicTimelineWithNegativePage()
- {
- $_REQUEST['page'] = -2;
- $result = api_statuses_networkpublic_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
- *
- * @return void
- */
- public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- api_statuses_networkpublic_timeline('json');
- }
-
- /**
- * Test the api_statuses_networkpublic_timeline() function with an RSS result.
- *
- * @return void
- */
- public function testApiStatusesNetworkpublicTimelineWithRss()
- {
- $result = api_statuses_networkpublic_timeline('rss');
- self::assertXml($result, 'statuses');
- }
-
- /**
- * Test the api_statuses_show() function.
- *
- * @return void
- */
- public function testApiStatusesShow()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- api_statuses_show('json');
- }
-
- /**
- * Test the api_statuses_show() function with an ID.
- *
- * @return void
- */
- public function testApiStatusesShowWithId()
- {
- DI::args()->setArgv(['', '', '', 1]);
- $result = api_statuses_show('json');
- self::assertStatus($result['status']);
- }
-
- /**
- * Test the api_statuses_show() function with the conversation parameter.
- *
- * @return void
- */
- public function testApiStatusesShowWithConversation()
- {
- DI::args()->setArgv(['', '', '', 1]);
- $_REQUEST['conversation'] = 1;
- $result = api_statuses_show('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_show() function with an unallowed user.
- *
- * @return void
- */
- public function testApiStatusesShowWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- api_statuses_show('json');
- }
-
- /**
- * Test the api_conversation_show() function.
- *
- * @return void
- */
- public function testApiConversationShow()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- api_conversation_show('json');
- }
-
- /**
- * Test the api_conversation_show() function with an ID.
- *
- * @return void
- */
- public function testApiConversationShowWithId()
- {
- DI::args()->setArgv(['', '', '', 1]);
- $_REQUEST['max_id'] = 10;
- $_REQUEST['page'] = -2;
- $result = api_conversation_show('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_conversation_show() function with an unallowed user.
- *
- * @return void
- */
- public function testApiConversationShowWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- api_conversation_show('json');
- }
-
- /**
- * Test the api_statuses_repeat() function.
- *
- * @return void
- */
- public function testApiStatusesRepeat()
- {
- $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
- api_statuses_repeat('json');
- }
-
- /**
- * Test the api_statuses_repeat() function without an authenticated user.
- *
- * @return void
- */
- public function testApiStatusesRepeatWithoutAuthenticatedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- $_SESSION['authenticated'] = false;
- api_statuses_repeat('json');
- }
-
- /**
- * Test the api_statuses_repeat() function with an ID.
- *
- * @return void
- */
- public function testApiStatusesRepeatWithId()
- {
- DI::args()->setArgv(['', '', '', 1]);
- $result = api_statuses_repeat('json');
- self::assertStatus($result['status']);
-
- // Also test with a shared status
- DI::args()->setArgv(['', '', '', 5]);
- $result = api_statuses_repeat('json');
- self::assertStatus($result['status']);
- }
-
- /**
- * Test the api_statuses_destroy() function.
- *
- * @return void
- */
- public function testApiStatusesDestroy()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- api_statuses_destroy('json');
- }
-
- /**
- * Test the api_statuses_destroy() function without an authenticated user.
- *
- * @return void
- */
- public function testApiStatusesDestroyWithoutAuthenticatedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- BasicAuth::setCurrentUserID();
- $_SESSION['authenticated'] = false;
- api_statuses_destroy('json');
- }
-
- /**
- * Test the api_statuses_destroy() function with an ID.
- *
- * @return void
- */
- public function testApiStatusesDestroyWithId()
- {
- DI::args()->setArgv(['', '', '', 1]);
- $result = api_statuses_destroy('json');
- self::assertStatus($result['status']);
- }
-
- /**
- * Test the api_statuses_mentions() function.
- *
- * @return void
- */
- public function testApiStatusesMentions()
- {
- $this->app->setLoggedInUserNickname($this->selfUser['nick']);
- $_REQUEST['max_id'] = 10;
- $result = api_statuses_mentions('json');
- self::assertEmpty($result['status']);
- // We should test with mentions in the database.
- }
-
- /**
- * Test the api_statuses_mentions() function with a negative page parameter.
- *
- * @return void
- */
- public function testApiStatusesMentionsWithNegativePage()