Merge branch 'develop' into rework-addon-class

This commit is contained in:
Art4 2025-05-13 07:06:09 +00:00
commit d88119139f
127 changed files with 2694 additions and 1217 deletions

View file

@ -11,6 +11,7 @@ use Friendica\Capabilities\ICanCreateResponses;
use Friendica\Core\Addon\AddonHelper;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\Hooks\HookEventBridge;
use Friendica\DI;
use Friendica\Module\Special\HTTPException;
use Friendica\Security\Authentication;
@ -159,6 +160,13 @@ abstract class ApiTestCase extends FixtureTestCase
;
DI::init($this->dice);
/** @var \Friendica\Event\EventDispatcher */
$eventDispatcher = DI::eventDispatcher();
foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
$eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
}
$this->httpExceptionMock = $this->dice->create(HTTPException::class);
AuthTestConfig::$authenticated = true;

View file

@ -32,15 +32,45 @@ class HookEventBridgeTest extends TestCase
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
ArrayFilterEvent::POST_LOCAL_START => 'onArrayFilterEvent',
ArrayFilterEvent::POST_LOCAL => 'onArrayFilterEvent',
ArrayFilterEvent::POST_LOCAL_END => 'onArrayFilterEvent',
ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT => 'onPermissionTooltipContentEvent',
ArrayFilterEvent::INSERT_POST_LOCAL_START => 'onArrayFilterEvent',
ArrayFilterEvent::INSERT_POST_LOCAL => 'onInsertPostLocalEvent',
ArrayFilterEvent::INSERT_POST_LOCAL_END => 'onInsertPostLocalEndEvent',
ArrayFilterEvent::INSERT_POST_REMOTE => 'onArrayFilterEvent',
ArrayFilterEvent::INSERT_POST_REMOTE_END => 'onArrayFilterEvent',
ArrayFilterEvent::PREPARE_POST_START => 'onPreparePostStartEvent',
ArrayFilterEvent::PREPARE_POST_FILTER_CONTENT => 'onArrayFilterEvent',
ArrayFilterEvent::PREPARE_POST => 'onArrayFilterEvent',
ArrayFilterEvent::PREPARE_POST_END => 'onArrayFilterEvent',
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
ArrayFilterEvent::PHOTO_UPLOAD_START => 'onPhotoUploadStartEvent',
ArrayFilterEvent::PHOTO_UPLOAD => 'onArrayFilterEvent',
ArrayFilterEvent::PHOTO_UPLOAD_END => 'onPhotoUploadEndEvent',
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
ArrayFilterEvent::NETWORK_CONTENT_START => 'onArrayFilterEvent',
ArrayFilterEvent::NETWORK_CONTENT_TABS => 'onArrayFilterEvent',
ArrayFilterEvent::PARSE_LINK => 'onArrayFilterEvent',
ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
ArrayFilterEvent::FETCH_ITEM_BY_LINK => 'onArrayFilterEvent',
ArrayFilterEvent::ITEM_TAGGED => 'onArrayFilterEvent',
ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::CACHE_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::CHECK_ITEM_NOTIFICATION => 'onArrayFilterEvent',
ArrayFilterEvent::ENOTIFY => 'onArrayFilterEvent',
ArrayFilterEvent::ENOTIFY_STORE => 'onArrayFilterEvent',
ArrayFilterEvent::ENOTIFY_MAIL => 'onArrayFilterEvent',
ArrayFilterEvent::DETECT_LANGUAGES => 'onArrayFilterEvent',
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
ArrayFilterEvent::DIRECTORY_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::CONTACT_PHOTO_MENU => 'onArrayFilterEvent',
ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY => 'onProfileSidebarEntryEvent',
ArrayFilterEvent::PROFILE_SIDEBAR => 'onArrayFilterEvent',
ArrayFilterEvent::PROFILE_TABS => 'onArrayFilterEvent',
ArrayFilterEvent::PROFILE_SETTINGS_FORM => 'onArrayFilterEvent',
ArrayFilterEvent::PROFILE_SETTINGS_POST => 'onArrayFilterEvent',
ArrayFilterEvent::MODERATION_USERS_TABS => 'onArrayFilterEvent',
ArrayFilterEvent::ACL_LOOKUP_END => 'onArrayFilterEvent',
ArrayFilterEvent::OEMBED_FETCH_END => 'onOembedFetchEndEvent',
ArrayFilterEvent::PAGE_INFO => 'onArrayFilterEvent',
ArrayFilterEvent::SMILEY_LIST => 'onArrayFilterEvent',
@ -51,11 +81,34 @@ class HookEventBridgeTest extends TestCase
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => 'onArrayFilterEvent',
ArrayFilterEvent::FOLLOW_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::UNFOLLOW_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::REVOKE_FOLLOW_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::BLOCK_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::UNBLOCK_CONTACT => 'onArrayFilterEvent',
ArrayFilterEvent::EDIT_CONTACT_FORM => 'onArrayFilterEvent',
ArrayFilterEvent::EDIT_CONTACT_POST => 'onArrayFilterEvent',
ArrayFilterEvent::AVATAR_LOOKUP => 'onArrayFilterEvent',
ArrayFilterEvent::ACCOUNT_AUTHENTICATE => 'onArrayFilterEvent',
ArrayFilterEvent::ACCOUNT_REGISTER_FORM => 'onArrayFilterEvent',
ArrayFilterEvent::ACCOUNT_REGISTER_POST => 'onArrayFilterEvent',
ArrayFilterEvent::ACCOUNT_REGISTER => 'onAccountRegisterEvent',
ArrayFilterEvent::ACCOUNT_REMOVE => 'onAccountRemoveEvent',
ArrayFilterEvent::EVENT_CREATED => 'onEventCreatedEvent',
ArrayFilterEvent::EVENT_UPDATED => 'onEventUpdatedEvent',
ArrayFilterEvent::ADD_WORKER_TASK => 'onArrayFilterEvent',
ArrayFilterEvent::STORAGE_CONFIG => 'onArrayFilterEvent',
ArrayFilterEvent::STORAGE_INSTANCE => 'onArrayFilterEvent',
ArrayFilterEvent::DB_STRUCTURE_DEFINITION => 'onArrayFilterEvent',
ArrayFilterEvent::DB_VIEW_DEFINITION => 'onArrayFilterEvent',
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
HtmlFilterEvent::MOD_HOME_CONTENT => 'onHtmlFilterEvent',
HtmlFilterEvent::MOD_ABOUT_CONTENT => 'onHtmlFilterEvent',
HtmlFilterEvent::MOD_PROFILE_CONTENT => 'onHtmlFilterEvent',
HtmlFilterEvent::JOT_TOOL => 'onHtmlFilterEvent',
HtmlFilterEvent::CONTACT_BLOCK_END => 'onHtmlFilterEvent',
];
@ -167,6 +220,155 @@ class HookEventBridgeTest extends TestCase
HookEventBridge::onCollectRoutesEvent($event);
}
public function testOnPermissionTooltipContentEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT, ['model' => ['uid' => -1]]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, array $data): array {
$this->assertSame('lockview_content', $name);
$this->assertSame(['uid' => -1], $data);
return ['uid' => 123];
});
HookEventBridge::onPermissionTooltipContentEvent($event);
$this->assertSame(
['model' => ['uid' => 123]],
$event->getArray(),
);
}
public function testOnInsertPostLocalEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL, ['item' => ['id' => -1]]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, array $data): array {
$this->assertSame('post_local', $name);
$this->assertSame(['id' => -1], $data);
return ['id' => 123];
});
HookEventBridge::onInsertPostLocalEvent($event);
$this->assertSame(
['item' => ['id' => 123]],
$event->getArray(),
);
}
public function testOnInsertPostLocalEndEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL_END, ['item' => ['id' => -1]]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, array $data): array {
$this->assertSame('post_local_end', $name);
$this->assertSame(['id' => -1], $data);
return ['id' => 123];
});
HookEventBridge::onInsertPostLocalEndEvent($event);
$this->assertSame(
['item' => ['id' => 123]],
$event->getArray(),
);
}
public function testOnPreparePostStartEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::PREPARE_POST_START, ['item' => ['id' => -1]]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, array $data): array {
$this->assertSame('prepare_body_init', $name);
$this->assertSame(['id' => -1], $data);
return ['id' => 123];
});
HookEventBridge::onPreparePostStartEvent($event);
$this->assertSame(
['item' => ['id' => 123]],
$event->getArray(),
);
}
public function testOnPhotoUploadStartEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::PHOTO_UPLOAD_START, ['request' => ['album' => -1]]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, array $data): array {
$this->assertSame('photo_post_init', $name);
$this->assertSame(['album' => -1], $data);
return ['album' => 123];
});
HookEventBridge::onPhotoUploadStartEvent($event);
$this->assertSame(
['request' => ['album' => 123]],
$event->getArray(),
);
}
public function testOnPhotoUploadEndEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::PHOTO_UPLOAD_END, ['id' => -1]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, int $data): int {
$this->assertSame('photo_post_end', $name);
$this->assertSame(-1, $data);
return 123;
});
HookEventBridge::onPhotoUploadEndEvent($event);
}
public function testOnProfileSidebarEntryEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY, ['profile' => ['uid' => 0, 'name' => 'original']]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, array $data): array {
$this->assertSame('profile_sidebar_enter', $name);
$this->assertSame(['uid' => 0, 'name' => 'original'], $data);
return ['uid' => 0, 'name' => 'changed'];
});
HookEventBridge::onProfileSidebarEntryEvent($event);
$this->assertSame(
['profile' => ['uid' => 0, 'name' => 'changed']],
$event->getArray(),
);
}
public function testOnOembedFetchEndEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::OEMBED_FETCH_END, ['url' => 'original_url']);
@ -255,6 +457,74 @@ class HookEventBridgeTest extends TestCase
);
}
public function testOnEventCreatedEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::EVENT_CREATED, ['event' => ['id' => 123]]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, int $data): int {
$this->assertSame('event_created', $name);
$this->assertSame(123, $data);
return 123;
});
HookEventBridge::onEventCreatedEvent($event);
}
public function testOnAccountRegisterEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::ACCOUNT_REGISTER, ['uid' => 123]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, int $data): int {
$this->assertSame('register_account', $name);
$this->assertSame(123, $data);
return $data;
});
HookEventBridge::onAccountRegisterEvent($event);
}
public function testOnAccountRemoveEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::ACCOUNT_REMOVE, ['user' => ['uid' => 123]]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, array $data): array {
$this->assertSame('remove_user', $name);
$this->assertSame(['uid' => 123], $data);
return $data;
});
HookEventBridge::onAccountRemoveEvent($event);
}
public function testOnEventUpdatedEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::EVENT_UPDATED, ['event' => ['id' => 123]]);
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, function (string $name, int $data): int {
$this->assertSame('event_updated', $name);
$this->assertSame(123, $data);
return 123;
});
HookEventBridge::onEventUpdatedEvent($event);
}
public static function getArrayFilterEventData(): array
{
return [
@ -263,21 +533,64 @@ class HookEventBridgeTest extends TestCase
[ArrayFilterEvent::NAV_INFO, 'nav_info'],
[ArrayFilterEvent::FEATURE_ENABLED, 'isEnabled'],
[ArrayFilterEvent::FEATURE_GET, 'get'],
[ArrayFilterEvent::POST_LOCAL_START, 'post_local_start'],
[ArrayFilterEvent::POST_LOCAL, 'post_local'],
[ArrayFilterEvent::POST_LOCAL_END, 'post_local_end'],
[ArrayFilterEvent::INSERT_POST_LOCAL_START, 'post_local_start'],
[ArrayFilterEvent::INSERT_POST_REMOTE, 'post_remote'],
[ArrayFilterEvent::INSERT_POST_REMOTE_END, 'post_remote_end'],
[ArrayFilterEvent::PREPARE_POST_FILTER_CONTENT, 'prepare_body_content_filter'],
[ArrayFilterEvent::PREPARE_POST, 'prepare_body'],
[ArrayFilterEvent::PREPARE_POST_END, 'prepare_body_final'],
[ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'photo_upload_form'],
[ArrayFilterEvent::PHOTO_UPLOAD, 'photo_post_file'],
[ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
[ArrayFilterEvent::NETWORK_CONTENT_START, 'network_content_init'],
[ArrayFilterEvent::NETWORK_CONTENT_TABS, 'network_tabs'],
[ArrayFilterEvent::PARSE_LINK, 'parse_link'],
[ArrayFilterEvent::CONVERSATION_START, 'conversation_start'],
[ArrayFilterEvent::FETCH_ITEM_BY_LINK, 'item_by_link'],
[ArrayFilterEvent::ITEM_TAGGED, 'tagged'],
[ArrayFilterEvent::DISPLAY_ITEM, 'display_item'],
[ArrayFilterEvent::CACHE_ITEM, 'put_item_in_cache'],
[ArrayFilterEvent::CHECK_ITEM_NOTIFICATION, 'check_item_notification'],
[ArrayFilterEvent::ENOTIFY, 'enotify'],
[ArrayFilterEvent::ENOTIFY_STORE, 'enotify_store'],
[ArrayFilterEvent::ENOTIFY_MAIL, 'enotify_mail'],
[ArrayFilterEvent::DETECT_LANGUAGES, 'detect_languages'],
[ArrayFilterEvent::RENDER_LOCATION, 'render_location'],
[ArrayFilterEvent::ITEM_PHOTO_MENU, 'item_photo_menu'],
[ArrayFilterEvent::DIRECTORY_ITEM, 'directory_item'],
[ArrayFilterEvent::CONTACT_PHOTO_MENU, 'contact_photo_menu'],
[ArrayFilterEvent::PROFILE_SIDEBAR, 'profile_sidebar'],
[ArrayFilterEvent::PROFILE_TABS, 'profile_tabs'],
[ArrayFilterEvent::PROFILE_SETTINGS_FORM, 'profile_edit'],
[ArrayFilterEvent::PROFILE_SETTINGS_POST, 'profile_post'],
[ArrayFilterEvent::MODERATION_USERS_TABS, 'moderation_users_tabs'],
[ArrayFilterEvent::ACL_LOOKUP_END, 'acl_lookup_end'],
[ArrayFilterEvent::PAGE_INFO, 'page_info_data'],
[ArrayFilterEvent::SMILEY_LIST, 'smilie'],
[ArrayFilterEvent::JOT_NETWORKS, 'jot_networks'],
[ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'support_follow'],
[ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'support_revoke_follow'],
[ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'support_probe'],
[ArrayFilterEvent::FOLLOW_CONTACT, 'follow'],
[ArrayFilterEvent::UNFOLLOW_CONTACT, 'unfollow'],
[ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, 'revoke_follow'],
[ArrayFilterEvent::BLOCK_CONTACT, 'block'],
[ArrayFilterEvent::UNBLOCK_CONTACT, 'unblock'],
[ArrayFilterEvent::EDIT_CONTACT_FORM, 'contact_edit'],
[ArrayFilterEvent::EDIT_CONTACT_POST, 'contact_edit_post'],
[ArrayFilterEvent::AVATAR_LOOKUP, 'avatar_lookup'],
[ArrayFilterEvent::ACCOUNT_AUTHENTICATE, 'authenticate'],
[ArrayFilterEvent::ACCOUNT_REGISTER_FORM, 'register_form'],
[ArrayFilterEvent::ACCOUNT_REGISTER_POST, 'register_post'],
[ArrayFilterEvent::ACCOUNT_REGISTER, 'register_account'],
[ArrayFilterEvent::ACCOUNT_REMOVE, 'remove_user'],
[ArrayFilterEvent::EVENT_CREATED, 'event_created'],
[ArrayFilterEvent::EVENT_UPDATED, 'event_updated'],
[ArrayFilterEvent::ADD_WORKER_TASK, 'proc_run'],
[ArrayFilterEvent::STORAGE_CONFIG, 'storage_config'],
[ArrayFilterEvent::STORAGE_INSTANCE, 'storage_instance'],
[ArrayFilterEvent::DB_STRUCTURE_DEFINITION, 'dbstructure_definition'],
[ArrayFilterEvent::DB_VIEW_DEFINITION, 'dbview_definition'],
];
}
@ -310,6 +623,9 @@ class HookEventBridgeTest extends TestCase
[HtmlFilterEvent::PAGE_HEADER, 'page_header'],
[HtmlFilterEvent::PAGE_CONTENT_TOP, 'page_content_top'],
[HtmlFilterEvent::PAGE_END, 'page_end'],
[HtmlFilterEvent::MOD_HOME_CONTENT, 'home_content'],
[HtmlFilterEvent::MOD_ABOUT_CONTENT, 'about_hook'],
[HtmlFilterEvent::MOD_PROFILE_CONTENT, 'profile_advanced'],
[HtmlFilterEvent::JOT_TOOL, 'jot_tool'],
[HtmlFilterEvent::CONTACT_BLOCK_END, 'contact_block_end'],
];

