Merge pull request #11003 from annando/fix-api

Fix legacy API
This commit is contained in:
Hypolite Petovan 2021-11-21 07:55:25 -05:00 committed by GitHub
commit 23c56b108b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 382 additions and 755 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,14 @@
namespace Friendica\Module\Api; namespace Friendica\Module\Api;
use Friendica\App\Arguments; use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Util\Arrays; use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPInputData; use Friendica\Util\HTTPInputData;
use Friendica\Util\XML; use Friendica\Util\XML;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Friendica\Factory\Api\Twitter\User as TwitterUser;
/** /**
* This class is used to format and return API responses * This class is used to format and return API responses
@ -26,11 +29,13 @@ class ApiResponse
* @param Arguments $args * @param Arguments $args
* @param LoggerInterface $logger * @param LoggerInterface $logger
*/ */
public function __construct(L10n $l10n, Arguments $args, LoggerInterface $logger) public function __construct(L10n $l10n, Arguments $args, LoggerInterface $logger, BaseURL $baseurl, TwitterUser $twitteruser)
{ {
$this->l10n = $l10n; $this->l10n = $l10n;
$this->args = $args; $this->args = $args;
$this->logger = $logger; $this->logger = $logger;
$this->baseurl = $baseurl;
$this->twitterUser = $twitteruser;
} }
/** /**
@ -102,20 +107,51 @@ class ApiResponse
return XML::fromArray($data3, $xml, false, $namespaces); return XML::fromArray($data3, $xml, false, $namespaces);
} }
/**
* Set values for RSS template
*
* @param array $arr Array to be passed to template
* @param int $cid Contact ID of template
* @return array
*/
private function addRSSValues(array $arr, int $cid)
{
if (empty($cid)) {
return $arr;
}
$user_info = $this->twitterUser->createFromContactId($cid)->toArray();
$arr['$user'] = $user_info;
$arr['$rss'] = [
'alternate' => $user_info['url'],
'self' => $this->baseurl . '/' . $this->args->getQueryString(),
'base' => $this->baseurl,
'updated' => DateTimeFormat::utc(null, DateTimeFormat::API),
'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
'language' => $user_info['lang'],
'logo' => $this->baseurl . '/images/friendica-32.png',
];
return $arr;
}
/** /**
* Formats the data according to the data type * Formats the data according to the data type
* *
* @param string $root_element Name of the root element * @param string $root_element Name of the root element
* @param string $type Return type (atom, rss, xml, json) * @param string $type Return type (atom, rss, xml, json)
* @param array $data JSON style array * @param array $data JSON style array
* @param int $cid ID of the contact for RSS
* *
* @return array|string (string|array) XML data or JSON data * @return array|string (string|array) XML data or JSON data
*/ */
public function formatData(string $root_element, string $type, array $data) public function formatData(string $root_element, string $type, array $data, int $cid = 0)
{ {
switch ($type) { switch ($type) {
case 'atom':
case 'rss': case 'rss':
$data = $this->addRSSValues($data, $cid);
case 'atom':
case 'xml': case 'xml':
return $this->createXML($data, $root_element); return $this->createXML($data, $root_element);
case 'json': case 'json':

View File

@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Friendica;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
require_once __DIR__ . '/../../../../include/api.php';
/** /**
* api/friendica * api/friendica

View File

@ -27,6 +27,7 @@ use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Security\BasicAuth; use Friendica\Security\BasicAuth;
use Friendica\Security\OAuth; use Friendica\Security\OAuth;
@ -292,12 +293,23 @@ class BaseApi extends BaseModule
} }
} }
public static function getContactIDForSearchterm($searchterm) public static function getContactIDForSearchterm(string $screen_name, int $cid, int $uid)
{ {
if (intval($searchterm) == 0) { if (!empty($cid)) {
$cid = Contact::getIdForURL($searchterm, 0, false); return $cid;
}
if (strpos($screen_name, '@') !== false) {
$cid = Contact::getIdForURL($screen_name, 0, false);
} else { } else {
$cid = intval($searchterm); $user = User::getByNickname($screen_name, ['uid']);
if (!empty($user['uid'])) {
$cid = Contact::getPublicIdByUserId($user['uid']);
}
}
if (empty($cid) && ($uid != 0)) {
$cid = Contact::getPublicIdByUserId($uid);
} }
return $cid; return $cid;

View File

@ -303,6 +303,7 @@ return [
'causer-id' => 42, 'causer-id' => 42,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
], ],
@ -317,6 +318,7 @@ return [
'causer-id' => 42, 'causer-id' => 42,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
], ],
@ -331,6 +333,7 @@ return [
'causer-id' => 43, 'causer-id' => 43,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
], ],
@ -345,6 +348,7 @@ return [
'causer-id' => 44, 'causer-id' => 44,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
], ],
@ -359,6 +363,7 @@ return [
'causer-id' => 42, 'causer-id' => 42,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
], ],
@ -373,6 +378,7 @@ return [
'causer-id' => 44, 'causer-id' => 44,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
], ],
@ -392,6 +398,7 @@ return [
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'gravity' => GRAVITY_PARENT, 'gravity' => GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'wall' => 1, 'wall' => 1,
@ -413,6 +420,7 @@ return [
'causer-id' => 42, 'causer-id' => 42,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 1, 'wall' => 1,
@ -433,6 +441,7 @@ return [
'causer-id' => 43, 'causer-id' => 43,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 1, 'wall' => 1,
@ -453,6 +462,7 @@ return [
'causer-id' => 44, 'causer-id' => 44,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 1, 'wall' => 1,
@ -473,6 +483,7 @@ return [
'causer-id' => 42, 'causer-id' => 42,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 1, 'wall' => 1,
@ -493,6 +504,7 @@ return [
'causer-id' => 44, 'causer-id' => 44,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 1, 'wall' => 1,
@ -513,6 +525,7 @@ return [
'causer-id' => 42, 'causer-id' => 42,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 0, 'wall' => 0,
@ -533,6 +546,7 @@ return [
'causer-id' => 42, 'causer-id' => 42,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 0, 'wall' => 0,
@ -553,6 +567,7 @@ return [
'causer-id' => 43, 'causer-id' => 43,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 0, 'wall' => 0,
@ -573,6 +588,7 @@ return [
'causer-id' => 44, 'causer-id' => 44,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 0, 'wall' => 0,
@ -593,6 +609,7 @@ return [
'causer-id' => 42, 'causer-id' => 42,
'vid' => 8, 'vid' => 8,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
'wall' => 0, 'wall' => 0,
@ -611,6 +628,7 @@ return [
'parent-uri-id' => 6, 'parent-uri-id' => 6,
'thr-parent-id' => 6, 'thr-parent-id' => 6,
'private' => Item::PUBLIC, 'private' => Item::PUBLIC,
'global' => true,
'gravity' => GRAVITY_PARENT, 'gravity' => GRAVITY_PARENT,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
'origin' => 0, 'origin' => 0,

View File

@ -10,6 +10,7 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Module\Api\ApiResponse; use Friendica\Module\Api\ApiResponse;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -555,6 +556,7 @@ class ApiTest extends FixtureTest
*/ */
public function testApiRssExtra() public function testApiRssExtra()
{ {
/*
$user_info = ['url' => 'user_url', 'lang' => 'en']; $user_info = ['url' => 'user_url', 'lang' => 'en'];
$result = api_rss_extra([], $user_info); $result = api_rss_extra([], $user_info);
self::assertEquals($user_info, $result['$user']); self::assertEquals($user_info, $result['$user']);
@ -565,6 +567,7 @@ class ApiTest extends FixtureTest
self::assertArrayHasKey('atom_updated', $result['$rss']); self::assertArrayHasKey('atom_updated', $result['$rss']);
self::assertArrayHasKey('language', $result['$rss']); self::assertArrayHasKey('language', $result['$rss']);
self::assertArrayHasKey('logo', $result['$rss']); self::assertArrayHasKey('logo', $result['$rss']);
*/
} }
/** /**
@ -574,6 +577,7 @@ class ApiTest extends FixtureTest
*/ */
public function testApiRssExtraWithoutUserInfo() public function testApiRssExtraWithoutUserInfo()
{ {
/*
$result = api_rss_extra([], null); $result = api_rss_extra([], null);
self::assertIsArray($result['$user']); self::assertIsArray($result['$user']);
self::assertArrayHasKey('alternate', $result['$rss']); self::assertArrayHasKey('alternate', $result['$rss']);
@ -583,26 +587,7 @@ class ApiTest extends FixtureTest
self::assertArrayHasKey('atom_updated', $result['$rss']); self::assertArrayHasKey('atom_updated', $result['$rss']);
self::assertArrayHasKey('language', $result['$rss']); self::assertArrayHasKey('language', $result['$rss']);
self::assertArrayHasKey('logo', $result['$rss']); self::assertArrayHasKey('logo', $result['$rss']);
} */
/**
* Test the api_unique_id_to_nurl() function.
*
* @return void
*/
public function testApiUniqueIdToNurl()
{
self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
}
/**
* Test the api_unique_id_to_nurl() function with a correct ID.
*
* @return void
*/
public function testApiUniqueIdToNurlWithCorrectId()
{
self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
} }
/** /**
@ -763,29 +748,6 @@ class ApiTest extends FixtureTest
self::assertSelfUser(DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray()); self::assertSelfUser(DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
} }
/**
* Test the api_item_get_user() function.
*
* @return void
*/
public function testApiItemGetUser()
{
$users = api_item_get_user($this->app, []);
self::assertSelfUser($users[0]);
}
/**
* Test the api_item_get_user() function with a different item parent.
*
* @return void
*/
public function testApiItemGetUserWithDifferentParent()
{
$users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
self::assertSelfUser($users[0]);
self::assertEquals($users[0], $users[1]);
}
/** /**
* Test the Arrays::walkRecursive() function. * Test the Arrays::walkRecursive() function.
* *
@ -1790,10 +1752,12 @@ class ApiTest extends FixtureTest
*/ */
public function testApiStatusesUserTimeline() public function testApiStatusesUserTimeline()
{ {
$_REQUEST['user_id'] = 42;
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true; $_REQUEST['exclude_replies'] = true;
$_REQUEST['conversation_id'] = 1; $_REQUEST['conversation_id'] = 7;
$result = api_statuses_user_timeline('json');
$result = api_statuses_user_timeline('json');
self::assertNotEmpty($result['status']); self::assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
self::assertStatus($status); self::assertStatus($status);
@ -1807,8 +1771,10 @@ class ApiTest extends FixtureTest
*/ */
public function testApiStatusesUserTimelineWithNegativePage() public function testApiStatusesUserTimelineWithNegativePage()
{ {
$_REQUEST['page'] = -2; $_REQUEST['user_id'] = 42;
$result = api_statuses_user_timeline('json'); $_REQUEST['page'] = -2;
$result = api_statuses_user_timeline('json');
self::assertNotEmpty($result['status']); self::assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
self::assertStatus($status); self::assertStatus($status);
@ -2262,21 +2228,9 @@ class ApiTest extends FixtureTest
*/ */
public function testApiFormatItems() public function testApiFormatItems()
{ {
$items = [ $items = Post::selectToArray([], ['uid' => 42]);
[ foreach ($items as $item) {
'item_network' => 'item_network', $status = api_format_item($item);
'source' => 'web',
'coord' => '5 7',
'body' => '',
'verb' => '',
'author-id' => 43,
'author-network' => Protocol::DFRN,
'author-link' => 'http://localhost/profile/othercontact',
'plink' => '',
]
];
$result = api_format_items($items, ['id' => 0], true);
foreach ($result as $status) {
self::assertStatus($status); self::assertStatus($status);
} }
} }
@ -2287,19 +2241,9 @@ class ApiTest extends FixtureTest
*/ */
public function testApiFormatItemsWithXml() public function testApiFormatItemsWithXml()
{ {
$items = [ $items = Post::selectToArray([], ['uid' => 42]);
[ foreach ($items as $item) {
'coord' => '5 7', $status = api_format_item($item, 'xml');
'body' => '',
'verb' => '',
'author-id' => 43,
'author-network' => Protocol::DFRN,
'author-link' => 'http://localhost/profile/othercontact',
'plink' => '',
]
];
$result = api_format_items($items, ['id' => 0], true, 'xml');
foreach ($result as $status) {
self::assertStatus($status); self::assertStatus($status);
} }
} }
@ -2602,9 +2546,9 @@ class ApiTest extends FixtureTest
public function testApiDirectMessagesNewWithScreenName() public function testApiDirectMessagesNewWithScreenName()
{ {
$this->app->setLoggedInUserNickname($this->selfUser['nick']); $this->app->setLoggedInUserNickname($this->selfUser['nick']);
$_POST['text'] = 'message_text'; $_POST['text'] = 'message_text';
$_POST['screen_name'] = $this->friendUser['nick']; $_POST['user_id'] = $this->friendUser['id'];
$result = api_direct_messages_new('json'); $result = api_direct_messages_new('json');
self::assertStringContainsString('message_text', $result['direct_message']['text']); self::assertStringContainsString('message_text', $result['direct_message']['text']);
self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']); self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
self::assertEquals(1, $result['direct_message']['friendica_seen']); self::assertEquals(1, $result['direct_message']['friendica_seen']);
@ -2618,10 +2562,10 @@ class ApiTest extends FixtureTest
public function testApiDirectMessagesNewWithTitle() public function testApiDirectMessagesNewWithTitle()
{ {
$this->app->setLoggedInUserNickname($this->selfUser['nick']); $this->app->setLoggedInUserNickname($this->selfUser['nick']);
$_POST['text'] = 'message_text'; $_POST['text'] = 'message_text';
$_POST['screen_name'] = $this->friendUser['nick']; $_POST['user_id'] = $this->friendUser['id'];
$_REQUEST['title'] = 'message_title'; $_REQUEST['title'] = 'message_title';
$result = api_direct_messages_new('json'); $result = api_direct_messages_new('json');
self::assertStringContainsString('message_text', $result['direct_message']['text']); self::assertStringContainsString('message_text', $result['direct_message']['text']);
self::assertStringContainsString('message_title', $result['direct_message']['text']); self::assertStringContainsString('message_title', $result['direct_message']['text']);
self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']); self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
@ -2636,9 +2580,9 @@ class ApiTest extends FixtureTest
public function testApiDirectMessagesNewWithRss() public function testApiDirectMessagesNewWithRss()
{ {
$this->app->setLoggedInUserNickname($this->selfUser['nick']); $this->app->setLoggedInUserNickname($this->selfUser['nick']);
$_POST['text'] = 'message_text'; $_POST['text'] = 'message_text';
$_POST['screen_name'] = $this->friendUser['nick']; $_POST['user_id'] = $this->friendUser['id'];
$result = api_direct_messages_new('rss'); $result = api_direct_messages_new('rss');
self::assertXml($result, 'direct-messages'); self::assertXml($result, 'direct-messages');
} }
@ -3068,7 +3012,7 @@ class ApiTest extends FixtureTest
*/ */
public function testCheckAclInput() public function testCheckAclInput()
{ {
$result = check_acl_input('<aclstring>'); $result = check_acl_input('<aclstring>', BaseApi::getCurrentUserID());
// Where does this result come from? // Where does this result come from?
self::assertEquals(1, $result); self::assertEquals(1, $result);
} }
@ -3080,7 +3024,7 @@ class ApiTest extends FixtureTest
*/ */
public function testCheckAclInputWithEmptyAclString() public function testCheckAclInputWithEmptyAclString()
{ {
$result = check_acl_input(' '); $result = check_acl_input(' ', BaseApi::getCurrentUserID());
self::assertFalse($result); self::assertFalse($result);
} }
@ -3161,18 +3105,6 @@ class ApiTest extends FixtureTest
self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result); self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
} }
/**
* Test the api_best_nickname() function.
*
* @return void
*/
public function testApiBestNickname()
{
$contacts = [];
$result = api_best_nickname($contacts);
self::assertNull($result);
}
/** /**
* Test the api_best_nickname() function with contacts. * Test the api_best_nickname() function with contacts.
* *

View File

@ -3,7 +3,9 @@
namespace Friendica\Test\src\Module\Api; namespace Friendica\Test\src\Module\Api;
use Friendica\App\Arguments; use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Factory\Api\Twitter\User;
use Friendica\Test\MockedTest; use Friendica\Test\MockedTest;
use Friendica\Test\Util\ApiResponseDouble; use Friendica\Test\Util\ApiResponseDouble;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
@ -22,8 +24,10 @@ class ApiResponseTest extends MockedTest
$l10n = \Mockery::mock(L10n::class); $l10n = \Mockery::mock(L10n::class);
$args = \Mockery::mock(Arguments::class); $args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn(''); $args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponseDouble($l10n, $args, new NullLogger()); $response = new ApiResponseDouble($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
$response->error(200, 'OK', 'error_message', 'json'); $response->error(200, 'OK', 'error_message', 'json');
self::assertEquals('{"error":"error_message","code":"200 OK","request":""}', ApiResponseDouble::getOutput()); self::assertEquals('{"error":"error_message","code":"200 OK","request":""}', ApiResponseDouble::getOutput());
@ -34,8 +38,10 @@ class ApiResponseTest extends MockedTest
$l10n = \Mockery::mock(L10n::class); $l10n = \Mockery::mock(L10n::class);
$args = \Mockery::mock(Arguments::class); $args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn(''); $args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponseDouble($l10n, $args, new NullLogger()); $response = new ApiResponseDouble($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
$response->error(200, 'OK', 'error_message', 'xml'); $response->error(200, 'OK', 'error_message', 'xml');
self::assertEquals('<?xml version="1.0"?>' . "\n" . self::assertEquals('<?xml version="1.0"?>' . "\n" .
@ -54,8 +60,10 @@ class ApiResponseTest extends MockedTest
$l10n = \Mockery::mock(L10n::class); $l10n = \Mockery::mock(L10n::class);
$args = \Mockery::mock(Arguments::class); $args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn(''); $args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponseDouble($l10n, $args, new NullLogger()); $response = new ApiResponseDouble($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
$response->error(200, 'OK', 'error_message', 'rss'); $response->error(200, 'OK', 'error_message', 'rss');
self::assertEquals( self::assertEquals(
@ -75,8 +83,10 @@ class ApiResponseTest extends MockedTest
$l10n = \Mockery::mock(L10n::class); $l10n = \Mockery::mock(L10n::class);
$args = \Mockery::mock(Arguments::class); $args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn(''); $args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponseDouble($l10n, $args, new NullLogger()); $response = new ApiResponseDouble($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
$response->error(200, 'OK', 'error_message', 'atom'); $response->error(200, 'OK', 'error_message', 'atom');
self::assertEquals( self::assertEquals(
@ -99,8 +109,10 @@ class ApiResponseTest extends MockedTest
}); });
$args = \Mockery::mock(Arguments::class); $args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn(''); $args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponseDouble($l10n, $args, new NullLogger()); $response = new ApiResponseDouble($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
$response->unsupported(); $response->unsupported();
self::assertEquals('{"error":"API endpoint %s %s is not implemented","error_description":"The API endpoint is currently not implemented but might be in the future."}', ApiResponseDouble::getOutput()); self::assertEquals('{"error":"API endpoint %s %s is not implemented","error_description":"The API endpoint is currently not implemented but might be in the future."}', ApiResponseDouble::getOutput());