Merge pull request #11127 from nupplaphil/feat/tests

Transform legacy API tests into new structure
This commit is contained in:
Hypolite Petovan 2022-01-02 01:06:48 +01:00 committed by GitHub
commit 0df539a65e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 1472 additions and 1298 deletions

View file

@ -51,7 +51,7 @@ class DirectMessage extends BaseFactory
* *
* @param int $id Mail id * @param int $id Mail id
* @param int $uid Mail user * @param int $uid Mail user
* @param string $text_mode Either empty, "html" or "text" * @param string $text_mode Either empty, "html" or "plain"
* *
* @return \Friendica\Object\Api\Twitter\DirectMessage * @return \Friendica\Object\Api\Twitter\DirectMessage
*/ */

View file

@ -119,7 +119,19 @@ class Status extends BaseFactory
$friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => GRAVITY_COMMENT]); $friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => GRAVITY_COMMENT]);
$text = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']); $text = '';
$title = '';
// Add the title to text / html if set
if (!empty($item['title'])) {
$text .= $item['title'] . ' ';
$title = sprintf("[h4]%s[/h4]\n", $item['title']);
}
$statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($title . ($item['raw-body'] ?? $item['body'])), BBCode::API);
$friendicaHtml = BBCode::convertForUriId($item['uri-id'], $title . $item['body'], BBCode::EXTERNAL);
$text .= Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
$text = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], $text, BBCode::API), 0)); $text = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], $text, BBCode::API), 0));
@ -190,6 +202,6 @@ class Status extends BaseFactory
$entities = []; $entities = [];
} }
return new \Friendica\Object\Api\Twitter\Status($text, $item, $author, $owner, $retweeted, $quoted, $geo, $friendica_activities, $entities, $attachments, $friendica_comments, $liked); return new \Friendica\Object\Api\Twitter\Status($text, $statusnetHtml, $friendicaHtml, $item, $author, $owner, $retweeted, $quoted, $geo, $friendica_activities, $entities, $attachments, $friendica_comments, $liked);
} }
} }

View file

@ -58,7 +58,7 @@ class Destroy extends BaseApi
$parenturi = $request['friendica_parenturi'] ?? ''; $parenturi = $request['friendica_parenturi'] ?? '';
// error if no id or parenturi specified (for clients posting parent-uri as well) // error if no id or parenturi specified (for clients posting parent-uri as well)
if ($verbose && ($id == 0 || $parenturi == "")) { if ($verbose && $id == 0 && $parenturi == "") {
$answer = ['result' => 'error', 'message' => 'message id or parenturi not specified']; $answer = ['result' => 'error', 'message' => 'message id or parenturi not specified'];
$this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); $this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null);
return; return;

View file

@ -23,7 +23,6 @@ namespace Friendica\Object\Api\Twitter;
use Friendica\BaseDataTransferObject; use Friendica\BaseDataTransferObject;
use Friendica\Content\ContactSelector; use Friendica\Content\ContactSelector;
use Friendica\Content\Text\BBCode;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -99,7 +98,7 @@ class Status extends BaseDataTransferObject
* @param array $item * @param array $item
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public function __construct(string $text, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked) public function __construct(string $text, string $statusnetHtml, string $friendicaHtml, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked)
{ {
$this->id = (int)$item['id']; $this->id = (int)$item['id'];
$this->id_str = (string)$item['id']; $this->id_str = (string)$item['id'];
@ -117,8 +116,8 @@ class Status extends BaseDataTransferObject
$this->text = $text; $this->text = $text;
$this->friendica_title = $item['title']; $this->friendica_title = $item['title'];
$this->statusnet_html = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API); $this->statusnet_html = $statusnetHtml;
$this->friendica_html = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL); $this->friendica_html = $friendicaHtml;
$this->user = $author->toArray(); $this->user = $author->toArray();
$this->friendica_author = $author->toArray(); $this->friendica_author = $author->toArray();
$this->friendica_owner = $owner->toArray(); $this->friendica_owner = $owner->toArray();

View file

