2018-04-09 21:23:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ApiTest class.
|
|
|
|
*/
|
|
|
|
|
2020-09-11 19:38:41 +02:00
|
|
|
namespace Friendica\Test\legacy;
|
2018-04-09 21:23:41 +02:00
|
|
|
|
2019-02-05 22:03:07 +01:00
|
|
|
use Friendica\App;
|
2021-10-26 21:44:29 +02:00
|
|
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
|
|
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
2018-07-10 04:39:59 +02:00
|
|
|
use Friendica\Core\Protocol;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2021-11-21 07:37:09 +01:00
|
|
|
use Friendica\Model\Post;
|
2021-11-12 19:52:01 +01:00
|
|
|
use Friendica\Module\Api\ApiResponse;
|
2021-11-27 10:42:05 +01:00
|
|
|
use Friendica\Module\Api\Twitter\Media\Upload;
|
2021-11-08 22:35:41 +01:00
|
|
|
use Friendica\Module\BaseApi;
|
2018-04-09 21:23:41 +02:00
|
|
|
use Friendica\Network\HTTPException;
|
2021-11-08 22:35:41 +01:00
|
|
|
use Friendica\Security\BasicAuth;
|
2020-09-11 19:38:41 +02:00
|
|
|
use Friendica\Test\FixtureTest;
|
2021-11-08 23:10:07 +01:00
|
|
|
use Friendica\Util\Arrays;
|
2021-09-18 07:08:29 +02:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
2020-01-31 21:40:45 +01:00
|
|
|
use Friendica\Util\Temporal;
|
2018-12-30 21:42:56 +01:00
|
|
|
use Monolog\Handler\TestHandler;
|
2018-04-09 21:23:41 +02:00
|
|
|
|
2018-11-01 13:45:21 +01:00
|
|
|
require_once __DIR__ . '/../../include/api.php';
|
2018-10-22 20:59:51 +02:00
|
|
|
|
2018-04-09 21:23:41 +02: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 21:19:45 +02:00
|
|
|
*
|
|
|
|
* @backupGlobals enabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
2020-06-09 14:38:31 +02:00
|
|
|
class ApiTest extends FixtureTest
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2018-12-30 21:42:56 +01:00
|
|
|
/**
|
|
|
|
* @var TestHandler Can handle log-outputs
|
|
|
|
*/
|
|
|
|
protected $logOutput;
|
|
|
|
|
2019-03-23 15:02:32 +01:00
|
|
|
/** @var array */
|
|
|
|
protected $selfUser;
|
|
|
|
/** @var array */
|
|
|
|
protected $friendUser;
|
|
|
|
/** @var array */
|
|
|
|
protected $otherUser;
|
|
|
|
|
|
|
|
protected $wrongUserId;
|
|
|
|
|
2019-07-26 15:54:14 +02:00
|
|
|
/** @var App */
|
|
|
|
protected $app;
|
|
|
|
|
2021-10-26 21:44:29 +02:00
|
|
|
/** @var IManageConfigValues */
|
2019-08-04 18:50:24 +02:00
|
|
|
protected $config;
|
|
|
|
|
2018-04-09 21:23:41 +02:00
|
|
|
/**
|
|
|
|
* Create variables used by tests.
|
|
|
|
*/
|
2021-04-01 23:04:30 +02:00
|
|
|
protected function setUp() : void
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2020-09-11 20:14:47 +02:00
|
|
|
global $API, $called_api;
|
|
|
|
$API = [];
|
|
|
|
$called_api = [];
|
|
|
|
|
2019-07-28 17:40:42 +02:00
|
|
|
parent::setUp();
|
2018-07-01 20:46:24 +02:00
|
|
|
|
2021-10-26 22:09:11 +02:00
|
|
|
/** @var IManageConfigValues $config */
|
2021-10-26 21:44:29 +02:00
|
|
|
$this->config = $this->dice->create(IManageConfigValues::class);
|
2019-08-04 19:02:16 +02: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 17:40:42 +02:00
|
|
|
|
2019-08-04 19:02:16 +02:00
|
|
|
/** @var App app */
|
2019-12-15 22:34:11 +01:00
|
|
|
$this->app = DI::app();
|
2019-07-27 14:37:24 +02:00
|
|
|
|
2021-07-25 16:27:13 +02:00
|
|
|
DI::args()->setArgc(1);
|
2019-07-26 15:54:14 +02:00
|
|
|
|
2018-04-09 21:23:41 +02:00
|
|
|
// User data that the test database is populated with
|
2019-07-28 17:40:42 +02:00
|
|
|
$this->selfUser = [
|
|
|
|
'id' => 42,
|
2018-04-09 21:23:41 +02:00
|
|
|
'name' => 'Self contact',
|
|
|
|
'nick' => 'selfcontact',
|
2018-07-01 21:07:50 +02:00
|
|
|
'nurl' => 'http://localhost/profile/selfcontact'
|
2018-07-01 20:46:24 +02:00
|
|
|
];
|
|
|
|
$this->friendUser = [
|
2019-07-28 17:40:42 +02:00
|
|
|
'id' => 44,
|
2018-07-01 20:46:24 +02:00
|
|
|
'name' => 'Friend contact',
|
|
|
|
'nick' => 'friendcontact',
|
2018-07-01 21:07:50 +02:00
|
|
|
'nurl' => 'http://localhost/profile/friendcontact'
|
2018-04-09 21:23:41 +02:00
|
|
|
];
|
2019-07-28 17:40:42 +02:00
|
|
|
$this->otherUser = [
|
|
|
|
'id' => 43,
|
2018-04-09 21:23:41 +02:00
|
|
|
'name' => 'othercontact',
|
|
|
|
'nick' => 'othercontact',
|
2018-07-01 21:07:50 +02:00
|
|
|
'nurl' => 'http://localhost/profile/othercontact'
|
2018-04-09 21:23:41 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
// User ID that we know is not in the database
|
|
|
|
$this->wrongUserId = 666;
|
|
|
|
|
2019-12-16 01:35:26 +01:00
|
|
|
DI::session()->start();
|
2019-12-10 22:29:49 +01:00
|
|
|
|
2018-04-09 21:23:41 +02:00
|
|
|
// Most API require login so we force the session
|
|
|
|
$_SESSION = [
|
|
|
|
'authenticated' => true,
|
2019-07-28 17:40:42 +02:00
|
|
|
'uid' => $this->selfUser['id']
|
2018-04-09 21:23:41 +02:00
|
|
|
];
|
2021-11-17 23:12:21 +01:00
|
|
|
BasicAuth::setCurrentUserID($this->selfUser['id']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that an user array contains expected keys.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @param array $user User array
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function assertSelfUser(array $user)
|
|
|
|
{
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals($this->selfUser['id'], $user['uid']);
|
|
|
|
self::assertEquals($this->selfUser['id'], $user['cid']);
|
|
|
|
self::assertEquals(1, $user['self']);
|
|
|
|
self::assertEquals('DFRN', $user['location']);
|
|
|
|
self::assertEquals($this->selfUser['name'], $user['name']);
|
|
|
|
self::assertEquals($this->selfUser['nick'], $user['screen_name']);
|
|
|
|
self::assertEquals('dfrn', $user['network']);
|
|
|
|
self::assertTrue($user['verified']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that an user array contains expected keys.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @param array $user User array
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-04-01 21:19:45 +02:00
|
|
|
private function assertOtherUser(array $user = [])
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals($this->otherUser['id'], $user['id']);
|
|
|
|
self::assertEquals($this->otherUser['id'], $user['id_str']);
|
|
|
|
self::assertEquals($this->otherUser['name'], $user['name']);
|
|
|
|
self::assertEquals($this->otherUser['nick'], $user['screen_name']);
|
|
|
|
self::assertFalse($user['verified']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that a status array contains expected keys.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @param array $status Status array
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-04-01 21:19:45 +02:00
|
|
|
private function assertStatus(array $status = [])
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-06-02 23:03:08 +02:00
|
|
|
self::assertIsString($status['text'] ?? '');
|
|
|
|
self::assertIsInt($status['id'] ?? '');
|
2018-04-09 21:23:41 +02:00
|
|
|
// We could probably do more checks here.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that a list array contains expected keys.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @param array $list List array
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-04-01 21:19:45 +02:00
|
|
|
private function assertList(array $list = [])
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-06-02 23:03:08 +02:00
|
|
|
self::assertIsString($list['name']);
|
|
|
|
self::assertIsInt($list['id']);
|
|
|
|
self::assertIsString('string', $list['id_str']);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertContains($list['mode'], ['public', 'private']);
|
2018-04-09 21:23:41 +02:00
|
|
|
// We could probably do more checks here.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that the string is XML and contain the root element.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @param string $result XML string
|
|
|
|
* @param string $root_element Root element name
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-04-01 21:19:45 +02:00
|
|
|
private function assertXml($result = '', $root_element = '')
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertStringStartsWith('<?xml version="1.0"?>', $result);
|
2021-05-23 23:16:33 +02:00
|
|
|
self::assertStringContainsString('<' . $root_element, $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
// We could probably do more checks here.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the path to a temporary empty PNG image.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return string Path
|
|
|
|
*/
|
|
|
|
private function getTempImage()
|
|
|
|
{
|
|
|
|
$tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
|
|
|
|
file_put_contents(
|
|
|
|
$tmpFile,
|
|
|
|
base64_decode(
|
2019-07-28 17:40:42 +02:00
|
|
|
// Empty 1x1 px PNG image
|
2018-04-09 21:23:41 +02:00
|
|
|
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $tmpFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_user() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiUser()
|
|
|
|
{
|
2021-11-18 07:58:43 +01:00
|
|
|
self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_user() function with an unallowed user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiUserWithUnallowedUser()
|
|
|
|
{
|
2021-11-18 08:14:23 +01:00
|
|
|
// self::assertEquals(false, api_user());
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_source() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiSource()
|
|
|
|
{
|
2021-11-24 08:26:22 +01:00
|
|
|
self::assertEquals('api', BasicAuth::getCurrentApplicationToken()['name']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_source() function with a Twidere user agent.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiSourceWithTwidere()
|
|
|
|
{
|
|
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Twidere';
|
2021-11-24 08:26:22 +01:00
|
|
|
self::assertEquals('Twidere', BasicAuth::getCurrentApplicationToken()['name']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_source() function with a GET parameter.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiSourceWithGet()
|
|
|
|
{
|
2021-11-24 08:11:33 +01:00
|
|
|
$_REQUEST['source'] = 'source_name';
|
2021-11-24 08:26:22 +01:00
|
|
|
self::assertEquals('source_name', BasicAuth::getCurrentApplicationToken()['name']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_date() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDate()
|
|
|
|
{
|
2021-11-18 22:43:13 +01:00
|
|
|
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_register_func() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiRegisterFunc()
|
|
|
|
{
|
|
|
|
global $API;
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertNull(
|
2018-04-09 21:23:41 +02:00
|
|
|
api_register_func(
|
|
|
|
'api_path',
|
|
|
|
function () {
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
'method'
|
|
|
|
)
|
|
|
|
);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertTrue(is_callable($API['api_path']['func']));
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function without any login.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 21:19:45 +02:00
|
|
|
* @preserveGlobalState disabled
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiLoginWithoutLogin()
|
|
|
|
{
|
2021-11-18 07:03:21 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-08 22:35:41 +01:00
|
|
|
BasicAuth::getCurrentUserID(true);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with a bad login.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 21:19:45 +02:00
|
|
|
* @preserveGlobalState disabled
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiLoginWithBadLogin()
|
|
|
|
{
|
2021-11-18 07:03:21 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SERVER['PHP_AUTH_USER'] = 'user@server';
|
2021-11-08 22:35:41 +01:00
|
|
|
BasicAuth::getCurrentUserID(true);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with oAuth.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiLoginWithOauth()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Can we test this easily?');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiLoginWithAddonAuth()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Can we test this easily?');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with a correct login.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2021-04-01 21:19:45 +02:00
|
|
|
* @doesNotPerformAssertions
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiLoginWithCorrectLogin()
|
|
|
|
{
|
2021-11-18 07:03:21 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SERVER['PHP_AUTH_USER'] = 'Test user';
|
2019-07-28 17:40:42 +02:00
|
|
|
$_SERVER['PHP_AUTH_PW'] = 'password';
|
2021-11-08 22:35:41 +01:00
|
|
|
BasicAuth::getCurrentUserID(true);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BasicAuth::getCurrentUserID() function with a remote user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiLoginWithRemoteUser()
|
|
|
|
{
|
2021-11-18 07:03:21 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
|
2021-11-08 22:35:41 +01:00
|
|
|
BasicAuth::getCurrentUserID(true);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiCall()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 17:40:42 +02:00
|
|
|
$API['api_path'] = [
|
2018-04-09 21:23:41 +02:00
|
|
|
'method' => 'method',
|
2019-07-28 17:40:42 +02:00
|
|
|
'func' => function () {
|
2018-04-09 21:23:41 +02:00
|
|
|
return ['data' => ['some_data']];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 06:21:04 +02:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path';
|
2019-07-28 17:40:42 +02:00
|
|
|
$_GET['callback'] = 'callback_name';
|
2018-04-09 21:23:41 +02:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
'callback_name(["some_data"])',
|
2021-11-26 08:55:02 +01:00
|
|
|
api_call('api_path', 'json')
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with the profiled enabled.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiCallWithProfiler()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 17:40:42 +02:00
|
|
|
$API['api_path'] = [
|
2018-04-09 21:23:41 +02:00
|
|
|
'method' => 'method',
|
2019-07-28 17:40:42 +02:00
|
|
|
'func' => function () {
|
2018-04-09 21:23:41 +02:00
|
|
|
return ['data' => ['some_data']];
|
|
|
|
}
|
|
|
|
];
|
2019-12-16 01:35:26 +01:00
|
|
|
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 06:21:04 +02:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path';
|
2019-12-16 01:35:26 +01:00
|
|
|
|
2019-08-04 19:02:16 +02:00
|
|
|
$this->config->set('system', 'profiler', true);
|
|
|
|
$this->config->set('rendertime', 'callstack', true);
|
2018-04-09 21:23:41 +02:00
|
|
|
$this->app->callstack = [
|
2019-07-28 17:40:42 +02:00
|
|
|
'database' => ['some_function' => 200],
|
2018-04-09 21:23:41 +02:00
|
|
|
'database_write' => ['some_function' => 200],
|
2019-07-28 17:40:42 +02:00
|
|
|
'cache' => ['some_function' => 200],
|
|
|
|
'cache_write' => ['some_function' => 200],
|
|
|
|
'network' => ['some_function' => 200]
|
2018-04-09 21:23:41 +02:00
|
|
|
];
|
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
'["some_data"]',
|
2021-11-26 08:55:02 +01:00
|
|
|
api_call('api_path', 'json')
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with a JSON result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiCallWithJson()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 17:40:42 +02:00
|
|
|
$API['api_path'] = [
|
2018-04-09 21:23:41 +02:00
|
|
|
'method' => 'method',
|
2019-07-28 17:40:42 +02:00
|
|
|
'func' => function () {
|
2018-04-09 21:23:41 +02:00
|
|
|
return ['data' => ['some_data']];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 06:21:04 +02:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
|
2019-12-16 01:35:26 +01:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
'["some_data"]',
|
2021-11-26 08:55:02 +01:00
|
|
|
api_call('api_path.json', 'json')
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with an XML result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiCallWithXml()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 17:40:42 +02:00
|
|
|
$API['api_path'] = [
|
2018-04-09 21:23:41 +02:00
|
|
|
'method' => 'method',
|
2019-07-28 17:40:42 +02:00
|
|
|
'func' => function () {
|
2018-04-09 21:23:41 +02:00
|
|
|
return 'some_data';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 06:21:04 +02:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
|
2019-12-16 01:35:26 +01:00
|
|
|
|
|
|
|
$args = DI::args()->determine($_SERVER, $_GET);
|
2018-04-09 21:23:41 +02:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
'some_data',
|
2021-11-26 08:55:02 +01:00
|
|
|
api_call('api_path.xml', 'xml')
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with an RSS result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiCallWithRss()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 17:40:42 +02:00
|
|
|
$API['api_path'] = [
|
2018-04-09 21:23:41 +02:00
|
|
|
'method' => 'method',
|
2019-07-28 17:40:42 +02:00
|
|
|
'func' => function () {
|
2018-04-09 21:23:41 +02:00
|
|
|
return 'some_data';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 06:21:04 +02:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
|
2019-12-16 01:35:26 +01:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2019-07-28 17:40:42 +02:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
|
|
|
'some_data',
|
2021-11-26 08:55:02 +01:00
|
|
|
api_call('api_path.rss', 'rss')
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_call() function with an Atom result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiCallWithAtom()
|
|
|
|
{
|
|
|
|
global $API;
|
2019-07-28 17:40:42 +02:00
|
|
|
$API['api_path'] = [
|
2018-04-09 21:23:41 +02:00
|
|
|
'method' => 'method',
|
2019-07-28 17:40:42 +02:00
|
|
|
'func' => function () {
|
2018-04-09 21:23:41 +02:00
|
|
|
return 'some_data';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$_SERVER['REQUEST_METHOD'] = 'method';
|
2020-09-09 06:21:04 +02:00
|
|
|
$_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
|
2019-12-16 01:35:26 +01:00
|
|
|
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2019-07-28 17:40:42 +02:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
|
|
|
'some_data',
|
2021-11-26 08:55:02 +01:00
|
|
|
api_call('api_path.atom', 'atom')
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_rss_extra() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiRssExtra()
|
|
|
|
{
|
2021-11-20 14:44:12 +01:00
|
|
|
/*
|
2018-07-04 23:55:06 +02:00
|
|
|
$user_info = ['url' => 'user_url', 'lang' => 'en'];
|
2021-11-17 22:28:51 +01:00
|
|
|
$result = api_rss_extra([], $user_info);
|
2020-10-17 14:19:57 +02: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 14:44:12 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_rss_extra() function without any user info.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiRssExtraWithoutUserInfo()
|
|
|
|
{
|
2021-11-20 14:44:12 +01:00
|
|
|
/*
|
2021-11-17 22:28:51 +01:00
|
|
|
$result = api_rss_extra([], null);
|
2021-06-02 23:03:08 +02:00
|
|
|
self::assertIsArray($result['$user']);
|
2020-10-17 14:19:57 +02: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 14:44:12 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetUser()
|
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// $user = api_get_user();
|
|
|
|
// self::assertSelfUser($user);
|
2021-11-17 00:41:17 +01:00
|
|
|
// self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
|
|
|
|
// self::assertEquals('6fdbe8', $user['profile_link_color']);
|
|
|
|
// self::assertEquals('ededed', $user['profile_background_color']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function with a Frio schema.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetUserWithFrioSchema()
|
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
|
|
|
|
// $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
|
|
|
|
// $user = api_get_user();
|
|
|
|
// self::assertSelfUser($user);
|
2021-11-17 00:41:17 +01:00
|
|
|
// self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
|
|
|
|
// self::assertEquals('6fdbe8', $user['profile_link_color']);
|
|
|
|
// self::assertEquals('ededed', $user['profile_background_color']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-09 14:38:31 +02:00
|
|
|
* Test the api_get_user() function with an empty Frio schema.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2020-06-09 14:38:31 +02:00
|
|
|
public function testApiGetUserWithEmptyFrioSchema()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
|
|
|
|
// $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
|
|
|
|
// $user = api_get_user();
|
|
|
|
// self::assertSelfUser($user);
|
2021-11-17 00:41:17 +01:00
|
|
|
// self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
|
|
|
|
// self::assertEquals('6fdbe8', $user['profile_link_color']);
|
|
|
|
// self::assertEquals('ededed', $user['profile_background_color']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-09 14:38:31 +02:00
|
|
|
* Test the api_get_user() function with a custom Frio schema.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2020-06-09 14:38:31 +02:00
|
|
|
public function testApiGetUserWithCustomFrioSchema()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
|
|
|
|
// $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
|
|
|
|
// $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
|
|
|
|
// $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
|
|
|
|
// $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
|
|
|
|
// $user = api_get_user();
|
|
|
|
// self::assertSelfUser($user);
|
2021-11-17 00:41:17 +01:00
|
|
|
// self::assertEquals('123456', $user['profile_sidebar_fill_color']);
|
|
|
|
// self::assertEquals('123456', $user['profile_link_color']);
|
|
|
|
// self::assertEquals('123456', $user['profile_background_color']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function with an user that is not allowed to use the API.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @runInSeparateProcess
|
2021-04-01 22:16:16 +02:00
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiGetUserWithoutApiUser()
|
|
|
|
{
|
2021-11-18 07:58:43 +01:00
|
|
|
// api_get_user() with empty parameters is not used anymore
|
|
|
|
/*
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SERVER['PHP_AUTH_USER'] = 'Test user';
|
2019-07-28 17:40:42 +02:00
|
|
|
$_SERVER['PHP_AUTH_PW'] = 'password';
|
2021-11-18 00:11:21 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2021-11-18 07:49:16 +01:00
|
|
|
self::assertFalse(api_get_user());
|
2021-11-18 07:58:43 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function with an user ID in a GET parameter.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetUserWithGetId()
|
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// self::assertOtherUser(api_get_user());
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function with a wrong user ID in a GET parameter.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetUserWithWrongGetId()
|
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
|
|
|
// self::assertOtherUser(api_get_user());
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function with an user name in a GET parameter.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetUserWithGetName()
|
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// self::assertSelfUser(api_get_user());
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function with a profile URL in a GET parameter.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetUserWithGetUrl()
|
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// self::assertSelfUser(api_get_user());
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function with an user ID in the API path.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetUserWithNumericCalledApi()
|
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// global $called_api;
|
|
|
|
// $called_api = ['api_path'];
|
|
|
|
// DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
|
|
|
|
// self::assertOtherUser(api_get_user());
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_user() function with the $called_api global variable.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetUserWithCalledApi()
|
|
|
|
{
|
2021-11-18 08:06:08 +01:00
|
|
|
// global $called_api;
|
|
|
|
// $called_api = ['api', 'api_path'];
|
|
|
|
// self::assertSelfUser(api_get_user());
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 23:10:07 +01:00
|
|
|
* Test the Arrays::walkRecursive() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiWalkRecursive()
|
|
|
|
{
|
|
|
|
$array = ['item1'];
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
$array,
|
2021-11-08 23:10:07 +01:00
|
|
|
Arrays::walkRecursive(
|
2018-04-09 21:23:41 +02:00
|
|
|
$array,
|
|
|
|
function () {
|
|
|
|
// Should we test this with a callback that actually does something?
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 23:10:07 +01:00
|
|
|
* Test the Arrays::walkRecursive() function with an array.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiWalkRecursiveWithArray()
|
|
|
|
{
|
|
|
|
$array = [['item1'], ['item2']];
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
$array,
|
2021-11-08 23:10:07 +01:00
|
|
|
Arrays::walkRecursive(
|
2018-04-09 21:23:41 +02:00
|
|
|
$array,
|
|
|
|
function () {
|
|
|
|
// Should we test this with a callback that actually does something?
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BaseApi::reformatXML() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiReformatXml()
|
|
|
|
{
|
|
|
|
$item = true;
|
2019-07-28 17:40:42 +02:00
|
|
|
$key = '';
|
2021-11-12 19:52:01 +01:00
|
|
|
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('true', $item);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BaseApi::reformatXML() function with a statusnet_api key.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiReformatXmlWithStatusnetKey()
|
|
|
|
{
|
|
|
|
$item = '';
|
2019-07-28 17:40:42 +02:00
|
|
|
$key = 'statusnet_api';
|
2021-11-12 19:52:01 +01:00
|
|
|
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('statusnet:api', $key);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BaseApi::reformatXML() function with a friendica_api key.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiReformatXmlWithFriendicaKey()
|
|
|
|
{
|
|
|
|
$item = '';
|
2019-07-28 17:40:42 +02:00
|
|
|
$key = 'friendica_api';
|
2021-11-12 19:52:01 +01:00
|
|
|
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('friendica:api', $key);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BaseApi::createXML() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiCreateXml()
|
|
|
|
{
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2019-07-28 17:40:42 +02: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 19:56:37 +01:00
|
|
|
DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BaseApi::createXML() function without any XML namespace.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiCreateXmlWithoutNamespaces()
|
|
|
|
{
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2019-07-28 17:40:42 +02:00
|
|
|
'<?xml version="1.0"?>' . "\n" .
|
|
|
|
'<ok>' . "\n" .
|
|
|
|
' <data>some_data</data>' . "\n" .
|
|
|
|
'</ok>' . "\n",
|
2021-11-12 19:56:37 +01:00
|
|
|
DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BaseApi::formatData() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatData()
|
|
|
|
{
|
|
|
|
$data = ['some_data'];
|
2021-11-12 19:59:16 +01:00
|
|
|
self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-08 22:35:41 +01:00
|
|
|
* Test the BaseApi::formatData() function with an XML result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatDataWithXml()
|
|
|
|
{
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2019-07-28 17:40:42 +02: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 19:59:16 +01:00
|
|
|
DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_statuses_mediap() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiStatusesMediap()
|
|
|
|
{
|
2021-11-27 14:41:49 +01:00
|
|
|
/*
|
2021-07-25 16:27:13 +02:00
|
|
|
DI::args()->setArgc(2);
|
2018-04-09 21:23:41 +02:00
|
|
|
|
2019-07-28 17:40:42 +02:00
|
|
|
$_FILES = [
|
2018-04-09 21:23:41 +02:00
|
|
|
'media' => [
|
2019-07-28 17:40:42 +02:00
|
|
|
'id' => 666,
|
|
|
|
'size' => 666,
|
|
|
|
'width' => 666,
|
|
|
|
'height' => 666,
|
2018-04-09 21:23:41 +02:00
|
|
|
'tmp_name' => $this->getTempImage(),
|
2019-07-28 17:40:42 +02:00
|
|
|
'name' => 'spacer.png',
|
|
|
|
'type' => 'image/png'
|
2018-04-09 21:23:41 +02:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$_GET['status'] = '<b>Status content</b>';
|
|
|
|
|
|
|
|
$result = api_statuses_mediap('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertStatus($result['status']);
|
2021-11-27 14:41:49 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_statuses_mediap() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiStatusesMediapWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-27 14:41:49 +01:00
|
|
|
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
|
|
|
// BasicAuth::setCurrentUserID();
|
|
|
|
// $_SESSION['authenticated'] = false;
|
|
|
|
// api_statuses_mediap('json');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_statuses_update() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiStatusesUpdate()
|
|
|
|
{
|
2021-11-25 00:16:07 +01:00
|
|
|
$_REQUEST['status'] = 'Status content #friendica';
|
|
|
|
$_REQUEST['in_reply_to_status_id'] = -1;
|
|
|
|
$_REQUEST['lat'] = 48;
|
|
|
|
$_REQUEST['long'] = 7;
|
|
|
|
$_FILES = [
|
2018-04-09 21:23:41 +02:00
|
|
|
'media' => [
|
2019-07-28 17:40:42 +02:00
|
|
|
'id' => 666,
|
|
|
|
'size' => 666,
|
|
|
|
'width' => 666,
|
|
|
|
'height' => 666,
|
2018-04-09 21:23:41 +02:00
|
|
|
'tmp_name' => $this->getTempImage(),
|
2019-07-28 17:40:42 +02:00
|
|
|
'name' => 'spacer.png',
|
|
|
|
'type' => 'image/png'
|
2018-04-09 21:23:41 +02:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$result = api_statuses_update('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertStatus($result['status']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_statuses_update() function with an HTML status.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiStatusesUpdateWithHtml()
|
|
|
|
{
|
2021-11-25 00:16:07 +01:00
|
|
|
$_REQUEST['htmlstatus'] = '<b>Status content</b>';
|
2018-04-09 21:23:41 +02:00
|
|
|
|
|
|
|
$result = api_statuses_update('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertStatus($result['status']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_statuses_update() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiStatusesUpdateWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-27 19:50:52 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_statuses_update('json');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 19:50:52 +01:00
|
|
|
* Test the api_statuses_update() function with a parent status.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiStatusesUpdateWithParent()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 19:50:52 +01:00
|
|
|
* Test the api_statuses_update() function with a media_ids parameter.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiStatusesUpdateWithMediaIds()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$this->markTestIncomplete();
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 19:50:52 +01:00
|
|
|
* Test the api_statuses_update() function with the throttle limit reached.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiStatusesUpdateWithDayThrottleReached()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$this->markTestIncomplete();
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 10:42:05 +01:00
|
|
|
* Test the \Friendica\Module\Api\Twitter\Media\Upload module.
|
2021-11-27 19:50:52 +01:00
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiMediaUpload()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2021-11-27 10:42:05 +01:00
|
|
|
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 10:42:05 +01:00
|
|
|
* Test the \Friendica\Module\Api\Twitter\Media\Upload module without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiMediaUploadWithoutAuthenticatedUser()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
|
|
|
BasicAuth::setCurrentUserID();
|
|
|
|
$_SESSION['authenticated'] = false;
|
2021-11-27 10:42:05 +01:00
|
|
|
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 10:42:05 +01:00
|
|
|
* Test the \Friendica\Module\Api\Twitter\Media\Upload module with an invalid uploaded media.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiMediaUploadWithMedia()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\InternalServerErrorException::class);
|
|
|
|
$_FILES = [
|
|
|
|
'media' => [
|
|
|
|
'id' => 666,
|
|
|
|
'tmp_name' => 'tmp_name'
|
|
|
|
]
|
|
|
|
];
|
2021-11-27 10:42:05 +01:00
|
|
|
(new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 10:42:05 +01:00
|
|
|
* Test the \Friendica\Module\Api\Twitter\Media\Upload module with an valid uploaded media.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiMediaUploadWithValidMedia()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$_FILES = [
|
|
|
|
'media' => [
|
|
|
|
'id' => 666,
|
|
|
|
'size' => 666,
|
|
|
|
'width' => 666,
|
|
|
|
'height' => 666,
|
|
|
|
'tmp_name' => $this->getTempImage(),
|
|
|
|
'name' => 'spacer.png',
|
|
|
|
'type' => 'image/png'
|
|
|
|
]
|
|
|
|
];
|
2021-11-21 08:10:10 +01:00
|
|
|
|
2021-11-27 10:42:05 +01:00
|
|
|
$response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), $_SERVER))->run();
|
|
|
|
$media = json_decode($response->getBody(), true);
|
|
|
|
|
|
|
|
self::assertEquals('image/png', $media['image']['image_type']);
|
|
|
|
self::assertEquals(1, $media['image']['w']);
|
|
|
|
self::assertEquals(1, $media['image']['h']);
|
|
|
|
self::assertNotEmpty($media['image']['friendica_preview_url']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 19:50:52 +01:00
|
|
|
* Test the api_statuses_repeat() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiStatusesRepeat()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
|
|
|
|
api_statuses_repeat('json');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 19:50:52 +01:00
|
|
|
* Test the api_statuses_repeat() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiStatusesRepeatWithoutAuthenticatedUser()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
|
|
|
BasicAuth::setCurrentUserID();
|
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_statuses_repeat('json');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-27 19:50:52 +01:00
|
|
|
* Test the api_statuses_repeat() function with an ID.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-11-27 19:50:52 +01:00
|
|
|
public function testApiStatusesRepeatWithId()
|
2018-04-09 21:23:41 +02:00
|
|
|
{
|
2021-11-27 19:50:52 +01:00
|
|
|
DI::args()->setArgv(['', '', '', 1]);
|
|
|
|
$result = api_statuses_repeat('json');
|
|
|
|
self::assertStatus($result['status']);
|
|
|
|
|
|
|
|
// Also test with a shared status
|
|
|
|
DI::args()->setArgv(['', '', '', 5]);
|
|
|
|
$result = api_statuses_repeat('json');
|
|
|
|
self::assertStatus($result['status']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_favorites_create_destroy() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFavoritesCreateDestroy()
|
|
|
|
{
|
2021-11-27 10:45:42 +01:00
|
|
|
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
|
|
|
// DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
|
|
|
|
// api_favorites_create_destroy('json');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_favorites_create_destroy() function with an invalid ID.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFavoritesCreateDestroyWithInvalidId()
|
|
|
|
{
|
2021-11-27 10:45:42 +01:00
|
|
|
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
|
|
|
// DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
|
|
|
|
// api_favorites_create_destroy('json');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_favorites_create_destroy() function with an invalid action.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFavoritesCreateDestroyWithInvalidAction()
|
|
|
|
{
|
2021-11-27 10:45:42 +01:00
|
|
|
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
|
|
|
// DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
|
|
|
|
// $_REQUEST['id'] = 1;
|
|
|
|
// api_favorites_create_destroy('json');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_favorites_create_destroy() function with the create action.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFavoritesCreateDestroyWithCreateAction()
|
|
|
|
{
|
2021-11-27 10:45:42 +01:00
|
|
|
// DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
|
|
|
|
// $_REQUEST['id'] = 3;
|
|
|
|
// $result = api_favorites_create_destroy('json');
|
|
|
|
// self::assertStatus($result['status']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_favorites_create_destroy() function with the create action and an RSS result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
|
|
|
|
{
|
2021-11-27 10:45:42 +01:00
|
|
|
// DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
|
|
|
|
// $_REQUEST['id'] = 3;
|
|
|
|
// $result = api_favorites_create_destroy('rss');
|
|
|
|
// self::assertXml($result, 'status');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_favorites_create_destroy() function with the destroy action.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFavoritesCreateDestroyWithDestroyAction()
|
|
|
|
{
|
2021-11-27 10:45:42 +01:00
|
|
|
// DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
|
|
|
|
// $_REQUEST['id'] = 3;
|
|
|
|
// $result = api_favorites_create_destroy('json');
|
|
|
|
// self::assertStatus($result['status']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_favorites_create_destroy() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-27 10:45:42 +01:00
|
|
|
/*
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-07-25 16:27:13 +02:00
|
|
|
DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
|
2021-11-18 07:10:20 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_favorites_create_destroy('json');
|
2021-11-27 10:45:42 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_messages() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatMessages()
|
|
|
|
{
|
|
|
|
$result = api_format_messages(
|
2021-07-10 16:02:03 +02:00
|
|
|
['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
|
|
|
|
['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
|
|
|
|
['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
|
|
|
|
self::assertEquals(1, $result['id']);
|
|
|
|
self::assertEquals(2, $result['recipient_id']);
|
|
|
|
self::assertEquals(3, $result['sender_id']);
|
|
|
|
self::assertEquals('recipient_name', $result['recipient_screen_name']);
|
|
|
|
self::assertEquals('sender_name', $result['sender_screen_name']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_messages() function with HTML.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatMessagesWithHtmlText()
|
|
|
|
{
|
|
|
|
$_GET['getText'] = 'html';
|
2019-07-28 17:40:42 +02:00
|
|
|
$result = api_format_messages(
|
2021-07-10 16:02:03 +02:00
|
|
|
['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
|
|
|
|
['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
|
|
|
|
['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('item_title', $result['title']);
|
|
|
|
self::assertEquals('<strong>item_body</strong>', $result['text']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_messages() function with plain text.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatMessagesWithPlainText()
|
|
|
|
{
|
|
|
|
$_GET['getText'] = 'plain';
|
2019-07-28 17:40:42 +02:00
|
|
|
$result = api_format_messages(
|
2021-07-10 16:02:03 +02:00
|
|
|
['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
|
|
|
|
['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
|
|
|
|
['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('item_title', $result['title']);
|
|
|
|
self::assertEquals('item_body', $result['text']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_messages() function with the getUserObjects GET parameter set to false.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatMessagesWithoutUserObjects()
|
|
|
|
{
|
|
|
|
$_GET['getUserObjects'] = 'false';
|
2019-07-28 17:40:42 +02:00
|
|
|
$result = api_format_messages(
|
2021-07-10 16:04:27 +02:00
|
|
|
['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
|
|
|
|
['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
|
|
|
|
['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
|
2018-04-09 21:23:41 +02:00
|
|
|
);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertTrue(!isset($result['sender']));
|
|
|
|
self::assertTrue(!isset($result['recipient']));
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_convert_item() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiConvertItem()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
/*
|
2018-04-09 21:23:41 +02:00
|
|
|
$result = api_convert_item(
|
|
|
|
[
|
|
|
|
'network' => 'feed',
|
2019-07-28 17:40:42 +02:00
|
|
|
'title' => 'item_title',
|
2021-05-24 13:47:02 +02:00
|
|
|
'uri-id' => 1,
|
2018-04-09 21:23:41 +02:00
|
|
|
// We need a long string to test that it is correctly cut
|
2019-07-28 17:40:42 +02:00
|
|
|
'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
|
2021-11-11 00:07:46 +01:00
|
|
|
'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',
|
2019-07-28 17:40:42 +02:00
|
|
|
'plink' => 'item_plink'
|
2018-04-09 21:23:41 +02:00
|
|
|
]
|
|
|
|
);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertStringStartsWith('item_title', $result['text']);
|
|
|
|
self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
|
2021-11-23 22:54:19 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_convert_item() function with an empty item body.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiConvertItemWithoutBody()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
/*
|
2018-04-09 21:23:41 +02:00
|
|
|
$result = api_convert_item(
|
|
|
|
[
|
|
|
|
'network' => 'feed',
|
2019-07-28 17:40:42 +02:00
|
|
|
'title' => 'item_title',
|
2021-05-25 09:21:37 +02:00
|
|
|
'uri-id' => -1,
|
2019-07-28 17:40:42 +02:00
|
|
|
'body' => '',
|
|
|
|
'plink' => 'item_plink'
|
2018-04-09 21:23:41 +02:00
|
|
|
]
|
|
|
|
);
|
2021-05-25 09:21:37 +02:00
|
|
|
self::assertEquals("item_title", $result['text']);
|
|
|
|
self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
|
2021-11-23 22:54:19 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_convert_item() function with the title in the body.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiConvertItemWithTitleInBody()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
/*
|
2018-04-09 21:23:41 +02:00
|
|
|
$result = api_convert_item(
|
|
|
|
[
|
2021-05-24 13:47:02 +02:00
|
|
|
'title' => 'item_title',
|
|
|
|
'body' => 'item_title item_body',
|
|
|
|
'uri-id' => 1,
|
2018-04-09 21:23:41 +02:00
|
|
|
]
|
|
|
|
);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('item_title item_body', $result['text']);
|
|
|
|
self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
|
2021-11-23 22:54:19 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_attachments() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetAttachments()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
// $body = 'body';
|
|
|
|
// self::assertEmpty(api_get_attachments($body, 0));
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_attachments() function with an img tag.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetAttachmentsWithImage()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
// $body = '[img]http://via.placeholder.com/1x1.png[/img]';
|
|
|
|
// self::assertIsArray(api_get_attachments($body, 0));
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_attachments() function with an img tag and an AndStatus user agent.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetAttachmentsWithImageAndAndStatus()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
// $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
|
|
|
|
// $body = '[img]http://via.placeholder.com/1x1.png[/img]';
|
|
|
|
// self::assertIsArray(api_get_attachments($body, 0));
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_entitities() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetEntitities()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
// $text = 'text';
|
|
|
|
// self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_get_entitities() function with the include_entities parameter.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiGetEntititiesWithIncludeEntities()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
/*
|
2018-04-09 21:23:41 +02:00
|
|
|
$_REQUEST['include_entities'] = 'true';
|
2019-07-28 17:40:42 +02:00
|
|
|
$text = 'text';
|
2021-07-06 08:38:15 +02:00
|
|
|
$result = api_get_entitities($text, 'bbcode', 0);
|
2021-06-02 23:03:08 +02:00
|
|
|
self::assertIsArray($result['hashtags']);
|
|
|
|
self::assertIsArray($result['symbols']);
|
|
|
|
self::assertIsArray($result['urls']);
|
|
|
|
self::assertIsArray($result['user_mentions']);
|
2021-11-23 22:54:19 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items_embeded_images() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatItemsEmbededImages()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
/*
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2019-12-30 23:00:08 +01:00
|
|
|
'text ' . DI::baseUrl() . '/display/item_guid',
|
2018-04-09 21:23:41 +02:00
|
|
|
api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
|
|
|
|
);
|
2021-11-23 22:54:19 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items_activities() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatItemsActivities()
|
|
|
|
{
|
2021-11-24 08:06:28 +01:00
|
|
|
$item = ['uid' => 0, 'uri-id' => 1];
|
|
|
|
$result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('like', $result);
|
|
|
|
self::assertArrayHasKey('dislike', $result);
|
|
|
|
self::assertArrayHasKey('attendyes', $result);
|
|
|
|
self::assertArrayHasKey('attendno', $result);
|
|
|
|
self::assertArrayHasKey('attendmaybe', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items_activities() function with an XML result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFormatItemsActivitiesWithXml()
|
|
|
|
{
|
2021-11-24 08:06:28 +01:00
|
|
|
$item = ['uid' => 0, 'uri-id' => 1];
|
|
|
|
$result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml');
|
2020-10-17 14:19:57 +02: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 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items() function.
|
2021-04-01 21:19:45 +02:00
|
|
|
* @doesNotPerformAssertions
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiFormatItems()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
/*
|
2021-11-21 07:37:09 +01:00
|
|
|
$items = Post::selectToArray([], ['uid' => 42]);
|
2021-11-21 00:38:52 +01:00
|
|
|
foreach ($items as $item) {
|
|
|
|
$status = api_format_item($item);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertStatus($status);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
2021-11-23 22:54:19 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_format_items() function with an XML result.
|
2021-04-01 21:19:45 +02:00
|
|
|
* @doesNotPerformAssertions
|
2018-04-09 21:23:41 +02:00
|
|
|
*/
|
|
|
|
public function testApiFormatItemsWithXml()
|
|
|
|
{
|
2021-11-23 22:54:19 +01:00
|
|
|
/*
|
2021-11-21 07:37:09 +01:00
|
|
|
$items = Post::selectToArray([], ['uid' => 42]);
|
2021-11-21 00:38:52 +01:00
|
|
|
foreach ($items as $item) {
|
|
|
|
$status = api_format_item($item, 'xml');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertStatus($status);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
2021-11-23 22:54:19 +01:00
|
|
|
*/
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_list() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsList()
|
|
|
|
{
|
|
|
|
$result = api_lists_list('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(['lists_list' => []], $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_ownerships() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsOwnerships()
|
|
|
|
{
|
|
|
|
$result = api_lists_ownerships('json');
|
|
|
|
foreach ($result['lists']['lists'] as $list) {
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertList($list);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_ownerships() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsOwnershipsWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 07:10:20 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_lists_ownerships('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_statuses_f() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiStatusesFWithIncoming()
|
|
|
|
{
|
2021-11-26 22:48:13 +01:00
|
|
|
// $result = api_statuses_f('incoming');
|
|
|
|
// self::assertArrayHasKey('user', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_new() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesNew()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_new('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertNull($result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_new() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesNewWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 07:10:20 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_direct_messages_new('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_new() function with an user ID.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesNewWithUserId()
|
|
|
|
{
|
2021-11-26 11:48:38 +01:00
|
|
|
$_POST['text'] = 'message_text';
|
|
|
|
$_REQUEST['user_id'] = $this->otherUser['id'];
|
2019-07-28 17:40:42 +02:00
|
|
|
$result = api_direct_messages_new('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(['direct_message' => ['error' => -1]], $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_new() function with a screen name.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesNewWithScreenName()
|
|
|
|
{
|
2021-08-09 22:56:15 +02:00
|
|
|
$this->app->setLoggedInUserNickname($this->selfUser['nick']);
|
2021-11-26 11:54:02 +01:00
|
|
|
$_POST['text'] = 'message_text';
|
|
|
|
$_REQUEST['user_id'] = $this->friendUser['id'];
|
|
|
|
$result = api_direct_messages_new('json');
|
2021-05-23 23:16:33 +02:00
|
|
|
self::assertStringContainsString('message_text', $result['direct_message']['text']);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
|
|
|
|
self::assertEquals(1, $result['direct_message']['friendica_seen']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_new() function with a title.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesNewWithTitle()
|
|
|
|
{
|
2021-08-09 22:56:15 +02:00
|
|
|
$this->app->setLoggedInUserNickname($this->selfUser['nick']);
|
2021-11-26 11:54:02 +01:00
|
|
|
$_POST['text'] = 'message_text';
|
|
|
|
$_REQUEST['user_id'] = $this->friendUser['id'];
|
|
|
|
$_REQUEST['title'] = 'message_title';
|
2021-11-21 06:16:21 +01:00
|
|
|
$result = api_direct_messages_new('json');
|
2021-05-23 23:16:33 +02:00
|
|
|
self::assertStringContainsString('message_text', $result['direct_message']['text']);
|
|
|
|
self::assertStringContainsString('message_title', $result['direct_message']['text']);
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
|
|
|
|
self::assertEquals(1, $result['direct_message']['friendica_seen']);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_new() function with an RSS result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesNewWithRss()
|
|
|
|
{
|
2021-08-09 22:56:15 +02:00
|
|
|
$this->app->setLoggedInUserNickname($this->selfUser['nick']);
|
2021-11-26 11:54:02 +01:00
|
|
|
$_POST['text'] = 'message_text';
|
|
|
|
$_REQUEST['user_id'] = $this->friendUser['id'];
|
|
|
|
$result = api_direct_messages_new('rss');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertXml($result, 'direct-messages');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_destroy() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesDestroy()
|
|
|
|
{
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 21:23:41 +02:00
|
|
|
api_direct_messages_destroy('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesDestroyWithVerbose()
|
|
|
|
{
|
|
|
|
$_GET['friendica_verbose'] = 'true';
|
2019-07-28 17:40:42 +02:00
|
|
|
$result = api_direct_messages_destroy('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
[
|
|
|
|
'$result' => [
|
2019-07-28 17:40:42 +02:00
|
|
|
'result' => 'error',
|
2018-04-09 21:23:41 +02:00
|
|
|
'message' => 'message id or parenturi not specified'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_destroy() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 07:10:20 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_direct_messages_destroy('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_destroy() function with a non-zero ID.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesDestroyWithId()
|
|
|
|
{
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 21:23:41 +02:00
|
|
|
$_REQUEST['id'] = 1;
|
|
|
|
api_direct_messages_destroy('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesDestroyWithIdAndVerbose()
|
|
|
|
{
|
2019-07-28 17:40:42 +02:00
|
|
|
$_REQUEST['id'] = 1;
|
2018-04-09 21:23:41 +02:00
|
|
|
$_REQUEST['friendica_parenturi'] = 'parent_uri';
|
2019-07-28 17:40:42 +02:00
|
|
|
$_GET['friendica_verbose'] = 'true';
|
|
|
|
$result = api_direct_messages_destroy('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
[
|
|
|
|
'$result' => [
|
2019-07-28 17:40:42 +02:00
|
|
|
'result' => 'error',
|
2018-04-09 21:23:41 +02:00
|
|
|
'message' => 'message id not in database'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_destroy() function with a non-zero ID.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesDestroyWithCorrectId()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('We need to add a dataset for this.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_box() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesBoxWithSentbox()
|
|
|
|
{
|
2019-07-28 17:40:42 +02:00
|
|
|
$_REQUEST['page'] = -1;
|
2018-04-09 21:23:41 +02:00
|
|
|
$_REQUEST['max_id'] = 10;
|
2019-07-28 17:40:42 +02:00
|
|
|
$result = api_direct_messages_box('json', 'sentbox', 'false');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('direct_message', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_box() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesBoxWithConversation()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_box('json', 'conversation', 'false');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('direct_message', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_box() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesBoxWithAll()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_box('json', 'all', 'false');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('direct_message', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_box() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesBoxWithInbox()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_box('json', 'inbox', 'false');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('direct_message', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_box() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesBoxWithVerbose()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_box('json', 'sentbox', 'true');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(
|
2018-04-09 21:23:41 +02:00
|
|
|
[
|
|
|
|
'$result' => [
|
2019-07-28 17:40:42 +02:00
|
|
|
'result' => 'error',
|
2018-04-09 21:23:41 +02:00
|
|
|
'message' => 'no mails available'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_box() function with a RSS result.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesBoxWithRss()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_box('rss', 'sentbox', 'false');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertXml($result, 'direct-messages');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_box() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesBoxWithUnallowedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 00:11:21 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02:00
|
|
|
api_direct_messages_box('json', 'sentbox', 'false');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_sentbox() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesSentbox()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_sentbox('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('direct_message', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_inbox() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesInbox()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_inbox('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('direct_message', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_all() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesAll()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_all('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('direct_message', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_direct_messages_conversation() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiDirectMessagesConversation()
|
|
|
|
{
|
|
|
|
$result = api_direct_messages_conversation('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('direct_message', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_oauth_request_token() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiOauthRequestToken()
|
|
|
|
{
|
2020-01-04 23:43:13 +01:00
|
|
|
$this->markTestIncomplete('exit() kills phpunit as well');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_oauth_access_token() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiOauthAccessToken()
|
|
|
|
{
|
2020-01-04 23:43:13 +01:00
|
|
|
$this->markTestIncomplete('exit() kills phpunit as well');
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photos_list() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotosList()
|
|
|
|
{
|
|
|
|
$result = api_fr_photos_list('json');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertArrayHasKey('photo', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photos_list() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotosListWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 07:10:20 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_fr_photos_list('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_create_update() function.
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdate()
|
|
|
|
{
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 21:23:41 +02:00
|
|
|
api_fr_photo_create_update('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_create_update() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 07:10:20 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02: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 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdateWithAlbum()
|
|
|
|
{
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 21:23:41 +02: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 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02: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 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoCreateUpdateWithFile()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_detail() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoDetail()
|
|
|
|
{
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 21:23:41 +02:00
|
|
|
api_fr_photo_detail('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_detail() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoDetailWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 07:10:20 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02:00
|
|
|
$_SESSION['authenticated'] = false;
|
|
|
|
api_fr_photo_detail('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_fr_photo_detail() function with a photo ID.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFrPhotoDetailWithPhotoId()
|
|
|
|
{
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
|
2018-04-09 21:23:41 +02: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 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02: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 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiAccountUpdateProfileImage()
|
|
|
|
{
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 21:23:41 +02:00
|
|
|
api_account_update_profile_image('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_account_update_profile_image() function without an authenticated user.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
|
|
|
|
{
|
2021-11-18 09:08:55 +01:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
2021-11-18 07:10:20 +01:00
|
|
|
BasicAuth::setCurrentUserID();
|
2018-04-09 21:23:41 +02: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 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiAccountUpdateProfileImageWithUpload()
|
|
|
|
{
|
2021-05-16 23:49:40 +02:00
|
|
|
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
2018-04-09 21:23:41 +02:00
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the check_acl_input() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheckAclInput()
|
|
|
|
{
|
2021-11-20 14:44:12 +01:00
|
|
|
$result = check_acl_input('<aclstring>', BaseApi::getCurrentUserID());
|
2018-04-09 21:23:41 +02:00
|
|
|
// Where does this result come from?
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals(1, $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the check_acl_input() function with an empty ACL string.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheckAclInputWithEmptyAclString()
|
|
|
|
{
|
2021-11-20 14:44:12 +01:00
|
|
|
$result = check_acl_input(' ', BaseApi::getCurrentUserID());
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertFalse($result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the save_media_to_database() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSaveMediaToDatabase()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the post_photo_item() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostPhotoItem()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the prepare_photo_data() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPreparePhotoData()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_share_as_retweet() function with a valid item.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiShareAsRetweetWithValidItem()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_in_reply_to() function with a valid item.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiInReplyToWithValidItem()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_clean_plain_items() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiCleanPlainItems()
|
|
|
|
{
|
|
|
|
$_REQUEST['include_entities'] = 'true';
|
2019-07-28 17:40:42 +02:00
|
|
|
$result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
|
2020-10-17 14:19:57 +02:00
|
|
|
self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
|
2018-04-09 21:23:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_best_nickname() function with contacts.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiBestNicknameWithContacts()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_group_show() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaGroupShow()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_group_delete() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaGroupDelete()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_destroy() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsDestroy()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the group_create() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGroupCreate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_group_create() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaGroupCreate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_create() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsCreate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_group_update() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaGroupUpdate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_lists_update() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiListsUpdate()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_activity() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaActivity()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_notification_seen() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaNotificationSeen()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_direct_messages_setseen() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaDirectMessagesSetseen()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the api_friendica_direct_messages_search() function.
|
2019-07-28 17:40:42 +02:00
|
|
|
*
|
2018-04-09 21:23:41 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testApiFriendicaDirectMessagesSearch()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
}
|
|
|
|
}
|