]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Api/ApiTest.php
Make API testable & move PhotoAlbum tests to new destination
[friendica.git] / tests / src / Module / Api / ApiTest.php
1 <?php
2
3 namespace Friendica\Test\src\Module\Api;
4
5 use Dice\Dice;
6 use Friendica\Core\Addon;
7 use Friendica\Core\Hook;
8 use Friendica\Database\Database;
9 use Friendica\DI;
10 use Friendica\Security\Authentication;
11 use Friendica\Test\FixtureTest;
12 use Friendica\Test\Util\AuthenticationDouble;
13
14 class ApiTest extends FixtureTest
15 {
16         protected function setUp(): void
17         {
18                 parent::setUp(); // TODO: Change the autogenerated stub
19
20                 $this->dice = $this->dice
21                         ->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true]);
22                 DI::init($this->dice);
23
24                 $this->installAuthTest();
25         }
26
27         /**
28          * installs auththest.
29          *
30          * @throws \Exception
31          */
32         public function installAuthTest()
33         {
34                 $addon           = 'authtest';
35                 $addon_file_path = __DIR__ . '/../../../Util/authtest/authtest.php';
36                 $t               = @filemtime($addon_file_path);
37
38                 @include_once($addon_file_path);
39                 if (function_exists($addon . '_install')) {
40                         $func = $addon . '_install';
41                         $func(DI::app());
42                 }
43
44                 /** @var Database $dba */
45                 $dba = $this->dice->create(Database::class);
46
47                 $dba->insert('addon', [
48                         'name'         => $addon,
49                         'installed'    => true,
50                         'timestamp'    => $t,
51                         'plugin_admin' => function_exists($addon . '_addon_admin'),
52                         'hidden'       => file_exists('addon/' . $addon . '/.hidden')
53                 ]);
54
55                 Addon::loadAddons();
56                 Hook::loadHooks();
57         }
58 }