@ -105,7 +105,11 @@ return [
'uri' => '6', 'uri' => '6',
'guid' => '6', 'guid' => '6',
], ],
[
'id' => 7,
'uri' => '7',
'guid' => '7',
],
[ [
'id' => 42, 'id' => 42,
'uri' => 'http://localhost/profile/selfcontact', 'uri' => 'http://localhost/profile/selfcontact',
@ -342,6 +346,34 @@ return [
'body' => 'Friend user status', 'body' => 'Friend user status',
'plink' => 'http://localhost/display/6', 'plink' => 'http://localhost/display/6',
], ],
[
'uri-id' => 7,
'title' => 'item_title',
'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' => 'http://localhost/display/6',
],
], ],
'post' => [ 'post' => [
[ [
@ -434,6 +466,21 @@ return [
'visible' => 1, 'visible' => 1,
'deleted' => 0, 'deleted' => 0,
], ],
[
'uri-id' => 7,
'parent-uri-id' => 7,
'thr-parent-id' => 7,
'gravity' => GRAVITY_PARENT,
'network' => Protocol::DFRN,
'owner-id' => 42,
'author-id' => 44,
'causer-id' => 44,
'vid' => 8,
'private' => Item::PUBLIC,
'global' => true,
'visible' => 1,
'deleted' => 0,
],
], ],
'post-user' => [ 'post-user' => [
[ [
@ -687,6 +734,27 @@ return [
'deleted' => 0, 'deleted' => 0,
'wall' => 0, 'wall' => 0,
], ],
[
'id' => 13,
'uri-id' => 7,
'visible' => 1,
'contact-id' => 44,
'author-id' => 44,
'owner-id' => 42,
'causer-id' => 44,
'uid' => 0,
'vid' => 8,
'unseen' => 0,
'parent-uri-id' => 7,
'thr-parent-id' => 7,
'private' => Item::PUBLIC,
'global' => true,
'gravity' => GRAVITY_PARENT,
'network' => Protocol::DFRN,
'origin' => 0,
'deleted' => 0,
'wall' => 0,
],
], ],
'post-thread' => [ 'post-thread' => [
[ [
@ -710,6 +778,13 @@ return [
'causer-id' => 44, 'causer-id' => 44,
'network' => Protocol::DFRN, 'network' => Protocol::DFRN,
], ],
[
'uri-id' => 7,
'author-id' => 44,
'owner-id' => 44,
'causer-id' => 44,
'network' => Protocol::DFRN,
],
], ],
'post-thread-user' => [ 'post-thread-user' => [
[ [
@ -790,6 +865,32 @@ return [
'starred' => 0, 'starred' => 0,
'origin' => 0, 'origin' => 0,
], ],
[
'uri-id' => 7,
'uid' => 42,
'wall' => 1,
'post-user-id' => 7,
'author-id' => 44,
'owner-id' => 44,
'causer-id' => 44,
'contact-id' => 44,
'network' => Protocol::DFRN,
'starred' => 0,
'origin' => 1,
],
[
'uri-id' => 7,
'uid' => 0,
'wall' => 0,
'post-user-id' => 12,
'author-id' => 44,
'owner-id' => 44,
'causer-id' => 44,
'contact-id' => 44,
'network' => Protocol::DFRN,
'starred' => 0,
'origin' => 0,
],
], ],
'notify' => [ 'notify' => [
[ [

View file

@ -10,8 +10,8 @@ return [
'thr-parent-id' => 44, 'thr-parent-id' => 44,
'guid' => '123456', 'guid' => '123456',
'from-name' => 'Tester', 'from-name' => 'Tester',
'title' => 'test message', 'title' => 'item_title',
'body' => 'this is a test', 'body' => '[b]item_body[/b]',
], ],
], ],
]; ];

File diff suppressed because it is too large Load diff

View file

@ -23,6 +23,7 @@ namespace Friendica\Test\src\Core\Lock;
use Friendica\Core\Lock\Type\DatabaseLock; use Friendica\Core\Lock\Type\DatabaseLock;
use Friendica\Core\Config\Factory\Config; use Friendica\Core\Config\Factory\Config;
use Friendica\DI;
use Friendica\Test\DatabaseTestTrait; use Friendica\Test\DatabaseTestTrait;
use Friendica\Test\Util\Database\StaticDatabase; use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait; use Friendica\Test\Util\VFSTrait;
@ -48,20 +49,7 @@ class DatabaseLockDriverTest extends LockTest
protected function getInstance() protected function getInstance()
{ {
$logger = new NullLogger(); return new DatabaseLock(DI::dba(), $this->pid);
$profiler = Mockery::mock(Profiler::class);
$profiler->shouldReceive('startRecording');
$profiler->shouldReceive('stopRecording');
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
// load real config to avoid mocking every config-entry which is related to the Database class
$configFactory = new Config();
$loader = (new Config())->createConfigFileLoader($this->root->url(), []);
$configCache = $configFactory->createCache($loader);
$dba = new StaticDatabase($configCache, $profiler, $logger);
return new DatabaseLock($dba, $this->pid);
} }
protected function tearDown(): void protected function tearDown(): void

View file

@ -0,0 +1,48 @@
<?php
namespace Friendica\Test\src\Factory\Api\Twitter;
use Friendica\DI;
use Friendica\Factory\Api\Friendica\Activities;
use Friendica\Test\FixtureTest;
class ActivitiesTest extends FixtureTest
{
/**
* Test the api_format_items_activities() function.
*
* @return void
*/
public function testApiFormatItemsActivities()
{
$item = ['uid' => 0, 'uri-id' => 1];
$result = (new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()))
->createFromUriId($item['uri-id'], $item['uid']);
self::assertArrayHasKey('like', $result);
self::assertArrayHasKey('dislike', $result);
self::assertArrayHasKey('attendyes', $result);
self::assertArrayHasKey('attendno', $result);
self::assertArrayHasKey('attendmaybe', $result);
}
/**
* Test the api_format_items_activities() function with an XML result.
*
* @return void
*/
public function testApiFormatItemsActivitiesWithXml()
{
$item = ['uid' => 0, 'uri-id' => 1];
$result = (new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()))
->createFromUriId($item['uri-id'], $item['uid'], 'xml');
self::assertArrayHasKey('friendica:like', $result);
self::assertArrayHasKey('friendica:dislike', $result);
self::assertArrayHasKey('friendica:attendyes', $result);
self::assertArrayHasKey('friendica:attendno', $result);
self::assertArrayHasKey('friendica:attendmaybe', $result);
}
}

View file

@ -0,0 +1,95 @@
<?php
namespace Friendica\Test\src\Factory\Api\Twitter;
use Friendica\DI;
use Friendica\Factory\Api\Twitter\DirectMessage;
use Friendica\Test\FixtureTest;
use Friendica\Test\src\Module\Api\ApiTest;
class DirectMessageTest extends FixtureTest
{
/**
* Test the api_format_messages() function.
*
* @return void
*/
public function testApiFormatMessages()
{
$this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
$ids = DI::dba()->selectToArray('mail', ['id']);
$id = $ids[0]['id'];
$directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
->createFromMailId($id, ApiTest::SELF_USER['id'])
->toArray();
self::assertEquals('item_title' . "\n" . 'item_body', $directMessage['text']);
self::assertIsInt($directMessage['id']);
self::assertIsInt($directMessage['recipient_id']);
self::assertIsInt($directMessage['sender_id']);
self::assertEquals('selfcontact', $directMessage['recipient_screen_name']);
self::assertEquals('friendcontact', $directMessage['sender_screen_name']);
}
/**
* Test the api_format_messages() function with HTML.
*
* @return void
*/
public function testApiFormatMessagesWithHtmlText()
{
$this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
$ids = DI::dba()->selectToArray('mail', ['id']);
$id = $ids[0]['id'];
$directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
->createFromMailId($id, ApiTest::SELF_USER['id'], 'html')
->toArray();
self::assertEquals('item_title', $directMessage['title']);
self::assertEquals('<strong>item_body</strong>', $directMessage['text']);
}
/**
* Test the api_format_messages() function with plain text.
*
* @return void
*/
public function testApiFormatMessagesWithPlainText()
{
$this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
$ids = DI::dba()->selectToArray('mail', ['id']);
$id = $ids[0]['id'];
$directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain')
->toArray();
self::assertEquals('item_title', $directMessage['title']);
self::assertEquals('item_body', $directMessage['text']);
}
/**
* Test the api_format_messages() function with the getUserObjects GET parameter set to false.
*
* @return void
*/
public function testApiFormatMessagesWithoutUserObjects()
{
self::markTestIncomplete('Needs processing of "getUserObjects" first');
/*
$this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
$ids = DI::dba()->selectToArray('mail', ['id']);
$id = $ids[0]['id'];
$directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain', $$GETUSEROBJECTS$$)
->toArray();
self::assertTrue(!isset($directMessage['sender']));
self::assertTrue(!isset($directMessage['recipient']));
*/
}
}

View file

@ -0,0 +1,131 @@
<?php
namespace Friendica\Test\src\Factory\Api\Twitter;
use Friendica\DI;
use Friendica\Factory\Api\Friendica\Activities;
use Friendica\Factory\Api\Twitter\Attachment;
use Friendica\Factory\Api\Twitter\Hashtag;
use Friendica\Factory\Api\Twitter\Media;
use Friendica\Factory\Api\Twitter\Mention;
use Friendica\Factory\Api\Twitter\Status;
use Friendica\Factory\Api\Twitter\Url;
use Friendica\Test\FixtureTest;
use Friendica\Test\src\Module\Api\ApiTest;
class StatusTest extends FixtureTest
{
protected $statusFactory;
protected function setUp(): void
{
parent::setUp();
$this->statusFactory = new Status(
DI::logger(),
DI::dba(),
DI::twitterUser(),
new Hashtag(DI::logger()),
new Media(DI::logger(), DI::baseUrl()),
new Url(DI::logger()),
new Mention(DI::logger(), DI::baseUrl()),
new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()),
new Attachment(DI::logger()));
}
/**
* Test the api_convert_item() function.
*
* @return void
*/
public function testApiConvertItem()
{
$status = $this->statusFactory
->createFromItemId(13, ApiTest::SELF_USER['id'])
->toArray();
self::assertStringStartsWith('item_title', $status['text']);
self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $status['friendica_html']);
}
/**
* Test the api_convert_item() function with an empty item body.
*
* @return void
*/
public function testApiConvertItemWithoutBody()
{
self::markTestIncomplete('Needs a dataset first');
/*
$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()
{
self::markTestIncomplete('Needs a dataset first');
/*
$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_entitities() function.
*
* @return void
*/
public function testApiGetEntititiesWithIncludeEntities()
{
$status = $this->statusFactory
->createFromItemId(13, ApiTest::SELF_USER['id'], true)
->toArray();
self::assertIsArray($status['entities']);
self::assertIsArray($status['extended_entities']);
self::assertIsArray($status['entities']['hashtags']);
self::assertIsArray($status['entities']['media']);
self::assertIsArray($status['entities']['urls']);
self::assertIsArray($status['entities']['user_mentions']);
}
/**
* Test the api_format_items() function.
*/
public function testApiFormatItems()
{
$posts = DI::dba()->selectToArray('post-view', ['uri-id']);
foreach ($posts as $item) {
$status = $this->statusFactory
->createFromUriId($item['uri-id'], ApiTest::SELF_USER['id'])
->toArray();
self::assertIsInt($status['id']);
self::assertIsString($status['text']);
}
}
}

