]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Api/ApiTest.php
Make PHP-CS happy and add (c) header
[friendica.git] / tests / src / Module / Api / ApiTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\src\Module\Api;
23
24 use Friendica\Core\Addon;
25 use Friendica\Core\Hook;
26 use Friendica\Database\Database;
27 use Friendica\DI;
28 use Friendica\Module\Api\ApiResponse;
29 use Friendica\Security\Authentication;
30 use Friendica\Test\FixtureTest;
31 use Friendica\Test\Util\ApiResponseDouble;
32 use Friendica\Test\Util\AuthenticationDouble;
33
34 class ApiTest extends FixtureTest
35 {
36         protected function setUp(): void
37         {
38                 parent::setUp(); // TODO: Change the autogenerated stub
39
40                 $this->dice = $this->dice
41                         ->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true])
42                         ->addRule(ApiResponse::class, ['instanceOf' => ApiResponseDouble::class, 'shared' => true]);
43                 DI::init($this->dice);
44
45                 $this->installAuthTest();
46         }
47
48         protected function tearDown(): void
49         {
50                 ApiResponseDouble::reset();
51
52                 parent::tearDown();
53         }
54
55         /**
56          * installs auththest.
57          *
58          * @throws \Exception
59          */
60         public function installAuthTest()
61         {
62                 $addon           = 'authtest';
63                 $addon_file_path = __DIR__ . '/../../../Util/authtest/authtest.php';
64                 $t               = @filemtime($addon_file_path);
65
66                 @include_once($addon_file_path);
67                 if (function_exists($addon . '_install')) {
68                         $func = $addon . '_install';
69                         $func(DI::app());
70                 }
71
72                 /** @var Database $dba */
73                 $dba = $this->dice->create(Database::class);
74
75                 $dba->insert('addon', [
76                         'name'         => $addon,
77                         'installed'    => true,
78                         'timestamp'    => $t,
79                         'plugin_admin' => function_exists($addon . '_addon_admin'),
80                         'hidden'       => file_exists('addon/' . $addon . '/.hidden')
81                 ]);
82
83                 Addon::loadAddons();
84                 Hook::loadHooks();
85         }
86 }