friendica/tests/src/Module/Api/ApiTest.php

69 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace Friendica\Test\src\Module\Api;
use Dice\Dice;
use Friendica\Core\Addon;
use Friendica\Core\Hook;
use Friendica\Database\Database;
use Friendica\DI;
2021-11-12 15:35:21 -05:00
use Friendica\Module\Api\ApiResponse;
use Friendica\Security\Authentication;
use Friendica\Test\FixtureTest;
2021-11-12 15:35:21 -05:00
use Friendica\Test\Util\ApiResponseDouble;
use Friendica\Test\Util\AuthenticationDouble;
class ApiTest extends FixtureTest
{
protected function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->dice = $this->dice
2021-11-12 15:35:21 -05:00
->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true])
->addRule(ApiResponse::class, ['instanceOf' => ApiResponseDouble::class, 'shared' => true]);
DI::init($this->dice);
$this->installAuthTest();
}
2021-11-12 15:35:21 -05:00
protected function tearDown(): void
{
ApiResponseDouble::reset();
parent::tearDown();
}
/**
* installs auththest.
*
* @throws \Exception
*/
public function installAuthTest()
{
$addon = 'authtest';
$addon_file_path = __DIR__ . '/../../../Util/authtest/authtest.php';
$t = @filemtime($addon_file_path);
@include_once($addon_file_path);
if (function_exists($addon . '_install')) {
$func = $addon . '_install';
$func(DI::app());
}
/** @var Database $dba */
$dba = $this->dice->create(Database::class);
$dba->insert('addon', [
'name' => $addon,
'installed' => true,
'timestamp' => $t,
'plugin_admin' => function_exists($addon . '_addon_admin'),
'hidden' => file_exists('addon/' . $addon . '/.hidden')
]);
Addon::loadAddons();
Hook::loadHooks();
}
}