1
1
Fork 0

Remove Phpunit/Dbunit

- Introduce own Yaml-to-SQL class
- Introduce new way of MySQL-DB-tests (per rollback)
- Remove dependency phpunit/dbunit
- Introduce new dev-dependency for YAML-ready (Symfony YAML reader)
This commit is contained in:
Philipp Holzer 2019-07-28 17:40:42 +02:00
commit b08ac3c0a7
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
9 changed files with 771 additions and 429 deletions

View file

@ -114,12 +114,12 @@
] ]
}, },
"require-dev": { "require-dev": {
"phpunit/dbunit": "^2.0",
"phpdocumentor/reflection-docblock": "^3.0.2", "phpdocumentor/reflection-docblock": "^3.0.2",
"phpunit/php-token-stream": "^1.4.2", "phpunit/php-token-stream": "^1.4.2",
"mikey179/vfsstream": "^1.6", "mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.2", "mockery/mockery": "^1.2",
"johnkary/phpunit-speedtrap": "1.1" "johnkary/phpunit-speedtrap": "1.1",
"symfony/yaml": "^3.0"
}, },
"scripts": { "scripts": {
"test": "phpunit" "test": "phpunit"

12
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "b9ea7162aa7ede630a2090c883e1174b", "content-hash": "ab69901def2561415a0de62fb86df9bf",
"packages": [ "packages": [
{ {
"name": "asika/simple-console", "name": "asika/simple-console",
@ -4267,16 +4267,16 @@
}, },
{ {
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "v3.4.16", "version": "v3.4.30",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/yaml.git", "url": "https://github.com/symfony/yaml.git",
"reference": "61973ecda60e9f3561e929e19c07d4878b960fc1" "reference": "051d045c684148060ebfc9affb7e3f5e0899d40b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/61973ecda60e9f3561e929e19c07d4878b960fc1", "url": "https://api.github.com/repos/symfony/yaml/zipball/051d045c684148060ebfc9affb7e3f5e0899d40b",
"reference": "61973ecda60e9f3561e929e19c07d4878b960fc1", "reference": "051d045c684148060ebfc9affb7e3f5e0899d40b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4322,7 +4322,7 @@
], ],
"description": "Symfony Yaml Component", "description": "Symfony Yaml Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-09-24T08:15:45+00:00" "time": "2019-07-24T13:01:31+00:00"
}, },
{ {
"name": "webmozart/assert", "name": "webmozart/assert",

View file

@ -6,41 +6,28 @@
namespace Friendica\Test; namespace Friendica\Test;
use Friendica\Test\Util\Database\StaticDatabase; use Friendica\Test\Util\Database\StaticDatabase;
use PHPUnit\DbUnit\DataSet\YamlDataSet;
use PHPUnit\DbUnit\TestCaseTrait;
use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
/** /**
* Abstract class used by tests that need a database. * Abstract class used by tests that need a database.
*/ */
abstract class DatabaseTest extends MockedTest abstract class DatabaseTest extends MockedTest
{ {
use TestCaseTrait; protected function setUp()
/**
* Get database connection.
*
* This function is executed before each test in order to get a database connection that can be used by tests.
* If no prior connection is available, it tries to create one using the USER, PASS and DB environment variables.
*
* If it could not connect to the database, the test is skipped.
*
* @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
* @see https://phpunit.de/manual/5.7/en/database.html
*/
protected function getConnection()
{ {
return $this->createDefaultDBConnection(StaticDatabase::getGlobConnection(), getenv('MYSQL_DATABASE')); parent::setUp();
StaticDatabase::statConnect($_SERVER);
// Rollbacks every DB usage (in case the test couldn't call tearDown)
StaticDatabase::statRollback();
// Start the first, outer transaction
StaticDatabase::getGlobConnection()->beginTransaction();
} }
/** protected function tearDown()
* Get dataset to populate the database with.
*
* @return YamlDataSet
* @see https://phtablepunit.de/manual/5.7/en/database.html
*/
protected function getDataSet()
{ {
return new YamlDataSet(__DIR__ . '/datasets/api.yml'); // Rollbacks every DB usage so we don't commit anything into the DB
StaticDatabase::statRollback();
parent::tearDown();
} }
} }

View file

@ -9,6 +9,8 @@ use PDOException;
/** /**
* Overrides the Friendica database class for re-using the connection * Overrides the Friendica database class for re-using the connection
* for different tests * for different tests
*
* Overrides functionality to enforce one transaction per call (for nested transactions)
*/ */
class StaticDatabase extends Database class StaticDatabase extends Database
{ {
@ -29,41 +31,7 @@ class StaticDatabase extends Database
} }
if (!isset(self::$staticConnection)) { if (!isset(self::$staticConnection)) {
self::statConnect($_SERVER);
$port = 0;
$serveraddr = trim($this->configCache->get('database', 'hostname'));
$serverdata = explode(':', $serveraddr);
$server = $serverdata[0];
if (count($serverdata) > 1) {
$port = trim($serverdata[1]);
}
$server = trim($server);
$user = trim($this->configCache->get('database', 'username'));
$pass = trim($this->configCache->get('database', 'password'));
$db = trim($this->configCache->get('database', 'database'));
$charset = trim($this->configCache->get('database', 'charset'));
if (!(strlen($server) && strlen($user))) {
return false;
}
$connect = "mysql:host=" . $server . ";dbname=" . $db;
if ($port > 0) {
$connect .= ";port=" . $port;
}
if ($charset) {
$connect .= ";charset=" . $charset;
}
try {
self::$staticConnection = @new ExtendedPDO($connect, $user, $pass);
self::$staticConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch (PDOException $e) {
/// @TODO At least log exception, don't ignore it!
}
} }
$this->driver = 'pdo'; $this->driver = 'pdo';
@ -80,7 +48,7 @@ class StaticDatabase extends Database
*/ */
public function transaction() public function transaction()
{ {
if (!$this->connection->inTransaction() && !$this->connection->beginTransaction()) { if (!$this->in_transaction && !$this->connection->beginTransaction()) {
return false; return false;
} }
@ -102,6 +70,64 @@ class StaticDatabase extends Database
return true; return true;
} }
/**
* Setup of the global, static connection
* Either through explicit calling or through implicit using the Database
*
* @param array $server $_SERVER variables
*/
public static function statConnect(array $server)
{
// Use environment variables for mysql if they are set beforehand
if (!empty($server['MYSQL_HOST'])
&& !empty($server['MYSQL_USERNAME'] || !empty($server['MYSQL_USER']))
&& $server['MYSQL_PASSWORD'] !== false
&& !empty($server['MYSQL_DATABASE']))
{
$db_host = $server['MYSQL_HOST'];
if (!empty($server['MYSQL_PORT'])) {
$db_host .= ':' . $server['MYSQL_PORT'];
}
if (!empty($server['MYSQL_USERNAME'])) {
$db_user = $server['MYSQL_USERNAME'];
} else {
$db_user = $server['MYSQL_USER'];
}
$db_pw = (string) $server['MYSQL_PASSWORD'];
$db_data = $server['MYSQL_DATABASE'];
}
$port = 0;
$serveraddr = trim($db_host);
$serverdata = explode(':', $serveraddr);
$server = $serverdata[0];
if (count($serverdata) > 1) {
$port = trim($serverdata[1]);
}
$server = trim($server);
$user = trim($db_user);
$pass = trim($db_pw);
$db = trim($db_data);
if (!(strlen($server) && strlen($user))) {
return;
}
$connect = "mysql:host=" . $server . ";dbname=" . $db;
if ($port > 0) {
$connect .= ";port=" . $port;
}
try {
self::$staticConnection = @new ExtendedPDO($connect, $user, $pass);
self::$staticConnection->setAttribute(PDO::ATTR_AUTOCOMMIT,0);
} catch (PDOException $e) {
/// @TODO At least log exception, don't ignore it!
}
}
/** /**
* @return ExtendedPDO The global, static connection * @return ExtendedPDO The global, static connection
*/ */

View file

@ -0,0 +1,50 @@
<?php
namespace Friendica\Test\Util\Database;
use Friendica\Database\Database;
use Symfony\Component\Yaml\Yaml;
/**
* Util class to load YAML files into the database
*/
class YamlDataSet
{
/**
* @var array
*/
private $tables = [];
public function __construct(string $yamlFile)
{
$this->addYamlFile($yamlFile);
}
public function addYamlFile(string $yamlFile)
{
$data = Yaml::parse(file_get_contents($yamlFile));
foreach ($data as $tableName => $rows) {
if (!isset($rows)) {
$rows = [];
}
if (!is_array($rows)) {
continue;
}
foreach ($rows as $key => $value) {
$this->tables[$tableName][$key] = $value;
}
}
}
public function load(Database $database)
{
foreach ($this->tables as $tableName => $rows) {
foreach ($rows as $row) {
$database->insert($tableName, $row);
}
}
}
}

View file

@ -80,7 +80,7 @@ item:
visible: 1 visible: 1
contact-id: 42 contact-id: 42
author-id: 42 author-id: 42
owner-id: 45 owner-id: 42
uid: 42 uid: 42
verb: http://activitystrea.ms/schema/1.0/post verb: http://activitystrea.ms/schema/1.0/post
unseen: 1 unseen: 1
@ -99,7 +99,7 @@ item:
visible: 1 visible: 1
contact-id: 42 contact-id: 42
author-id: 42 author-id: 42
owner-id: 45 owner-id: 42
uid: 42 uid: 42
verb: http://activitystrea.ms/schema/1.0/post verb: http://activitystrea.ms/schema/1.0/post
unseen: 0 unseen: 0

View file

@ -15,6 +15,7 @@ use Friendica\Core\System;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Test\Util\Database\StaticDatabase; use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\Database\YamlDataSet;
use Monolog\Handler\TestHandler; use Monolog\Handler\TestHandler;
require_once __DIR__ . '/../../include/api.php'; require_once __DIR__ . '/../../include/api.php';
@ -47,36 +48,42 @@ class ApiTest extends DatabaseTest
/** /**
* Create variables used by tests. * Create variables used by tests.
*/ */
public function setUp() protected function setUp()
{ {
StaticDatabase::statRollback(); parent::setUp();
$dice = new Dice(); $dice = new Dice();
$dice = $dice->addRules(include __DIR__ . '/../../static/dependencies.config.php'); $dice = $dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
$dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); $dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
BaseObject::setDependencyInjection($dice); BaseObject::setDependencyInjection($dice);
$this->app = BaseObject::getApp();
parent::setUp(); /** @var Database $dba */
$dba = $dice->create(Database::class);
// Load the API dataset for the whole API
$ymlTester = new YamlDataSet(__DIR__ . '/../datasets/api.yml');
$ymlTester->load($dba);
$this->app = BaseObject::getApp();
$this->app->argc = 1; $this->app->argc = 1;
$this->app->argv = ['home']; $this->app->argv = ['home'];
// User data that the test database is populated with // User data that the test database is populated with
$this->selfUser = [ $this->selfUser = [
'id' => 42, 'id' => 42,
'name' => 'Self contact', 'name' => 'Self contact',
'nick' => 'selfcontact', 'nick' => 'selfcontact',
'nurl' => 'http://localhost/profile/selfcontact' 'nurl' => 'http://localhost/profile/selfcontact'
]; ];
$this->friendUser = [ $this->friendUser = [
'id' => 44, 'id' => 44,
'name' => 'Friend contact', 'name' => 'Friend contact',
'nick' => 'friendcontact', 'nick' => 'friendcontact',
'nurl' => 'http://localhost/profile/friendcontact' 'nurl' => 'http://localhost/profile/friendcontact'
]; ];
$this->otherUser = [ $this->otherUser = [
'id' => 43, 'id' => 43,
'name' => 'othercontact', 'name' => 'othercontact',
'nick' => 'othercontact', 'nick' => 'othercontact',
'nurl' => 'http://localhost/profile/othercontact' 'nurl' => 'http://localhost/profile/othercontact'
@ -87,11 +94,15 @@ class ApiTest extends DatabaseTest
// Most API require login so we force the session // Most API require login so we force the session
$_SESSION = [ $_SESSION = [
'allow_api' => true, 'allow_api' => true,
'authenticated' => true, 'authenticated' => true,
'uid' => $this->selfUser['id'] 'uid' => $this->selfUser['id']
]; ];
$_POST = [];
$_GET = [];
$_SERVER = [];
Config::set('system', 'url', 'http://localhost'); Config::set('system', 'url', 'http://localhost');
Config::set('system', 'hostname', 'localhost'); Config::set('system', 'hostname', 'localhost');
Config::set('system', 'worker_dont_fork', true); Config::set('system', 'worker_dont_fork', true);
@ -104,14 +115,11 @@ class ApiTest extends DatabaseTest
Config::set('system', 'theme', 'system_theme'); Config::set('system', 'theme', 'system_theme');
} }
protected function tearDown()
{
StaticDatabase::statRollback();
}
/** /**
* Assert that an user array contains expected keys. * Assert that an user array contains expected keys.
*
* @param array $user User array * @param array $user User array
*
* @return void * @return void
*/ */
private function assertSelfUser(array $user) private function assertSelfUser(array $user)
@ -128,7 +136,9 @@ class ApiTest extends DatabaseTest
/** /**
* Assert that an user array contains expected keys. * Assert that an user array contains expected keys.
*
* @param array $user User array * @param array $user User array
*
* @return void * @return void
*/ */
private function assertOtherUser(array $user) private function assertOtherUser(array $user)
@ -143,7 +153,9 @@ class ApiTest extends DatabaseTest
/** /**
* Assert that a status array contains expected keys. * Assert that a status array contains expected keys.
*
* @param array $status Status array * @param array $status Status array
*
* @return void * @return void
*/ */
private function assertStatus(array $status) private function assertStatus(array $status)
@ -155,7 +167,9 @@ class ApiTest extends DatabaseTest
/** /**
* Assert that a list array contains expected keys. * Assert that a list array contains expected keys.
*
* @param array $list List array * @param array $list List array
*
* @return void * @return void
*/ */
private function assertList(array $list) private function assertList(array $list)
@ -169,19 +183,22 @@ class ApiTest extends DatabaseTest
/** /**
* Assert that the string is XML and contain the root element. * Assert that the string is XML and contain the root element.
*
* @param string $result XML string * @param string $result XML string
* @param string $root_element Root element name * @param string $root_element Root element name
*
* @return void * @return void
*/ */
private function assertXml($result, $root_element) private function assertXml($result, $root_element)
{ {
$this->assertStringStartsWith('<?xml version="1.0"?>', $result); $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
$this->assertContains('<'.$root_element, $result); $this->assertContains('<' . $root_element, $result);
// We could probably do more checks here. // We could probably do more checks here.
} }
/** /**
* Get the path to a temporary empty PNG image. * Get the path to a temporary empty PNG image.
*
* @return string Path * @return string Path
*/ */
private function getTempImage() private function getTempImage()
@ -190,7 +207,7 @@ class ApiTest extends DatabaseTest
file_put_contents( file_put_contents(
$tmpFile, $tmpFile,
base64_decode( base64_decode(
// Empty 1x1 px PNG image // Empty 1x1 px PNG image
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==' 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
) )
); );
@ -200,6 +217,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_user() function. * Test the api_user() function.
*
* @return void * @return void
*/ */
public function testApiUser() public function testApiUser()
@ -209,6 +227,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_user() function with an unallowed user. * Test the api_user() function with an unallowed user.
*
* @return void * @return void
*/ */
public function testApiUserWithUnallowedUser() public function testApiUserWithUnallowedUser()
@ -219,6 +238,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_source() function. * Test the api_source() function.
*
* @return void * @return void
*/ */
public function testApiSource() public function testApiSource()
@ -228,6 +248,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_source() function with a Twidere user agent. * Test the api_source() function with a Twidere user agent.
*
* @return void * @return void
*/ */
public function testApiSourceWithTwidere() public function testApiSourceWithTwidere()
@ -238,6 +259,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_source() function with a GET parameter. * Test the api_source() function with a GET parameter.
*
* @return void * @return void
*/ */
public function testApiSourceWithGet() public function testApiSourceWithGet()
@ -248,6 +270,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_date() function. * Test the api_date() function.
*
* @return void * @return void
*/ */
public function testApiDate() public function testApiDate()
@ -257,6 +280,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_register_func() function. * Test the api_register_func() function.
*
* @return void * @return void
*/ */
public function testApiRegisterFunc() public function testApiRegisterFunc()
@ -278,6 +302,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_login() function without any login. * Test the api_login() function without any login.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
* @expectedException Friendica\Network\HTTPException\UnauthorizedException * @expectedException Friendica\Network\HTTPException\UnauthorizedException
@ -289,6 +314,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_login() function with a bad login. * Test the api_login() function with a bad login.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
* @expectedException Friendica\Network\HTTPException\UnauthorizedException * @expectedException Friendica\Network\HTTPException\UnauthorizedException
@ -301,6 +327,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_login() function with oAuth. * Test the api_login() function with oAuth.
*
* @return void * @return void
*/ */
public function testApiLoginWithOauth() public function testApiLoginWithOauth()
@ -310,6 +337,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_login() function with authentication provided by an addon. * Test the api_login() function with authentication provided by an addon.
*
* @return void * @return void
*/ */
public function testApiLoginWithAddonAuth() public function testApiLoginWithAddonAuth()
@ -319,18 +347,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_login() function with a correct login. * Test the api_login() function with a correct login.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiLoginWithCorrectLogin() public function testApiLoginWithCorrectLogin()
{ {
$_SERVER['PHP_AUTH_USER'] = 'Test user'; $_SERVER['PHP_AUTH_USER'] = 'Test user';
$_SERVER['PHP_AUTH_PW'] = 'password'; $_SERVER['PHP_AUTH_PW'] = 'password';
api_login($this->app); api_login($this->app);
} }
/** /**
* Test the api_login() function with a remote user. * Test the api_login() function with a remote user.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
* @expectedException Friendica\Network\HTTPException\UnauthorizedException * @expectedException Friendica\Network\HTTPException\UnauthorizedException
@ -343,6 +373,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_check_method() function. * Test the api_check_method() function.
*
* @return void * @return void
*/ */
public function testApiCheckMethod() public function testApiCheckMethod()
@ -352,6 +383,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_check_method() function with a correct method. * Test the api_check_method() function with a correct method.
*
* @return void * @return void
*/ */
public function testApiCheckMethodWithCorrectMethod() public function testApiCheckMethodWithCorrectMethod()
@ -362,6 +394,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_check_method() function with a wildcard. * Test the api_check_method() function with a wildcard.
*
* @return void * @return void
*/ */
public function testApiCheckMethodWithWildcard() public function testApiCheckMethodWithWildcard()
@ -371,20 +404,21 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_call() function. * Test the api_call() function.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiCall() public function testApiCall()
{ {
global $API; global $API;
$API['api_path'] = [ $API['api_path'] = [
'method' => 'method', 'method' => 'method',
'func' => function () { 'func' => function () {
return ['data' => ['some_data']]; return ['data' => ['some_data']];
} }
]; ];
$_SERVER['REQUEST_METHOD'] = 'method'; $_SERVER['REQUEST_METHOD'] = 'method';
$_GET['callback'] = 'callback_name'; $_GET['callback'] = 'callback_name';
$this->app->query_string = 'api_path'; $this->app->query_string = 'api_path';
$this->assertEquals( $this->assertEquals(
@ -395,15 +429,16 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_call() function with the profiled enabled. * Test the api_call() function with the profiled enabled.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiCallWithProfiler() public function testApiCallWithProfiler()
{ {
global $API; global $API;
$API['api_path'] = [ $API['api_path'] = [
'method' => 'method', 'method' => 'method',
'func' => function () { 'func' => function () {
return ['data' => ['some_data']]; return ['data' => ['some_data']];
} }
]; ];
@ -411,11 +446,11 @@ class ApiTest extends DatabaseTest
Config::set('system', 'profiler', true); Config::set('system', 'profiler', true);
Config::set('rendertime', 'callstack', true); Config::set('rendertime', 'callstack', true);
$this->app->callstack = [ $this->app->callstack = [
'database' => ['some_function' => 200], 'database' => ['some_function' => 200],
'database_write' => ['some_function' => 200], 'database_write' => ['some_function' => 200],
'cache' => ['some_function' => 200], 'cache' => ['some_function' => 200],
'cache_write' => ['some_function' => 200], 'cache_write' => ['some_function' => 200],
'network' => ['some_function' => 200] 'network' => ['some_function' => 200]
]; ];
$this->app->query_string = 'api_path'; $this->app->query_string = 'api_path';
@ -427,15 +462,16 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_call() function without any result. * Test the api_call() function without any result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiCallWithNoResult() public function testApiCallWithNoResult()
{ {
global $API; global $API;
$API['api_path'] = [ $API['api_path'] = [
'method' => 'method', 'method' => 'method',
'func' => function () { 'func' => function () {
return false; return false;
} }
]; ];
@ -450,6 +486,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_call() function with an unimplemented API. * Test the api_call() function with an unimplemented API.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
@ -463,15 +500,16 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_call() function with a JSON result. * Test the api_call() function with a JSON result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiCallWithJson() public function testApiCallWithJson()
{ {
global $API; global $API;
$API['api_path'] = [ $API['api_path'] = [
'method' => 'method', 'method' => 'method',
'func' => function () { 'func' => function () {
return ['data' => ['some_data']]; return ['data' => ['some_data']];
} }
]; ];
@ -486,15 +524,16 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_call() function with an XML result. * Test the api_call() function with an XML result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiCallWithXml() public function testApiCallWithXml()
{ {
global $API; global $API;
$API['api_path'] = [ $API['api_path'] = [
'method' => 'method', 'method' => 'method',
'func' => function () { 'func' => function () {
return 'some_data'; return 'some_data';
} }
]; ];
@ -509,15 +548,16 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_call() function with an RSS result. * Test the api_call() function with an RSS result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiCallWithRss() public function testApiCallWithRss()
{ {
global $API; global $API;
$API['api_path'] = [ $API['api_path'] = [
'method' => 'method', 'method' => 'method',
'func' => function () { 'func' => function () {
return 'some_data'; return 'some_data';
} }
]; ];
@ -525,23 +565,24 @@ class ApiTest extends DatabaseTest
$this->app->query_string = 'api_path.rss'; $this->app->query_string = 'api_path.rss';
$this->assertEquals( $this->assertEquals(
'<?xml version="1.0" encoding="UTF-8"?>'."\n". '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
'some_data', 'some_data',
api_call($this->app) api_call($this->app)
); );
} }
/** /**
* Test the api_call() function with an Atom result. * Test the api_call() function with an Atom result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiCallWithAtom() public function testApiCallWithAtom()
{ {
global $API; global $API;
$API['api_path'] = [ $API['api_path'] = [
'method' => 'method', 'method' => 'method',
'func' => function () { 'func' => function () {
return 'some_data'; return 'some_data';
} }
]; ];
@ -549,14 +590,15 @@ class ApiTest extends DatabaseTest
$this->app->query_string = 'api_path.atom'; $this->app->query_string = 'api_path.atom';
$this->assertEquals( $this->assertEquals(
'<?xml version="1.0" encoding="UTF-8"?>'."\n". '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
'some_data', 'some_data',
api_call($this->app) api_call($this->app)
); );
} }
/** /**
* Test the api_call() function with an unallowed method. * Test the api_call() function with an unallowed method.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
@ -574,15 +616,16 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_call() function with an unauthorized user. * Test the api_call() function with an unauthorized user.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiCallWithWrongAuth() public function testApiCallWithWrongAuth()
{ {
global $API; global $API;
$API['api_path'] = [ $API['api_path'] = [
'method' => 'method', 'method' => 'method',
'auth' => true 'auth' => true
]; ];
$_SERVER['REQUEST_METHOD'] = 'method'; $_SERVER['REQUEST_METHOD'] = 'method';
$_SESSION['authenticated'] = false; $_SESSION['authenticated'] = false;
@ -596,6 +639,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_error() function with a JSON result. * Test the api_error() function with a JSON result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
@ -609,72 +653,76 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_error() function with an XML result. * Test the api_error() function with an XML result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiErrorWithXml() public function testApiErrorWithXml()
{ {
$this->assertEquals( $this->assertEquals(
'<?xml version="1.0"?>'."\n". '<?xml version="1.0"?>' . "\n" .
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '. '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" '. 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">'."\n". 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <error>error_message</error>'."\n". ' <error>error_message</error>' . "\n" .
' <code>200 OK</code>'."\n". ' <code>200 OK</code>' . "\n" .
' <request/>'."\n". ' <request/>' . "\n" .
'</status>'."\n", '</status>' . "\n",
api_error('xml', new HTTPException\OKException('error_message')) api_error('xml', new HTTPException\OKException('error_message'))
); );
} }
/** /**
* Test the api_error() function with an RSS result. * Test the api_error() function with an RSS result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiErrorWithRss() public function testApiErrorWithRss()
{ {
$this->assertEquals( $this->assertEquals(
'<?xml version="1.0"?>'."\n". '<?xml version="1.0"?>' . "\n" .
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '. '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" '. 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">'."\n". 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <error>error_message</error>'."\n". ' <error>error_message</error>' . "\n" .
' <code>200 OK</code>'."\n". ' <code>200 OK</code>' . "\n" .
' <request/>'."\n". ' <request/>' . "\n" .
'</status>'."\n", '</status>' . "\n",
api_error('rss', new HTTPException\OKException('error_message')) api_error('rss', new HTTPException\OKException('error_message'))
); );
} }
/** /**
* Test the api_error() function with an Atom result. * Test the api_error() function with an Atom result.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiErrorWithAtom() public function testApiErrorWithAtom()
{ {
$this->assertEquals( $this->assertEquals(
'<?xml version="1.0"?>'."\n". '<?xml version="1.0"?>' . "\n" .
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '. '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" '. 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">'."\n". 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <error>error_message</error>'."\n". ' <error>error_message</error>' . "\n" .
' <code>200 OK</code>'."\n". ' <code>200 OK</code>' . "\n" .
' <request/>'."\n". ' <request/>' . "\n" .
'</status>'."\n", '</status>' . "\n",
api_error('atom', new HTTPException\OKException('error_message')) api_error('atom', new HTTPException\OKException('error_message'))
); );
} }
/** /**
* Test the api_rss_extra() function. * Test the api_rss_extra() function.
*
* @return void * @return void
*/ */
public function testApiRssExtra() public function testApiRssExtra()
{ {
$user_info = ['url' => 'user_url', 'lang' => 'en']; $user_info = ['url' => 'user_url', 'lang' => 'en'];
$result = api_rss_extra($this->app, [], $user_info); $result = api_rss_extra($this->app, [], $user_info);
$this->assertEquals($user_info, $result['$user']); $this->assertEquals($user_info, $result['$user']);
$this->assertEquals($user_info['url'], $result['$rss']['alternate']); $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
$this->assertArrayHasKey('self', $result['$rss']); $this->assertArrayHasKey('self', $result['$rss']);
@ -687,8 +735,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_rss_extra() function without any user info. * Test the api_rss_extra() function without any user info.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiRssExtraWithoutUserInfo() public function testApiRssExtraWithoutUserInfo()
{ {
@ -705,6 +753,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_unique_id_to_nurl() function. * Test the api_unique_id_to_nurl() function.
*
* @return void * @return void
*/ */
public function testApiUniqueIdToNurl() public function testApiUniqueIdToNurl()
@ -714,6 +763,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_unique_id_to_nurl() function with a correct ID. * Test the api_unique_id_to_nurl() function with a correct ID.
*
* @return void * @return void
*/ */
public function testApiUniqueIdToNurlWithCorrectId() public function testApiUniqueIdToNurlWithCorrectId()
@ -723,8 +773,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function. * Test the api_get_user() function.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUser() public function testApiGetUser()
{ {
@ -737,8 +787,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with a Frio schema. * Test the api_get_user() function with a Frio schema.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithFrioSchema() public function testApiGetUserWithFrioSchema()
{ {
@ -752,8 +802,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with a custom Frio schema. * Test the api_get_user() function with a custom Frio schema.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithCustomFrioSchema() public function testApiGetUserWithCustomFrioSchema()
{ {
@ -770,8 +820,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with an empty Frio schema. * Test the api_get_user() function with an empty Frio schema.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithEmptyFrioSchema() public function testApiGetUserWithEmptyFrioSchema()
{ {
@ -785,21 +835,22 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with an user that is not allowed to use the API. * Test the api_get_user() function with an user that is not allowed to use the API.
*
* @return void * @return void
* @runInSeparateProcess * @runInSeparateProcess
*/ */
public function testApiGetUserWithoutApiUser() public function testApiGetUserWithoutApiUser()
{ {
$_SERVER['PHP_AUTH_USER'] = 'Test user'; $_SERVER['PHP_AUTH_USER'] = 'Test user';
$_SERVER['PHP_AUTH_PW'] = 'password'; $_SERVER['PHP_AUTH_PW'] = 'password';
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$this->assertFalse(api_get_user($this->app)); $this->assertFalse(api_get_user($this->app));
} }
/** /**
* Test the api_get_user() function with an user ID in a GET parameter. * Test the api_get_user() function with an user ID in a GET parameter.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithGetId() public function testApiGetUserWithGetId()
{ {
@ -809,8 +860,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with a wrong user ID in a GET parameter. * Test the api_get_user() function with a wrong user ID in a GET parameter.
*
* @return void * @return void
* @runInSeparateProcess
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
public function testApiGetUserWithWrongGetId() public function testApiGetUserWithWrongGetId()
@ -821,8 +872,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with an user name in a GET parameter. * Test the api_get_user() function with an user name in a GET parameter.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithGetName() public function testApiGetUserWithGetName()
{ {
@ -832,8 +883,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with a profile URL in a GET parameter. * Test the api_get_user() function with a profile URL in a GET parameter.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithGetUrl() public function testApiGetUserWithGetUrl()
{ {
@ -843,21 +894,21 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with an user ID in the API path. * Test the api_get_user() function with an user ID in the API path.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithNumericCalledApi() public function testApiGetUserWithNumericCalledApi()
{ {
global $called_api; global $called_api;
$called_api = ['api_path']; $called_api = ['api_path'];
$this->app->argv[1] = $this->otherUser['id'].'.json'; $this->app->argv[1] = $this->otherUser['id'] . '.json';
$this->assertOtherUser(api_get_user($this->app)); $this->assertOtherUser(api_get_user($this->app));
} }
/** /**
* Test the api_get_user() function with the $called_api global variable. * Test the api_get_user() function with the $called_api global variable.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithCalledApi() public function testApiGetUserWithCalledApi()
{ {
@ -868,8 +919,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with a valid user. * Test the api_get_user() function with a valid user.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithCorrectUser() public function testApiGetUserWithCorrectUser()
{ {
@ -878,8 +929,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with a wrong user ID. * Test the api_get_user() function with a wrong user ID.
*
* @return void * @return void
* @runInSeparateProcess
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
public function testApiGetUserWithWrongUser() public function testApiGetUserWithWrongUser()
@ -889,8 +940,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_user() function with a 0 user ID. * Test the api_get_user() function with a 0 user ID.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiGetUserWithZeroUser() public function testApiGetUserWithZeroUser()
{ {
@ -899,8 +950,8 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_item_get_user() function. * Test the api_item_get_user() function.
*
* @return void * @return void
* @runInSeparateProcess
*/ */
public function testApiItemGetUser() public function testApiItemGetUser()
{ {
@ -910,6 +961,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_item_get_user() function with a different item parent. * Test the api_item_get_user() function with a different item parent.
*
* @return void * @return void
*/ */
public function testApiItemGetUserWithDifferentParent() public function testApiItemGetUserWithDifferentParent()
@ -921,6 +973,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_walk_recursive() function. * Test the api_walk_recursive() function.
*
* @return void * @return void
*/ */
public function testApiWalkRecursive() public function testApiWalkRecursive()
@ -940,6 +993,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_walk_recursive() function with an array. * Test the api_walk_recursive() function with an array.
*
* @return void * @return void
*/ */
public function testApiWalkRecursiveWithArray() public function testApiWalkRecursiveWithArray()
@ -959,74 +1013,80 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_reformat_xml() function. * Test the api_reformat_xml() function.
*
* @return void * @return void
*/ */
public function testApiReformatXml() public function testApiReformatXml()
{ {
$item = true; $item = true;
$key = ''; $key = '';
$this->assertTrue(api_reformat_xml($item, $key)); $this->assertTrue(api_reformat_xml($item, $key));
$this->assertEquals('true', $item); $this->assertEquals('true', $item);
} }
/** /**
* Test the api_reformat_xml() function with a statusnet_api key. * Test the api_reformat_xml() function with a statusnet_api key.
*
* @return void * @return void
*/ */
public function testApiReformatXmlWithStatusnetKey() public function testApiReformatXmlWithStatusnetKey()
{ {
$item = ''; $item = '';
$key = 'statusnet_api'; $key = 'statusnet_api';
$this->assertTrue(api_reformat_xml($item, $key)); $this->assertTrue(api_reformat_xml($item, $key));
$this->assertEquals('statusnet:api', $key); $this->assertEquals('statusnet:api', $key);
} }
/** /**
* Test the api_reformat_xml() function with a friendica_api key. * Test the api_reformat_xml() function with a friendica_api key.
*
* @return void * @return void
*/ */
public function testApiReformatXmlWithFriendicaKey() public function testApiReformatXmlWithFriendicaKey()
{ {
$item = ''; $item = '';
$key = 'friendica_api'; $key = 'friendica_api';
$this->assertTrue(api_reformat_xml($item, $key)); $this->assertTrue(api_reformat_xml($item, $key));
$this->assertEquals('friendica:api', $key); $this->assertEquals('friendica:api', $key);
} }
/** /**
* Test the api_create_xml() function. * Test the api_create_xml() function.
*
* @return void * @return void
*/ */
public function testApiCreateXml() public function testApiCreateXml()
{ {
$this->assertEquals( $this->assertEquals(
'<?xml version="1.0"?>'."\n". '<?xml version="1.0"?>' . "\n" .
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '. '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" '. 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">'."\n". 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <data>some_data</data>'."\n". ' <data>some_data</data>' . "\n" .
'</root_element>'."\n", '</root_element>' . "\n",
api_create_xml(['data' => ['some_data']], 'root_element') api_create_xml(['data' => ['some_data']], 'root_element')
); );
} }
/** /**
* Test the api_create_xml() function without any XML namespace. * Test the api_create_xml() function without any XML namespace.
*
* @return void * @return void
*/ */
public function testApiCreateXmlWithoutNamespaces() public function testApiCreateXmlWithoutNamespaces()
{ {
$this->assertEquals( $this->assertEquals(
'<?xml version="1.0"?>'."\n". '<?xml version="1.0"?>' . "\n" .
'<ok>'."\n". '<ok>' . "\n" .
' <data>some_data</data>'."\n". ' <data>some_data</data>' . "\n" .
'</ok>'."\n", '</ok>' . "\n",
api_create_xml(['data' => ['some_data']], 'ok') api_create_xml(['data' => ['some_data']], 'ok')
); );
} }
/** /**
* Test the api_format_data() function. * Test the api_format_data() function.
*
* @return void * @return void
*/ */
public function testApiFormatData() public function testApiFormatData()
@ -1037,23 +1097,25 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_data() function with an XML result. * Test the api_format_data() function with an XML result.
*
* @return void * @return void
*/ */
public function testApiFormatDataWithXml() public function testApiFormatDataWithXml()
{ {
$this->assertEquals( $this->assertEquals(
'<?xml version="1.0"?>'."\n". '<?xml version="1.0"?>' . "\n" .
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '. '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" '. 'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">'."\n". 'xmlns:georss="http://www.georss.org/georss">' . "\n" .
' <data>some_data</data>'."\n". ' <data>some_data</data>' . "\n" .
'</root_element>'."\n", '</root_element>' . "\n",
api_format_data('root_element', 'xml', ['data' => ['some_data']]) api_format_data('root_element', 'xml', ['data' => ['some_data']])
); );
} }
/** /**
* Test the api_account_verify_credentials() function. * Test the api_account_verify_credentials() function.
*
* @return void * @return void
*/ */
public function testApiAccountVerifyCredentials() public function testApiAccountVerifyCredentials()
@ -1063,6 +1125,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_account_verify_credentials() function without an authenticated user. * Test the api_account_verify_credentials() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -1074,6 +1137,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the requestdata() function. * Test the requestdata() function.
*
* @return void * @return void
*/ */
public function testRequestdata() public function testRequestdata()
@ -1083,6 +1147,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the requestdata() function with a POST parameter. * Test the requestdata() function with a POST parameter.
*
* @return void * @return void
*/ */
public function testRequestdataWithPost() public function testRequestdataWithPost()
@ -1093,6 +1158,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the requestdata() function with a GET parameter. * Test the requestdata() function with a GET parameter.
*
* @return void * @return void
*/ */
public function testRequestdataWithGet() public function testRequestdataWithGet()
@ -1103,21 +1169,22 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_mediap() function. * Test the api_statuses_mediap() function.
*
* @return void * @return void
*/ */
public function testApiStatusesMediap() public function testApiStatusesMediap()
{ {
$this->app->argc = 2; $this->app->argc = 2;
$_FILES = [ $_FILES = [
'media' => [ 'media' => [
'id' => 666, 'id' => 666,
'size' => 666, 'size' => 666,
'width' => 666, 'width' => 666,
'height' => 666, 'height' => 666,
'tmp_name' => $this->getTempImage(), 'tmp_name' => $this->getTempImage(),
'name' => 'spacer.png', 'name' => 'spacer.png',
'type' => 'image/png' 'type' => 'image/png'
] ]
]; ];
$_GET['status'] = '<b>Status content</b>'; $_GET['status'] = '<b>Status content</b>';
@ -1128,6 +1195,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_mediap() function without an authenticated user. * Test the api_statuses_mediap() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -1139,23 +1207,24 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_update() function. * Test the api_statuses_update() function.
*
* @return void * @return void
*/ */
public function testApiStatusesUpdate() public function testApiStatusesUpdate()
{ {
$_GET['status'] = 'Status content #friendica'; $_GET['status'] = 'Status content #friendica';
$_GET['in_reply_to_status_id'] = -1; $_GET['in_reply_to_status_id'] = -1;
$_GET['lat'] = 48; $_GET['lat'] = 48;
$_GET['long'] = 7; $_GET['long'] = 7;
$_FILES = [ $_FILES = [
'media' => [ 'media' => [
'id' => 666, 'id' => 666,
'size' => 666, 'size' => 666,
'width' => 666, 'width' => 666,
'height' => 666, 'height' => 666,
'tmp_name' => $this->getTempImage(), 'tmp_name' => $this->getTempImage(),
'name' => 'spacer.png', 'name' => 'spacer.png',
'type' => 'image/png' 'type' => 'image/png'
] ]
]; ];
@ -1165,6 +1234,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_update() function with an HTML status. * Test the api_statuses_update() function with an HTML status.
*
* @return void * @return void
*/ */
public function testApiStatusesUpdateWithHtml() public function testApiStatusesUpdateWithHtml()
@ -1177,6 +1247,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_update() function without an authenticated user. * Test the api_statuses_update() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -1188,6 +1259,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_update() function with a parent status. * Test the api_statuses_update() function with a parent status.
*
* @return void * @return void
*/ */
public function testApiStatusesUpdateWithParent() public function testApiStatusesUpdateWithParent()
@ -1197,6 +1269,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_update() function with a media_ids parameter. * Test the api_statuses_update() function with a media_ids parameter.
*
* @return void * @return void
*/ */
public function testApiStatusesUpdateWithMediaIds() public function testApiStatusesUpdateWithMediaIds()
@ -1206,6 +1279,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_update() function with the throttle limit reached. * Test the api_statuses_update() function with the throttle limit reached.
*
* @return void * @return void
*/ */
public function testApiStatusesUpdateWithDayThrottleReached() public function testApiStatusesUpdateWithDayThrottleReached()
@ -1215,6 +1289,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_media_upload() function. * Test the api_media_upload() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1225,6 +1300,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_media_upload() function without an authenticated user. * Test the api_media_upload() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -1236,6 +1312,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_media_upload() function with an invalid uploaded media. * Test the api_media_upload() function with an invalid uploaded media.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\InternalServerErrorException * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
*/ */
@ -1243,7 +1320,7 @@ class ApiTest extends DatabaseTest
{ {
$_FILES = [ $_FILES = [
'media' => [ 'media' => [
'id' => 666, 'id' => 666,
'tmp_name' => 'tmp_name' 'tmp_name' => 'tmp_name'
] ]
]; ];
@ -1252,22 +1329,23 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_media_upload() function with an valid uploaded media. * Test the api_media_upload() function with an valid uploaded media.
*
* @return void * @return void
*/ */
public function testApiMediaUploadWithValidMedia() public function testApiMediaUploadWithValidMedia()
{ {
$_FILES = [ $_FILES = [
'media' => [ 'media' => [
'id' => 666, 'id' => 666,
'size' => 666, 'size' => 666,
'width' => 666, 'width' => 666,
'height' => 666, 'height' => 666,
'tmp_name' => $this->getTempImage(), 'tmp_name' => $this->getTempImage(),
'name' => 'spacer.png', 'name' => 'spacer.png',
'type' => 'image/png' 'type' => 'image/png'
] ]
]; ];
$app = \get_app(); $app = \get_app();
$app->argc = 2; $app->argc = 2;
$result = api_media_upload(); $result = api_media_upload();
@ -1307,6 +1385,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_users_show() function. * Test the api_users_show() function.
*
* @return void * @return void
*/ */
public function testApiUsersShow() public function testApiUsersShow()
@ -1323,6 +1402,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_users_show() function with an XML result. * Test the api_users_show() function with an XML result.
*
* @return void * @return void
*/ */
public function testApiUsersShowWithXml() public function testApiUsersShowWithXml()
@ -1333,28 +1413,31 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_users_search() function. * Test the api_users_search() function.
*
* @return void * @return void
*/ */
public function testApiUsersSearch() public function testApiUsersSearch()
{ {
$_GET['q'] = 'othercontact'; $_GET['q'] = 'othercontact';
$result = api_users_search('json'); $result = api_users_search('json');
$this->assertOtherUser($result['users'][0]); $this->assertOtherUser($result['users'][0]);
} }
/** /**
* Test the api_users_search() function with an XML result. * Test the api_users_search() function with an XML result.
*
* @return void * @return void
*/ */
public function testApiUsersSearchWithXml() public function testApiUsersSearchWithXml()
{ {
$_GET['q'] = 'othercontact'; $_GET['q'] = 'othercontact';
$result = api_users_search('xml'); $result = api_users_search('xml');
$this->assertXml($result, 'users'); $this->assertXml($result, 'users');
} }
/** /**
* Test the api_users_search() function without a GET q parameter. * Test the api_users_search() function without a GET q parameter.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1365,6 +1448,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_users_lookup() function. * Test the api_users_lookup() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\NotFoundException * @expectedException Friendica\Network\HTTPException\NotFoundException
*/ */
@ -1375,24 +1459,26 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_users_lookup() function with an user ID. * Test the api_users_lookup() function with an user ID.
*
* @return void * @return void
*/ */
public function testApiUsersLookupWithUserId() public function testApiUsersLookupWithUserId()
{ {
$_REQUEST['user_id'] = $this->otherUser['id']; $_REQUEST['user_id'] = $this->otherUser['id'];
$result = api_users_lookup('json'); $result = api_users_lookup('json');
$this->assertOtherUser($result['users'][0]); $this->assertOtherUser($result['users'][0]);
} }
/** /**
* Test the api_search() function. * Test the api_search() function.
*
* @return void * @return void
*/ */
public function testApiSearch() public function testApiSearch()
{ {
$_REQUEST['q'] = 'reply'; $_REQUEST['q'] = 'reply';
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
$this->assertContains('reply', $status['text'], null, true); $this->assertContains('reply', $status['text'], null, true);
@ -1401,13 +1487,14 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_search() function a count parameter. * Test the api_search() function a count parameter.
*
* @return void * @return void
*/ */
public function testApiSearchWithCount() public function testApiSearchWithCount()
{ {
$_REQUEST['q'] = 'reply'; $_REQUEST['q'] = 'reply';
$_REQUEST['count'] = 20; $_REQUEST['count'] = 20;
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
$this->assertContains('reply', $status['text'], null, true); $this->assertContains('reply', $status['text'], null, true);
@ -1416,13 +1503,14 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_search() function with an rpp parameter. * Test the api_search() function with an rpp parameter.
*
* @return void * @return void
*/ */
public function testApiSearchWithRpp() public function testApiSearchWithRpp()
{ {
$_REQUEST['q'] = 'reply'; $_REQUEST['q'] = 'reply';
$_REQUEST['rpp'] = 20; $_REQUEST['rpp'] = 20;
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
$this->assertContains('reply', $status['text'], null, true); $this->assertContains('reply', $status['text'], null, true);
@ -1431,12 +1519,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_search() function with an q parameter contains hashtag. * Test the api_search() function with an q parameter contains hashtag.
*
* @return void * @return void
*/ */
public function testApiSearchWithHashtag() public function testApiSearchWithHashtag()
{ {
$_REQUEST['q'] = '%23friendica'; $_REQUEST['q'] = '%23friendica';
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
$this->assertContains('#friendica', $status['text'], null, true); $this->assertContains('#friendica', $status['text'], null, true);
@ -1445,14 +1534,15 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_search() function with an exclude_replies parameter. * Test the api_search() function with an exclude_replies parameter.
*
* @return void * @return void
*/ */
public function testApiSearchWithExcludeReplies() public function testApiSearchWithExcludeReplies()
{ {
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true; $_REQUEST['exclude_replies'] = true;
$_REQUEST['q'] = 'friendica'; $_REQUEST['q'] = 'friendica';
$result = api_search('json'); $result = api_search('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
} }
@ -1460,18 +1550,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_search() function without an authenticated user. * Test the api_search() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiSearchWithUnallowedUser() public function testApiSearchWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_search('json'); api_search('json');
} }
/** /**
* Test the api_search() function without any GET query parameter. * Test the api_search() function without any GET query parameter.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1482,14 +1574,15 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_home_timeline() function. * Test the api_statuses_home_timeline() function.
*
* @return void * @return void
*/ */
public function testApiStatusesHomeTimeline() public function testApiStatusesHomeTimeline()
{ {
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true; $_REQUEST['exclude_replies'] = true;
$_REQUEST['conversation_id'] = 1; $_REQUEST['conversation_id'] = 1;
$result = api_statuses_home_timeline('json'); $result = api_statuses_home_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1498,12 +1591,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_home_timeline() function with a negative page parameter. * Test the api_statuses_home_timeline() function with a negative page parameter.
*
* @return void * @return void
*/ */
public function testApiStatusesHomeTimelineWithNegativePage() public function testApiStatusesHomeTimelineWithNegativePage()
{ {
$_REQUEST['page'] = -2; $_REQUEST['page'] = -2;
$result = api_statuses_home_timeline('json'); $result = api_statuses_home_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1512,18 +1606,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_home_timeline() with an unallowed user. * Test the api_statuses_home_timeline() with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiStatusesHomeTimelineWithUnallowedUser() public function testApiStatusesHomeTimelineWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_statuses_home_timeline('json'); api_statuses_home_timeline('json');
} }
/** /**
* Test the api_statuses_home_timeline() function with an RSS result. * Test the api_statuses_home_timeline() function with an RSS result.
*
* @return void * @return void
*/ */
public function testApiStatusesHomeTimelineWithRss() public function testApiStatusesHomeTimelineWithRss()
@ -1534,13 +1630,14 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_public_timeline() function. * Test the api_statuses_public_timeline() function.
*
* @return void * @return void
*/ */
public function testApiStatusesPublicTimeline() public function testApiStatusesPublicTimeline()
{ {
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$_REQUEST['conversation_id'] = 1; $_REQUEST['conversation_id'] = 1;
$result = api_statuses_public_timeline('json'); $result = api_statuses_public_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1549,13 +1646,14 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_public_timeline() function with the exclude_replies parameter. * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
*
* @return void * @return void
*/ */
public function testApiStatusesPublicTimelineWithExcludeReplies() public function testApiStatusesPublicTimelineWithExcludeReplies()
{ {
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true; $_REQUEST['exclude_replies'] = true;
$result = api_statuses_public_timeline('json'); $result = api_statuses_public_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1564,12 +1662,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_public_timeline() function with a negative page parameter. * Test the api_statuses_public_timeline() function with a negative page parameter.
*
* @return void * @return void
*/ */
public function testApiStatusesPublicTimelineWithNegativePage() public function testApiStatusesPublicTimelineWithNegativePage()
{ {
$_REQUEST['page'] = -2; $_REQUEST['page'] = -2;
$result = api_statuses_public_timeline('json'); $result = api_statuses_public_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1578,18 +1677,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_public_timeline() function with an unallowed user. * Test the api_statuses_public_timeline() function with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiStatusesPublicTimelineWithUnallowedUser() public function testApiStatusesPublicTimelineWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_statuses_public_timeline('json'); api_statuses_public_timeline('json');
} }
/** /**
* Test the api_statuses_public_timeline() function with an RSS result. * Test the api_statuses_public_timeline() function with an RSS result.
*
* @return void * @return void
*/ */
public function testApiStatusesPublicTimelineWithRss() public function testApiStatusesPublicTimelineWithRss()
@ -1600,12 +1701,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_networkpublic_timeline() function. * Test the api_statuses_networkpublic_timeline() function.
*
* @return void * @return void
*/ */
public function testApiStatusesNetworkpublicTimeline() public function testApiStatusesNetworkpublicTimeline()
{ {
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$result = api_statuses_networkpublic_timeline('json'); $result = api_statuses_networkpublic_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1614,12 +1716,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_networkpublic_timeline() function with a negative page parameter. * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
*
* @return void * @return void
*/ */
public function testApiStatusesNetworkpublicTimelineWithNegativePage() public function testApiStatusesNetworkpublicTimelineWithNegativePage()
{ {
$_REQUEST['page'] = -2; $_REQUEST['page'] = -2;
$result = api_statuses_networkpublic_timeline('json'); $result = api_statuses_networkpublic_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1628,18 +1731,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_networkpublic_timeline() function with an unallowed user. * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiStatusesNetworkpublicTimelineWithUnallowedUser() public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_statuses_networkpublic_timeline('json'); api_statuses_networkpublic_timeline('json');
} }
/** /**
* Test the api_statuses_networkpublic_timeline() function with an RSS result. * Test the api_statuses_networkpublic_timeline() function with an RSS result.
*
* @return void * @return void
*/ */
public function testApiStatusesNetworkpublicTimelineWithRss() public function testApiStatusesNetworkpublicTimelineWithRss()
@ -1650,6 +1755,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_show() function. * Test the api_statuses_show() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1660,24 +1766,26 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_show() function with an ID. * Test the api_statuses_show() function with an ID.
*
* @return void * @return void
*/ */
public function testApiStatusesShowWithId() public function testApiStatusesShowWithId()
{ {
$this->app->argv[3] = 1; $this->app->argv[3] = 1;
$result = api_statuses_show('json'); $result = api_statuses_show('json');
$this->assertStatus($result['status']); $this->assertStatus($result['status']);
} }
/** /**
* Test the api_statuses_show() function with the conversation parameter. * Test the api_statuses_show() function with the conversation parameter.
*
* @return void * @return void
*/ */
public function testApiStatusesShowWithConversation() public function testApiStatusesShowWithConversation()
{ {
$this->app->argv[3] = 1; $this->app->argv[3] = 1;
$_REQUEST['conversation'] = 1; $_REQUEST['conversation'] = 1;
$result = api_statuses_show('json'); $result = api_statuses_show('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1686,18 +1794,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_show() function with an unallowed user. * Test the api_statuses_show() function with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiStatusesShowWithUnallowedUser() public function testApiStatusesShowWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_statuses_show('json'); api_statuses_show('json');
} }
/** /**
* Test the api_conversation_show() function. * Test the api_conversation_show() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1708,14 +1818,15 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_conversation_show() function with an ID. * Test the api_conversation_show() function with an ID.
*
* @return void * @return void
*/ */
public function testApiConversationShowWithId() public function testApiConversationShowWithId()
{ {
$this->app->argv[3] = 1; $this->app->argv[3] = 1;
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$_REQUEST['page'] = -2; $_REQUEST['page'] = -2;
$result = api_conversation_show('json'); $result = api_conversation_show('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1724,18 +1835,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_conversation_show() function with an unallowed user. * Test the api_conversation_show() function with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiConversationShowWithUnallowedUser() public function testApiConversationShowWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_conversation_show('json'); api_conversation_show('json');
} }
/** /**
* Test the api_statuses_repeat() function. * Test the api_statuses_repeat() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -1746,6 +1859,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_repeat() function without an authenticated user. * Test the api_statuses_repeat() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -1757,22 +1871,24 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_repeat() function with an ID. * Test the api_statuses_repeat() function with an ID.
*
* @return void * @return void
*/ */
public function testApiStatusesRepeatWithId() public function testApiStatusesRepeatWithId()
{ {
$this->app->argv[3] = 1; $this->app->argv[3] = 1;
$result = api_statuses_repeat('json'); $result = api_statuses_repeat('json');
$this->assertStatus($result['status']); $this->assertStatus($result['status']);
// Also test with a shared status // Also test with a shared status
$this->app->argv[3] = 5; $this->app->argv[3] = 5;
$result = api_statuses_repeat('json'); $result = api_statuses_repeat('json');
$this->assertStatus($result['status']); $this->assertStatus($result['status']);
} }
/** /**
* Test the api_statuses_destroy() function. * Test the api_statuses_destroy() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1783,6 +1899,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_destroy() function without an authenticated user. * Test the api_statuses_destroy() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -1794,53 +1911,58 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_destroy() function with an ID. * Test the api_statuses_destroy() function with an ID.
*
* @return void * @return void
*/ */
public function testApiStatusesDestroyWithId() public function testApiStatusesDestroyWithId()
{ {
$this->app->argv[3] = 1; $this->app->argv[3] = 1;
$result = api_statuses_destroy('json'); $result = api_statuses_destroy('json');
$this->assertStatus($result['status']); $this->assertStatus($result['status']);
} }
/** /**
* Test the api_statuses_mentions() function. * Test the api_statuses_mentions() function.
*
* @return void * @return void
*/ */
public function testApiStatusesMentions() public function testApiStatusesMentions()
{ {
$this->app->user = ['nickname' => $this->selfUser['nick']]; $this->app->user = ['nickname' => $this->selfUser['nick']];
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$result = api_statuses_mentions('json'); $result = api_statuses_mentions('json');
$this->assertEmpty($result['status']); $this->assertEmpty($result['status']);
// We should test with mentions in the database. // We should test with mentions in the database.
} }
/** /**
* Test the api_statuses_mentions() function with a negative page parameter. * Test the api_statuses_mentions() function with a negative page parameter.
*
* @return void * @return void
*/ */
public function testApiStatusesMentionsWithNegativePage() public function testApiStatusesMentionsWithNegativePage()
{ {
$_REQUEST['page'] = -2; $_REQUEST['page'] = -2;
$result = api_statuses_mentions('json'); $result = api_statuses_mentions('json');
$this->assertEmpty($result['status']); $this->assertEmpty($result['status']);
} }
/** /**
* Test the api_statuses_mentions() function with an unallowed user. * Test the api_statuses_mentions() function with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiStatusesMentionsWithUnallowedUser() public function testApiStatusesMentionsWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_statuses_mentions('json'); api_statuses_mentions('json');
} }
/** /**
* Test the api_statuses_mentions() function with an RSS result. * Test the api_statuses_mentions() function with an RSS result.
*
* @return void * @return void
*/ */
public function testApiStatusesMentionsWithRss() public function testApiStatusesMentionsWithRss()
@ -1851,14 +1973,15 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_user_timeline() function. * Test the api_statuses_user_timeline() function.
*
* @return void * @return void
*/ */
public function testApiStatusesUserTimeline() public function testApiStatusesUserTimeline()
{ {
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true; $_REQUEST['exclude_replies'] = true;
$_REQUEST['conversation_id'] = 1; $_REQUEST['conversation_id'] = 1;
$result = api_statuses_user_timeline('json'); $result = api_statuses_user_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1867,12 +1990,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_user_timeline() function with a negative page parameter. * Test the api_statuses_user_timeline() function with a negative page parameter.
*
* @return void * @return void
*/ */
public function testApiStatusesUserTimelineWithNegativePage() public function testApiStatusesUserTimelineWithNegativePage()
{ {
$_REQUEST['page'] = -2; $_REQUEST['page'] = -2;
$result = api_statuses_user_timeline('json'); $result = api_statuses_user_timeline('json');
$this->assertNotEmpty($result['status']); $this->assertNotEmpty($result['status']);
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
@ -1881,6 +2005,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_user_timeline() function with an RSS result. * Test the api_statuses_user_timeline() function with an RSS result.
*
* @return void * @return void
*/ */
public function testApiStatusesUserTimelineWithRss() public function testApiStatusesUserTimelineWithRss()
@ -1891,18 +2016,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_user_timeline() function with an unallowed user. * Test the api_statuses_user_timeline() function with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiStatusesUserTimelineWithUnallowedUser() public function testApiStatusesUserTimelineWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_statuses_user_timeline('json'); api_statuses_user_timeline('json');
} }
/** /**
* Test the api_favorites_create_destroy() function. * Test the api_favorites_create_destroy() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1915,6 +2042,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_favorites_create_destroy() function with an invalid ID. * Test the api_favorites_create_destroy() function with an invalid ID.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1927,6 +2055,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_favorites_create_destroy() function with an invalid action. * Test the api_favorites_create_destroy() function with an invalid action.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -1934,71 +2063,76 @@ class ApiTest extends DatabaseTest
{ {
$this->app->argv = ['api', '1.1', 'favorites', 'change.json']; $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
$this->app->argc = count($this->app->argv); $this->app->argc = count($this->app->argv);
$_REQUEST['id'] = 1; $_REQUEST['id'] = 1;
api_favorites_create_destroy('json'); api_favorites_create_destroy('json');
} }
/** /**
* Test the api_favorites_create_destroy() function with the create action. * Test the api_favorites_create_destroy() function with the create action.
*
* @return void * @return void
*/ */
public function testApiFavoritesCreateDestroyWithCreateAction() public function testApiFavoritesCreateDestroyWithCreateAction()
{ {
$this->app->argv = ['api', '1.1', 'favorites', 'create.json']; $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
$this->app->argc = count($this->app->argv); $this->app->argc = count($this->app->argv);
$_REQUEST['id'] = 3; $_REQUEST['id'] = 3;
$result = api_favorites_create_destroy('json'); $result = api_favorites_create_destroy('json');
$this->assertStatus($result['status']); $this->assertStatus($result['status']);
} }
/** /**
* Test the api_favorites_create_destroy() function with the create action and an RSS result. * Test the api_favorites_create_destroy() function with the create action and an RSS result.
*
* @return void * @return void
*/ */
public function testApiFavoritesCreateDestroyWithCreateActionAndRss() public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
{ {
$this->app->argv = ['api', '1.1', 'favorites', 'create.rss']; $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
$this->app->argc = count($this->app->argv); $this->app->argc = count($this->app->argv);
$_REQUEST['id'] = 3; $_REQUEST['id'] = 3;
$result = api_favorites_create_destroy('rss'); $result = api_favorites_create_destroy('rss');
$this->assertXml($result, 'status'); $this->assertXml($result, 'status');
} }
/** /**
* Test the api_favorites_create_destroy() function with the destroy action. * Test the api_favorites_create_destroy() function with the destroy action.
*
* @return void * @return void
*/ */
public function testApiFavoritesCreateDestroyWithDestroyAction() public function testApiFavoritesCreateDestroyWithDestroyAction()
{ {
$this->app->argv = ['api', '1.1', 'favorites', 'destroy.json']; $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
$this->app->argc = count($this->app->argv); $this->app->argc = count($this->app->argv);
$_REQUEST['id'] = 3; $_REQUEST['id'] = 3;
$result = api_favorites_create_destroy('json'); $result = api_favorites_create_destroy('json');
$this->assertStatus($result['status']); $this->assertStatus($result['status']);
} }
/** /**
* Test the api_favorites_create_destroy() function without an authenticated user. * Test the api_favorites_create_destroy() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser() public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
{ {
$this->app->argv = ['api', '1.1', 'favorites', 'create.json']; $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
$this->app->argc = count($this->app->argv); $this->app->argc = count($this->app->argv);
$_SESSION['authenticated'] = false; $_SESSION['authenticated'] = false;
api_favorites_create_destroy('json'); api_favorites_create_destroy('json');
} }
/** /**
* Test the api_favorites() function. * Test the api_favorites() function.
*
* @return void * @return void
*/ */
public function testApiFavorites() public function testApiFavorites()
{ {
$_REQUEST['page'] = -1; $_REQUEST['page'] = -1;
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$result = api_favorites('json'); $result = api_favorites('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
} }
@ -2006,6 +2140,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_favorites() function with an RSS result. * Test the api_favorites() function with an RSS result.
*
* @return void * @return void
*/ */
public function testApiFavoritesWithRss() public function testApiFavoritesWithRss()
@ -2016,18 +2151,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_favorites() function with an unallowed user. * Test the api_favorites() function with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiFavoritesWithUnallowedUser() public function testApiFavoritesWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_favorites('json'); api_favorites('json');
} }
/** /**
* Test the api_format_messages() function. * Test the api_format_messages() function.
*
* @return void * @return void
*/ */
public function testApiFormatMessages() public function testApiFormatMessages()
@ -2037,7 +2174,7 @@ class ApiTest extends DatabaseTest
['id' => 2, 'screen_name' => 'recipient_name'], ['id' => 2, 'screen_name' => 'recipient_name'],
['id' => 3, 'screen_name' => 'sender_name'] ['id' => 3, 'screen_name' => 'sender_name']
); );
$this->assertEquals('item_title'."\n".'item_body', $result['text']); $this->assertEquals('item_title' . "\n" . 'item_body', $result['text']);
$this->assertEquals(1, $result['id']); $this->assertEquals(1, $result['id']);
$this->assertEquals(2, $result['recipient_id']); $this->assertEquals(2, $result['recipient_id']);
$this->assertEquals(3, $result['sender_id']); $this->assertEquals(3, $result['sender_id']);
@ -2047,12 +2184,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_messages() function with HTML. * Test the api_format_messages() function with HTML.
*
* @return void * @return void
*/ */
public function testApiFormatMessagesWithHtmlText() public function testApiFormatMessagesWithHtmlText()
{ {
$_GET['getText'] = 'html'; $_GET['getText'] = 'html';
$result = api_format_messages( $result = api_format_messages(
['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'], ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
['id' => 2, 'screen_name' => 'recipient_name'], ['id' => 2, 'screen_name' => 'recipient_name'],
['id' => 3, 'screen_name' => 'sender_name'] ['id' => 3, 'screen_name' => 'sender_name']
@ -2063,12 +2201,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_messages() function with plain text. * Test the api_format_messages() function with plain text.
*
* @return void * @return void
*/ */
public function testApiFormatMessagesWithPlainText() public function testApiFormatMessagesWithPlainText()
{ {
$_GET['getText'] = 'plain'; $_GET['getText'] = 'plain';
$result = api_format_messages( $result = api_format_messages(
['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'], ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
['id' => 2, 'screen_name' => 'recipient_name'], ['id' => 2, 'screen_name' => 'recipient_name'],
['id' => 3, 'screen_name' => 'sender_name'] ['id' => 3, 'screen_name' => 'sender_name']
@ -2079,12 +2218,13 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_messages() function with the getUserObjects GET parameter set to false. * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
*
* @return void * @return void
*/ */
public function testApiFormatMessagesWithoutUserObjects() public function testApiFormatMessagesWithoutUserObjects()
{ {
$_GET['getUserObjects'] = 'false'; $_GET['getUserObjects'] = 'false';
$result = api_format_messages( $result = api_format_messages(
['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'], ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
['id' => 2, 'screen_name' => 'recipient_name'], ['id' => 2, 'screen_name' => 'recipient_name'],
['id' => 3, 'screen_name' => 'sender_name'] ['id' => 3, 'screen_name' => 'sender_name']
@ -2095,6 +2235,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_convert_item() function. * Test the api_convert_item() function.
*
* @return void * @return void
*/ */
public function testApiConvertItem() public function testApiConvertItem()
@ -2102,32 +2243,32 @@ class ApiTest extends DatabaseTest
$result = api_convert_item( $result = api_convert_item(
[ [
'network' => 'feed', 'network' => 'feed',
'title' => 'item_title', 'title' => 'item_title',
// We need a long string to test that it is correctly cut // We need a long string to test that it is correctly cut
'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '. 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '. 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
'officiis pariatur doloremque nemo culpa aut quidem qui dolore '. 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
'laudantium atque commodi alias voluptatem non possimus aperiam '. 'laudantium atque commodi alias voluptatem non possimus aperiam ' .
'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '. 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
'repellendus quibusdam et et inventore mollitia rerum sit autem '. 'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
'pariatur maiores ipsum accusantium perferendis vel sit possimus '. 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
'veritatis nihil distinctio qui eum repellat officia illum quos '. 'veritatis nihil distinctio qui eum repellat officia illum quos ' .
'impedit quam iste esse unde qui suscipit aut facilis ut inventore '. 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
'omnis exercitationem quo magnam consequatur maxime aut illum '. 'omnis exercitationem quo magnam consequatur maxime aut illum ' .
'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '. 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
'temporibus corporis ratione blanditiis perspiciatis impedit '. 'temporibus corporis ratione blanditiis perspiciatis impedit ' .
'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '. 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
'sunt consequatur inventore dolor officiis pariatur doloremque '. 'sunt consequatur inventore dolor officiis pariatur doloremque ' .
'nemo culpa aut quidem qui dolore laudantium atque commodi alias '. 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
'voluptatem non possimus aperiam ipsum rerum consequuntur aut '. 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
'amet fugit quia aliquid praesentium repellendus quibusdam et et '. 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '. 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
'perferendis vel sit possimus veritatis nihil distinctio qui eum '. 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
'repellat officia illum quos impedit quam iste esse unde qui '. 'repellat officia illum quos impedit quam iste esse unde qui ' .
'suscipit aut facilis ut inventore omnis exercitationem quo magnam '. 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
'consequatur maxime aut illum soluta quaerat natus unde aspernatur '. 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
'et sed beatae nihil ullam temporibus corporis ratione blanditiis', 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
'plink' => 'item_plink' 'plink' => 'item_plink'
] ]
); );
$this->assertStringStartsWith('item_title', $result['text']); $this->assertStringStartsWith('item_title', $result['text']);
@ -2136,6 +2277,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_convert_item() function with an empty item body. * Test the api_convert_item() function with an empty item body.
*
* @return void * @return void
*/ */
public function testApiConvertItemWithoutBody() public function testApiConvertItemWithoutBody()
@ -2143,9 +2285,9 @@ class ApiTest extends DatabaseTest
$result = api_convert_item( $result = api_convert_item(
[ [
'network' => 'feed', 'network' => 'feed',
'title' => 'item_title', 'title' => 'item_title',
'body' => '', 'body' => '',
'plink' => 'item_plink' 'plink' => 'item_plink'
] ]
); );
$this->assertEquals('item_title', $result['text']); $this->assertEquals('item_title', $result['text']);
@ -2154,6 +2296,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_convert_item() function with the title in the body. * Test the api_convert_item() function with the title in the body.
*
* @return void * @return void
*/ */
public function testApiConvertItemWithTitleInBody() public function testApiConvertItemWithTitleInBody()
@ -2161,7 +2304,7 @@ class ApiTest extends DatabaseTest
$result = api_convert_item( $result = api_convert_item(
[ [
'title' => 'item_title', 'title' => 'item_title',
'body' => 'item_title item_body' 'body' => 'item_title item_body'
] ]
); );
$this->assertEquals('item_title item_body', $result['text']); $this->assertEquals('item_title item_body', $result['text']);
@ -2170,6 +2313,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_attachments() function. * Test the api_get_attachments() function.
*
* @return void * @return void
*/ */
public function testApiGetAttachments() public function testApiGetAttachments()
@ -2180,6 +2324,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_attachments() function with an img tag. * Test the api_get_attachments() function with an img tag.
*
* @return void * @return void
*/ */
public function testApiGetAttachmentsWithImage() public function testApiGetAttachmentsWithImage()
@ -2190,17 +2335,19 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_attachments() function with an img tag and an AndStatus user agent. * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
*
* @return void * @return void
*/ */
public function testApiGetAttachmentsWithImageAndAndStatus() public function testApiGetAttachmentsWithImageAndAndStatus()
{ {
$_SERVER['HTTP_USER_AGENT'] = 'AndStatus'; $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
$body = '[img]http://via.placeholder.com/1x1.png[/img]'; $body = '[img]http://via.placeholder.com/1x1.png[/img]';
$this->assertInternalType('array', api_get_attachments($body)); $this->assertInternalType('array', api_get_attachments($body));
} }
/** /**
* Test the api_get_entitities() function. * Test the api_get_entitities() function.
*
* @return void * @return void
*/ */
public function testApiGetEntitities() public function testApiGetEntitities()
@ -2211,13 +2358,14 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_entitities() function with the include_entities parameter. * Test the api_get_entitities() function with the include_entities parameter.
*
* @return void * @return void
*/ */
public function testApiGetEntititiesWithIncludeEntities() public function testApiGetEntititiesWithIncludeEntities()
{ {
$_REQUEST['include_entities'] = 'true'; $_REQUEST['include_entities'] = 'true';
$text = 'text'; $text = 'text';
$result = api_get_entitities($text, 'bbcode'); $result = api_get_entitities($text, 'bbcode');
$this->assertInternalType('array', $result['hashtags']); $this->assertInternalType('array', $result['hashtags']);
$this->assertInternalType('array', $result['symbols']); $this->assertInternalType('array', $result['symbols']);
$this->assertInternalType('array', $result['urls']); $this->assertInternalType('array', $result['urls']);
@ -2226,6 +2374,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_items_embeded_images() function. * Test the api_format_items_embeded_images() function.
*
* @return void * @return void
*/ */
public function testApiFormatItemsEmbededImages() public function testApiFormatItemsEmbededImages()
@ -2238,6 +2387,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_contactlink_to_array() function. * Test the api_contactlink_to_array() function.
*
* @return void * @return void
*/ */
public function testApiContactlinkToArray() public function testApiContactlinkToArray()
@ -2245,7 +2395,7 @@ class ApiTest extends DatabaseTest
$this->assertEquals( $this->assertEquals(
[ [
'name' => 'text', 'name' => 'text',
'url' => '', 'url' => '',
], ],
api_contactlink_to_array('text') api_contactlink_to_array('text')
); );
@ -2253,6 +2403,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_contactlink_to_array() function with an URL. * Test the api_contactlink_to_array() function with an URL.
*
* @return void * @return void
*/ */
public function testApiContactlinkToArrayWithUrl() public function testApiContactlinkToArrayWithUrl()
@ -2260,7 +2411,7 @@ class ApiTest extends DatabaseTest
$this->assertEquals( $this->assertEquals(
[ [
'name' => ['link_text'], 'name' => ['link_text'],
'url' => ['url'], 'url' => ['url'],
], ],
api_contactlink_to_array('text <a href="url">link_text</a>') api_contactlink_to_array('text <a href="url">link_text</a>')
); );
@ -2268,11 +2419,12 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_items_activities() function. * Test the api_format_items_activities() function.
*
* @return void * @return void
*/ */
public function testApiFormatItemsActivities() public function testApiFormatItemsActivities()
{ {
$item = ['uid' => 0, 'uri' => '']; $item = ['uid' => 0, 'uri' => ''];
$result = api_format_items_activities($item); $result = api_format_items_activities($item);
$this->assertArrayHasKey('like', $result); $this->assertArrayHasKey('like', $result);
$this->assertArrayHasKey('dislike', $result); $this->assertArrayHasKey('dislike', $result);
@ -2283,11 +2435,12 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_items_activities() function with an XML result. * Test the api_format_items_activities() function with an XML result.
*
* @return void * @return void
*/ */
public function testApiFormatItemsActivitiesWithXml() public function testApiFormatItemsActivitiesWithXml()
{ {
$item = ['uid' => 0, 'uri' => '']; $item = ['uid' => 0, 'uri' => ''];
$result = api_format_items_activities($item, 'xml'); $result = api_format_items_activities($item, 'xml');
$this->assertArrayHasKey('friendica:like', $result); $this->assertArrayHasKey('friendica:like', $result);
$this->assertArrayHasKey('friendica:dislike', $result); $this->assertArrayHasKey('friendica:dislike', $result);
@ -2298,94 +2451,95 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_items_profiles() function. * Test the api_format_items_profiles() function.
*
* @return void * @return void
*/ */
public function testApiFormatItemsProfiles() public function testApiFormatItemsProfiles()
{ {
$profile_row = [ $profile_row = [
'id' => 'profile_id', 'id' => 'profile_id',
'profile-name' => 'profile_name', 'profile-name' => 'profile_name',
'is-default' => true, 'is-default' => true,
'hide-friends' => true, 'hide-friends' => true,
'photo' => 'profile_photo', 'photo' => 'profile_photo',
'thumb' => 'profile_thumb', 'thumb' => 'profile_thumb',
'publish' => true, 'publish' => true,
'net-publish' => true, 'net-publish' => true,
'pdesc' => 'description', 'pdesc' => 'description',
'dob' => 'date_of_birth', 'dob' => 'date_of_birth',
'address' => 'address', 'address' => 'address',
'locality' => 'city', 'locality' => 'city',
'region' => 'region', 'region' => 'region',
'postal-code' => 'postal_code', 'postal-code' => 'postal_code',
'country-name' => 'country', 'country-name' => 'country',
'hometown' => 'hometown', 'hometown' => 'hometown',
'gender' => 'gender', 'gender' => 'gender',
'marital' => 'marital', 'marital' => 'marital',
'with' => 'marital_with', 'with' => 'marital_with',
'howlong' => 'marital_since', 'howlong' => 'marital_since',
'sexual' => 'sexual', 'sexual' => 'sexual',
'politic' => 'politic', 'politic' => 'politic',
'religion' => 'religion', 'religion' => 'religion',
'pub_keywords' => 'public_keywords', 'pub_keywords' => 'public_keywords',
'prv_keywords' => 'private_keywords', 'prv_keywords' => 'private_keywords',
'likes' => 'likes', 'likes' => 'likes',
'dislikes' => 'dislikes', 'dislikes' => 'dislikes',
'about' => 'about', 'about' => 'about',
'music' => 'music', 'music' => 'music',
'book' => 'book', 'book' => 'book',
'tv' => 'tv', 'tv' => 'tv',
'film' => 'film', 'film' => 'film',
'interest' => 'interest', 'interest' => 'interest',
'romance' => 'romance', 'romance' => 'romance',
'work' => 'work', 'work' => 'work',
'education' => 'education', 'education' => 'education',
'contact' => 'social_networks', 'contact' => 'social_networks',
'homepage' => 'homepage' 'homepage' => 'homepage'
]; ];
$result = api_format_items_profiles($profile_row); $result = api_format_items_profiles($profile_row);
$this->assertEquals( $this->assertEquals(
[ [
'profile_id' => 'profile_id', 'profile_id' => 'profile_id',
'profile_name' => 'profile_name', 'profile_name' => 'profile_name',
'is_default' => true, 'is_default' => true,
'hide_friends' => true, 'hide_friends' => true,
'profile_photo' => 'profile_photo', 'profile_photo' => 'profile_photo',
'profile_thumb' => 'profile_thumb', 'profile_thumb' => 'profile_thumb',
'publish' => true, 'publish' => true,
'net_publish' => true, 'net_publish' => true,
'description' => 'description', 'description' => 'description',
'date_of_birth' => 'date_of_birth', 'date_of_birth' => 'date_of_birth',
'address' => 'address', 'address' => 'address',
'city' => 'city', 'city' => 'city',
'region' => 'region', 'region' => 'region',
'postal_code' => 'postal_code', 'postal_code' => 'postal_code',
'country' => 'country', 'country' => 'country',
'hometown' => 'hometown', 'hometown' => 'hometown',
'gender' => 'gender', 'gender' => 'gender',
'marital' => 'marital', 'marital' => 'marital',
'marital_with' => 'marital_with', 'marital_with' => 'marital_with',
'marital_since' => 'marital_since', 'marital_since' => 'marital_since',
'sexual' => 'sexual', 'sexual' => 'sexual',
'politic' => 'politic', 'politic' => 'politic',
'religion' => 'religion', 'religion' => 'religion',
'public_keywords' => 'public_keywords', 'public_keywords' => 'public_keywords',
'private_keywords' => 'private_keywords', 'private_keywords' => 'private_keywords',
'likes' => 'likes', 'likes' => 'likes',
'dislikes' => 'dislikes', 'dislikes' => 'dislikes',
'about' => 'about', 'about' => 'about',
'music' => 'music', 'music' => 'music',
'book' => 'book', 'book' => 'book',
'tv' => 'tv', 'tv' => 'tv',
'film' => 'film', 'film' => 'film',
'interest' => 'interest', 'interest' => 'interest',
'romance' => 'romance', 'romance' => 'romance',
'work' => 'work', 'work' => 'work',
'education' => 'education', 'education' => 'education',
'social_networks' => 'social_networks', 'social_networks' => 'social_networks',
'homepage' => 'homepage', 'homepage' => 'homepage',
'users' => null 'users' => null
], ],
$result $result
); );
@ -2393,21 +2547,22 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_items() function. * Test the api_format_items() function.
*
* @return void * @return void
*/ */
public function testApiFormatItems() public function testApiFormatItems()
{ {
$items = [ $items = [
[ [
'item_network' => 'item_network', 'item_network' => 'item_network',
'source' => 'web', 'source' => 'web',
'coord' => '5 7', 'coord' => '5 7',
'body' => '', 'body' => '',
'verb' => '', 'verb' => '',
'author-id' => 43, 'author-id' => 43,
'author-network' => Protocol::DFRN, 'author-network' => Protocol::DFRN,
'author-link' => 'http://localhost/profile/othercontact', 'author-link' => 'http://localhost/profile/othercontact',
'plink' => '', 'plink' => '',
] ]
]; ];
$result = api_format_items($items, ['id' => 0], true); $result = api_format_items($items, ['id' => 0], true);
@ -2418,19 +2573,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_items() function with an XML result. * Test the api_format_items() function with an XML result.
*
* @return void * @return void
*/ */
public function testApiFormatItemsWithXml() public function testApiFormatItemsWithXml()
{ {
$items = [ $items = [
[ [
'coord' => '5 7', 'coord' => '5 7',
'body' => '', 'body' => '',
'verb' => '', 'verb' => '',
'author-id' => 43, 'author-id' => 43,
'author-network' => Protocol::DFRN, 'author-network' => Protocol::DFRN,
'author-link' => 'http://localhost/profile/othercontact', 'author-link' => 'http://localhost/profile/othercontact',
'plink' => '', 'plink' => '',
] ]
]; ];
$result = api_format_items($items, ['id' => 0], true, 'xml'); $result = api_format_items($items, ['id' => 0], true, 'xml');
@ -2441,6 +2597,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_items() function. * Test the api_format_items() function.
*
* @return void * @return void
*/ */
public function testApiAccountRateLimitStatus() public function testApiAccountRateLimitStatus()
@ -2453,6 +2610,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_format_items() function with an XML result. * Test the api_format_items() function with an XML result.
*
* @return void * @return void
*/ */
public function testApiAccountRateLimitStatusWithXml() public function testApiAccountRateLimitStatusWithXml()
@ -2463,6 +2621,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_help_test() function. * Test the api_help_test() function.
*
* @return void * @return void
*/ */
public function testApiHelpTest() public function testApiHelpTest()
@ -2473,6 +2632,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_help_test() function with an XML result. * Test the api_help_test() function with an XML result.
*
* @return void * @return void
*/ */
public function testApiHelpTestWithXml() public function testApiHelpTestWithXml()
@ -2483,6 +2643,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_list() function. * Test the api_lists_list() function.
*
* @return void * @return void
*/ */
public function testApiListsList() public function testApiListsList()
@ -2493,6 +2654,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_ownerships() function. * Test the api_lists_ownerships() function.
*
* @return void * @return void
*/ */
public function testApiListsOwnerships() public function testApiListsOwnerships()
@ -2505,6 +2667,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_ownerships() function without an authenticated user. * Test the api_lists_ownerships() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -2516,6 +2679,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_statuses() function. * Test the api_lists_statuses() function.
*
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
* @return void * @return void
*/ */
@ -2526,14 +2690,15 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_statuses() function with a list ID. * Test the api_lists_statuses() function with a list ID.
*
* @return void * @return void
*/ */
public function testApiListsStatusesWithListId() public function testApiListsStatusesWithListId()
{ {
$_REQUEST['list_id'] = 1; $_REQUEST['list_id'] = 1;
$_REQUEST['page'] = -1; $_REQUEST['page'] = -1;
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$result = api_lists_statuses('json'); $result = api_lists_statuses('json');
foreach ($result['status'] as $status) { foreach ($result['status'] as $status) {
$this->assertStatus($status); $this->assertStatus($status);
} }
@ -2541,40 +2706,44 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_statuses() function with a list ID and a RSS result. * Test the api_lists_statuses() function with a list ID and a RSS result.
*
* @return void * @return void
*/ */
public function testApiListsStatusesWithListIdAndRss() public function testApiListsStatusesWithListIdAndRss()
{ {
$_REQUEST['list_id'] = 1; $_REQUEST['list_id'] = 1;
$result = api_lists_statuses('rss'); $result = api_lists_statuses('rss');
$this->assertXml($result, 'statuses'); $this->assertXml($result, 'statuses');
} }
/** /**
* Test the api_lists_statuses() function with an unallowed user. * Test the api_lists_statuses() function with an unallowed user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiListsStatusesWithUnallowedUser() public function testApiListsStatusesWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_lists_statuses('json'); api_lists_statuses('json');
} }
/** /**
* Test the api_statuses_f() function. * Test the api_statuses_f() function.
*
* @return void * @return void
*/ */
public function testApiStatusesFWithFriends() public function testApiStatusesFWithFriends()
{ {
$_GET['page'] = -1; $_GET['page'] = -1;
$result = api_statuses_f('friends'); $result = api_statuses_f('friends');
$this->assertArrayHasKey('user', $result); $this->assertArrayHasKey('user', $result);
} }
/** /**
* Test the api_statuses_f() function. * Test the api_statuses_f() function.
*
* @return void * @return void
*/ */
public function testApiStatusesFWithFollowers() public function testApiStatusesFWithFollowers()
@ -2585,6 +2754,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_f() function. * Test the api_statuses_f() function.
*
* @return void * @return void
*/ */
public function testApiStatusesFWithBlocks() public function testApiStatusesFWithBlocks()
@ -2595,6 +2765,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_f() function. * Test the api_statuses_f() function.
*
* @return void * @return void
*/ */
public function testApiStatusesFWithIncoming() public function testApiStatusesFWithIncoming()
@ -2605,6 +2776,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_f() function an undefined cursor GET variable. * Test the api_statuses_f() function an undefined cursor GET variable.
*
* @return void * @return void
*/ */
public function testApiStatusesFWithUndefinedCursor() public function testApiStatusesFWithUndefinedCursor()
@ -2615,6 +2787,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_friends() function. * Test the api_statuses_friends() function.
*
* @return void * @return void
*/ */
public function testApiStatusesFriends() public function testApiStatusesFriends()
@ -2625,6 +2798,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_friends() function an undefined cursor GET variable. * Test the api_statuses_friends() function an undefined cursor GET variable.
*
* @return void * @return void
*/ */
public function testApiStatusesFriendsWithUndefinedCursor() public function testApiStatusesFriendsWithUndefinedCursor()
@ -2635,6 +2809,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_followers() function. * Test the api_statuses_followers() function.
*
* @return void * @return void
*/ */
public function testApiStatusesFollowers() public function testApiStatusesFollowers()
@ -2645,6 +2820,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statuses_followers() function an undefined cursor GET variable. * Test the api_statuses_followers() function an undefined cursor GET variable.
*
* @return void * @return void
*/ */
public function testApiStatusesFollowersWithUndefinedCursor() public function testApiStatusesFollowersWithUndefinedCursor()
@ -2655,6 +2831,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_blocks_list() function. * Test the api_blocks_list() function.
*
* @return void * @return void
*/ */
public function testApiBlocksList() public function testApiBlocksList()
@ -2665,6 +2842,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_blocks_list() function an undefined cursor GET variable. * Test the api_blocks_list() function an undefined cursor GET variable.
*
* @return void * @return void
*/ */
public function testApiBlocksListWithUndefinedCursor() public function testApiBlocksListWithUndefinedCursor()
@ -2675,6 +2853,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendships_incoming() function. * Test the api_friendships_incoming() function.
*
* @return void * @return void
*/ */
public function testApiFriendshipsIncoming() public function testApiFriendshipsIncoming()
@ -2685,6 +2864,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendships_incoming() function an undefined cursor GET variable. * Test the api_friendships_incoming() function an undefined cursor GET variable.
*
* @return void * @return void
*/ */
public function testApiFriendshipsIncomingWithUndefinedCursor() public function testApiFriendshipsIncomingWithUndefinedCursor()
@ -2695,6 +2875,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statusnet_config() function. * Test the api_statusnet_config() function.
*
* @return void * @return void
*/ */
public function testApiStatusnetConfig() public function testApiStatusnetConfig()
@ -2714,6 +2895,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_statusnet_version() function. * Test the api_statusnet_version() function.
*
* @return void * @return void
*/ */
public function testApiStatusnetVersion() public function testApiStatusnetVersion()
@ -2724,6 +2906,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_ff_ids() function. * Test the api_ff_ids() function.
*
* @return void * @return void
*/ */
public function testApiFfIds() public function testApiFfIds()
@ -2734,6 +2917,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_ff_ids() function with a result. * Test the api_ff_ids() function with a result.
*
* @return void * @return void
*/ */
public function testApiFfIdsWithResult() public function testApiFfIdsWithResult()
@ -2743,6 +2927,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_ff_ids() function without an authenticated user. * Test the api_ff_ids() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -2754,6 +2939,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friends_ids() function. * Test the api_friends_ids() function.
*
* @return void * @return void
*/ */
public function testApiFriendsIds() public function testApiFriendsIds()
@ -2764,6 +2950,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_followers_ids() function. * Test the api_followers_ids() function.
*
* @return void * @return void
*/ */
public function testApiFollowersIds() public function testApiFollowersIds()
@ -2774,6 +2961,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_new() function. * Test the api_direct_messages_new() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesNew() public function testApiDirectMessagesNew()
@ -2784,6 +2972,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_new() function without an authenticated user. * Test the api_direct_messages_new() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -2795,26 +2984,27 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_new() function with an user ID. * Test the api_direct_messages_new() function with an user ID.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesNewWithUserId() public function testApiDirectMessagesNewWithUserId()
{ {
$_POST['text'] = 'message_text'; $_POST['text'] = 'message_text';
$_POST['user_id'] = $this->otherUser['id']; $_POST['user_id'] = $this->otherUser['id'];
$result = api_direct_messages_new('json'); $result = api_direct_messages_new('json');
$this->assertEquals(['direct_message' => ['error' => -1]], $result); $this->assertEquals(['direct_message' => ['error' => -1]], $result);
} }
/** /**
* Test the api_direct_messages_new() function with a screen name. * Test the api_direct_messages_new() function with a screen name.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesNewWithScreenName() public function testApiDirectMessagesNewWithScreenName()
{ {
$_POST['text'] = 'message_text'; $_POST['text'] = 'message_text';
$_POST['screen_name'] = $this->friendUser['nick']; $_POST['screen_name'] = $this->friendUser['nick'];
$result = api_direct_messages_new('json'); $result = api_direct_messages_new('json');
$this->assertEquals(1, $result['direct_message']['id']);
$this->assertContains('message_text', $result['direct_message']['text']); $this->assertContains('message_text', $result['direct_message']['text']);
$this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']); $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
$this->assertEquals(1, $result['direct_message']['friendica_seen']); $this->assertEquals(1, $result['direct_message']['friendica_seen']);
@ -2822,15 +3012,15 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_new() function with a title. * Test the api_direct_messages_new() function with a title.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesNewWithTitle() public function testApiDirectMessagesNewWithTitle()
{ {
$_POST['text'] = 'message_text'; $_POST['text'] = 'message_text';
$_POST['screen_name'] = $this->friendUser['nick']; $_POST['screen_name'] = $this->friendUser['nick'];
$_REQUEST['title'] = 'message_title'; $_REQUEST['title'] = 'message_title';
$result = api_direct_messages_new('json'); $result = api_direct_messages_new('json');
$this->assertEquals(1, $result['direct_message']['id']);
$this->assertContains('message_text', $result['direct_message']['text']); $this->assertContains('message_text', $result['direct_message']['text']);
$this->assertContains('message_title', $result['direct_message']['text']); $this->assertContains('message_title', $result['direct_message']['text']);
$this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']); $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
@ -2839,18 +3029,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_new() function with an RSS result. * Test the api_direct_messages_new() function with an RSS result.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesNewWithRss() public function testApiDirectMessagesNewWithRss()
{ {
$_POST['text'] = 'message_text'; $_POST['text'] = 'message_text';
$_POST['screen_name'] = $this->friendUser['nick']; $_POST['screen_name'] = $this->friendUser['nick'];
$result = api_direct_messages_new('rss'); $result = api_direct_messages_new('rss');
$this->assertXml($result, 'direct-messages'); $this->assertXml($result, 'direct-messages');
} }
/** /**
* Test the api_direct_messages_destroy() function. * Test the api_direct_messages_destroy() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -2861,16 +3053,17 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_destroy() function with the friendica_verbose GET param. * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesDestroyWithVerbose() public function testApiDirectMessagesDestroyWithVerbose()
{ {
$_GET['friendica_verbose'] = 'true'; $_GET['friendica_verbose'] = 'true';
$result = api_direct_messages_destroy('json'); $result = api_direct_messages_destroy('json');
$this->assertEquals( $this->assertEquals(
[ [
'$result' => [ '$result' => [
'result' => 'error', 'result' => 'error',
'message' => 'message id or parenturi not specified' 'message' => 'message id or parenturi not specified'
] ]
], ],
@ -2880,6 +3073,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_destroy() function without an authenticated user. * Test the api_direct_messages_destroy() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -2891,6 +3085,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_destroy() function with a non-zero ID. * Test the api_direct_messages_destroy() function with a non-zero ID.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -2902,18 +3097,19 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param. * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesDestroyWithIdAndVerbose() public function testApiDirectMessagesDestroyWithIdAndVerbose()
{ {
$_REQUEST['id'] = 1; $_REQUEST['id'] = 1;
$_REQUEST['friendica_parenturi'] = 'parent_uri'; $_REQUEST['friendica_parenturi'] = 'parent_uri';
$_GET['friendica_verbose'] = 'true'; $_GET['friendica_verbose'] = 'true';
$result = api_direct_messages_destroy('json'); $result = api_direct_messages_destroy('json');
$this->assertEquals( $this->assertEquals(
[ [
'$result' => [ '$result' => [
'result' => 'error', 'result' => 'error',
'message' => 'message id not in database' 'message' => 'message id not in database'
] ]
], ],
@ -2923,6 +3119,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_destroy() function with a non-zero ID. * Test the api_direct_messages_destroy() function with a non-zero ID.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesDestroyWithCorrectId() public function testApiDirectMessagesDestroyWithCorrectId()
@ -2932,18 +3129,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_box() function. * Test the api_direct_messages_box() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesBoxWithSentbox() public function testApiDirectMessagesBoxWithSentbox()
{ {
$_REQUEST['page'] = -1; $_REQUEST['page'] = -1;
$_REQUEST['max_id'] = 10; $_REQUEST['max_id'] = 10;
$result = api_direct_messages_box('json', 'sentbox', 'false'); $result = api_direct_messages_box('json', 'sentbox', 'false');
$this->assertArrayHasKey('direct_message', $result); $this->assertArrayHasKey('direct_message', $result);
} }
/** /**
* Test the api_direct_messages_box() function. * Test the api_direct_messages_box() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesBoxWithConversation() public function testApiDirectMessagesBoxWithConversation()
@ -2954,6 +3153,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_box() function. * Test the api_direct_messages_box() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesBoxWithAll() public function testApiDirectMessagesBoxWithAll()
@ -2964,6 +3164,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_box() function. * Test the api_direct_messages_box() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesBoxWithInbox() public function testApiDirectMessagesBoxWithInbox()
@ -2974,6 +3175,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_box() function. * Test the api_direct_messages_box() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesBoxWithVerbose() public function testApiDirectMessagesBoxWithVerbose()
@ -2982,7 +3184,7 @@ class ApiTest extends DatabaseTest
$this->assertEquals( $this->assertEquals(
[ [
'$result' => [ '$result' => [
'result' => 'error', 'result' => 'error',
'message' => 'no mails available' 'message' => 'no mails available'
] ]
], ],
@ -2992,6 +3194,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_box() function with a RSS result. * Test the api_direct_messages_box() function with a RSS result.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesBoxWithRss() public function testApiDirectMessagesBoxWithRss()
@ -3002,18 +3205,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_box() function without an authenticated user. * Test the api_direct_messages_box() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
public function testApiDirectMessagesBoxWithUnallowedUser() public function testApiDirectMessagesBoxWithUnallowedUser()
{ {
$_SESSION['allow_api'] = false; $_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick']; $_GET['screen_name'] = $this->selfUser['nick'];
api_direct_messages_box('json', 'sentbox', 'false'); api_direct_messages_box('json', 'sentbox', 'false');
} }
/** /**
* Test the api_direct_messages_sentbox() function. * Test the api_direct_messages_sentbox() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesSentbox() public function testApiDirectMessagesSentbox()
@ -3024,6 +3229,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_inbox() function. * Test the api_direct_messages_inbox() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesInbox() public function testApiDirectMessagesInbox()
@ -3034,6 +3240,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_all() function. * Test the api_direct_messages_all() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesAll() public function testApiDirectMessagesAll()
@ -3044,6 +3251,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_direct_messages_conversation() function. * Test the api_direct_messages_conversation() function.
*
* @return void * @return void
*/ */
public function testApiDirectMessagesConversation() public function testApiDirectMessagesConversation()
@ -3054,6 +3262,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_oauth_request_token() function. * Test the api_oauth_request_token() function.
*
* @return void * @return void
*/ */
public function testApiOauthRequestToken() public function testApiOauthRequestToken()
@ -3063,6 +3272,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_oauth_access_token() function. * Test the api_oauth_access_token() function.
*
* @return void * @return void
*/ */
public function testApiOauthAccessToken() public function testApiOauthAccessToken()
@ -3072,6 +3282,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photoalbum_delete() function. * Test the api_fr_photoalbum_delete() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3082,6 +3293,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photoalbum_delete() function with an album name. * Test the api_fr_photoalbum_delete() function with an album name.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3093,6 +3305,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photoalbum_delete() function with an album name. * Test the api_fr_photoalbum_delete() function with an album name.
*
* @return void * @return void
*/ */
public function testApiFrPhotoalbumDeleteWithValidAlbum() public function testApiFrPhotoalbumDeleteWithValidAlbum()
@ -3102,6 +3315,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photoalbum_delete() function. * Test the api_fr_photoalbum_delete() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3112,6 +3326,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photoalbum_delete() function with an album name. * Test the api_fr_photoalbum_delete() function with an album name.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3123,18 +3338,20 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photoalbum_delete() function with an album name. * Test the api_fr_photoalbum_delete() function with an album name.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum() public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
{ {
$_REQUEST['album'] = 'album_name'; $_REQUEST['album'] = 'album_name';
$_REQUEST['album_new'] = 'album_name'; $_REQUEST['album_new'] = 'album_name';
api_fr_photoalbum_update('json'); api_fr_photoalbum_update('json');
} }
/** /**
* Test the api_fr_photoalbum_update() function without an authenticated user. * Test the api_fr_photoalbum_update() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -3146,6 +3363,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photoalbum_delete() function with an album name. * Test the api_fr_photoalbum_delete() function with an album name.
*
* @return void * @return void
*/ */
public function testApiFrPhotoalbumUpdateWithValidAlbum() public function testApiFrPhotoalbumUpdateWithValidAlbum()
@ -3155,6 +3373,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photos_list() function. * Test the api_fr_photos_list() function.
*
* @return void * @return void
*/ */
public function testApiFrPhotosList() public function testApiFrPhotosList()
@ -3165,6 +3384,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photos_list() function without an authenticated user. * Test the api_fr_photos_list() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -3176,6 +3396,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_create_update() function. * Test the api_fr_photo_create_update() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3186,6 +3407,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_create_update() function without an authenticated user. * Test the api_fr_photo_create_update() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -3197,6 +3419,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_create_update() function with an album name. * Test the api_fr_photo_create_update() function with an album name.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3208,6 +3431,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_create_update() function with the update mode. * Test the api_fr_photo_create_update() function with the update mode.
*
* @return void * @return void
*/ */
public function testApiFrPhotoCreateUpdateWithUpdate() public function testApiFrPhotoCreateUpdateWithUpdate()
@ -3217,6 +3441,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_create_update() function with an uploaded file. * Test the api_fr_photo_create_update() function with an uploaded file.
*
* @return void * @return void
*/ */
public function testApiFrPhotoCreateUpdateWithFile() public function testApiFrPhotoCreateUpdateWithFile()
@ -3226,6 +3451,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_delete() function. * Test the api_fr_photo_delete() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3236,6 +3462,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_delete() function without an authenticated user. * Test the api_fr_photo_delete() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -3247,6 +3474,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_delete() function with a photo ID. * Test the api_fr_photo_delete() function with a photo ID.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3258,6 +3486,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_delete() function with a correct photo ID. * Test the api_fr_photo_delete() function with a correct photo ID.
*
* @return void * @return void
*/ */
public function testApiFrPhotoDeleteWithCorrectPhotoId() public function testApiFrPhotoDeleteWithCorrectPhotoId()
@ -3267,6 +3496,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_detail() function. * Test the api_fr_photo_detail() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3277,6 +3507,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_detail() function without an authenticated user. * Test the api_fr_photo_detail() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -3288,6 +3519,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_detail() function with a photo ID. * Test the api_fr_photo_detail() function with a photo ID.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\NotFoundException * @expectedException Friendica\Network\HTTPException\NotFoundException
*/ */
@ -3299,6 +3531,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_fr_photo_detail() function with a correct photo ID. * Test the api_fr_photo_detail() function with a correct photo ID.
*
* @return void * @return void
*/ */
public function testApiFrPhotoDetailCorrectPhotoId() public function testApiFrPhotoDetailCorrectPhotoId()
@ -3308,6 +3541,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_account_update_profile_image() function. * Test the api_account_update_profile_image() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3318,6 +3552,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_account_update_profile_image() function without an authenticated user. * Test the api_account_update_profile_image() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -3329,6 +3564,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_account_update_profile_image() function with an uploaded file. * Test the api_account_update_profile_image() function with an uploaded file.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3340,13 +3576,14 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_account_update_profile() function. * Test the api_account_update_profile() function.
*
* @return void * @return void
*/ */
public function testApiAccountUpdateProfile() public function testApiAccountUpdateProfile()
{ {
$_POST['name'] = 'new_name'; $_POST['name'] = 'new_name';
$_POST['description'] = 'new_description'; $_POST['description'] = 'new_description';
$result = api_account_update_profile('json'); $result = api_account_update_profile('json');
// We can't use assertSelfUser() here because the user object is missing some properties. // We can't use assertSelfUser() here because the user object is missing some properties.
$this->assertEquals($this->selfUser['id'], $result['user']['cid']); $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
$this->assertEquals('DFRN', $result['user']['location']); $this->assertEquals('DFRN', $result['user']['location']);
@ -3358,6 +3595,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the check_acl_input() function. * Test the check_acl_input() function.
*
* @return void * @return void
*/ */
public function testCheckAclInput() public function testCheckAclInput()
@ -3369,6 +3607,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the check_acl_input() function with an empty ACL string. * Test the check_acl_input() function with an empty ACL string.
*
* @return void * @return void
*/ */
public function testCheckAclInputWithEmptyAclString() public function testCheckAclInputWithEmptyAclString()
@ -3379,6 +3618,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the save_media_to_database() function. * Test the save_media_to_database() function.
*
* @return void * @return void
*/ */
public function testSaveMediaToDatabase() public function testSaveMediaToDatabase()
@ -3388,6 +3628,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the post_photo_item() function. * Test the post_photo_item() function.
*
* @return void * @return void
*/ */
public function testPostPhotoItem() public function testPostPhotoItem()
@ -3397,6 +3638,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the prepare_photo_data() function. * Test the prepare_photo_data() function.
*
* @return void * @return void
*/ */
public function testPreparePhotoData() public function testPreparePhotoData()
@ -3406,6 +3648,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_remoteauth() function. * Test the api_friendica_remoteauth() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3416,41 +3659,45 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_remoteauth() function with an URL. * Test the api_friendica_remoteauth() function with an URL.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
public function testApiFriendicaRemoteauthWithUrl() public function testApiFriendicaRemoteauthWithUrl()
{ {
$_GET['url'] = 'url'; $_GET['url'] = 'url';
$_GET['c_url'] = 'url'; $_GET['c_url'] = 'url';
api_friendica_remoteauth(); api_friendica_remoteauth();
} }
/** /**
* Test the api_friendica_remoteauth() function with a correct URL. * Test the api_friendica_remoteauth() function with a correct URL.
*
* @return void * @return void
*/ */
public function testApiFriendicaRemoteauthWithCorrectUrl() public function testApiFriendicaRemoteauthWithCorrectUrl()
{ {
$this->markTestIncomplete("We can't use an assertion here because of App->redirect()."); $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
$_GET['url'] = 'url'; $_GET['url'] = 'url';
$_GET['c_url'] = $this->selfUser['nurl']; $_GET['c_url'] = $this->selfUser['nurl'];
api_friendica_remoteauth(); api_friendica_remoteauth();
} }
/** /**
* Test the api_share_as_retweet() function. * Test the api_share_as_retweet() function.
*
* @return void * @return void
*/ */
public function testApiShareAsRetweet() public function testApiShareAsRetweet()
{ {
$item = ['body' => '', 'author-id' => 1, 'owner-id' => 1]; $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
$result = api_share_as_retweet($item); $result = api_share_as_retweet($item);
$this->assertFalse($result); $this->assertFalse($result);
} }
/** /**
* Test the api_share_as_retweet() function with a valid item. * Test the api_share_as_retweet() function with a valid item.
*
* @return void * @return void
*/ */
public function testApiShareAsRetweetWithValidItem() public function testApiShareAsRetweetWithValidItem()
@ -3460,6 +3707,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_nick() function. * Test the api_get_nick() function.
*
* @return void * @return void
*/ */
public function testApiGetNick() public function testApiGetNick()
@ -3470,6 +3718,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_get_nick() function with a wrong URL. * Test the api_get_nick() function with a wrong URL.
*
* @return void * @return void
*/ */
public function testApiGetNickWithWrongUrl() public function testApiGetNickWithWrongUrl()
@ -3480,6 +3729,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_in_reply_to() function. * Test the api_in_reply_to() function.
*
* @return void * @return void
*/ */
public function testApiInReplyTo() public function testApiInReplyTo()
@ -3494,6 +3744,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_in_reply_to() function with a valid item. * Test the api_in_reply_to() function with a valid item.
*
* @return void * @return void
*/ */
public function testApiInReplyToWithValidItem() public function testApiInReplyToWithValidItem()
@ -3503,17 +3754,19 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_clean_plain_items() function. * Test the api_clean_plain_items() function.
*
* @return void * @return void
*/ */
public function testApiCleanPlainItems() public function testApiCleanPlainItems()
{ {
$_REQUEST['include_entities'] = 'true'; $_REQUEST['include_entities'] = 'true';
$result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]'); $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
$this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result); $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
} }
/** /**
* Test the api_clean_attachments() function. * Test the api_clean_attachments() function.
*
* @return void * @return void
*/ */
public function testApiCleanAttachments() public function testApiCleanAttachments()
@ -3523,17 +3776,19 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_best_nickname() function. * Test the api_best_nickname() function.
*
* @return void * @return void
*/ */
public function testApiBestNickname() public function testApiBestNickname()
{ {
$contacts = []; $contacts = [];
$result = api_best_nickname($contacts); $result = api_best_nickname($contacts);
$this->assertNull($result); $this->assertNull($result);
} }
/** /**
* Test the api_best_nickname() function with contacts. * Test the api_best_nickname() function with contacts.
*
* @return void * @return void
*/ */
public function testApiBestNicknameWithContacts() public function testApiBestNicknameWithContacts()
@ -3543,6 +3798,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_group_show() function. * Test the api_friendica_group_show() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaGroupShow() public function testApiFriendicaGroupShow()
@ -3552,6 +3808,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_group_delete() function. * Test the api_friendica_group_delete() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaGroupDelete() public function testApiFriendicaGroupDelete()
@ -3561,6 +3818,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_destroy() function. * Test the api_lists_destroy() function.
*
* @return void * @return void
*/ */
public function testApiListsDestroy() public function testApiListsDestroy()
@ -3570,6 +3828,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the group_create() function. * Test the group_create() function.
*
* @return void * @return void
*/ */
public function testGroupCreate() public function testGroupCreate()
@ -3579,6 +3838,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_group_create() function. * Test the api_friendica_group_create() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaGroupCreate() public function testApiFriendicaGroupCreate()
@ -3588,6 +3848,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_create() function. * Test the api_lists_create() function.
*
* @return void * @return void
*/ */
public function testApiListsCreate() public function testApiListsCreate()
@ -3597,6 +3858,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_group_update() function. * Test the api_friendica_group_update() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaGroupUpdate() public function testApiFriendicaGroupUpdate()
@ -3606,6 +3868,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_lists_update() function. * Test the api_lists_update() function.
*
* @return void * @return void
*/ */
public function testApiListsUpdate() public function testApiListsUpdate()
@ -3615,6 +3878,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_activity() function. * Test the api_friendica_activity() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaActivity() public function testApiFriendicaActivity()
@ -3624,6 +3888,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_notification() function. * Test the api_friendica_notification() function.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3634,6 +3899,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_notification() function without an authenticated user. * Test the api_friendica_notification() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -3645,30 +3911,33 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_notification() function with an argument count. * Test the api_friendica_notification() function with an argument count.
*
* @return void * @return void
*/ */
public function testApiFriendicaNotificationWithArgumentCount() public function testApiFriendicaNotificationWithArgumentCount()
{ {
$this->app->argv = ['api', 'friendica', 'notification']; $this->app->argv = ['api', 'friendica', 'notification'];
$this->app->argc = count($this->app->argv); $this->app->argc = count($this->app->argv);
$result = api_friendica_notification('json'); $result = api_friendica_notification('json');
$this->assertEquals(['note' => false], $result); $this->assertEquals(['note' => false], $result);
} }
/** /**
* Test the api_friendica_notification() function with an XML result. * Test the api_friendica_notification() function with an XML result.
*
* @return void * @return void
*/ */
public function testApiFriendicaNotificationWithXmlResult() public function testApiFriendicaNotificationWithXmlResult()
{ {
$this->app->argv = ['api', 'friendica', 'notification']; $this->app->argv = ['api', 'friendica', 'notification'];
$this->app->argc = count($this->app->argv); $this->app->argc = count($this->app->argv);
$result = api_friendica_notification('xml'); $result = api_friendica_notification('xml');
$this->assertXml($result, 'notes'); $this->assertXml($result, 'notes');
} }
/** /**
* Test the api_friendica_notification_seen() function. * Test the api_friendica_notification_seen() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaNotificationSeen() public function testApiFriendicaNotificationSeen()
@ -3678,6 +3947,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_direct_messages_setseen() function. * Test the api_friendica_direct_messages_setseen() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaDirectMessagesSetseen() public function testApiFriendicaDirectMessagesSetseen()
@ -3687,6 +3957,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_direct_messages_search() function. * Test the api_friendica_direct_messages_search() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaDirectMessagesSearch() public function testApiFriendicaDirectMessagesSearch()
@ -3696,6 +3967,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_profile_show() function. * Test the api_friendica_profile_show() function.
*
* @return void * @return void
*/ */
public function testApiFriendicaProfileShow() public function testApiFriendicaProfileShow()
@ -3713,6 +3985,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_profile_show() function with a profile ID. * Test the api_friendica_profile_show() function with a profile ID.
*
* @return void * @return void
*/ */
public function testApiFriendicaProfileShowWithProfileId() public function testApiFriendicaProfileShowWithProfileId()
@ -3722,6 +3995,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_profile_show() function with a wrong profile ID. * Test the api_friendica_profile_show() function with a wrong profile ID.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException * @expectedException Friendica\Network\HTTPException\BadRequestException
*/ */
@ -3733,6 +4007,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_friendica_profile_show() function without an authenticated user. * Test the api_friendica_profile_show() function without an authenticated user.
*
* @return void * @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException * @expectedException Friendica\Network\HTTPException\ForbiddenException
*/ */
@ -3744,6 +4019,7 @@ class ApiTest extends DatabaseTest
/** /**
* Test the api_saved_searches_list() function. * Test the api_saved_searches_list() function.
*
* @return void * @return void
*/ */
public function testApiSavedSearchesList() public function testApiSavedSearchesList()

View file

@ -4,8 +4,10 @@ namespace Friendica\Test\src\Database;
use Dice\Dice; use Dice\Dice;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Test\DatabaseTest; use Friendica\Test\DatabaseTest;
use Friendica\Test\Util\Database\StaticDatabase;
class DBATest extends DatabaseTest class DBATest extends DatabaseTest
{ {
@ -15,6 +17,7 @@ class DBATest extends DatabaseTest
$dice = new Dice(); $dice = new Dice();
$dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
$dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
BaseObject::setDependencyInjection($dice); BaseObject::setDependencyInjection($dice);
// Default config // Default config

View file

@ -4,20 +4,20 @@ namespace Friendica\Test\src\Database;
use Dice\Dice; use Dice\Dice;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Database\Database;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\Test\DatabaseTest; use Friendica\Test\DatabaseTest;
use Friendica\Test\Util\Database\StaticDatabase;
class DBStructureTest extends DatabaseTest class DBStructureTest extends DatabaseTest
{ {
/** protected function setUp()
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function setUp()
{ {
parent::setUp(); parent::setUp();
$dice = new Dice(); $dice = new Dice();
$dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
$dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
BaseObject::setDependencyInjection($dice); BaseObject::setDependencyInjection($dice);
} }