3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Module\Api;
24 use Friendica\Core\Addon;
25 use Friendica\Core\Hook;
26 use Friendica\Database\Database;
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;
34 class ApiTest extends FixtureTest
37 * Assert that the string is XML and contain the root element.
39 * @param string $result XML string
40 * @param string $root_element Root element name
44 protected function assertXml(string $result = '', string $root_element = '')
46 self::assertStringStartsWith('<?xml version="1.0"?>', $result);
47 self::assertStringContainsString('<' . $root_element, $result);
48 // We could probably do more checks here.
51 protected function setUp(): void
53 parent::setUp(); // TODO: Change the autogenerated stub
55 $this->dice = $this->dice
56 ->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true])
57 ->addRule(ApiResponse::class, ['instanceOf' => ApiResponseDouble::class, 'shared' => true]);
58 DI::init($this->dice);
60 $this->installAuthTest();
63 protected function tearDown(): void
65 ApiResponseDouble::reset();
75 public function installAuthTest()
78 $addon_file_path = __DIR__ . '/../../../Util/authtest/authtest.php';
79 $t = @filemtime($addon_file_path);
81 @include_once($addon_file_path);
82 if (function_exists($addon . '_install')) {
83 $func = $addon . '_install';
87 /** @var Database $dba */
88 $dba = $this->dice->create(Database::class);
90 $dba->insert('addon', [
94 'plugin_admin' => function_exists($addon . '_addon_admin'),
95 'hidden' => file_exists('addon/' . $addon . '/.hidden')