View file

@ -0,0 +1,139 @@
<?php
namespace Friendica\Test\src\Factory\Api\Twitter;
use Friendica\DI;
use Friendica\Factory\Api\Twitter\User;
use Friendica\Test\FixtureTest;
use Friendica\Test\src\Module\Api\ApiTest;
class UserTest extends FixtureTest
{
/**
* Assert that an user array contains expected keys.
*
* @return void
*/
protected function assertSelfUser(array $user)
{
self::assertEquals(ApiTest::SELF_USER['id'], $user['uid']);
self::assertEquals(ApiTest::SELF_USER['id'], $user['cid']);
self::assertEquals('DFRN', $user['location']);
self::assertEquals(ApiTest::SELF_USER['name'], $user['name']);
self::assertEquals(ApiTest::SELF_USER['nick'], $user['screen_name']);
self::assertTrue($user['verified']);
}
/**
* Test the api_get_user() function.
*
* @return void
*/
public function testApiGetUser()
{
$user = (new User(DI::logger(), DI::twitterStatus()))
->createFromUserId(ApiTest::SELF_USER['id'])
->toArray();
$this->assertSelfUser($user);
}
/**
* Test the api_get_user() function with a Frio schema.
*
* @return void
*/
public function testApiGetUserWithFrioSchema()
{
$this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
/*
DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', 'red');
$userFactory = new User(DI::logger(), DI::twitterStatus());
$user = $userFactory->createFromUserId(42);
$this->assertSelfUser($user->toArray());
self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
self::assertEquals('6fdbe8', $user['profile_link_color']);
self::assertEquals('ededed', $user['profile_background_color']);
*/
}
/**
* Test the api_get_user() function with an empty Frio schema.
*
* @return void
*/
public function testApiGetUserWithEmptyFrioSchema()
{
$this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
/*
DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', '---');
$userFactory = new User(DI::logger(), DI::twitterStatus());
$user = $userFactory->createFromUserId(42);
$this->assertSelfUser($user->toArray());
self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
self::assertEquals('6fdbe8', $user['profile_link_color']);
self::assertEquals('ededed', $user['profile_background_color']);
*/
}
/**
* Test the api_get_user() function with a custom Frio schema.
*
* @return void
*/
public function testApiGetUserWithCustomFrioSchema()
{
$this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
/*
DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', '---');
DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'nav_bg', '#123456');
DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'link_color', '#123456');
DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'background_color', '#123456');
$userFactory = new User(DI::logger(), DI::twitterStatus());
$user = $userFactory->createFromUserId(42);
$this->assertSelfUser($user->toArray());
self::assertEquals('123456', $user['profile_sidebar_fill_color']);
self::assertEquals('123456', $user['profile_link_color']);
self::assertEquals('123456', $user['profile_background_color']);
*/
}
/**
* Test the api_get_user() function with a wrong user ID in a GET parameter.
*
* @return void
*/
public function testApiGetUserWithWrongGetId()
{
$user = (new User(DI::logger(), DI::twitterStatus()))
->createFromUserId(-1)
->toArray();
self::assertEquals(0, $user['id']);
self::assertEquals(0, $user['uid']);
self::assertEquals(0, $user['cid']);
self::assertEquals(0, $user['pid']);
self::assertEmpty($user['name']);
}
/**
* Test the api_user() function with an unallowed user.
*
* @return void
*/
public function testApiUserWithUnallowedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// self::assertEquals(false, api_user());
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Friendica\Test\src\Model\Post;
use Friendica\Test\MockedTest;
class MediaTest extends MockedTest
{
/**
* Test the api_get_attachments() function.
*
* @return void
*/
public function testApiGetAttachments()
{
self::markTestIncomplete('Needs Model\Post\Media refactoring first.');
// $body = 'body';
// self::assertEmpty(api_get_attachments($body, 0));
}
/**
* Test the api_get_attachments() function with an img tag.
*
* @return void
*/
public function testApiGetAttachmentsWithImage()
{
self::markTestIncomplete('Needs Model\Post\Media refactoring first.');
// $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()
{
self::markTestIncomplete('Needs Model\Post\Media refactoring first.');
// $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
// $body = '[img]http://via.placeholder.com/1x1.png[/img]';
// self::assertIsArray(api_get_attachments($body, 0));
}
}

View file

@ -113,4 +113,214 @@ class ApiResponseTest extends MockedTest
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."}', $response->getContent()); 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."}', $response->getContent());
} }
/**
* Test the BaseApi::reformatXML() function.
*
* @return void
*/
public function testApiReformatXml()
{
$item = true;
$key = '';
self::assertTrue(ApiResponse::reformatXML($item, $key));
self::assertEquals('true', $item);
}
/**
* Test the BaseApi::reformatXML() function with a statusnet_api key.
*
* @return void
*/
public function testApiReformatXmlWithStatusnetKey()
{
$item = '';
$key = 'statusnet_api';
self::assertTrue(ApiResponse::reformatXML($item, $key));
self::assertEquals('statusnet:api', $key);
}
/**
* Test the BaseApi::reformatXML() function with a friendica_api key.
*
* @return void
*/
public function testApiReformatXmlWithFriendicaKey()
{
$item = '';
$key = 'friendica_api';
self::assertTrue(ApiResponse::reformatXML($item, $key));
self::assertEquals('friendica:api', $key);
}
/**
* Test the BaseApi::createXML() function.
*
* @return void
*/
public function testApiCreateXml()
{
$l10n = \Mockery::mock(L10n::class);
$l10n->shouldReceive('t')->andReturnUsing(function ($args) {
return $args;
});
$args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
self::assertEquals(
'<?xml version="1.0"?>' . "\n" .
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <data>some_data</data>' . "\n" .
'</root_element>' . "\n",
$response->createXML(['data' => ['some_data']], 'root_element')
);
}
/**
* Test the BaseApi::createXML() function without any XML namespace.
*
* @return void
*/
public function testApiCreateXmlWithoutNamespaces()
{
$l10n = \Mockery::mock(L10n::class);
$l10n->shouldReceive('t')->andReturnUsing(function ($args) {
return $args;
});
$args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
self::assertEquals(
'<?xml version="1.0"?>' . "\n" .
'<ok>' . "\n" .
' <data>some_data</data>' . "\n" .
'</ok>' . "\n",
$response->createXML(['data' => ['some_data']], 'ok')
);
}
/**
* Test the BaseApi::formatData() function.
*
* @return void
*/
public function testApiFormatData()
{
$l10n = \Mockery::mock(L10n::class);
$l10n->shouldReceive('t')->andReturnUsing(function ($args) {
return $args;
});
$args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
$data = ['some_data'];
self::assertEquals($data, $response->formatData('root_element', 'json', $data));
}
/**
* Test the BaseApi::formatData() function with an XML result.
*
* @return void
*/
public function testApiFormatDataWithXml()
{
$l10n = \Mockery::mock(L10n::class);
$l10n->shouldReceive('t')->andReturnUsing(function ($args) {
return $args;
});
$args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$twitterUser = \Mockery::mock(User::class);
$response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
self::assertEquals(
'<?xml version="1.0"?>' . "\n" .
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <data>some_data</data>' . "\n" .
'</root_element>' . "\n",
$response->formatData('root_element', 'xml', ['data' => ['some_data']])
);
}
/**
* Test the api_rss_extra() function.
*
* @return void
*/
public function testApiRssExtra()
{
self::markTestIncomplete('Cannot mock it yet.');
/*
$user_info = ['url' => 'user_url', 'lang' => 'en'];
$userMock = \Mockery::mock(\Friendica\Object\Api\Twitter\User::class);
$userMock->shouldReceive('toArray')->andReturn($user_info);
$l10n = \Mockery::mock(L10n::class);
$l10n->shouldReceive('t')->andReturnUsing(function ($args) {
return $args;
});
$args = \Mockery::mock(Arguments::class);
$args->shouldReceive('getQueryString')->andReturn('');
$baseUrl = \Mockery::mock(BaseURL::class);
$baseUrl->shouldReceive('__toString')->andReturn('https://friendica.local');
$twitterUser = \Mockery::mock(User::class);
$twitterUser->shouldReceive('createFromContactId')->with(1)->andReturn($userMock);
$response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
$result = $response->formatData('root_element', 'rss', ['data' => ['some_data']], 1);
print_r($result);
self::assertEquals($user_info, $result['$user']);
self::assertEquals($user_info['url'], $result['$rss']['alternate']);
self::assertArrayHasKey('self', $result['$rss']);
self::assertArrayHasKey('base', $result['$rss']);
self::assertArrayHasKey('updated', $result['$rss']);
self::assertArrayHasKey('atom_updated', $result['$rss']);
self::assertArrayHasKey('language', $result['$rss']);
self::assertArrayHasKey('logo', $result['$rss']);
*/
}
/**
* Test the api_rss_extra() function without any user info.
*
* @return void
*/
public function testApiRssExtraWithoutUserInfo()
{
self::markTestIncomplete('Cannot mock it yet.');
/*
$result = api_rss_extra([], null);
self::assertIsArray($result['$user']);
self::assertArrayHasKey('alternate', $result['$rss']);
self::assertArrayHasKey('self', $result['$rss']);
self::assertArrayHasKey('base', $result['$rss']);
self::assertArrayHasKey('updated', $result['$rss']);
self::assertArrayHasKey('atom_updated', $result['$rss']);
self::assertArrayHasKey('language', $result['$rss']);
self::assertArrayHasKey('logo', $result['$rss']);
*/
}
} }

