]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Api/ApiTest.php
Moved API\Notification tests
[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\Module\Api\ApiResponse;
11 use Friendica\Security\Authentication;
12 use Friendica\Test\FixtureTest;
13 use Friendica\Test\Util\ApiResponseDouble;
14 use Friendica\Test\Util\AuthenticationDouble;
15
16 class ApiTest extends FixtureTest
17 {
18         protected function setUp(): void
19         {
20                 parent::setUp(); // TODO: Change the autogenerated stub
21
22                 $this->dice = $this->dice
23                         ->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true])
24                         ->addRule(ApiResponse::class, ['instanceOf' => ApiResponseDouble::class, 'shared' => true]);
25                 DI::init($this->dice);
26
27                 $this->installAuthTest();
28         }
29
30         protected function tearDown(): void
31         {
32                 ApiResponseDouble::reset();
33
34                 parent::tearDown();
35         }
36
37         /**
38          * installs auththest.
39          *
40          * @throws \Exception
41          */
42         public function installAuthTest()
43         {
44                 $addon           = 'authtest';
45                 $addon_file_path = __DIR__ . '/../../../Util/authtest/authtest.php';
46                 $t               = @filemtime($addon_file_path);
47
48                 @include_once($addon_file_path);
49                 if (function_exists($addon . '_install')) {
50                         $func = $addon . '_install';
51                         $func(DI::app());
52                 }
53
54                 /** @var Database $dba */
55                 $dba = $this->dice->create(Database::class);
56
57                 $dba->insert('addon', [
58                         'name'         => $addon,
59                         'installed'    => true,
60                         'timestamp'    => $t,
61                         'plugin_admin' => function_exists($addon . '_addon_admin'),
62                         'hidden'       => file_exists('addon/' . $addon . '/.hidden')
63                 ]);
64
65                 Addon::loadAddons();
66                 Hook::loadHooks();
67         }
68 }