View file

@ -29,24 +29,75 @@ class ArrayFilterEventTest extends TestCase
[ArrayFilterEvent::NAV_INFO, 'friendica.data.nav_info'],
[ArrayFilterEvent::FEATURE_ENABLED, 'friendica.data.feature_enabled'],
[ArrayFilterEvent::FEATURE_GET, 'friendica.data.feature_get'],
[ArrayFilterEvent::POST_LOCAL_START, 'friendica.data.post_local_start'],
[ArrayFilterEvent::POST_LOCAL, 'friendica.data.post_local'],
[ArrayFilterEvent::POST_LOCAL_END, 'friendica.data.post_local_end'],
[ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT, 'friendica.data.permission_tooltip_content'],
[ArrayFilterEvent::INSERT_POST_LOCAL_START, 'friendica.data.insert_post_local_start'],
[ArrayFilterEvent::INSERT_POST_LOCAL, 'friendica.data.insert_post_local'],
[ArrayFilterEvent::INSERT_POST_LOCAL_END, 'friendica.data.insert_post_local_end'],
[ArrayFilterEvent::INSERT_POST_REMOTE, 'friendica.data.insert_post_remote'],
[ArrayFilterEvent::INSERT_POST_REMOTE_END, 'friendica.data.insert_post_remote_end'],
[ArrayFilterEvent::PREPARE_POST_START, 'friendica.data.prepare_post_start'],
[ArrayFilterEvent::PREPARE_POST_FILTER_CONTENT, 'friendica.data.prepare_post_filter_content'],
[ArrayFilterEvent::PREPARE_POST, 'friendica.data.prepare_post'],
[ArrayFilterEvent::PREPARE_POST_END, 'friendica.data.prepare_post_end'],
[ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'friendica.data.photo_upload_form'],
[ArrayFilterEvent::PHOTO_UPLOAD_START, 'friendica.data.photo_upload_start'],
[ArrayFilterEvent::PHOTO_UPLOAD, 'friendica.data.photo_upload'],
[ArrayFilterEvent::PHOTO_UPLOAD_END, 'friendica.data.photo_upload_end'],
[ArrayFilterEvent::NETWORK_TO_NAME, 'friendica.data.network_to_name'],
[ArrayFilterEvent::NETWORK_CONTENT_START, 'friendica.data.network_content_start'],
[ArrayFilterEvent::NETWORK_CONTENT_TABS, 'friendica.data.network_content_tabs'],
[ArrayFilterEvent::PARSE_LINK, 'friendica.data.parse_link'],
[ArrayFilterEvent::CONVERSATION_START, 'friendica.data.conversation_start'],
[ArrayFilterEvent::FETCH_ITEM_BY_LINK, 'friendica.data.fetch_item_by_link'],
[ArrayFilterEvent::ITEM_TAGGED, 'friendica.data.item_tagged'],
[ArrayFilterEvent::DISPLAY_ITEM, 'friendica.data.display_item'],
[ArrayFilterEvent::CACHE_ITEM, 'friendica.data.cache_item'],
[ArrayFilterEvent::CHECK_ITEM_NOTIFICATION, 'friendica.data.check_item_notification'],
[ArrayFilterEvent::ENOTIFY, 'friendica.data.enotify'],
[ArrayFilterEvent::ENOTIFY_STORE, 'friendica.data.enotify_store'],
[ArrayFilterEvent::ENOTIFY_MAIL, 'friendica.data.enotify_mail'],
[ArrayFilterEvent::DETECT_LANGUAGES, 'friendica.data.detect_languages'],
[ArrayFilterEvent::RENDER_LOCATION, 'friendica.data.render_location'],
[ArrayFilterEvent::ITEM_PHOTO_MENU, 'friendica.data.item_photo_menu'],
[ArrayFilterEvent::DIRECTORY_ITEM, 'friendica.data.directory_item'],
[ArrayFilterEvent::CONTACT_PHOTO_MENU, 'friendica.data.contact_photo_menu'],
[ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY, 'friendica.data.profile_sidebar_entry'],
[ArrayFilterEvent::PROFILE_SIDEBAR, 'friendica.data.profile_sidebar'],
[ArrayFilterEvent::PROFILE_TABS, 'friendica.data.profile_tabs'],
[ArrayFilterEvent::PROFILE_SETTINGS_FORM, 'friendica.data.profile_settings_form'],
[ArrayFilterEvent::PROFILE_SETTINGS_POST, 'friendica.data.profile_settings_post'],
[ArrayFilterEvent::MODERATION_USERS_TABS, 'friendica.data.moderation_users_tabs'],
[ArrayFilterEvent::ACL_LOOKUP_END, 'friendica.data.acl_lookup_end'],
[ArrayFilterEvent::OEMBED_FETCH_END, 'friendica.data.oembed_fetch_end'],
[ArrayFilterEvent::PAGE_INFO, 'friendica.data.page_info'],
[ArrayFilterEvent::SMILEY_LIST, 'friendica.data.smiley_list'],
[ArrayFilterEvent::BBCODE_TO_HTML_START, 'friendica.data.bbcode_to_html_start'],
[ArrayFilterEvent::HTML_TO_BBCODE_END, 'friendica.data.html_to_bbcode_end'],
[ArrayFilterEvent::BBCODE_TO_MARKDOWN_END, 'friendica.data.bbcode_to_markdown_end'],
[ArrayFilterEvent::JOT_NETWORKS, 'friendica.data.jot_networks'],
[ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'friendica.data.protocol_supports_follow'],
[ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'friendica.data.protocol_supports_revoke_follow'],
[ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'friendica.data.protocol_supports_probe'],
[ArrayFilterEvent::FOLLOW_CONTACT, 'friendica.data.follow_contact'],
[ArrayFilterEvent::UNFOLLOW_CONTACT, 'friendica.data.unfollow_contact'],
[ArrayFilterEvent::REVOKE_FOLLOW_CONTACT, 'friendica.data.revoke_follow_contact'],
[ArrayFilterEvent::BLOCK_CONTACT, 'friendica.data.block_contact'],
[ArrayFilterEvent::UNBLOCK_CONTACT, 'friendica.data.unblock_contact'],
[ArrayFilterEvent::EDIT_CONTACT_FORM, 'friendica.data.edit_contact_form'],
[ArrayFilterEvent::EDIT_CONTACT_POST, 'friendica.data.edit_contact_post'],
[ArrayFilterEvent::AVATAR_LOOKUP, 'friendica.data.avatar_lookup'],
[ArrayFilterEvent::ACCOUNT_AUTHENTICATE, 'friendica.data.account_authenticate'],
[ArrayFilterEvent::ACCOUNT_REGISTER_FORM, 'friendica.data.account_register_form'],
[ArrayFilterEvent::ACCOUNT_REGISTER_POST, 'friendica.data.account_register_post'],
[ArrayFilterEvent::ACCOUNT_REGISTER, 'friendica.data.account_register'],
[ArrayFilterEvent::ACCOUNT_REMOVE, 'friendica.data.account_remove'],
[ArrayFilterEvent::EVENT_CREATED, 'friendica.data.event_created'],
[ArrayFilterEvent::EVENT_UPDATED, 'friendica.data.event_updated'],
[ArrayFilterEvent::ADD_WORKER_TASK, 'friendica.data.add_worker_task'],
[ArrayFilterEvent::STORAGE_CONFIG, 'friendica.data.storage_config'],
[ArrayFilterEvent::STORAGE_INSTANCE, 'friendica.data.storage_instance'],
[ArrayFilterEvent::DB_STRUCTURE_DEFINITION, 'friendica.data.db_structure_definition'],
[ArrayFilterEvent::DB_VIEW_DEFINITION, 'friendica.data.db_view_definition'],
];
}