View file

@ -34,7 +34,8 @@ class SearchTest extends ApiTest
{ {
$directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser()); $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser());
$response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))->run(); $response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
->run();
$json = $this->toJson($response); $json = $this->toJson($response);
@ -51,8 +52,10 @@ class SearchTest extends ApiTest
$directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser()); $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser());
$search = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $search->run(['searchstring' => 'test']); ->run([
'searchstring' => 'item_body'
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -70,8 +73,10 @@ class SearchTest extends ApiTest
{ {
$directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser()); $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser());
$search = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $search->run(['searchstring' => 'test']); ->run([
'searchstring' => 'test'
]);
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -66,17 +66,20 @@ class NotificationTest extends ApiTest
</notes> </notes>
XML; XML;
$notification = new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']); $response = (new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']))
$response = $notification->run(); ->run();
self::assertXmlStringEqualsXmlString($assertXml, (string)$response->getBody()); self::assertXmlStringEqualsXmlString($assertXml, (string)$response->getBody());
self::assertEquals(['Content-type' => ['text/xml'], ICanCreateResponses::X_HEADER => ['xml']], $response->getHeaders()); self::assertEquals([
'Content-type' => ['text/xml'],
ICanCreateResponses::X_HEADER => ['xml']
], $response->getHeaders());
} }
public function testWithJsonResult() public function testWithJsonResult()
{ {
$notification = new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); $response = (new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
$response = $notification->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);
@ -88,6 +91,9 @@ XML;
self::assertIsString($note->msg); self::assertIsString($note->msg);
} }
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals([
'Content-type' => ['application/json'],
ICanCreateResponses::X_HEADER => ['json']
], $response->getHeaders());
} }
} }

View file

