]> git.mxchange.org Git - friendica.git/blob - tests/functional/DependencyCheckTest.php
Friendica copyright changed from 2023 to 2034
[friendica.git] / tests / functional / DependencyCheckTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2024, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\functional;
23
24 use Friendica\App;
25 use Friendica\Core\Cache\Capability\ICanCache;
26 use Friendica\Core\Cache\Capability\ICanCacheInMemory;
27 use Friendica\Core\Config\ValueObject\Cache;
28 use Friendica\Core\Config\Capability\IManageConfigValues;
29 use Friendica\Core\Lock\Capability\ICanLock;
30 use Friendica\Database\Database;
31 use Friendica\Test\FixtureTest;
32 use Friendica\Util\BasePath;
33 use Friendica\Core\Config\Util\ConfigFileManager;
34 use Psr\Log\LoggerInterface;
35
36 class DependencyCheckTest extends FixtureTest
37 {
38         protected function setUp() : void
39         {
40                 parent::setUp();
41
42                 /** @var IManageConfigValues $config */
43                 $config = $this->dice->create(IManageConfigValues::class);
44                 $config->set('system', 'logfile', $this->root->url() . '/logs/friendica.log');
45         }
46
47         /**
48          * Test the creation of the BasePath
49          */
50         public function testBasePath()
51         {
52                 /** @var BasePath $basePath */
53                 $basePath = $this->dice->create(BasePath::class, [$this->root->url()]);
54
55                 self::assertInstanceOf(BasePath::class, $basePath);
56                 self::assertEquals($this->root->url(), $basePath->getPath());
57
58                 /** @var Database $dba */
59                 $dba = $this->dice->create(Database::class);
60         }
61
62         /**
63          * Test the initial config cache
64          * Should not need any other files
65          */
66         public function testConfigFileLoader()
67         {
68                 /** @var ConfigFileManager $configFileManager */
69                 $configFileManager = $this->dice->create(ConfigFileManager::class);
70
71                 self::assertInstanceOf(ConfigFileManager::class, $configFileManager);
72
73                 $configCache = new Cache();
74                 $configFileManager->setupCache($configCache);
75
76                 self::assertNotEmpty($configCache->getAll());
77                 self::assertArrayHasKey('database', $configCache->getAll());
78                 self::assertArrayHasKey('system', $configCache->getAll());
79         }
80
81         public function testDatabase()
82         {
83                 /** @var Database $database */
84                 $database = $this->dice->create(Database::class);
85
86                 self::assertInstanceOf(Database::class, $database);
87                 self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
88                 self::assertNotNull($database->getConnection(), 'There is no database connection');
89
90                 $result = $database->p("SELECT 1");
91                 self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
92                 self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
93
94                 self::assertTrue($database->connected(), 'The database is not connected');
95         }
96
97         public function testAppMode()
98         {
99                 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
100                 if (version_compare(PHP_VERSION, '7.3') < 0) {
101                         $configCache = $this->dice->create(Cache::class);
102                         $configCache->set('database', 'disable_pdo', true);
103                 }
104
105                 /** @var App\Mode $mode */
106                 $mode = $this->dice->create(App\Mode::class);
107
108                 self::assertInstanceOf(App\Mode::class, $mode);
109
110                 self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
111                 self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
112                 self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
113
114                 self::assertTrue($mode->isNormal(), 'Not in normal mode');
115         }
116
117         public function testConfiguration()
118         {
119                 /** @var IManageConfigValues $config */
120                 $config = $this->dice->create(IManageConfigValues::class);
121
122                 self::assertInstanceOf(IManageConfigValues::class, $config);
123
124                 self::assertNotEmpty($config->get('database', 'username'));
125         }
126
127         public function testLogger()
128         {
129                 /** @var LoggerInterface $logger */
130                 $logger = $this->dice->create(LoggerInterface::class, [['$channel' => 'test']]);
131
132                 self::assertInstanceOf(LoggerInterface::class, $logger);
133         }
134
135         public function testDevLogger()
136         {
137                 /** @var IManageConfigValues $config */
138                 $config = $this->dice->create(IManageConfigValues::class);
139                 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
140
141                 /** @var LoggerInterface $logger */
142                 $logger = $this->dice->create('$devLogger', ['dev']);
143
144                 self::assertInstanceOf(LoggerInterface::class, $logger);
145         }
146
147         public function testCache()
148         {
149                 /** @var ICanCache $cache */
150                 $cache = $this->dice->create(ICanCache::class);
151
152
153                 self::assertInstanceOf(ICanCache::class, $cache);
154         }
155
156         public function testMemoryCache()
157         {
158                 /** @var ICanCacheInMemory $cache */
159                 $cache = $this->dice->create(ICanCacheInMemory::class);
160
161                 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
162                 self::assertInstanceOf(ICanCache::class, $cache);
163         }
164
165         public function testLock()
166         {
167                 /** @var ICanLock $cache */
168                 $lock = $this->dice->create(ICanLock::class);
169
170                 self::assertInstanceOf(ICanLock::class, $lock);
171         }
172 }