]> git.mxchange.org Git - friendica.git/blob - tests/functional/DependencyCheckTest.php
Use the owner, not the author
[friendica.git] / tests / functional / DependencyCheckTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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                 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
84                 if (version_compare(PHP_VERSION, '7.3') < 0) {
85                         $configCache = $this->dice->create(Cache::class);
86                         $configCache->set('database', 'disable_pdo', true);
87                 }
88
89                 /** @var Database $database */
90                 $database = $this->dice->create(Database::class);
91
92                 self::assertInstanceOf(Database::class, $database);
93                 self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
94                 self::assertNotNull($database->getConnection(), 'There is no database connection');
95
96                 $result = $database->p("SELECT 1");
97                 self::assertEquals('', $database->errorMessage(), 'There had been a database error message');
98                 self::assertEquals(0, $database->errorNo(), 'There had been a database error number');
99
100                 self::assertTrue($database->connected(), 'The database is not connected');
101         }
102
103         public function testAppMode()
104         {
105                 // PDO needs to be disabled for PHP 7.2, see https://jira.mariadb.org/browse/MDEV-24121
106                 if (version_compare(PHP_VERSION, '7.3') < 0) {
107                         $configCache = $this->dice->create(Cache::class);
108                         $configCache->set('database', 'disable_pdo', true);
109                 }
110
111                 /** @var App\Mode $mode */
112                 $mode = $this->dice->create(App\Mode::class);
113
114                 self::assertInstanceOf(App\Mode::class, $mode);
115
116                 self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
117                 self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
118                 self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
119
120                 self::assertTrue($mode->isNormal(), 'Not in normal mode');
121         }
122
123         public function testConfiguration()
124         {
125                 /** @var IManageConfigValues $config */
126                 $config = $this->dice->create(IManageConfigValues::class);
127
128                 self::assertInstanceOf(IManageConfigValues::class, $config);
129
130                 self::assertNotEmpty($config->get('database', 'username'));
131         }
132
133         public function testLogger()
134         {
135                 /** @var LoggerInterface $logger */
136                 $logger = $this->dice->create(LoggerInterface::class, [['$channel' => 'test']]);
137
138                 self::assertInstanceOf(LoggerInterface::class, $logger);
139         }
140
141         public function testDevLogger()
142         {
143                 /** @var IManageConfigValues $config */
144                 $config = $this->dice->create(IManageConfigValues::class);
145                 $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log');
146
147                 /** @var LoggerInterface $logger */
148                 $logger = $this->dice->create('$devLogger', ['dev']);
149
150                 self::assertInstanceOf(LoggerInterface::class, $logger);
151         }
152
153         public function testCache()
154         {
155                 /** @var ICanCache $cache */
156                 $cache = $this->dice->create(ICanCache::class);
157
158
159                 self::assertInstanceOf(ICanCache::class, $cache);
160         }
161
162         public function testMemoryCache()
163         {
164                 /** @var ICanCacheInMemory $cache */
165                 $cache = $this->dice->create(ICanCacheInMemory::class);
166
167                 // We need to check "just" ICache, because the default Cache is DB-Cache, which isn't a memorycache
168                 self::assertInstanceOf(ICanCache::class, $cache);
169         }
170
171         public function testLock()
172         {
173                 /** @var ICanLock $cache */
174                 $lock = $this->dice->create(ICanLock::class);
175
176                 self::assertInstanceOf(ICanLock::class, $lock);
177         }
178 }