@ -50,8 +50,10 @@ class DeleteTest extends ApiTest
{ {
$this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba()); $this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba());
$delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $delete->run(['photo_id' => '709057080661a283a6aa598501504178']); ->run([
'photo_id' => '709057080661a283a6aa598501504178'
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -63,8 +65,10 @@ class DeleteTest extends ApiTest
{ {
$this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba()); $this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba());
$delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $delete->run(['photo_id' => '709057080661a283a6aa598501504178']); ->run([
'photo_id' => '709057080661a283a6aa598501504178'
]);
$responseText = (string)$response->getBody(); $responseText = (string)$response->getBody();

View file

@ -32,22 +32,28 @@ class DeleteTest extends ApiTest
public function testEmpty() public function testEmpty()
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
(new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run();
} }
public function testWrong() public function testWrong()
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
(new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'album_name']); (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run([
'album' => 'album_name'
]);
} }
public function testValidWithDelete() public function testValidWithDelete()
{ {
$this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba()); $this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba());
$delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $delete->run(['album' => 'test_album']); ->run([
'album' => 'test_album']
);
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -32,19 +32,27 @@ class UpdateTest extends ApiTest
public function testEmpty() public function testEmpty()
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
(new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run();
} }
public function testTooFewArgs() public function testTooFewArgs()
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
(new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'album_name']); (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run([
'album' => 'album_name'
]);
} }
public function testWrongUpdate() public function testWrongUpdate()
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
(new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'album_name', 'album_new' => 'album_name']); (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run([
'album' => 'album_name',
'album_new' => 'album_name'
]);
} }
public function testWithoutAuthenticatedUser() public function testWithoutAuthenticatedUser()
@ -56,7 +64,11 @@ class UpdateTest extends ApiTest
{ {
$this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba()); $this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba());
$response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'test_album', 'album_new' => 'test_album_2']); $response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run([
'album' => 'test_album',
'album_new' => 'test_album_2'
]);
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -17,8 +17,8 @@ class ConfigTest extends ApiTest
{ {
DI::config()->set('system', 'ssl_policy', BaseURL::SSL_POLICY_FULL); DI::config()->set('system', 'ssl_policy', BaseURL::SSL_POLICY_FULL);
$config = new Config(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Config(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $config->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -11,10 +11,13 @@ class VersionTest extends ApiTest
{ {
public function test() public function test()
{ {
$version = new Version(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); $response = (new Version(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
$response = $version->run(); ->run();
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals([
'Content-type' => ['application/json'],
ICanCreateResponses::X_HEADER => ['json']
], $response->getHeaders());
self::assertEquals('"0.9.7"', $response->getBody()); self::assertEquals('"0.9.7"', $response->getBody());
} }
} }

View file

@ -11,21 +11,27 @@ class TestTest extends ApiTest
{ {
public function testJson() public function testJson()
{ {
$test = new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); $response = (new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
$response = $test->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals([
'Content-type' => ['application/json'],
ICanCreateResponses::X_HEADER => ['json']
], $response->getHeaders());
self::assertEquals('ok', $json); self::assertEquals('ok', $json);
} }
public function testXml() public function testXml()
{ {
$test = new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']); $response = (new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']))
$response = $test->run(); ->run();
self::assertEquals(['Content-type' => ['text/xml'], ICanCreateResponses::X_HEADER => ['xml']], $response->getHeaders()); self::assertEquals([
'Content-type' => ['text/xml'],
ICanCreateResponses::X_HEADER => ['xml']
], $response->getHeaders());
self::assertxml($response->getBody(), 'ok'); self::assertxml($response->getBody(), 'ok');
} }
} }

View file

@ -16,8 +16,8 @@ class VerifyCredentialsTest extends ApiTest
*/ */
public function testApiAccountVerifyCredentials() public function testApiAccountVerifyCredentials()
{ {
$verifyCredentials = new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $verifyCredentials->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -12,12 +12,15 @@ class RateLimitStatusTest extends ApiTest
{ {
public function testWithJson() public function testWithJson()
{ {
$rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); $response = (new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
$response = $rateLimitStatus->run(); ->run();
$result = $this->toJson($response); $result = $this->toJson($response);
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals([
'Content-type' => ['application/json'],
ICanCreateResponses::X_HEADER => ['json']
], $response->getHeaders());
self::assertEquals(150, $result->remaining_hits); self::assertEquals(150, $result->remaining_hits);
self::assertEquals(150, $result->hourly_limit); self::assertEquals(150, $result->hourly_limit);
self::assertIsInt($result->reset_time_in_seconds); self::assertIsInt($result->reset_time_in_seconds);
@ -25,10 +28,13 @@ class RateLimitStatusTest extends ApiTest
public function testWithXml() public function testWithXml()
{ {
$rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']); $response = (new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']))
$response = $rateLimitStatus->run(); ->run();
self::assertEquals(['Content-type' => ['text/xml'], ICanCreateResponses::X_HEADER => ['xml']], $response->getHeaders()); self::assertEquals([
'Content-type' => ['text/xml'],
ICanCreateResponses::X_HEADER => ['xml']
], $response->getHeaders());
self::assertXml($response->getBody(), 'hash'); self::assertXml($response->getBody(), 'hash');
} }
} }

View file

@ -14,8 +14,11 @@ class UpdateProfileTest extends ApiTest
*/ */
public function testApiAccountUpdateProfile() public function testApiAccountUpdateProfile()
{ {
$updateProfile = new UpdateProfile(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => 'json']); $response = (new UpdateProfile(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => 'json']))
$response = $updateProfile->run(['name' => 'new_name', 'description' => 'new_description']); ->run([
'name' => 'new_name',
'description' => 'new_description'
]);
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -14,8 +14,8 @@ class ListsTest extends ApiTest
*/ */
public function testApiStatusesFWithBlocks() public function testApiStatusesFWithBlocks()
{ {
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $lists->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -0,0 +1,36 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\DirectMessages\All;
use Friendica\Factory\Api\Twitter\DirectMessage;
use Friendica\Test\src\Module\Api\ApiTest;
class AllTest extends ApiTest
{
/**
* Test the api_direct_messages_box() function.
*
* @return void
*/
public function testApiDirectMessagesBoxWithAll()
{
$this->loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba());
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new All($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run();
$json = $this->toJson($response);
self::assertGreaterThan(0, count($json));
foreach ($json as $item) {
self::assertIsInt($item->id);
self::assertIsString($item->text);
}
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Factory\Api\Twitter\DirectMessage;
use Friendica\Module\Api\Twitter\DirectMessages\Conversation;
use Friendica\Test\src\Module\Api\ApiTest;
class ConversationTest extends ApiTest
{
/**
* Test the api_direct_messages_box() function.
*
* @return void
*/
public function testApiDirectMessagesBoxWithConversation()
{
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new Conversation($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'friendica_verbose' => true,
]);
$json = $this->toJson($response);
self::assertEquals('error', $json->result);
self::assertEquals('no mails available', $json->message);
}
}

View file

@ -0,0 +1,116 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
use Friendica\App\Router;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Api\Twitter\DirectMessages\Destroy;
use Friendica\Test\src\Module\Api\ApiTest;
class DestroyTest extends ApiTest
{
/**
* Test the api_direct_messages_destroy() function.
*
* @return void
*/
public function testApiDirectMessagesDestroy()
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
(new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run();
}
/**
* Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
*
* @return void
*/
public function testApiDirectMessagesDestroyWithVerbose()
{
$response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'friendica_verbose' => true,
]);
$json = $this->toJson($response);
self::assertEquals('error', $json->result);
self::assertEquals('message id or parenturi not specified', $json->message);
}
/**
* Test the api_direct_messages_destroy() function without an authenticated user.
*
* @return void
*/
public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
/*
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_direct_messages_destroy('json');
*/
}
/**
* Test the api_direct_messages_destroy() function with a non-zero ID.
*
* @return void
*/
public function testApiDirectMessagesDestroyWithId()
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
(new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'id' => 1
]);
}
/**
* Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
*
* @return void
*/
public function testApiDirectMessagesDestroyWithIdAndVerbose()
{
$response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'id' => 1,
'friendica_parenturi' => 'parent_uri',
'friendica_verbose' => true,
]);
$json = $this->toJson($response);
self::assertEquals('error', $json->result);
self::assertEquals('message id not in database', $json->message);
}
/**
* Test the api_direct_messages_destroy() function with a non-zero ID.
*
* @return void
*/
public function testApiDirectMessagesDestroyWithCorrectId()
{
$this->loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba());
$ids = DBA::selectToArray('mail', ['id']);
$id = $ids[0]['id'];
$response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'id' => $id,
'friendica_verbose' => true,
]);
$json = $this->toJson($response);
self::assertEquals('ok', $json->result);
self::assertEquals('message deleted', $json->message);
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Factory\Api\Twitter\DirectMessage;
use Friendica\Module\Api\Twitter\DirectMessages\Inbox;
use Friendica\Test\src\Module\Api\ApiTest;
class InboxTest extends ApiTest
{
/**
* Test the api_direct_messages_box() function.
*
* @return void
*/
public function testApiDirectMessagesBoxWithInbox()
{
$this->loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba());
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new Inbox($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run();
$json = $this->toJson($response);
self::assertGreaterThan(0, count($json));
foreach ($json as $item) {
self::assertIsInt($item->id);
self::assertIsString($item->text);
}
}
}

