friendica-github/tests/src/Module/Api/Twitter/Users/SearchTest.php
2024-12-15 21:51:22 +00:00

63 lines
1.7 KiB
PHP

<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace Friendica\Test\src\Module\Api\Twitter\Users;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Users\Search;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\ApiTestCase;
class SearchTest extends ApiTestCase
{
/**
* Test the api_users_search() function.
*
* @return void
*/
public function testApiUsersSearch()
{
$response = (new Search(DI::mstdnError(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
->run($this->httpExceptionMock, [
'q' => static::OTHER_USER['name']
]);
$json = $this->toJson($response);
self::assertOtherUser($json[0]);
}
/**
* Test the api_users_search() function with an XML result.
*
* @return void
*/
public function testApiUsersSearchWithXml()
{
$response = (new Search(DI::mstdnError(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
'extension' => ICanCreateResponses::TYPE_XML
]))->run($this->httpExceptionMock, [
'q' => static::OTHER_USER['name']
]);
self::assertXml((string)$response->getBody(), 'users');
}
/**
* Test the api_users_search() function without a GET q parameter.
*
* @return void
*/
public function testApiUsersSearchWithoutQuery()
{
$this->expectException(BadRequestException::class);
(new Search(DI::mstdnError(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
->run($this->httpExceptionMock);
}
}