$dice->create(\Friendica\Core\PConfig\Capability\IManagePersonalConfigValues::class),
$dice->create(\Friendica\Security\Authentication::class),
$dice->create(\Friendica\App\Page::class),
+ $dice->create(Friendica\Module\Special\HTTPException::class),
new \Friendica\Util\HTTPInputData($_SERVER),
$start_time
);
* @param IManagePersonalConfigValues $pconfig
* @param Authentication $auth The Authentication backend of the node
* @param App\Page $page The Friendica page printing container
+ * @param ModuleHTTPException $httpException The possible HTTP Exception container
* @param HTTPInputData $httpInput A library for processing PHP input streams
* @param float $start_time The start time of the overall script execution
*
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, HTTPInputData $httpInput, float $start_time)
+ public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, ModuleHTTPException $httpException, HTTPInputData $httpInput, float $start_time)
{
$this->profiler->set($start_time, 'start');
$this->profiler->set(microtime(true), 'classinit');
$httpinput = $httpInput->process();
$input = array_merge($httpinput['variables'], $httpinput['files'], $request ?? $_REQUEST);
- // Let the module run it's internal process (init, get, post, ...)
+ // Let the module run its internal process (init, get, post, ...)
$timestamp = microtime(true);
- $response = $module->run($input);
+ $response = $module->run($httpException, $input);
$this->profiler->set(microtime(true) - $timestamp, 'content');
if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) {
$page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $this->session->getLocalUserId());
$page->exit($response);
}
} catch (HTTPException $e) {
- (new ModuleHTTPException())->rawContent($e);
+ $httpException->rawContent($e);
}
$page->logRuntime($this->config, 'runFrontend');
}
/**
* {@inheritDoc}
*/
- public function run(array $request = []): ResponseInterface
+ public function run(ModuleHTTPException $httpException, array $request = []): ResponseInterface
{
// @see https://github.com/tootsuite/mastodon/blob/c3aef491d66aec743a3a53e934a494f653745b61/config/initializers/cors.rb
if (substr($this->args->getQueryString(), 0, 12) == '.well-known/') {
$this->response->addContent($arr['content']);
$this->response->addContent($this->content($request));
} catch (HTTPException $e) {
- $this->response->addContent((new ModuleHTTPException())->content($e));
+ $this->response->addContent($httpException->content($e));
} finally {
$this->profiler->set(microtime(true) - $timestamp, 'content');
}
namespace Friendica\Capabilities;
+use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Psr\Http\Message\ResponseInterface;
interface ICanHandleRequests
{
/**
- * @param array $request The $_REQUEST content (including content from the PHP input stream)
+ * @param ModuleHTTPException $httpException The special HTTPException Module in case of underlying errors
+ * @param array $request The $_REQUEST content (including content from the PHP input stream)
*
* @return ResponseInterface responding to the request handling
*
* @throws HTTPException\InternalServerErrorException
*/
- public function run(array $request = []): ResponseInterface;
+ public function run(ModuleHTTPException $httpException, array $request = []): ResponseInterface;
}
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseApi;
+use Friendica\Module\Special\HTTPException;
use Friendica\Util\Network;
use Psr\Http\Message\ResponseInterface;
*/
class Apps extends BaseApi
{
- public function run(array $request = [], bool $scopecheck = true): ResponseInterface
+ public function run(HTTPException $httpException, array $request = [], bool $scopecheck = true): ResponseInterface
{
- return parent::run($request, false);
+ return parent::run($httpException, $request, false);
}
/**
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Module\Api\ApiResponse;
+use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Security\BasicAuth;
use Friendica\Security\OAuth;
*
* @throws HTTPException\ForbiddenException
*/
- public function run(array $request = [], bool $scopecheck = true): ResponseInterface
+ public function run(ModuleHTTPException $httpException, array $request = [], bool $scopecheck = true): ResponseInterface
{
if ($scopecheck) {
switch ($this->args->getMethod()) {
}
}
- return parent::run($request);
+ return parent::run($httpException, $request);
}
/**
namespace Friendica\Module\HTTPException;
use Friendica\BaseModule;
-use Friendica\DI;
use Friendica\Network\HTTPException;
class MethodNotAllowed extends BaseModule
{
protected function content(array $request = []): string
{
- throw new HTTPException\MethodNotAllowedException(DI::l10n()->t('Method Not Allowed.'));
+ throw new HTTPException\MethodNotAllowedException($this->t('Method Not Allowed.'));
}
}
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\System;
-use Friendica\DI;
use Friendica\Module\Response;
+use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Util\Profiler;
use Psr\Http\Message\ResponseInterface;
protected function content(array $request = []): string
{
- throw new HTTPException\NotFoundException(DI::l10n()->t('Page not found.'));
+ throw new HTTPException\NotFoundException($this->t('Page not found.'));
}
- public function run(array $request = []): ResponseInterface
+ public function run(ModuleHTTPException $httpException, array $request = []): ResponseInterface
{
/* The URL provided does not resolve to a valid module.
*
'query' => $this->server['QUERY_STRING']
]);
- return parent::run($request); // TODO: Change the autogenerated stub
+ return parent::run($httpException, $request);
}
}
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseApi;
+use Friendica\Module\Special\HTTPException;
use Psr\Http\Message\ResponseInterface;
/**
*/
class Acknowledge extends BaseApi
{
- public function run(array $request = [], bool $scopecheck = true): ResponseInterface
+ public function run(HTTPException $httpException, array $request = [], bool $scopecheck = true): ResponseInterface
{
- return parent::run($request, false);
+ return parent::run($httpException, $request, false);
}
protected function post(array $request = [])
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseApi;
+use Friendica\Module\Special\HTTPException;
use Psr\Http\Message\ResponseInterface;
/**
*/
class Revoke extends BaseApi
{
- public function run(array $request = [], bool $scopecheck = true): ResponseInterface
+ public function run(HTTPException $httpException, array $request = [], bool $scopecheck = true): ResponseInterface
{
- return parent::run($request, false);
+ return parent::run($httpException, $request, false);
}
protected function post(array $request = [])
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseApi;
+use Friendica\Module\Special\HTTPException;
use Friendica\Security\OAuth;
use Friendica\Util\DateTimeFormat;
use Psr\Http\Message\ResponseInterface;
*/
class Token extends BaseApi
{
- public function run(array $request = [], bool $scopecheck = true): ResponseInterface
+ public function run(HTTPException $httpException, array $request = [], bool $scopecheck = true): ResponseInterface
{
- return parent::run($request, false);
+ return parent::run($httpException, $request, false);
}
protected function post(array $request = [])
namespace Friendica\Module\Special;
-use Friendica\Core\Logger;
+use Friendica\App\Arguments;
+use Friendica\App\Request;
+use Friendica\Core\L10n;
use Friendica\Core\Renderer;
+use Friendica\Core\Session\Model\UserSession;
use Friendica\Core\System;
-use Friendica\DI;
+use Psr\Log\LoggerInterface;
/**
* This special module displays HTTPException when they are thrown in modules.
*/
class HTTPException
{
+ /** @var L10n */
+ protected $l10n;
+ /** @var LoggerInterface */
+ protected $logger;
+ /** @var Arguments */
+ protected $args;
+ /** @var bool */
+ protected $isSiteAdmin;
+ /** @var array */
+ protected $server;
+ /** @var string */
+ protected $requestId;
+
+ public function __construct(L10n $l10n, LoggerInterface $logger, Arguments $args, UserSession $session, Request $request, array $server = [])
+ {
+ $this->logger = $logger;
+ $this->l10n = $l10n;
+ $this->args = $args;
+ $this->isSiteAdmin = $session->isSiteAdmin();
+ $this->server = $server;
+ $this->requestId = $request->getRequestId();
+ }
+
/**
* Generates the necessary template variables from the caught HTTPException.
*
* Fills in the blanks if title or descriptions aren't provided by the exception.
*
* @param \Friendica\Network\HTTPException $e
+ *
* @return array ['$title' => ..., '$description' => ...]
*/
- private static function getVars(\Friendica\Network\HTTPException $e)
+ private function getVars(\Friendica\Network\HTTPException $e)
{
// Explanations are mostly taken from https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
$vars = [
- '$title' => $e->getDescription() ?: 'Error ' . $e->getCode(),
- '$message' => $e->getMessage() ?: $e->getExplanation(),
- '$back' => DI::l10n()->t('Go back'),
- '$stack_trace' => DI::l10n()->t('Stack trace:'),
+ '$title' => $e->getDescription() ?: 'Error ' . $e->getCode(),
+ '$message' => $e->getMessage() ?: $e->getExplanation(),
+ '$back' => $this->l10n->t('Go back'),
+ '$stack_trace' => $this->l10n->t('Stack trace:'),
+ '$request_id' => $this->requestId,
];
- if (DI::app()->isSiteAdmin()) {
- $vars['$thrown'] = DI::l10n()->t('Exception thrown in %s:%d', $e->getFile(), $e->getLine());
- $vars['$trace'] = $e->getTraceAsString();
+ if ($this->isSiteAdmin) {
+ $vars['$thrown'] = $this->l10n->t('Exception thrown in %s:%d', $e->getFile(), $e->getLine());
+ $vars['$trace'] = $e->getTraceAsString();
}
return $vars;
* Displays a bare message page with no theming at all.
*
* @param \Friendica\Network\HTTPException $e
+ *
* @throws \Exception
*/
public function rawContent(\Friendica\Network\HTTPException $e)
$content = '';
if ($e->getCode() >= 400) {
- $vars = self::getVars($e);
+ $vars = $this->getVars($e);
try {
- $tpl = Renderer::getMarkupTemplate('http_status.tpl');
+ $tpl = Renderer::getMarkupTemplate('http_status.tpl');
$content = Renderer::replaceMacros($tpl, $vars);
} catch (\Exception $e) {
$content = "<h1>{$vars['$title']}</h1><p>{$vars['$message']}</p>";
- if (DI::app()->isSiteAdmin()) {
+ if ($this->isSiteAdmin) {
$content .= "<p>{$vars['$thrown']}</p>";
$content .= "<pre>{$vars['$trace']}</pre>";
}
* Returns a content string that can be integrated in the current theme.
*
* @param \Friendica\Network\HTTPException $e
+ *
* @return string
* @throws \Exception
*/
public function content(\Friendica\Network\HTTPException $e): string
{
- header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->getDescription());
+ header($this->server['SERVER_PROTOCOL'] ?? 'HTTP/1.0' . ' ' . $e->getCode() . ' ' . $e->getDescription());
if ($e->getCode() >= 400) {
- Logger::debug('Exit with error', ['code' => $e->getCode(), 'description' => $e->getDescription(), 'query' => DI::args()->getQueryString(), 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
+ $this->logger->debug('Exit with error',
+ [
+ 'code' => $e->getCode(),
+ 'description' => $e->getDescription(),
+ 'query' => $this->args->getQueryString(),
+ 'callstack' => System::callstack(20),
+ 'method' => $this->args->getMethod(),
+ 'agent' => $this->server['HTTP_USER_AGENT'] ?? ''
+ ]);
}
$tpl = Renderer::getMarkupTemplate('exception.tpl');
- return Renderer::replaceMacros($tpl, self::getVars($e));
+ return Renderer::replaceMacros($tpl, $this->getVars($e));
}
}
],
\Psr\Clock\ClockInterface::class => [
'instanceOf' => Util\Clock\SystemClock::class
- ]
+ ],
+ \Friendica\Module\Special\HTTPException::class => [
+ 'constructParams' => [
+ $_SERVER
+ ],
+ ],
];
use Friendica\Core\Hook;
use Friendica\Database\Database;
use Friendica\DI;
+use Friendica\Module\Special\HTTPException;
use Friendica\Security\Authentication;
use Friendica\Security\BasicAuth;
use Friendica\Test\FixtureTest;
use Friendica\Test\Util\AppDouble;
use Friendica\Test\Util\AuthenticationDouble;
use Friendica\Test\Util\AuthTestConfig;
+use Mockery\MockInterface;
use Psr\Http\Message\ResponseInterface;
abstract class ApiTest extends FixtureTest
'nurl' => 'http://localhost/profile/othercontact'
];
+ /** @var HTTPException */
+ protected $httpExceptionMock;
+
// User ID that we know is not in the database
const WRONG_USER_ID = 666;
// Manual override to bypass API authentication
DI::app()->setIsLoggedIn(true);
+ $this->httpExceptionMock = $this->dice->create(HTTPException::class);
+
AuthTestConfig::$authenticated = true;
AuthTestConfig::$user_id = 42;
$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(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
$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(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'searchstring' => 'item_body'
]);
$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(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'searchstring' => 'test'
]);
XML;
$response = (new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertXmlStringEqualsXmlString($assertXml, (string)$response->getBody());
self::assertEquals([
public function testWithJsonResult()
{
$response = (new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
public function testEmpty()
{
$this->expectException(BadRequestException::class);
- (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run();
+ (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run($this->httpExceptionMock);
}
public function testWithoutAuthenticatedUser()
public function testWrong()
{
$this->expectException(BadRequestException::class);
- (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run(['photo_id' => 1]);
+ (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run($this->httpExceptionMock, ['photo_id' => 1]);
}
public function testValidWithPost()
$this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba());
$response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'photo_id' => '709057080661a283a6aa598501504178'
]);
$this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba());
$response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'photo_id' => '709057080661a283a6aa598501504178'
]);
{
$this->expectException(BadRequestException::class);
(new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
{
$this->expectException(BadRequestException::class);
(new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'album' => 'album_name'
]);
}
$this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba());
$response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'album' => 'test_album']
);
{
$this->expectException(BadRequestException::class);
(new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
public function testTooFewArgs()
{
$this->expectException(BadRequestException::class);
(new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'album' => 'album_name'
]);
}
{
$this->expectException(BadRequestException::class);
(new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'album' => 'album_name',
'album_new' => 'album_name'
]);
$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(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'album' => 'test_album',
'album_new' => 'test_album_2'
]);
DI::config()->set('system', 'ssl_policy', BaseURL::SSL_POLICY_FULL);
$response = (new Config(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
self::assertEquals('localhost', $json->site->server);
public function test()
{
$response = (new Version(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertEquals([
'Content-type' => ['application/json'],
public function testJson()
{
$response = (new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
public function testXml()
{
$response = (new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertEquals([
'Content-type' => ['text/xml'],
public function testApiAccountVerifyCredentials()
{
$response = (new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
public function testWithJson()
{
$response = (new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
$result = $this->toJson($response);
public function testWithXml()
{
$response = (new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertEquals([
'Content-type' => ['text/xml'],
$this->useHttpMethod(Router::POST);
$response = (new UpdateProfile(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'name' => 'new_name',
'description' => 'new_description'
]);
public function testApiStatusesFWithBlocks()
{
$response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
$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(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
$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(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'friendica_verbose' => true,
]);
{
$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(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
public function testApiDirectMessagesDestroyWithVerbose()
{
$response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'friendica_verbose' => true,
]);
{
$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(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 1
]);
}
public function testApiDirectMessagesDestroyWithIdAndVerbose()
{
$response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 1,
'friendica_parenturi' => 'parent_uri',
'friendica_verbose' => true,
$id = $ids[0]['id'];
$response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => $id,
'friendica_verbose' => true,
]);
$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(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
$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(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertEmpty((string)$response->getBody());
}
$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(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'text' => 'message_text',
'user_id' => 43
]);
$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(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'text' => 'message_text',
'user_id' => 44
]);
$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(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'text' => 'message_text',
'user_id' => 44,
'title' => 'message_title',
$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(), [], ['extension' => 'rss']))
- ->run([
+ ->run($this->httpExceptionMock, [
'text' => 'message_text',
'user_id' => 44,
'title' => 'message_title',
$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(), [], ['extension' => 'json']))
- ->run([
+ ->run($this->httpExceptionMock, [
'friendica_verbose' => true,
]);
$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(), [], ['extension' => 'rss']))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertXml((string)$response->getBody(), 'direct-messages');
}
$this->expectException(BadRequestException::class);
(new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
public function testApiFavoritesCreateDestroyWithCreateAction()
{
$response = (new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 3
]);
public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
{
$response = (new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => ICanCreateResponses::TYPE_RSS]))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 3
]);
$this->expectException(BadRequestException::class);
(new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
public function testApiFavoritesCreateDestroyWithDestroyAction()
{
$response = (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 3
]);
public function testApiFavorites()
{
$response = (new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'page' => -1,
'max_id' => 10,
]);
{
$response = (new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
'extension' => ICanCreateResponses::TYPE_RSS
- ]))->run();
+ ]))->run($this->httpExceptionMock);
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
public function testApiStatusesFWithFollowers()
{
$response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
public function testApiStatusesFWithFriends()
{
$response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
public function testApiFriendshipsIncoming()
{
$response = (new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
$this->expectException(BadRequestException::class);
(new Statuses(DI::dba(), DI::twitterStatus(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
public function testApiListsStatusesWithListId()
{
$response = (new Statuses(DI::dba(), DI::twitterStatus(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'list_id' => 1,
'page' => -1,
'max_id' => 10
public function testApiListsStatusesWithListIdAndRss()
{
$response = (new Statuses(DI::dba(), DI::twitterStatus(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'rss']))
- ->run([
+ ->run($this->httpExceptionMock, [
'list_id' => 1
]);
$this->expectException(BadRequestException::class);
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
AuthTestConfig::$authenticated = false;
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
];
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
];
$response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$media = $this->toJson($response);
public function test()
{
$response = (new SavedSearches(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
- ->run();
+ ->run($this->httpExceptionMock);
$result = $this->toJson($response);
$this->expectException(BadRequestException::class);
(new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
public function testApiStatusesDestroyWithId()
{
$response = (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 1
]);
public function testApiStatusesMentions()
{
$response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'max_id' => 10
]);
public function testApiStatusesMentionsWithNegativePage()
{
$response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'page' => -2
]);
public function testApiStatusesMentionsWithRss()
{
$response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => ICanCreateResponses::TYPE_RSS]))
- ->run([
+ ->run($this->httpExceptionMock, [
'page' => -2
]);
public function testApiStatusesNetworkpublicTimeline()
{
$response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'max_id' => 10
]);
public function testApiStatusesNetworkpublicTimelineWithNegativePage()
{
$response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'page' => -2
]);
{
$response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
'extension' => ICanCreateResponses::TYPE_RSS
- ]))->run([
+ ]))->run($this->httpExceptionMock, [
'page' => -2
]);
$this->expectException(BadRequestException::class);
(new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
public function testApiStatusesRepeatWithId()
{
$response = (new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 1
]);
public function testApiStatusesRepeatWithSharedId()
{
$response = (new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 5
]);
(new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
public function testApiStatusesShowWithId()
{
$response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 1
]);
public function testApiStatusesShowWithConversation()
{
$response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'id' => 1,
'conversation' => 1
]);
];
$response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'status' => 'Status content #friendica',
'in_reply_to_status_id' => 0,
'lat' => 48,
public function testApiStatusesUpdateWithHtml()
{
$response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'htmlstatus' => '<b>Status content</b>',
]);
public function testApiStatusesUserTimeline()
{
$response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'user_id' => 42,
'max_id' => 10,
'exclude_replies' => true,
public function testApiStatusesUserTimelineWithNegativePage()
{
$response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'user_id' => 42,
'page' => -2,
]);
{
$response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
'extension' => ICanCreateResponses::TYPE_RSS
- ]))->run();
+ ]))->run($this->httpExceptionMock);
self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
$this->expectException(NotFoundException::class);
(new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
/**
public function testApiUsersLookupWithUserId()
{
$respone = (new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'user_id' => static::OTHER_USER['id']
]);
public function testApiUsersSearch()
{
$respone = (new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run([
+ ->run($this->httpExceptionMock, [
'q' => static::OTHER_USER['name']
]);
{
$respone = (new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
'extension' => ICanCreateResponses::TYPE_XML
- ]))->run([
+ ]))->run($this->httpExceptionMock, [
'q' => static::OTHER_USER['name']
]);
$this->expectException(BadRequestException::class);
(new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
}
}
public function testApiUsersShow()
{
$response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
- ->run();
+ ->run($this->httpExceptionMock);
$json = $this->toJson($response);
{
$response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
'extension' => ICanCreateResponses::TYPE_XML
- ]))->run();
+ ]))->run($this->httpExceptionMock);
self::assertEquals(ICanCreateResponses::TYPE_XML, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
use Friendica\Module\NodeInfo110;
use Friendica\Module\NodeInfo120;
use Friendica\Module\NodeInfo210;
+use Friendica\Module\Special\HTTPException;
use Friendica\Test\FixtureTest;
+use Mockery\MockInterface;
class NodeInfoTest extends FixtureTest
{
+ /** @var MockInterface|HTTPException */
+ protected $httpExceptionMock;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ $this->httpExceptionMock = \Mockery::mock(HTTPException::class);
+ }
+
public function testNodeInfo110()
{
$response = (new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertJson($response->getBody());
self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
public function testNodeInfo120()
{
$response = (new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertJson($response->getBody());
self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
public function testNodeInfo210()
{
$response = (new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
- ->run();
+ ->run($this->httpExceptionMock);
self::assertJson($response->getBody());
self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
+use Friendica\Module\Special\HTTPException;
use Friendica\Module\Special\Options;
use Friendica\Test\FixtureTest;
+use Mockery\MockInterface;
class OptionsTest extends FixtureTest
{
+ /** @var MockInterface|HTTPException */
+ protected $httpExceptionMock;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ $this->httpExceptionMock = \Mockery::mock(HTTPException::class);
+ }
+
public function testOptionsAll()
{
$this->useHttpMethod(Router::OPTIONS);
- $response = (new Options(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run();
+ $response = (new Options(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run($this->httpExceptionMock);
self::assertEmpty((string)$response->getBody());
self::assertEquals(204, $response->getStatusCode());
$response = (new Options(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
'AllowedMethods' => [Router::GET, Router::POST],
- ]))->run();
+ ]))->run($this->httpExceptionMock);
self::assertEmpty((string)$response->getBody());
self::assertEquals(204, $response->getStatusCode());
{{$stack_trace}}
{{$trace}}</pre>
{{/if}}
+{{if $request_id}}
+ <pre>Request: {{$request_id}}</pre>
+{{/if}}
{{if $back}}
<p><button type="button" onclick="window.history.back()" class="btn btn-primary">{{$back}}</button></p>
{{/if}}
{{if $trace}}
<pre>{{$trace nofilter}}</pre>
{{/if}}
+ {{if $request_id}}
+ <pre>Request: {{$request_id}}</pre>
+ {{/if}}
</body>
</html>