View file

@ -0,0 +1,135 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Factory\Api\Twitter\DirectMessage;
use Friendica\Module\Api\Twitter\DirectMessages\NewDM;
use Friendica\Test\src\Module\Api\ApiTest;
class NewDMTest extends ApiTest
{
/**
* Test the api_direct_messages_new() function.
*
* @return void
*/
public function testApiDirectMessagesNew()
{
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run();
self::assertEmpty((string)$response->getBody());
}
/**
* Test the api_direct_messages_new() function without an authenticated user.
*
* @return void
*/
public function testApiDirectMessagesNewWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
/*
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_direct_messages_new('json');
*/
}
/**
* Test the api_direct_messages_new() function with an user ID.
*
* @return void
*/
public function testApiDirectMessagesNewWithUserId()
{
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'text' => 'message_text',
'user_id' => 43
]);
$json = $this->toJson($response);
self::assertEquals(-1, $json->error);
}
/**
* Test the api_direct_messages_new() function with a screen name.
*
* @return void
*/
public function testApiDirectMessagesNewWithScreenName()
{
DI::app()->setLoggedInUserNickname('selfcontact');
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'text' => 'message_text',
'user_id' => 44
]);
$json = $this->toJson($response);
self::assertStringContainsString('message_text', $json->text);
self::assertEquals('selfcontact', $json->sender_screen_name);
self::assertEquals(1, $json->friendica_seen);
}
/**
* Test the api_direct_messages_new() function with a title.
*
* @return void
*/
public function testApiDirectMessagesNewWithTitle()
{
DI::app()->setLoggedInUserNickname('selfcontact');
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'text' => 'message_text',
'user_id' => 44,
'title' => 'message_title',
]);
$json = $this->toJson($response);
self::assertStringContainsString('message_text', $json->text);
self::assertStringContainsString('message_title', $json->text);
self::assertEquals('selfcontact', $json->sender_screen_name);
self::assertEquals(1, $json->friendica_seen);
}
/**
* Test the api_direct_messages_new() function with an RSS result.
*
* @return void
*/
public function testApiDirectMessagesNewWithRss()
{
DI::app()->setLoggedInUserNickname('selfcontact');
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']))
->run([
'text' => 'message_text',
'user_id' => 44,
'title' => 'message_title',
]);
self::assertXml((string)$response->getBody(), 'direct-messages');
}
}

View file

@ -0,0 +1,61 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Factory\Api\Twitter\DirectMessage;
use Friendica\Module\Api\Twitter\DirectMessages\Sent;
use Friendica\Test\src\Module\Api\ApiTest;
class SentTest extends ApiTest
{
/**
* Test the api_direct_messages_box() function.
*
* @return void
*/
public function testApiDirectMessagesBoxWithVerbose()
{
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new Sent($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
->run([
'friendica_verbose' => true,
]);
$json = $this->toJson($response);
self::assertEquals('error', $json->result);
self::assertEquals('no mails available', $json->message);
}
/**
* Test the api_direct_messages_box() function with a RSS result.
*
* @return void
*/
public function testApiDirectMessagesBoxWithRss()
{
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
$response = (new Sent($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']))
->run();
self::assertXml((string)$response->getBody(), 'direct-messages');
}
/**
* Test the api_direct_messages_box() function without an authenticated user.
*
* @return void
*/
public function testApiDirectMessagesBoxWithUnallowedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
//$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
//BasicAuth::setCurrentUserID();
//api_direct_messages_box('json', 'sentbox', 'false');
}
}

View file

@ -20,8 +20,8 @@ class CreateTest extends ApiTest
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
$create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); (new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$create->run(); ->run();
} }
/** /**
@ -31,8 +31,10 @@ class CreateTest extends ApiTest
*/ */
public function testApiFavoritesCreateDestroyWithCreateAction() public function testApiFavoritesCreateDestroyWithCreateAction()
{ {
$create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $create->run(['id' => 3]); ->run([
'id' => 3
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -46,8 +48,10 @@ class CreateTest extends ApiTest
*/ */
public function testApiFavoritesCreateDestroyWithCreateActionAndRss() public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
{ {
$create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => ICanCreateResponses::TYPE_RSS]); $response = (new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => ICanCreateResponses::TYPE_RSS]))
$response = $create->run(['id' => 3]); ->run([
'id' => 3
]);
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));

