use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Protocol;
use Friendica\DI;
+use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
+use Friendica\Security\BasicAuth;
use Friendica\Test\FixtureTest;
+use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
use Monolog\Handler\TestHandler;
}
/**
- * Test the api_login() function without any login.
+ * Test the BasicAuth::getCurrentUserID() function without any login.
*
* @runInSeparateProcess
* @preserveGlobalState disabled
public function testApiLoginWithoutLogin()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
- api_login($this->app);
+ BasicAuth::getCurrentUserID(true);
}
/**
- * Test the api_login() function with a bad login.
+ * Test the BasicAuth::getCurrentUserID() function with a bad login.
*
* @runInSeparateProcess
* @preserveGlobalState disabled
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
$_SERVER['PHP_AUTH_USER'] = 'user@server';
- api_login($this->app);
+ BasicAuth::getCurrentUserID(true);
}
/**
- * Test the api_login() function with oAuth.
+ * Test the BasicAuth::getCurrentUserID() function with oAuth.
*
* @return void
*/
}
/**
- * Test the api_login() function with authentication provided by an addon.
+ * Test the BasicAuth::getCurrentUserID() function with authentication provided by an addon.
*
* @return void
*/
}
/**
- * Test the api_login() function with a correct login.
+ * Test the BasicAuth::getCurrentUserID() function with a correct login.
*
* @runInSeparateProcess
* @preserveGlobalState disabled
{
$_SERVER['PHP_AUTH_USER'] = 'Test user';
$_SERVER['PHP_AUTH_PW'] = 'password';
- api_login($this->app);
+ BasicAuth::getCurrentUserID(true);
}
/**
- * Test the api_login() function with a remote user.
+ * Test the BasicAuth::getCurrentUserID() function with a remote user.
*
* @runInSeparateProcess
* @preserveGlobalState disabled
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
$_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
- api_login($this->app);
+ BasicAuth::getCurrentUserID(true);
}
/**
*/
public function testApiGetUser()
{
- $user = api_get_user($this->app);
+ $user = api_get_user();
self::assertSelfUser($user);
self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
self::assertEquals('6fdbe8', $user['profile_link_color']);
{
$pConfig = $this->dice->create(IManagePersonalConfigValues::class);
$pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
- $user = api_get_user($this->app);
+ $user = api_get_user();
self::assertSelfUser($user);
self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
self::assertEquals('6fdbe8', $user['profile_link_color']);
{
$pConfig = $this->dice->create(IManagePersonalConfigValues::class);
$pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
- $user = api_get_user($this->app);
+ $user = api_get_user();
self::assertSelfUser($user);
self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
self::assertEquals('6fdbe8', $user['profile_link_color']);
$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($this->app);
+ $user = api_get_user();
self::assertSelfUser($user);
self::assertEquals('123456', $user['profile_sidebar_fill_color']);
self::assertEquals('123456', $user['profile_link_color']);
$_SERVER['PHP_AUTH_USER'] = 'Test user';
$_SERVER['PHP_AUTH_PW'] = 'password';
$_SESSION['allow_api'] = false;
- self::assertFalse(api_get_user($this->app));
+ self::assertFalse(api_get_user());
}
/**
public function testApiGetUserWithGetId()
{
$_GET['user_id'] = $this->otherUser['id'];
- self::assertOtherUser(api_get_user($this->app));
+ self::assertOtherUser(api_get_user());
}
/**
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
$_GET['user_id'] = $this->wrongUserId;
- self::assertOtherUser(api_get_user($this->app));
+ self::assertOtherUser(api_get_user());
}
/**
public function testApiGetUserWithGetName()
{
$_GET['screen_name'] = $this->selfUser['nick'];
- self::assertSelfUser(api_get_user($this->app));
+ self::assertSelfUser(api_get_user());
}
/**
public function testApiGetUserWithGetUrl()
{
$_GET['profileurl'] = $this->selfUser['nurl'];
- self::assertSelfUser(api_get_user($this->app));
+ self::assertSelfUser(api_get_user());
}
/**
global $called_api;
$called_api = ['api_path'];
DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
- self::assertOtherUser(api_get_user($this->app));
+ self::assertOtherUser(api_get_user());
}
/**
{
global $called_api;
$called_api = ['api', 'api_path'];
- self::assertSelfUser(api_get_user($this->app));
+ self::assertSelfUser(api_get_user());
}
/**
*/
public function testApiGetUserWithCorrectUser()
{
- self::assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
+ self::assertOtherUser(api_get_user($this->otherUser['id']));
}
/**
public function testApiGetUserWithWrongUser()
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- self::assertOtherUser(api_get_user($this->app, $this->wrongUserId));
+ self::assertOtherUser(api_get_user($this->wrongUserId));
}
/**
*/
public function testApiGetUserWithZeroUser()
{
- self::assertSelfUser(api_get_user($this->app, 0));
+ self::assertSelfUser(api_get_user(0));
}
/**
}
/**
- * Test the api_walk_recursive() function.
+ * Test the Arrays::walkRecursive() function.
*
* @return void
*/
$array = ['item1'];
self::assertEquals(
$array,
- api_walk_recursive(
+ Arrays::walkRecursive(
$array,
function () {
// Should we test this with a callback that actually does something?
}
/**
- * Test the api_walk_recursive() function with an array.
+ * Test the Arrays::walkRecursive() function with an array.
*
* @return void
*/
$array = [['item1'], ['item2']];
self::assertEquals(
$array,
- api_walk_recursive(
+ Arrays::walkRecursive(
$array,
function () {
// Should we test this with a callback that actually does something?
}
/**
- * Test the api_reformat_xml() function.
+ * Test the BaseApi::reformatXML() function.
*
* @return void
*/
{
$item = true;
$key = '';
- self::assertTrue(api_reformat_xml($item, $key));
+ self::assertTrue(BaseApi::reformatXML($item, $key));
self::assertEquals('true', $item);
}
/**
- * Test the api_reformat_xml() function with a statusnet_api key.
+ * Test the BaseApi::reformatXML() function with a statusnet_api key.
*
* @return void
*/
{
$item = '';
$key = 'statusnet_api';
- self::assertTrue(api_reformat_xml($item, $key));
+ self::assertTrue(BaseApi::reformatXML($item, $key));
self::assertEquals('statusnet:api', $key);
}
/**
- * Test the api_reformat_xml() function with a friendica_api key.
+ * Test the BaseApi::reformatXML() function with a friendica_api key.
*
* @return void
*/
{
$item = '';
$key = 'friendica_api';
- self::assertTrue(api_reformat_xml($item, $key));
+ self::assertTrue(BaseApi::reformatXML($item, $key));
self::assertEquals('friendica:api', $key);
}
/**
- * Test the api_create_xml() function.
+ * Test the BaseApi::createXML() function.
*
* @return void
*/
'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <data>some_data</data>' . "\n" .
'</root_element>' . "\n",
- api_create_xml(['data' => ['some_data']], 'root_element')
+ BaseApi::createXML(['data' => ['some_data']], 'root_element')
);
}
/**
- * Test the api_create_xml() function without any XML namespace.
+ * Test the BaseApi::createXML() function without any XML namespace.
*
* @return void
*/
'<ok>' . "\n" .
' <data>some_data</data>' . "\n" .
'</ok>' . "\n",
- api_create_xml(['data' => ['some_data']], 'ok')
+ BaseApi::createXML(['data' => ['some_data']], 'ok')
);
}
/**
- * Test the api_format_data() function.
+ * Test the BaseApi::formatData() function.
*
* @return void
*/
public function testApiFormatData()
{
$data = ['some_data'];
- self::assertEquals($data, api_format_data('root_element', 'json', $data));
+ self::assertEquals($data, BaseApi::formatData('root_element', 'json', $data));
}
/**
- * Test the api_format_data() function with an XML result.
+ * Test the BaseApi::formatData() function with an XML result.
*
* @return void
*/
'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <data>some_data</data>' . "\n" .
'</root_element>' . "\n",
- api_format_data('root_element', 'xml', ['data' => ['some_data']])
+ BaseApi::formatData('root_element', 'xml', ['data' => ['some_data']])
);
}
*/
public function testApiHelpTest()
{
- $result = api_help_test('json');
- self::assertEquals(['ok' => 'ok'], $result);
+ // @todo How to test the new API?
+ // $result = \Friendica\Module\Api\Friendica\Help\Test::rawcontent(['extension' => 'json']);
+ // self::assertEquals(['ok' => 'ok'], $result);
}
/**
*/
public function testApiHelpTestWithXml()
{
- $result = api_help_test('xml');
- self::assertXml($result, 'ok');
+ // @todo How to test the new API?
+ // $result = api_help_test('xml');
+ // self::assertXml($result, 'ok');
}
/**
*/
public function testApiStatusnetVersion()
{
- $result = api_statusnet_version('json');
- self::assertEquals('0.9.7', $result['version']);
+ // @todo How to test the new API?
+ // $result = api_statusnet_version('json');
+ // self::assertEquals('0.9.7', $result['version']);
}
/**