use Dice\Dice;
use Friendica\App;
use Friendica\BaseObject;
-use Friendica\Core\Config;
-use Friendica\Core\PConfig;
+use Friendica\Core\Config\Configuration;
+use Friendica\Core\Config\PConfiguration;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\Database;
+use Friendica\Model\Contact;
use Friendica\Network\HTTPException;
use Friendica\Test\Util\Database\StaticDatabase;
-use Friendica\Test\Util\Database\YamlDataSet;
use Monolog\Handler\TestHandler;
require_once __DIR__ . '/../../include/api.php';
/** @var App */
protected $app;
+ /** @var Configuration */
+ protected $config;
+
+ /** @var Dice */
+ protected $dice;
+
/**
* Create variables used by tests.
*/
{
parent::setUp();
- $dice = new Dice();
- $dice = $dice->addRules(include __DIR__ . '/../../static/dependencies.config.php');
- $dice = $dice->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
- BaseObject::setDependencyInjection($dice);
+ $this->dice = (new Dice())
+ ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
+ ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]);
+ BaseObject::setDependencyInjection($this->dice);
/** @var Database $dba */
- $dba = $dice->create(Database::class);
+ $dba = $this->dice->create(Database::class);
+
+ /** @var Configuration $config */
+ $this->config = $this->dice->create(Configuration::class);
+
+ $this->config->set('system', 'url', 'http://localhost');
+ $this->config->set('system', 'hostname', 'localhost');
+ $this->config->set('system', 'worker_dont_fork', true);
+
+ // Default config
+ $this->config->set('config', 'hostname', 'localhost');
+ $this->config->set('system', 'throttle_limit_day', 100);
+ $this->config->set('system', 'throttle_limit_week', 100);
+ $this->config->set('system', 'throttle_limit_month', 100);
+ $this->config->set('system', 'theme', 'system_theme');
// Load the API dataset for the whole API
- $ymlTester = new YamlDataSet(__DIR__ . '/../datasets/api.yml');
- $ymlTester->load($dba);
+ $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
+ /** @var App app */
$this->app = BaseObject::getApp();
$this->app->argc = 1;
$_POST = [];
$_GET = [];
$_SERVER = [];
-
- Config::set('system', 'url', 'http://localhost');
- Config::set('system', 'hostname', 'localhost');
- Config::set('system', 'worker_dont_fork', true);
-
- // Default config
- Config::set('config', 'hostname', 'localhost');
- Config::set('system', 'throttle_limit_day', 100);
- Config::set('system', 'throttle_limit_week', 100);
- Config::set('system', 'throttle_limit_month', 100);
- Config::set('system', 'theme', 'system_theme');
}
/**
}
];
$_SERVER['REQUEST_METHOD'] = 'method';
- Config::set('system', 'profiler', true);
- Config::set('rendertime', 'callstack', true);
+ $this->config->set('system', 'profiler', true);
+ $this->config->set('rendertime', 'callstack', true);
$this->app->callstack = [
'database' => ['some_function' => 200],
'database_write' => ['some_function' => 200],
*/
public function testApiGetUserWithFrioSchema()
{
- PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
+ $pConfig = $this->dice->create(PConfiguration::class);
+ $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
$user = api_get_user($this->app);
$this->assertSelfUser($user);
$this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
*/
public function testApiGetUserWithCustomFrioSchema()
{
- $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
- $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
- $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
- $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
+ $pConfig = $this->dice->create(PConfiguration::class);
+ $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
+ $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
+ $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
+ $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
$user = api_get_user($this->app);
$this->assertSelfUser($user);
$this->assertEquals('123456', $user['profile_sidebar_fill_color']);
*/
public function testApiGetUserWithEmptyFrioSchema()
{
- PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
+ $pConfig = $this->dice->create(PConfiguration::class);
+ $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
$user = api_get_user($this->app);
$this->assertSelfUser($user);
$this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
*/
public function testApiFfIds()
{
- $result = api_ff_ids('json');
- $this->assertNull($result);
+ $result = api_ff_ids('json', Contact::FOLLOWER);
+ $this->assertEquals(['id' => []], $result);
}
/**
public function testApiFfIdsWithoutAuthenticatedUser()
{
$_SESSION['authenticated'] = false;
- api_ff_ids('json');
+ api_ff_ids('json', Contact::FOLLOWER);
}
/**
public function testApiFriendsIds()
{
$result = api_friends_ids('json');
- $this->assertNull($result);
+ $this->assertEquals(['id' => []], $result);
}
/**
public function testApiFollowersIds()
{
$result = api_followers_ids('json');
- $this->assertNull($result);
+ $this->assertEquals(['id' => []], $result);
}
/**
$this->markTestIncomplete();
}
- /**
- * Test the api_get_nick() function.
- *
- * @return void
- */
- public function testApiGetNick()
- {
- $result = api_get_nick($this->otherUser['nurl']);
- $this->assertEquals('othercontact', $result);
- }
-
- /**
- * Test the api_get_nick() function with a wrong URL.
- *
- * @return void
- */
- public function testApiGetNickWithWrongUrl()
- {
- $result = api_get_nick('wrong_url');
- $this->assertFalse($result);
- }
-
/**
* Test the api_in_reply_to() function.
*
$this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
}
- /**
- * Test the api_clean_attachments() function.
- *
- * @return void
- */
- public function testApiCleanAttachments()
- {
- $this->markTestIncomplete();
- }
-
/**
* Test the api_best_nickname() function.
*