View file

@ -27,8 +27,14 @@ class HtmlFilterEventTest extends TestCase
return [
[HtmlFilterEvent::HEAD, 'friendica.html.head'],
[HtmlFilterEvent::FOOTER, 'friendica.html.footer'],
[HtmlFilterEvent::PAGE_HEADER, 'friendica.html.page_header'],
[HtmlFilterEvent::PAGE_CONTENT_TOP, 'friendica.html.page_content_top'],
[HtmlFilterEvent::PAGE_END, 'friendica.html.page_end'],
[HtmlFilterEvent::MOD_HOME_CONTENT, 'friendica.html.mod_home_content'],
[HtmlFilterEvent::MOD_ABOUT_CONTENT, 'friendica.html.mod_about_content'],
[HtmlFilterEvent::MOD_PROFILE_CONTENT, 'friendica.html.mod_profile_content'],
[HtmlFilterEvent::JOT_TOOL, 'friendica.html.jot_tool'],
[HtmlFilterEvent::CONTACT_BLOCK_END, 'friendica.html.contact_block_end'],
];
}

View file

@ -0,0 +1,31 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Test\Util;
use Psr\EventDispatcher\EventDispatcherInterface;
/**
* Defines a dispatcher for events.
*/
final class FakeEventDispatcher implements EventDispatcherInterface
{
/**
* Provide all relevant listeners with an event to process.
*
* @template T of object
* @param T $event
*
* @return T The passed $event MUST be returned
*/
public function dispatch(object $event): object
{
return $event;
}
}

