2018-04-09 15:23:41 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ApiTest class.
|
|
|
|
*/
|
|
|
|
|
2020-09-11 13:38:41 -04:00
|
|
|
namespace Friendica\Test\legacy;
|
2018-04-09 15:23:41 -04:00
|
|
|
|
2019-02-05 16:03:07 -05:00
|
|
|
use Friendica\App;
|
2021-10-26 15:44:29 -04:00
|
|
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
2019-12-15 16:34:11 -05:00
|
|
|
use Friendica\DI;
|
2021-11-12 13:52:01 -05:00
|
|
|
use Friendica\Module\Api\ApiResponse;
|
2021-11-08 16:35:41 -05:00
|
|
|
use Friendica\Module\BaseApi;
|
|
|
|
use Friendica\Security\BasicAuth;
|
2020-09-11 13:38:41 -04:00
|
|
|
use Friendica\Test\FixtureTest;
|
2021-11-08 17:10:07 -05:00
|
|
|
use Friendica\Util\Arrays;
|
2021-09-18 01:08:29 -04:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
2018-12-30 15:42:56 -05:00
|
|
|
use Monolog\Handler\TestHandler;
|
2018-04-09 15:23:41 -04:00
|
|
|
|
2018-11-01 08:45:21 -04:00
|
|
|
require_once __DIR__ . '/../../include/api.php';
|
2018-10-22 14:59:51 -04:00
|
|
|
|
2018-04-09 15:23:41 -04:00
|
|
|
/**
|
|
|
|
* Tests for the API functions.
|
|
|
|
*
|
|
|
|
* Functions that use header() need to be tested in a separate process.
|
|
|
|
* @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
|
2021-04-01 15:19:45 -04:00
|
|
|
*
|
|
|
|
* @backupGlobals enabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
2020-06-09 08:38:31 -04:00
|
|
|
class ApiTest extends FixtureTest
|
2018-04-09 15:23:41 -04:00
|
|
|
{
|
2018-12-30 15:42:56 -05:00
|
|
|
/**
|
|
|
|
* @var TestHandler Can handle log-outputs
|
|
|
|
*/
|
|
|
|
protected $logOutput;
|
|
|
|
|
2019-03-23 10:02:32 -04:00
|
|
|
/** @var array */
|
|
|
|
protected $selfUser;
|
|
|
|
/** @var array */
|
|
|
|
protected $friendUser;
|
|
|
|
/** @var array */
|
|
|
|
protected $otherUser;
|
|
|
|
|
|
|
|
protected $wrongUserId;
|
|
|
|
|
2019-07-26 09:54:14 -04:00
|
|
|
/** @var App */
|
|
|
|
protected $app;
|
|
|
|
|
2021-10-26 15:44:29 -04:00
|
|
|
/** @var IManageConfigValues */
|
2019-08-04 12:50:24 -04:00
|
|
|
protected $config;
|
|
|
|
|
2018-04-09 15:23:41 -04:00
|
|
|
/**
|
|
|
|
* Create variables used by tests.
|
|
|
|
*/
|
2021-04-01 17:04:30 -04:00
|
|
|
protected function setUp() : void
|
2018-04-09 15:23:41 -04:00
|
|
|
{
|
2020-09-11 14:14:47 -04:00
|
|
|
global $API, $called_api;
|
|
|
|
$API = [];
|
|
|
|
$called_api = [];
|
|
|
|
|
2019-07-28 11:40:42 -04:00
|
|
|
parent::setUp();
|
2018-07-01 14:46:24 -04:00
|
|
|
|
2021-10-26 16:09:11 -04:00
|
|
|
/** @var IManageConfigValues $config */
|
2021-10-26 15:44:29 -04:00
|
|
|
$this->config = $this->dice->create(IManageConfigValues::class);
|
2019-08-04 13:02:16 -04:00
|
|
|
|
|
|
|
$this->config->set('system', 'url', 'http://localhost');
|
|
|
|
$this->config->set('system', 'hostname', 'localhost');
|
|
|
|
$this->config->set('system', 'worker_dont_fork', true);
|
|
|
|
|
|
|
|
// Default config
|
|
|
|
$this->config->set('config', 'hostname', 'localhost');
|
|
|
|
$this->config->set('system', 'throttle_limit_day', 100);
|
|
|
|
$this->config->set('system', 'throttle_limit_week', 100);
|
|
|
|
$this->config->set('system', 'throttle_limit_month', 100);
|
|
|
|
$this->config->set('system', 'theme', 'system_theme');
|
|
|
|
|
2019-07-28 11:40:42 -04:00
|
|
|
|
2019-08-04 13:02:16 -04:00
|
|
|
/** @var App app */
|
2019-12-15 16:34:11 -05:00
|
|
|
$this->app = DI::app();
|
2019-07-27 08:37:24 -04:00
|
|
|
|
2021-07-25 10:27:13 -04:00
|
|
|
DI::args()->setArgc(1);
|
2019-07-26 09:54:14 -04:00
|
|
|
|
2018-04-09 15:23:41 -04:00
|
|
|
// User data that the test database is populated with
|
2019-07-28 11:40:42 -04:00
|
|
|
$this->selfUser = [
|
|
|
|
'id' => 42,
|
2018-04-09 15:23:41 -04:00
|
|
|
'name' => 'Self contact',
|
|
|
|
'nick' => 'selfcontact',
|
2018-07-01 15:07:50 -04:00
|
|
|
'nurl' => 'http://localhost/profile/selfcontact'
|
2018-07-01 14:46:24 -04:00
|
|
|
];
|
|
|
|
$this->friendUser = [
|
2019-07-28 11:40:42 -04:00
|
|
|
'id' => 44,
|
2018-07-01 14:46:24 -04:00
|
|
|
'name' => 'Friend contact',
|
|
|
|
'nick' => 'friendcontact',
|
2018-07-01 15:07:50 -04:00
|
|
|
'nurl' => 'http://localhost/profile/friendcontact'
|
2018-04-09 15:23:41 -04:00
|
|
|
];
|
2019-07-28 11:40:42 -04:00
|
|
|
$this->otherUser = [
|
|
|
|
'id' => 43,
|
2018-04-09 15:23:41 -04:00
|
|
|
'name' => 'othercontact',
|
|
|
|
'nick' => 'othercontact',
|
2018-07-01 15:07:50 -04:00
|
|
|
'nurl' => 'http://localhost/profile/othercontact'
|
2018-04-09 15:23:41 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
// User ID that we know is not in the database
|
|
|
|
$this->wrongUserId = 666;
|
|
|
|
|
2019-12-15 19:35:26 -05:00
|
|
|
DI::session()->start();
|
2019-12-10 16:29:49 -05:00
|
|
|
|
2018-04-09 15:23:41 -04:00
|
|
|
// Most API require login so we force the session
|
|
|
|
$_SESSION = [
|
|
|
|
'authenticated' => true,
|
2019-07-28 11:40:42 -04:00
|
|
|
'uid' => $this->selfUser['id']
|
2018-04-09 15:23:41 -04:00
|
|
|
];
|
2021-11-17 17:12:21 -05:00
|
|
|
BasicAuth::setCurrentUserID($this->selfUser['id']);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that a list array contains expected keys.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @param array $list List array
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-04-01 15:19:45 -04:00
|
|
|
private function assertList(array $list = [])
|
2018-04-09 15:23:41 -04:00
|
|
|
{
|
2021-06-02 17:03:08 -04:00
|
|
|
self::assertIsString($list['name']);
|
|
|
|
self::assertIsInt($list['id']);
|
|
|
|
self::assertIsString('string', $list['id_str']);
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertContains($list['mode'], ['public', 'private']);
|
2018-04-09 15:23:41 -04:00
|
|
|
// We could probably do more checks here.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that the string is XML and contain the root element.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @param string $result XML string
|
|
|
|
* @param string $root_element Root element name
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-04-01 15:19:45 -04:00
|
|
|
private function assertXml($result = '', $root_element = '')
|
2018-04-09 15:23:41 -04:00
|
|
|
{
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertStringStartsWith('<?xml version="1.0"?>', $result);
|
2021-05-23 17:16:33 -04:00
|
|
|
self::assertStringContainsString('<' . $root_element, $result);
|
2018-04-09 15:23:41 -04:00
|
|
|
// We could probably do more checks here.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_user() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiUser()
|
|
|
|
{
|
2021-11-18 01:58:43 -05:00
|
|
|
self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
2021-12-30 14:51:21 -05:00
|
|
|
|
2018-04-09 15:23:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_source() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiSource()
|
|
|
|
{
|
2021-11-24 02:26:22 -05:00
|
|
|
self::assertEquals('api', BasicAuth::getCurrentApplicationToken()['name']);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_source() function with a Twidere user agent.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiSourceWithTwidere()
|
|
|
|
{
|
|
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Twidere';
|
2021-11-24 02:26:22 -05:00
|
|
|
self::assertEquals('Twidere', BasicAuth::getCurrentApplicationToken()['name']);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_source() function with a GET parameter.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiSourceWithGet()
|
|
|
|
{
|
2021-11-24 02:11:33 -05:00
|
|
|
$_REQUEST['source'] = 'source_name';
|
2021-11-24 02:26:22 -05:00
|
|
|
self::assertEquals('source_name', BasicAuth::getCurrentApplicationToken()['name']);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_date() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDate()
|
|
|
|
{
|
2021-11-18 16:43:13 -05:00
|
|
|
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_register_func() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiRegisterFunc()
|
|
|
|
{
|
|
|
|
global $API;
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertNull(
|
2018-04-09 15:23:41 -04:00
|
|
|
api_register_func(
|
|
|
|
'api_path',
|
|
|
|
function () {
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
'method'
|
|
|
|
)
|
|
|
|
);
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertTrue(is_callable($API['api_path']['func']));
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function without any login.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 15:19:45 -04:00
|
|
|
* @preserveGlobalState disabled
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiLoginWithoutLogin()
|
|
|
|
{
|
2021-11-18 01:03:21 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-08 16:35:41 -05:00
|
|
|
BasicAuth::getCurrentUserID(true);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with a bad login.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 15:19:45 -04:00
|
|
|
* @preserveGlobalState disabled
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiLoginWithBadLogin()
|
|
|
|
{
|
2021-11-18 01:03:21 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SERVER['PHP_AUTH_USER'] = 'user@server';
|
2021-11-08 16:35:41 -05:00
|
|
|
BasicAuth::getCurrentUserID(true);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with oAuth.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiLoginWithOauth()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Can we test this easily?');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiLoginWithAddonAuth()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Can we test this easily?');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with a correct login.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2021-04-01 15:19:45 -04:00
|
|
|
* @doesNotPerformAssertions
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiLoginWithCorrectLogin()
|
|
|
|
{
|
2021-11-18 01:03:21 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SERVER['PHP_AUTH_USER'] = 'Test user';
|
2019-07-28 11:40:42 -04:00
|
|
|
$_SERVER['PHP_AUTH_PW'] = 'password';
|
2021-11-08 16:35:41 -05:00
|
|
|
BasicAuth::getCurrentUserID(true);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with a remote user.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiLoginWithRemoteUser()
|
|
|
|
{
|
2021-11-18 01:03:21 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
|
2021-11-08 16:35:41 -05:00
|
|
|
BasicAuth::getCurrentUserID(true);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiCall()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 11:40:42 -04:00
|
|
|
$API['api_path'] = [
|
2018-04-09 15:23:41 -04:00
|
|
|
'method' => 'method',
|
2019-07-28 11:40:42 -04:00
|
|
|
'func' => function () {
|
2018-04-09 15:23:41 -04:00
|
|
|
return ['data' => ['some_data']];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 00:21:04 -04:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path';
|
2019-07-28 11:40:42 -04:00
|
|
|
$_GET['callback'] = 'callback_name';
|
2018-04-09 15:23:41 -04:00
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2018-04-09 15:23:41 -04:00
|
|
|
'callback_name(["some_data"])',
|
2021-11-26 02:55:02 -05:00
|
|
|
api_call('api_path', 'json')
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with the profiled enabled.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiCallWithProfiler()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 11:40:42 -04:00
|
|
|
$API['api_path'] = [
|
2018-04-09 15:23:41 -04:00
|
|
|
'method' => 'method',
|
2019-07-28 11:40:42 -04:00
|
|
|
'func' => function () {
|
2018-04-09 15:23:41 -04:00
|
|
|
return ['data' => ['some_data']];
|
|
|
|
}
|
|
|
|
];
|
2019-12-15 19:35:26 -05:00
|
|
|
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 00:21:04 -04:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path';
|
2019-12-15 19:35:26 -05:00
|
|
|
|
2019-08-04 13:02:16 -04:00
|
|
|
$this->config->set('system', 'profiler', true);
|
|
|
|
$this->config->set('rendertime', 'callstack', true);
|
2018-04-09 15:23:41 -04:00
|
|
|
$this->app->callstack = [
|
2019-07-28 11:40:42 -04:00
|
|
|
'database' => ['some_function' => 200],
|
2018-04-09 15:23:41 -04:00
|
|
|
'database_write' => ['some_function' => 200],
|
2019-07-28 11:40:42 -04:00
|
|
|
'cache' => ['some_function' => 200],
|
|
|
|
'cache_write' => ['some_function' => 200],
|
|
|
|
'network' => ['some_function' => 200]
|
2018-04-09 15:23:41 -04:00
|
|
|
];
|
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2018-04-09 15:23:41 -04:00
|
|
|
'["some_data"]',
|
2021-11-26 02:55:02 -05:00
|
|
|
api_call('api_path', 'json')
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with a JSON result.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiCallWithJson()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 11:40:42 -04:00
|
|
|
$API['api_path'] = [
|
2018-04-09 15:23:41 -04:00
|
|
|
'method' => 'method',
|
2019-07-28 11:40:42 -04:00
|
|
|
'func' => function () {
|
2018-04-09 15:23:41 -04:00
|
|
|
return ['data' => ['some_data']];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 00:21:04 -04:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
|
2019-12-15 19:35:26 -05:00
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2018-04-09 15:23:41 -04:00
|
|
|
'["some_data"]',
|
2021-11-26 02:55:02 -05:00
|
|
|
api_call('api_path.json', 'json')
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with an XML result.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiCallWithXml()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 11:40:42 -04:00
|
|
|
$API['api_path'] = [
|
2018-04-09 15:23:41 -04:00
|
|
|
'method' => 'method',
|
2019-07-28 11:40:42 -04:00
|
|
|
'func' => function () {
|
2018-04-09 15:23:41 -04:00
|
|
|
return 'some_data';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 00:21:04 -04:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
|
2019-12-15 19:35:26 -05:00
|
|
|
|
|
|
|
$args = DI::args()->determine($_SERVER, $_GET);
|
2018-04-09 15:23:41 -04:00
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2018-04-09 15:23:41 -04:00
|
|
|
'some_data',
|
2021-11-26 02:55:02 -05:00
|
|
|
api_call('api_path.xml', 'xml')
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with an RSS result.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiCallWithRss()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 11:40:42 -04:00
|
|
|
$API['api_path'] = [
|
2018-04-09 15:23:41 -04:00
|
|
|
'method' => 'method',
|
2019-07-28 11:40:42 -04:00
|
|
|
'func' => function () {
|
2018-04-09 15:23:41 -04:00
|
|
|
return 'some_data';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 00:21:04 -04:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
|
2019-12-15 19:35:26 -05:00
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2019-07-28 11:40:42 -04:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
|
|
|
'some_data',
|
2021-11-26 02:55:02 -05:00
|
|
|
api_call('api_path.rss', 'rss')
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with an Atom result.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 16:16:16 -04:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiCallWithAtom()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 11:40:42 -04:00
|
|
|
$API['api_path'] = [
|
2018-04-09 15:23:41 -04:00
|
|
|
'method' => 'method',
|
2019-07-28 11:40:42 -04:00
|
|
|
'func' => function () {
|
2018-04-09 15:23:41 -04:00
|
|
|
return 'some_data';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 00:21:04 -04:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
|
2019-12-15 19:35:26 -05:00
|
|
|
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2019-07-28 11:40:42 -04:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
|
|
|
'some_data',
|
2021-11-26 02:55:02 -05:00
|
|
|
api_call('api_path.atom', 'atom')
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_rss_extra() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiRssExtra()
|
|
|
|
{
|
2021-11-20 08:44:12 -05:00
|
|
|
/*
|
2018-07-04 17:55:06 -04:00
|
|
|
$user_info = ['url' => 'user_url', 'lang' => 'en'];
|
2021-11-17 16:28:51 -05:00
|
|
|
$result = api_rss_extra([], $user_info);
|
2020-10-17 08:19:57 -04:00
|
|
|
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']);
|
2021-11-20 08:44:12 -05:00
|
|
|
*/
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_rss_extra() function without any user info.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiRssExtraWithoutUserInfo()
|
|
|
|
{
|
2021-11-20 08:44:12 -05:00
|
|
|
/*
|
2021-11-17 16:28:51 -05:00
|
|
|
$result = api_rss_extra([], null);
|
2021-06-02 17:03:08 -04:00
|
|
|
self::assertIsArray($result['$user']);
|
2020-10-17 08:19:57 -04:00
|
|
|
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']);
|
2021-11-20 08:44:12 -05:00
|
|
|
*/
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 17:10:07 -05:00
|
|
|
* Test the Arrays::walkRecursive() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiWalkRecursive()
|
|
|
|
{
|
|
|
|
$array = ['item1'];
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2018-04-09 15:23:41 -04:00
|
|
|
$array,
|
2021-11-08 17:10:07 -05:00
|
|
|
Arrays::walkRecursive(
|
2018-04-09 15:23:41 -04:00
|
|
|
$array,
|
|
|
|
function () {
|
|
|
|
// Should we test this with a callback that actually does something?
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 17:10:07 -05:00
|
|
|
* Test the Arrays::walkRecursive() function with an array.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiWalkRecursiveWithArray()
|
|
|
|
{
|
|
|
|
$array = [['item1'], ['item2']];
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2018-04-09 15:23:41 -04:00
|
|
|
$array,
|
2021-11-08 17:10:07 -05:00
|
|
|
Arrays::walkRecursive(
|
2018-04-09 15:23:41 -04:00
|
|
|
$array,
|
|
|
|
function () {
|
|
|
|
// Should we test this with a callback that actually does something?
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BaseApi::reformatXML() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiReformatXml()
|
|
|
|
{
|
|
|
|
$item = true;
|
2019-07-28 11:40:42 -04:00
|
|
|
$key = '';
|
2021-11-12 13:52:01 -05:00
|
|
|
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals('true', $item);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BaseApi::reformatXML() function with a statusnet_api key.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiReformatXmlWithStatusnetKey()
|
|
|
|
{
|
|
|
|
$item = '';
|
2019-07-28 11:40:42 -04:00
|
|
|
$key = 'statusnet_api';
|
2021-11-12 13:52:01 -05:00
|
|
|
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals('statusnet:api', $key);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BaseApi::reformatXML() function with a friendica_api key.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiReformatXmlWithFriendicaKey()
|
|
|
|
{
|
|
|
|
$item = '';
|
2019-07-28 11:40:42 -04:00
|
|
|
$key = 'friendica_api';
|
2021-11-12 13:52:01 -05:00
|
|
|
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals('friendica:api', $key);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BaseApi::createXML() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiCreateXml()
|
|
|
|
{
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2019-07-28 11:40:42 -04:00
|
|
|
'<?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",
|
2021-11-12 13:56:37 -05:00
|
|
|
DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BaseApi::createXML() function without any XML namespace.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiCreateXmlWithoutNamespaces()
|
|
|
|
{
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2019-07-28 11:40:42 -04:00
|
|
|
'<?xml version="1.0"?>' . "\n" .
|
|
|
|
'<ok>' . "\n" .
|
|
|
|
' <data>some_data</data>' . "\n" .
|
|
|
|
'</ok>' . "\n",
|
2021-11-12 13:56:37 -05:00
|
|
|
DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BaseApi::formatData() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatData()
|
|
|
|
{
|
|
|
|
$data = ['some_data'];
|
2021-11-12 13:59:16 -05:00
|
|
|
self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 16:35:41 -05:00
|
|
|
* Test the BaseApi::formatData() function with an XML result.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatDataWithXml()
|
|
|
|
{
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2019-07-28 11:40:42 -04:00
|
|
|
'<?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",
|
2021-11-12 13:59:16 -05:00
|
|
|
DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
|
2018-04-09 15:23:41 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_entitities() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetEntitities()
|
|
|
|
{
|
2021-11-23 16:54:19 -05:00
|
|
|
// $text = 'text';
|
|
|
|
// self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_entitities() function with the include_entities parameter.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetEntititiesWithIncludeEntities()
|
|
|
|
{
|
2021-11-23 16:54:19 -05:00
|
|
|
/*
|
2018-04-09 15:23:41 -04:00
|
|
|
$_REQUEST['include_entities'] = 'true';
|
2019-07-28 11:40:42 -04:00
|
|
|
$text = 'text';
|
2021-07-06 02:38:15 -04:00
|
|
|
$result = api_get_entitities($text, 'bbcode', 0);
|
2021-06-02 17:03:08 -04:00
|
|
|
self::assertIsArray($result['hashtags']);
|
|
|
|
self::assertIsArray($result['symbols']);
|
|
|
|
self::assertIsArray($result['urls']);
|
|
|
|
self::assertIsArray($result['user_mentions']);
|
2021-11-23 16:54:19 -05:00
|
|
|
*/
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items_embeded_images() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatItemsEmbededImages()
|
|
|
|
{
|
2021-11-23 16:54:19 -05:00
|
|
|
/*
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(
|
2019-12-30 17:00:08 -05:00
|
|
|
'text ' . DI::baseUrl() . '/display/item_guid',
|
2018-04-09 15:23:41 -04:00
|
|
|
api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
|
|
|
|
);
|
2021-11-23 16:54:19 -05:00
|
|
|
*/
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items_activities() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatItemsActivities()
|
|
|
|
{
|
2021-11-24 02:06:28 -05:00
|
|
|
$item = ['uid' => 0, 'uri-id' => 1];
|
|
|
|
$result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']);
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertArrayHasKey('like', $result);
|
|
|
|
self::assertArrayHasKey('dislike', $result);
|
|
|
|
self::assertArrayHasKey('attendyes', $result);
|
|
|
|
self::assertArrayHasKey('attendno', $result);
|
|
|
|
self::assertArrayHasKey('attendmaybe', $result);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items_activities() function with an XML result.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatItemsActivitiesWithXml()
|
|
|
|
{
|
2021-11-24 02:06:28 -05:00
|
|
|
$item = ['uid' => 0, 'uri-id' => 1];
|
|
|
|
$result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml');
|
2020-10-17 08:19:57 -04:00
|
|
|
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);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items() function.
|
2021-04-01 15:19:45 -04:00
|
|
|
* @doesNotPerformAssertions
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiFormatItems()
|
|
|
|
{
|
2021-11-23 16:54:19 -05:00
|
|
|
/*
|
2021-11-21 01:37:09 -05:00
|
|
|
$items = Post::selectToArray([], ['uid' => 42]);
|
2021-11-20 18:38:52 -05:00
|
|
|
foreach ($items as $item) {
|
|
|
|
$status = api_format_item($item);
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertStatus($status);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
2021-11-23 16:54:19 -05:00
|
|
|
*/
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items() function with an XML result.
|
2021-04-01 15:19:45 -04:00
|
|
|
* @doesNotPerformAssertions
|
2018-04-09 15:23:41 -04:00
|
|
|
*/
|
|
|
|
public function testApiFormatItemsWithXml()
|
|
|
|
{
|
2021-11-23 16:54:19 -05:00
|
|
|
/*
|
2021-11-21 01:37:09 -05:00
|
|
|
$items = Post::selectToArray([], ['uid' => 42]);
|
2021-11-20 18:38:52 -05:00
|
|
|
foreach ($items as $item) {
|
|
|
|
$status = api_format_item($item, 'xml');
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertStatus($status);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
2021-11-23 16:54:19 -05:00
|
|
|
*/
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_list() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsList()
|
|
|
|
{
|
|
|
|
$result = api_lists_list('json');
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(['lists_list' => []], $result);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_ownerships() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsOwnerships()
|
|
|
|
{
|
|
|
|
$result = api_lists_ownerships('json');
|
|
|
|
foreach ($result['lists']['lists'] as $list) {
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertList($list);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_ownerships() function without an authenticated user.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsOwnershipsWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 03:08:55 -05:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 01:10:20 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_lists_ownerships('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_statuses_f() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiStatusesFWithIncoming()
|
|
|
|
{
|
2021-11-26 16:48:13 -05:00
|
|
|
// $result = api_statuses_f('incoming');
|
|
|
|
// self::assertArrayHasKey('user', $result);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photos_list() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotosList()
|
|
|
|
{
|
|
|
|
$result = api_fr_photos_list('json');
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertArrayHasKey('photo', $result);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photos_list() function without an authenticated user.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotosListWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 03:08:55 -05:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 01:10:20 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_fr_photos_list('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_create_update() function.
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdate()
|
|
|
|
{
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 15:23:41 -04:00
|
|
|
api_fr_photo_create_update('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_create_update() function without an authenticated user.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 03:08:55 -05:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 01:10:20 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_fr_photo_create_update('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_create_update() function with an album name.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdateWithAlbum()
|
|
|
|
{
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 15:23:41 -04:00
|
|
|
$_REQUEST['album'] = 'album_name';
|
|
|
|
api_fr_photo_create_update('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_create_update() function with the update mode.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdateWithUpdate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('We need to create a dataset for this');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_create_update() function with an uploaded file.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdateWithFile()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_detail() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoDetail()
|
|
|
|
{
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 15:23:41 -04:00
|
|
|
api_fr_photo_detail('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_detail() function without an authenticated user.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoDetailWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 03:08:55 -05:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 01:10:20 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_fr_photo_detail('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_detail() function with a photo ID.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoDetailWithPhotoId()
|
|
|
|
{
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
|
2018-04-09 15:23:41 -04:00
|
|
|
$_REQUEST['photo_id'] = 1;
|
|
|
|
api_fr_photo_detail('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_detail() function with a correct photo ID.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoDetailCorrectPhotoId()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('We need to create a dataset for this.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_account_update_profile_image() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiAccountUpdateProfileImage()
|
|
|
|
{
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 15:23:41 -04:00
|
|
|
api_account_update_profile_image('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_account_update_profile_image() function without an authenticated user.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 03:08:55 -05:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 01:10:20 -05:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 15:23:41 -04:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_account_update_profile_image('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_account_update_profile_image() function with an uploaded file.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiAccountUpdateProfileImageWithUpload()
|
|
|
|
{
|
2021-05-16 17:49:40 -04:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 15:23:41 -04:00
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the check_acl_input() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheckAclInput()
|
|
|
|
{
|
2021-11-20 08:44:12 -05:00
|
|
|
$result = check_acl_input('<aclstring>', BaseApi::getCurrentUserID());
|
2018-04-09 15:23:41 -04:00
|
|
|
// Where does this result come from?
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertEquals(1, $result);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the check_acl_input() function with an empty ACL string.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheckAclInputWithEmptyAclString()
|
|
|
|
{
|
2021-11-20 08:44:12 -05:00
|
|
|
$result = check_acl_input(' ', BaseApi::getCurrentUserID());
|
2020-10-17 08:19:57 -04:00
|
|
|
self::assertFalse($result);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the save_media_to_database() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSaveMediaToDatabase()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the post_photo_item() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostPhotoItem()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the prepare_photo_data() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPreparePhotoData()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_clean_plain_items() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiCleanPlainItems()
|
|
|
|
{
|
2021-12-16 17:44:50 -05:00
|
|
|
//$_REQUEST['include_entities'] = 'true';
|
|
|
|
//$result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
|
|
|
|
//self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
|
2018-04-09 15:23:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_group_show() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaGroupShow()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_destroy() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsDestroy()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the group_create() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGroupCreate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_group_create() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaGroupCreate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_create() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsCreate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_update() function.
|
2019-07-28 11:40:42 -04:00
|
|
|
*
|
2018-04-09 15:23:41 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsUpdate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
}
|