2019-07-20 23:22:10 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 14:45:36 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-07-20 23:22:10 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
namespace Friendica\Test\functional;
|
2019-07-20 23:22:10 +00:00
|
|
|
|
|
|
|
use Dice\Dice;
|
|
|
|
use Friendica\App;
|
2021-10-26 19:44:29 +00:00
|
|
|
use Friendica\Core\Cache\Capability\ICanCache;
|
|
|
|
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
|
|
|
|
use Friendica\Core\Config\ValueObject\Cache;
|
|
|
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
|
|
|
use Friendica\Core\Lock\Capability\ICanLock;
|
2019-07-20 23:22:10 +00:00
|
|
|
use Friendica\Database\Database;
|
|
|
|
use Friendica\Test\Util\VFSTrait;
|
|
|
|
use Friendica\Util\BasePath;
|
2021-10-26 19:44:29 +00:00
|
|
|
use Friendica\Core\Config\Util\ConfigFileLoader;
|
2019-07-20 23:22:10 +00:00
|
|
|
use Friendica\Util\Profiler;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
2020-10-18 18:31:57 +00:00
|
|
|
class DependencyCheckTest extends TestCase
|
2019-07-20 23:22:10 +00:00
|
|
|
{
|
|
|
|
use VFSTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Dice
|
|
|
|
*/
|
|
|
|
private $dice;
|
|
|
|
|
2021-04-01 21:04:30 +00:00
|
|
|
protected function setUp() : void
|
2019-07-20 23:22:10 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->setUpVfsDir();
|
|
|
|
|
2019-08-05 07:02:55 +00:00
|
|
|
$this->dice = (new Dice())
|
|
|
|
->addRules(include __DIR__ . '/../../static/dependencies.config.php');
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the creation of the BasePath
|
|
|
|
*/
|
|
|
|
public function testBasePath()
|
|
|
|
{
|
|
|
|
/** @var BasePath $basePath */
|
|
|
|
$basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertInstanceOf(BasePath::class, $basePath);
|
|
|
|
self::assertEquals($this->root->url(), $basePath->getPath());
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the initial config cache
|
|
|
|
* Should not need any other files
|
|
|
|
*/
|
|
|
|
public function testConfigFileLoader()
|
|
|
|
{
|
|
|
|
/** @var ConfigFileLoader $configFileLoader */
|
|
|
|
$configFileLoader = $this->dice->create(ConfigFileLoader::class);
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertInstanceOf(ConfigFileLoader::class, $configFileLoader);
|
2019-07-20 23:22:10 +00:00
|
|
|
|
2020-01-19 21:23:44 +00:00
|
|
|
$configCache = new Cache();
|
2019-07-20 23:22:10 +00:00
|
|
|
$configFileLoader->setupCache($configCache);
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertNotEmpty($configCache->getAll());
|
|
|
|
self::assertArrayHasKey('database', $configCache->getAll());
|
|
|
|
self::assertArrayHasKey('system', $configCache->getAll());
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the construction of a profiler class with DI
|
|
|
|
*/
|
|
|
|
public function testProfiler()
|
|
|
|
{
|
|
|
|
/** @var Profiler $profiler */
|
|
|
|
$profiler = $this->dice->create(Profiler::class);
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertInstanceOf(Profiler::class, $profiler);
|
2019-07-20 23:22:10 +00:00
|
|
|
|
2020-01-19 21:23:44 +00:00
|
|
|
$configCache = new Cache([
|
2019-07-20 23:22:10 +00:00
|
|
|
'system' => [
|
|
|
|
'profiler' => true,
|
|
|
|
],
|
|
|
|
'rendertime' => [
|
|
|
|
'callstack' => true,
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
2019-07-24 10:48:29 +00:00
|
|
|
// create new DI-library because of shared instance rule (so the Profiler wouldn't get created twice)
|
2019-08-06 05:43:13 +00:00
|
|
|
$this->dice = new Dice();
|
2019-08-05 07:22:06 +00:00
|
|
|
$profiler = $this->dice->create(Profiler::class, [$configCache]);
|
2019-07-20 23:22:10 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertInstanceOf(Profiler::class, $profiler);
|
|
|
|
self::assertTrue($profiler->isRendertime());
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDatabase()
|
|
|
|
{
|
2020-11-08 17:45:50 +00:00
|
|
|
// PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
|
|
|
|
if (version_compare(PHP_VERSION, '7.3') < 0) {
|
|
|
|
$configCache = $this->dice->create(Cache::class);
|
|
|
|
$configCache->set('database', 'disable_pdo', true);
|
|
|
|
}
|
2020-11-08 17:13:12 +00:00
|
|
|
|
2019-07-20 23:22:10 +00:00
|
|
|
/** @var Database $database */
|
|
|
|
$database = $this->dice->create(Database::class);
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertInstanceOf(Database::class, $database);
|
2020-11-08 17:45:50 +00:00
|
|
|
self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
|
2020-11-07 11:44:39 +00:00
|
|
|
self::assertNotNull($database->getConnection(), 'There is no database connection');
|
2020-11-08 07:29:13 +00:00
|
|
|
|
|
|
|
$result = $database->p("SELECT 1");
|
2020-11-08 16:47:41 +00:00
|
|
|
self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
|
|
|
|
self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
|
2020-11-08 07:29:13 +00:00
|
|
|
|
2020-11-07 11:44:39 +00:00
|
|
|
self::assertTrue($database->connected(), 'The database is not connected');
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAppMode()
|
|
|
|
{
|
2020-11-08 17:45:50 +00:00
|
|
|
// PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
|
|
|
|
if (version_compare(PHP_VERSION, '7.3') < 0) {
|
|
|
|
$configCache = $this->dice->create(Cache::class);
|
|
|
|
$configCache->set('database', 'disable_pdo', true);
|
|
|
|
}
|
2020-11-08 17:26:20 +00:00
|
|
|
|
2019-07-20 23:22:10 +00:00
|
|
|
/** @var App\Mode $mode */
|
|
|
|
$mode = $this->dice->create(App\Mode::class);
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertInstanceOf(App\Mode::class, $mode);
|
2019-07-20 23:22:10 +00:00
|
|
|
|
2020-11-07 12:45:04 +00:00
|
|
|
self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
|
|
|
|
self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
|
|
|
|
self::assertTrue($mode->has(App\Mode::DBCONFIGAVAILABLE), 'Database config is not available');
|
|
|
|
self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
|
2020-11-07 10:45:38 +00:00
|
|
|
|
2020-11-07 11:26:56 +00:00
|
|
|
self::assertTrue($mode->isNormal(), 'Not in normal mode');
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testConfiguration()
|
|
|
|
{
|
2021-10-26 19:44:29 +00:00
|
|
|
/** @var IManageConfigValues $config */
|
|
|
|
$config = $this->dice->create(IManageConfigValues::class);
|
2019-07-20 23:22:10 +00:00
|
|
|
|
2021-10-26 19:44:29 +00:00
|
|
|
self::assertInstanceOf(IManageConfigValues::class, $config);
|
2019-07-20 23:22:10 +00:00
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertNotEmpty($config->get('database', 'username'));
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLogger()
|
|
|
|
{
|
|
|
|
/** @var LoggerInterface $logger */
|
|
|
|
$logger = $this->dice->create(LoggerInterface::class, ['test']);
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertInstanceOf(LoggerInterface::class, $logger);
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDevLogger()
|
|
|
|
{
|
2021-10-26 19:44:29 +00:00
|
|
|
/** @var IManageConfigValues $config */
|
|
|
|
$config = $this->dice->create(IManageConfigValues::class);
|
2019-12-11 19:30:31 +00:00
|
|
|
$config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
|
|
|
|
|
2019-07-20 23:22:10 +00:00
|
|
|
/** @var LoggerInterface $logger */
|
|
|
|
$logger = $this->dice->create('$devLogger', ['dev']);
|
|
|
|
|
2020-10-17 12:19:57 +00:00
|
|
|
self::assertInstanceOf(LoggerInterface::class, $logger);
|
2019-08-04 13:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCache()
|
|
|
|
{
|
2021-10-26 19:44:29 +00:00
|
|
|
/** @var ICanCache $cache */
|
|
|
|
$cache = $this->dice->create(ICanCache::class);
|
2019-08-04 13:42:39 +00:00
|
|
|
|
2021-10-26 19:44:29 +00:00
|
|
|
self::assertInstanceOf(ICanCache::class, $cache);
|
2019-08-04 13:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMemoryCache()
|
|
|
|
{
|
2021-10-26 19:44:29 +00:00
|
|
|
/** @var ICanCacheInMemory $cache */
|
|
|
|
$cache = $this->dice->create(ICanCacheInMemory::class);
|
2019-08-04 13:42:39 +00:00
|
|
|
|
|
|
|
// We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
|
2021-10-26 19:44:29 +00:00
|
|
|
self::assertInstanceOf(ICanCache::class, $cache);
|
2019-08-04 13:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLock()
|
|
|
|
{
|
2021-10-26 19:44:29 +00:00
|
|
|
/** @var ICanLock $cache */
|
|
|
|
$lock = $this->dice->create(ICanLock::class);
|
2019-08-04 13:42:39 +00:00
|
|
|
|
2021-10-26 19:44:29 +00:00
|
|
|
self::assertInstanceOf(ICanLock::class, $lock);
|
2019-07-20 23:22:10 +00:00
|
|
|
}
|
|
|
|
}
|