View file

@ -17,16 +17,16 @@ class SyslogLoggerFactoryWrapper extends SyslogLogger
{
public function create(IManageConfigValues $config): LoggerInterface
{
$logOpts = $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS;
$logFacility = $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY;
$logOpts = (int) $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS;
$logFacility = (int) $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY;
$loglevel = SyslogLogger::mapLegacyConfigDebugLevel($config->get('system', 'loglevel'));
if (array_key_exists($loglevel, SyslogLoggerClass::logLevels)) {
$loglevel = SyslogLoggerClass::logLevels[$loglevel];
} else {
if (!array_key_exists($loglevel, SyslogLoggerClass::logLevels)) {
throw new LogLevelException(sprintf('The level "%s" is not valid.', $loglevel));
}
$loglevel = SyslogLoggerClass::logLevels[$loglevel];
return new SyslogLoggerWrapper($this->channel, $this->introspection, $loglevel, $logOpts, $logFacility);
}
}

View file

@ -17,7 +17,7 @@ class SyslogLoggerWrapper extends SyslogLogger
{
private $content;
public function __construct(string $channel, IHaveCallIntrospections $introspection, string $logLevel, string $logOptions, string $logFacility)
public function __construct(string $channel, IHaveCallIntrospections $introspection, int $logLevel, int $logOptions, int $logFacility)
{
parent::__construct($channel, $introspection, $logLevel, $logOptions, $logFacility);

View file

@ -152,13 +152,13 @@ class UserSessionTest extends MockedTestCase
'data' => [
'remote' => ['3' => '21'],
],
'expected' => false,
'expected' => 0,
],
'empty' => [
'cid' => 21,
'data' => [
],
'expected' => false,
'expected' => 0,
],
];
}
@ -167,7 +167,7 @@ class UserSessionTest extends MockedTestCase
public function testGetUserIdForVisitorContactID(int $cid, array $data, $expected)
{
$userSession = new UserSession(new ArraySession($data));
$this->assertEquals($expected, $userSession->getUserIDForVisitorContactID($cid));
$this->assertSame($expected, $userSession->getUserIDForVisitorContactID($cid));
}
public function dataAuthenticated()

