1
0
Fork 0

Reenable Twitter/Search test

This commit is contained in:
Philipp Holzer 2021-12-09 21:37:16 +01:00
parent 616cf012f9
commit e10045f13f
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
2 changed files with 26 additions and 15 deletions

View file

@ -42,15 +42,15 @@ class Search extends BaseApi
$userlist = [];
if (!empty($_GET['q'])) {
if (!empty($request['q'])) {
$contacts = Contact::selectToArray(
['id'],
[
'`uid` = 0 AND (`name` = ? OR `nick` = ? OR `url` = ? OR `addr` = ?)',
$_GET['q'],
$_GET['q'],
$_GET['q'],
$_GET['q'],
$request['q'],
$request['q'],
$request['q'],
$request['q'],
]
);
@ -63,12 +63,12 @@ class Search extends BaseApi
}
$userlist = ['users' => $userlist];
} else {
throw new NotFoundException('User ' . $_GET['q'] . ' not found.');
throw new NotFoundException('User ' . $request['q'] . ' not found.');
}
} else {
throw new BadRequestException('No search term specified.');
}
$this->response->exit('users', ['user' => $userlist], $this->parameters['extension'] ?? null);
$this->response->exit('users', $userlist, $this->parameters['extension'] ?? null);
}
}

View file

@ -2,6 +2,11 @@
namespace Friendica\Test\src\Module\Api\Twitter\Users;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Users\Search;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest;
class SearchTest extends ApiTest
@ -13,9 +18,12 @@ class SearchTest extends ApiTest
*/
public function testApiUsersSearch()
{
// $_GET['q'] = 'othercontact';
// $result = api_users_search('json');
// self::assertOtherUser($result['users'][0]);
$search = 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']]);
$json = $this->toJson($respone);
self::assertOtherUser($json[0]);
}
/**
@ -25,9 +33,10 @@ class SearchTest extends ApiTest
*/
public function testApiUsersSearchWithXml()
{
// $_GET['q'] = 'othercontact';
// $result = api_users_search('xml');
// self::assertXml($result, 'users');
$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 = $search->run(['q' => static::OTHER_USER['name']]);
self::assertXml((string)$respone->getBody(), 'users');
}
/**
@ -37,7 +46,9 @@ class SearchTest extends ApiTest
*/
public function testApiUsersSearchWithoutQuery()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// api_users_search('json');
$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]);
$search->run();
}
}