- $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\ForbiddenException::class);
- $_SESSION['allow_api'] = false;
- $_GET['screen_name'] = $this->selfUser['nick'];
- 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\ForbiddenException::class);
- $_SESSION['allow_api'] = false;
- $_GET['screen_name'] = $this->selfUser['nick'];
- 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\ForbiddenException::class);
- $_SESSION['allow_api'] = false;
- $_GET['screen_name'] = $this->selfUser['nick'];
- 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\ForbiddenException::class);
- $_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\ForbiddenException::class);
- $_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()
- {
- $_REQUEST['page'] = -2;
- $result = api_statuses_mentions('json');
- self::assertEmpty($result['status']);
- }
-
- /**
- * Test the api_statuses_mentions() function with an unallowed user.
- *
- * @return void
- */
- public function testApiStatusesMentionsWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
- $_SESSION['allow_api'] = false;
- $_GET['screen_name'] = $this->selfUser['nick'];
- api_statuses_mentions('json');
- }
-
- /**
- * Test the api_statuses_mentions() function with an RSS result.
- *
- * @return void
- */
- public function testApiStatusesMentionsWithRss()
- {
- $result = api_statuses_mentions('rss');
- self::assertXml($result, 'statuses');
- }
-
- /**
- * Test the api_statuses_user_timeline() function.
- *
- * @return void
- */
- public function testApiStatusesUserTimeline()
- {
- $_REQUEST['max_id'] = 10;
- $_REQUEST['exclude_replies'] = true;
- $_REQUEST['conversation_id'] = 1;
- $result = api_statuses_user_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_user_timeline() function with a negative page parameter.
- *
- * @return void
- */
- public function testApiStatusesUserTimelineWithNegativePage()
- {
- $_REQUEST['page'] = -2;
- $result = api_statuses_user_timeline('json');
- self::assertNotEmpty($result['status']);
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_statuses_user_timeline() function with an RSS result.
- *
- * @return void
- */
- public function testApiStatusesUserTimelineWithRss()
- {
- $result = api_statuses_user_timeline('rss');
- self::assertXml($result, 'statuses');
- }
-
- /**
- * Test the api_statuses_user_timeline() function with an unallowed user.
- *
- * @return void
- */
- public function testApiStatusesUserTimelineWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
- $_SESSION['allow_api'] = false;
- $_GET['screen_name'] = $this->selfUser['nick'];
- api_statuses_user_timeline('json');
- }
-
- /**
- * Test the api_favorites_create_destroy() function.
- *
- * @return void
- */
- public function testApiFavoritesCreateDestroy()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
- api_favorites_create_destroy('json');
- }
-
- /**
- * Test the api_favorites_create_destroy() function with an invalid ID.
- *
- * @return void
- */
- public function testApiFavoritesCreateDestroyWithInvalidId()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
- api_favorites_create_destroy('json');
- }
-
- /**
- * Test the api_favorites_create_destroy() function with an invalid action.
- *
- * @return void
- */
- public function testApiFavoritesCreateDestroyWithInvalidAction()
- {
- $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
- $_REQUEST['id'] = 1;
- api_favorites_create_destroy('json');
- }
-
- /**
- * Test the api_favorites_create_destroy() function with the create action.
- *
- * @return void
- */
- public function testApiFavoritesCreateDestroyWithCreateAction()
- {
- DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
- $_REQUEST['id'] = 3;
- $result = api_favorites_create_destroy('json');
- self::assertStatus($result['status']);
- }
-
- /**
- * Test the api_favorites_create_destroy() function with the create action and an RSS result.
- *
- * @return void
- */
- public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
- {
- DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
- $_REQUEST['id'] = 3;
- $result = api_favorites_create_destroy('rss');
- self::assertXml($result, 'status');
- }
-
- /**
- * Test the api_favorites_create_destroy() function with the destroy action.
- *
- * @return void
- */
- public function testApiFavoritesCreateDestroyWithDestroyAction()
- {
- DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
- $_REQUEST['id'] = 3;
- $result = api_favorites_create_destroy('json');
- self::assertStatus($result['status']);
- }
-
- /**
- * Test the api_favorites_create_destroy() function without an authenticated user.
- *
- * @return void
- */
- public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
- DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
- $_SESSION['authenticated'] = false;
- api_favorites_create_destroy('json');
- }
-
- /**
- * Test the api_favorites() function.
- *
- * @return void
- */
- public function testApiFavorites()
- {
- $_REQUEST['page'] = -1;
- $_REQUEST['max_id'] = 10;
- $result = api_favorites('json');
- foreach ($result['status'] as $status) {
- self::assertStatus($status);
- }
- }
-
- /**
- * Test the api_favorites() function with an RSS result.
- *
- * @return void
- */
- public function testApiFavoritesWithRss()
- {
- $result = api_favorites('rss');
- self::assertXml($result, 'statuses');
- }
-
- /**
- * Test the api_favorites() function with an unallowed user.
- *
- * @return void
- */
- public function testApiFavoritesWithUnallowedUser()
- {
- $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
- $_SESSION['allow_api'] = false;
- $_GET['screen_name'] = $this->selfUser['nick'];
- api_favorites('json');
- }
-
- /**
- * Test the api_format_messages() function.
- *
- * @return void
- */
- public function testApiFormatMessages()
- {
- $result = api_format_messages(
- ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
- ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
- ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
- );
- self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
- self::assertEquals(1, $result['id']);
- self::assertEquals(2, $result['recipient_id']);
- self::assertEquals(3, $result['sender_id']);
- self::assertEquals('recipient_name', $result['recipient_screen_name']);
- self::assertEquals('sender_name', $result['sender_screen_name']);
- }
-
- /**
- * Test the api_format_messages() function with HTML.
- *
- * @return void
- */
- public function testApiFormatMessagesWithHtmlText()
- {
- $_GET['getText'] = 'html';
- $result = api_format_messages(
- ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
- ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
- ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
- );
- self::assertEquals('item_title', $result['title']);
- self::assertEquals('<strong>item_body</strong>', $result['text']);
- }
-
- /**
- * Test the api_format_messages() function with plain text.
- *
- * @return void
- */
- public function testApiFormatMessagesWithPlainText()
- {
- $_GET['getText'] = 'plain';
- $result = api_format_messages(
- ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
- ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
- ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
- );
- self::assertEquals('item_title', $result['title']);
- self::assertEquals('item_body', $result['text']);
- }
-
- /**
- * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
- *
- * @return void
- */
- public function testApiFormatMessagesWithoutUserObjects()
- {
- $_GET['getUserObjects'] = 'false';
- $result = api_format_messages(
- ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
- ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
- ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
- );
- self::assertTrue(!isset($result['sender']));
- self::assertTrue(!isset($result['recipient']));
- }
-
- /**
- * Test the api_convert_item() function.
- *
- * @return void
- */
- public function testApiConvertItem()
- {
- $result = api_convert_item(
- [
- 'network' => 'feed',
- 'title' => 'item_title',
- 'uri-id' => 1,
- // We need a long string to test that it is correctly cut
- 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
- 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
- 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
- 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
- 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
- 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
- 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
- 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
- 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
- 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
- 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
- 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
- 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
- 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
- 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
- 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
- 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
- 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
- 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
- 'repellat officia illum quos impedit quam iste esse unde qui ' .
- 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
- 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
- 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
- 'plink' => 'item_plink'
- ]
- );
- self::assertStringStartsWith('item_title', $result['text']);
- self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
- }
-
- /**
- * Test the api_convert_item() function with an empty item body.
- *
- * @return void
- */
- public function testApiConvertItemWithoutBody()
- {
- $result = api_convert_item(
- [
- 'network' => 'feed',
- 'title' => 'item_title',
- 'uri-id' => -1,
- 'body' => '',
- 'plink' => 'item_plink'
- ]
- );
- self::assertEquals("item_title", $result['text']);
- self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
- }
-
- /**
- * Test the api_convert_item() function with the title in the body.
- *
- * @return void
- */
- public function testApiConvertItemWithTitleInBody()
- {
- $result = api_convert_item(
- [
- 'title' => 'item_title',
- 'body' => 'item_title item_body',
- 'uri-id' => 1,
- ]
- );
- self::assertEquals('item_title item_body', $result['text']);
- self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
- }
-
- /**
- * Test the api_get_attachments() function.
- *
- * @return void
- */
- public function testApiGetAttachments()
- {
- $body = 'body';
- self::assertEmpty(api_get_attachments($body, 0));
- }
-
- /**
- * Test the api_get_attachments() function with an img tag.
- *
- * @return void
- */
- public function testApiGetAttachmentsWithImage()
- {
- $body = '[img]http://via.placeholder.com/1x1.png[/img]';
- self::assertIsArray(api_get_attachments($body, 0));
- }
-
- /**
- * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
- *
- * @return void
- */
- public function testApiGetAttachmentsWithImageAndAndStatus()
- {
- $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
- $body = '[img]http://via.placeholder.com/1x1.png[/img]';
- self::assertIsArray(api_get_attachments($body, 0));
- }
-
- /**
- * Test the api_get_entitities() function.
- *
- * @return void
- */
- public function testApiGetEntitities()
- {
- $text = 'text';
- self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
- }
-
- /**
- * Test the api_get_entitities() function with the include_entities parameter.
- *
- * @return void
- */
- public function testApiGetEntititiesWithIncludeEntities()
- {
- $_REQUEST['include_entities'] = 'true';
- $text = 'text';
- $result = api_get_entitities($text, 'bbcode', 0);
- self::assertIsArray($result['hashtags']);
- self::assertIsArray($result['symbols']);
- self::assertIsArray($result['urls']);
- self::assertIsArray($result['user_mentions']);
- }
-
- /**
- * Test the api_format_items_embeded_images() function.
- *
- * @return void
- */
- public function testApiFormatItemsEmbededImages()
- {
- self::assertEquals(
- 'text ' . DI::baseUrl() . '/display/item_guid',
- api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
- );
- }
-
- /**
- * Test the api_contactlink_to_array() function.
- *
- * @return void
- */
- public function testApiContactlinkToArray()
- {
- self::assertEquals(
- [
- 'name' => 'text',
- 'url' => '',
- ],
- api_contactlink_to_array('text')
- );
- }
-
- /**
- * Test the api_contactlink_to_array() function with an URL.
- *
- * @return void
- */
- public function testApiContactlinkToArrayWithUrl()
- {
- self::assertEquals(
- [
- 'name' => ['link_text'],
- 'url' => ['url'],
- ],
- api_contactlink_to_array('text <a href="url">link_text</a>')