View file

@ -23,12 +23,13 @@ use Friendica\Core\Storage\Type\SystemResource;
use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Core\Config\Factory\Config;
use Friendica\Core\Hooks\HookEventBridge;
use Friendica\Core\Storage\Type;
use Friendica\Test\DatabaseTestCase;
use Friendica\Test\Util\CreateDatabaseTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\FakeEventDispatcher;
use org\bovigo\vfs\vfsStream;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Friendica\Test\Util\SampleStorageBackend;
@ -38,8 +39,6 @@ class StorageManagerTest extends DatabaseTestCase
/** @var IManageConfigValues */
private $config;
/** @var LoggerInterface */
private $logger;
/** @var L10n */
private $l10n;
@ -56,7 +55,6 @@ class StorageManagerTest extends DatabaseTestCase
vfsStream::newDirectory(Type\FilesystemConfig::DEFAULT_BASE_FOLDER, 0777)->at($this->root);
$this->logger = new NullLogger();
$this->database = $this->getDbInstance();
$configFactory = new Config();
@ -87,7 +85,14 @@ class StorageManagerTest extends DatabaseTestCase
*/
public function testInstance()
{
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
self::assertInstanceOf(StorageManager::class, $storageManager);
}
@ -149,7 +154,14 @@ class StorageManagerTest extends DatabaseTestCase
$this->config->set('storage', 'name', $name);
}
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
if ($interface === ICanWriteToStorage::class) {
$storage = $storageManager->getWritableStorageByName($name);
@ -169,7 +181,14 @@ class StorageManagerTest extends DatabaseTestCase
*/
public function testIsValidBackend($name, $valid, $interface, $assert, $assertName)
{
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
// true in every of the backends
self::assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
@ -183,7 +202,14 @@ class StorageManagerTest extends DatabaseTestCase
*/
public function testListBackends()
{
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
self::assertEquals(StorageManager::DEFAULT_BACKENDS, $storageManager->listBackends());
}
@ -199,7 +225,14 @@ class StorageManagerTest extends DatabaseTestCase
static::markTestSkipped('only works for ICanWriteToStorage');
}
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
$selBackend = $storageManager->getWritableStorageByName($name);
$storageManager->setBackend($selBackend);
@ -219,7 +252,14 @@ class StorageManagerTest extends DatabaseTestCase
$this->expectException(InvalidClassStorageException::class);
}
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
self::assertInstanceOf($assert, $storageManager->getBackend());
}
@ -240,7 +280,14 @@ class StorageManagerTest extends DatabaseTestCase
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
DI::init($dice);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
self::assertTrue($storageManager->register(SampleStorageBackend::class));
@ -268,7 +315,21 @@ class StorageManagerTest extends DatabaseTestCase
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null]);
DI::init($dice);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
/** @var \Friendica\Event\EventDispatcher */
$eventDispatcher = DI::eventDispatcher();
foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
$eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
}
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
$eventDispatcher,
$this->l10n,
false
);
self::assertTrue($storageManager->register(SampleStorageBackend::class));
@ -307,8 +368,15 @@ class StorageManagerTest extends DatabaseTestCase
$this->loadFixture(__DIR__ . '/../../../../datasets/storage/database.fixture.php', $this->database);
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storage = $storageManager->getWritableStorageByName($name);
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
$storage = $storageManager->getWritableStorageByName($name);
$storageManager->move($storage);
$photos = $this->database->select('photo', ['backend-ref', 'backend-class', 'id', 'data']);
@ -331,8 +399,15 @@ class StorageManagerTest extends DatabaseTestCase
$this->expectException(InvalidClassStorageException::class);
$this->expectExceptionMessage('Backend SystemResource is not valid');
$storageManager = new StorageManager($this->database, $this->config, $this->logger, $this->l10n, false);
$storage = $storageManager->getWritableStorageByName(SystemResource::getName());
$storageManager = new StorageManager(
$this->database,
$this->config,
new NullLogger(),
new FakeEventDispatcher(),
$this->l10n,
false
);
$storage = $storageManager->getWritableStorageByName(SystemResource::getName());
$storageManager->move($storage);
}
}