View file

@ -19,8 +19,8 @@ class DestroyTest extends ApiTest
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
$destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$destroy->run(); ->run();
} }
/** /**
@ -30,8 +30,10 @@ class DestroyTest extends ApiTest
*/ */
public function testApiFavoritesCreateDestroyWithDestroyAction() public function testApiFavoritesCreateDestroyWithDestroyAction()
{ {
$destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $destroy->run(['id' => 3]); ->run([
'id' => 3
]);
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -17,8 +17,8 @@ class FavoritesTest extends ApiTest
*/ */
public function testApiFavorites() public function testApiFavorites()
{ {
$favorites = new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $favorites->run([ ->run([
'page' => -1, 'page' => -1,
'max_id' => 10, 'max_id' => 10,
]); ]);
@ -37,8 +37,9 @@ class FavoritesTest extends ApiTest
*/ */
public function testApiFavoritesWithRss() public function testApiFavoritesWithRss()
{ {
$favorites = new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]); $response = (new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [
$response = $favorites->run(); 'extension' => ICanCreateResponses::TYPE_RSS
]))->run();
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));

View file

@ -14,8 +14,8 @@ class ListsTest extends ApiTest
*/ */
public function testApiStatusesFWithFollowers() public function testApiStatusesFWithFollowers()
{ {
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $lists->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -16,8 +16,8 @@ class ListsTest extends ApiTest
*/ */
public function testApiStatusesFWithFriends() public function testApiStatusesFWithFriends()
{ {
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $lists->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -16,8 +16,8 @@ class IncomingTest extends ApiTest
*/ */
public function testApiFriendshipsIncoming() public function testApiFriendshipsIncoming()
{ {
$lists = new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $lists->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -19,8 +19,8 @@ class StatusesTest extends ApiTest
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
$lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); (new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$lists->run(); ->run();
} }
/** /**
@ -28,8 +28,12 @@ class StatusesTest extends ApiTest
*/ */
public function testApiListsStatusesWithListId() public function testApiListsStatusesWithListId()
{ {
$lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $lists->run(['list_id' => 1, 'page' => -1, 'max_id' => 10]); ->run([
'list_id' => 1,
'page' => -1,
'max_id' => 10
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -44,8 +48,10 @@ class StatusesTest extends ApiTest
*/ */
public function testApiListsStatusesWithListIdAndRss() public function testApiListsStatusesWithListIdAndRss()
{ {
$lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']); $response = (new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']))
$response = $lists->run(['list_id' => 1]); ->run([
'list_id' => 1
]);
self::assertXml((string)$response->getBody()); self::assertXml((string)$response->getBody());
} }

View file

@ -19,8 +19,9 @@ class UploadTest extends ApiTest
public function testApiMediaUpload() public function testApiMediaUpload()
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
$upload = new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
$upload->run(); (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run();
} }
/** /**
@ -32,7 +33,9 @@ class UploadTest extends ApiTest
{ {
$this->expectException(UnauthorizedException::class); $this->expectException(UnauthorizedException::class);
AuthTestConfig::$authenticated = false; AuthTestConfig::$authenticated = false;
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run();
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run();
} }
/** /**
@ -49,7 +52,9 @@ class UploadTest extends ApiTest
'tmp_name' => 'tmp_name' 'tmp_name' => 'tmp_name'
] ]
]; ];
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run();
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run();
} }
/** /**
@ -71,7 +76,8 @@ class UploadTest extends ApiTest
] ]
]; ];
$response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); $response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
->run();
$media = $this->toJson($response); $media = $this->toJson($response);

View file

@ -11,8 +11,8 @@ class SavedSearchesTest extends ApiTest
{ {
public function test() public function test()
{ {
$savedSearch = new SavedSearches(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); $response = (new SavedSearches(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
$response = $savedSearch->run(); ->run();
$result = $this->toJson($response); $result = $this->toJson($response);

View file

@ -19,8 +19,8 @@ class DestroyTest extends ApiTest
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
$destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$destroy->run(); ->run();
} }
/** /**
@ -45,8 +45,10 @@ class DestroyTest extends ApiTest
*/ */
public function testApiStatusesDestroyWithId() public function testApiStatusesDestroyWithId()
{ {
$destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $destroy->run(['id' => 1]); ->run([
'id' => 1
]);
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -17,8 +17,10 @@ class MentionsTest extends ApiTest
*/ */
public function testApiStatusesMentions() public function testApiStatusesMentions()
{ {
$mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $mentions->run(['max_id' => 10]); ->run([
'max_id' => 10
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -33,8 +35,10 @@ class MentionsTest extends ApiTest
*/ */
public function testApiStatusesMentionsWithNegativePage() public function testApiStatusesMentionsWithNegativePage()
{ {
$mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $mentions->run(['page' => -2]); ->run([
'page' => -2
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -63,8 +67,10 @@ class MentionsTest extends ApiTest
*/ */
public function testApiStatusesMentionsWithRss() public function testApiStatusesMentionsWithRss()
{ {
$mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]); $response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]))
$response = $mentions->run(['page' => -2]); ->run([
'page' => -2
]);
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));

View file

@ -17,8 +17,10 @@ class NetworkPublicTimelineTest extends ApiTest
*/ */
public function testApiStatusesNetworkpublicTimeline() public function testApiStatusesNetworkpublicTimeline()
{ {
$networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $networkPublicTimeline->run(['max_id' => 10]); ->run([
'max_id' => 10
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -37,8 +39,10 @@ class NetworkPublicTimelineTest extends ApiTest
*/ */
public function testApiStatusesNetworkpublicTimelineWithNegativePage() public function testApiStatusesNetworkpublicTimelineWithNegativePage()
{ {
$networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $networkPublicTimeline->run(['page' => -2]); ->run([
'page' => -2
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -71,8 +75,11 @@ class NetworkPublicTimelineTest extends ApiTest
*/ */
public function testApiStatusesNetworkpublicTimelineWithRss() public function testApiStatusesNetworkpublicTimelineWithRss()
{ {
$networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]); $response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [
$response = $networkPublicTimeline->run(['page' => -2]); 'extension' => ICanCreateResponses::TYPE_RSS
]))->run([
'page' => -2
]);
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));

View file

@ -19,8 +19,8 @@ class RetweetTest extends ApiTest
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
$retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); (new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$retweet->run(); ->run();
} }
/** /**
@ -45,8 +45,10 @@ class RetweetTest extends ApiTest
*/ */
public function testApiStatusesRepeatWithId() public function testApiStatusesRepeatWithId()
{ {
$retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $retweet->run(['id' => 1]); ->run([
'id' => 1
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -60,8 +62,10 @@ class RetweetTest extends ApiTest
*/ */
public function testApiStatusesRepeatWithSharedId() public function testApiStatusesRepeatWithSharedId()
{ {
$retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $retweet->run(['id' => 5]); ->run([
'id' => 5
]);
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -19,8 +19,9 @@ class ShowTest extends ApiTest
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$show->run(); (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
->run();
} }
/** /**
@ -30,8 +31,10 @@ class ShowTest extends ApiTest
*/ */
public function testApiStatusesShowWithId() public function testApiStatusesShowWithId()
{ {
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $show->run(['id' => 1]); ->run([
'id' => 1
]);
$json = $this->toJson($response); $json = $this->toJson($response);
@ -46,8 +49,11 @@ class ShowTest extends ApiTest
*/ */
public function testApiStatusesShowWithConversation() public function testApiStatusesShowWithConversation()
{ {
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $show->run(['id' => 1, 'conversation' => 1]); ->run([
'id' => 1,
'conversation' => 1
]);
$json = $this->toJson($response); $json = $this->toJson($response);

View file

@ -28,8 +28,8 @@ class UpdateTest extends ApiTest
] ]
]; ];
$show = new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $show->run([ ->run([
'status' => 'Status content #friendica', 'status' => 'Status content #friendica',
'in_reply_to_status_id' => 0, 'in_reply_to_status_id' => 0,
'lat' => 48, 'lat' => 48,
@ -50,8 +50,8 @@ class UpdateTest extends ApiTest
*/ */
public function testApiStatusesUpdateWithHtml() public function testApiStatusesUpdateWithHtml()
{ {
$show = new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); $response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))
$response = $show->run([ ->run([
'htmlstatus' => '<b>Status content</b>', 'htmlstatus' => '<b>Status content</b>',
]); ]);

View file

@ -17,9 +17,8 @@ class UserTimelineTest extends ApiTest
*/ */
public function testApiStatusesUserTimeline() public function testApiStatusesUserTimeline()
{ {
$networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
->run([
$response = $networkPublicTimeline->run([
'user_id' => 42, 'user_id' => 42,
'max_id' => 10, 'max_id' => 10,
'exclude_replies' => true, 'exclude_replies' => true,
@ -43,9 +42,8 @@ class UserTimelineTest extends ApiTest
*/ */
public function testApiStatusesUserTimelineWithNegativePage() public function testApiStatusesUserTimelineWithNegativePage()
{ {
$networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
->run([
$response = $networkPublicTimeline->run([
'user_id' => 42, 'user_id' => 42,
'page' => -2, 'page' => -2,
]); ]);
@ -67,9 +65,9 @@ class UserTimelineTest extends ApiTest
*/ */
public function testApiStatusesUserTimelineWithRss() public function testApiStatusesUserTimelineWithRss()
{ {
$networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]); $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [
'extension' => ICanCreateResponses::TYPE_RSS
$response = $networkPublicTimeline->run(); ]))->run();
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));

View file

@ -19,8 +19,8 @@ class LookupTest extends ApiTest
{ {
$this->expectException(NotFoundException::class); $this->expectException(NotFoundException::class);
$lookup = new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); (new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$lookup->run(); ->run();
} }
/** /**
@ -30,8 +30,10 @@ class LookupTest extends ApiTest
*/ */
public function testApiUsersLookupWithUserId() public function testApiUsersLookupWithUserId()
{ {
$lookup = new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $respone = (new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$respone = $lookup->run(['user_id' => static::OTHER_USER['id']]); ->run([
'user_id' => static::OTHER_USER['id']
]);
$json = $this->toJson($respone); $json = $this->toJson($respone);

View file

@ -18,8 +18,10 @@ class SearchTest extends ApiTest
*/ */
public function testApiUsersSearch() public function testApiUsersSearch()
{ {
$search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $respone = (new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$respone = $search->run(['q' => static::OTHER_USER['name']]); ->run([
'q' => static::OTHER_USER['name']
]);
$json = $this->toJson($respone); $json = $this->toJson($respone);
@ -33,8 +35,11 @@ class SearchTest extends ApiTest
*/ */
public function testApiUsersSearchWithXml() public function testApiUsersSearchWithXml()
{ {
$search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_XML]); $respone = (new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [
$respone = $search->run(['q' => static::OTHER_USER['name']]); 'extension' => ICanCreateResponses::TYPE_XML
]))->run([
'q' => static::OTHER_USER['name']
]);
self::assertXml((string)$respone->getBody(), 'users'); self::assertXml((string)$respone->getBody(), 'users');
} }
@ -48,7 +53,7 @@ class SearchTest extends ApiTest
{ {
$this->expectException(BadRequestException::class); $this->expectException(BadRequestException::class);
$search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); (new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$search->run(); ->run();
} }
} }

View file

@ -17,8 +17,8 @@ class ShowTest extends ApiTest
*/ */
public function testApiUsersShow() public function testApiUsersShow()
{ {
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); $response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))
$response = $show->run(); ->run();
$json = $this->toJson($response); $json = $this->toJson($response);
@ -37,8 +37,9 @@ class ShowTest extends ApiTest
*/ */
public function testApiUsersShowWithXml() public function testApiUsersShowWithXml()
{ {
$show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_XML]); $response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [
$response = $show->run(); 'extension' => ICanCreateResponses::TYPE_XML
]))->run();
self::assertEquals(ICanCreateResponses::TYPE_XML, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); self::assertEquals(ICanCreateResponses::TYPE_XML, $response->getHeaderLine(ICanCreateResponses::X_HEADER));

View file

@ -14,10 +14,8 @@ class NodeInfoTest extends FixtureTest
{ {
public function testNodeInfo110() public function testNodeInfo110()
{ {
$response = new Response(); $response = (new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
->run();
$nodeinfo = new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []);
$response = $nodeinfo->run();
self::assertJson($response->getBody()); self::assertJson($response->getBody());
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
@ -37,10 +35,8 @@ class NodeInfoTest extends FixtureTest
public function testNodeInfo120() public function testNodeInfo120()
{ {
$response = new Response(); $response = (new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
->run();
$nodeinfo = new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []);
$response = $nodeinfo->run();
self::assertJson($response->getBody()); self::assertJson($response->getBody());
self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
@ -59,10 +55,8 @@ class NodeInfoTest extends FixtureTest
public function testNodeInfo210() public function testNodeInfo210()
{ {
$response = new Response(); $response = (new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
->run();
$nodeinfo = new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []);
$response = $nodeinfo->run();
self::assertJson($response->getBody()); self::assertJson($response->getBody());
self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());