mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-17 02:45:16 +02:00
Add ArrayFilterEvent, replace app_menu hook
This commit is contained in:
parent
5b28b3d28f
commit
715248d6a2
5 changed files with 158 additions and 8 deletions
66
tests/Unit/Event/ArrayFilterEventTest.php
Normal file
66
tests/Unit/Event/ArrayFilterEventTest.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?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\Unit\Event;
|
||||
|
||||
use Friendica\Event\ArrayFilterEvent;
|
||||
use Friendica\Event\NamedEvent;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ArrayFilterEventTest extends TestCase
|
||||
{
|
||||
public function testImplementationOfInstances(): void
|
||||
{
|
||||
$event = new ArrayFilterEvent('test', []);
|
||||
|
||||
$this->assertInstanceOf(NamedEvent::class, $event);
|
||||
}
|
||||
|
||||
public static function getPublicConstants(): array
|
||||
{
|
||||
return [
|
||||
[ArrayFilterEvent::APP_MENU, 'friendica.data.app_menu'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPublicConstants
|
||||
*/
|
||||
public function testPublicConstantsAreAvailable($value, $expected): void
|
||||
{
|
||||
$this->assertSame($expected, $value);
|
||||
}
|
||||
|
||||
public function testGetNameReturnsName(): void
|
||||
{
|
||||
$event = new ArrayFilterEvent('test', []);
|
||||
|
||||
$this->assertSame('test', $event->getName());
|
||||
}
|
||||
|
||||
public function testGetArrayReturnsCorrectString(): void
|
||||
{
|
||||
$data = ['original'];
|
||||
|
||||
$event = new ArrayFilterEvent('test', $data);
|
||||
|
||||
$this->assertSame($data, $event->getArray());
|
||||
}
|
||||
|
||||
public function testSetArrayUpdatesHtml(): void
|
||||
{
|
||||
$event = new ArrayFilterEvent('test', ['original']);
|
||||
|
||||
$expected = ['updated'];
|
||||
|
||||
$event->setArray($expected);
|
||||
|
||||
$this->assertSame($expected, $event->getArray());
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
namespace Friendica\Test\Unit\EventSubscriber;
|
||||
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
use Friendica\Event\ArrayFilterEvent;
|
||||
use Friendica\Event\ConfigLoadedEvent;
|
||||
use Friendica\Event\Event;
|
||||
use Friendica\Event\HtmlFilterEvent;
|
||||
|
@ -23,6 +24,7 @@ class HookEventBridgeTest extends TestCase
|
|||
$expected = [
|
||||
Event::INIT => 'onNamedEvent',
|
||||
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
||||
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
||||
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
|
||||
|
@ -105,6 +107,34 @@ class HookEventBridgeTest extends TestCase
|
|||
HookEventBridge::onConfigLoadedEvent($event);
|
||||
}
|
||||
|
||||
public static function getArrayFilterEventData(): array
|
||||
{
|
||||
return [
|
||||
['test', 'test'],
|
||||
[ArrayFilterEvent::APP_MENU, 'app_menu'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getArrayFilterEventData
|
||||
*/
|
||||
public function testOnArrayFilterEventCallsHookWithCorrectValue($name, $expected): void
|
||||
{
|
||||
$event = new ArrayFilterEvent($name, ['original']);
|
||||
|
||||
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
|
||||
$reflectionProperty->setValue(null, function (string $name, $data) use ($expected) {
|
||||
$this->assertSame($expected, $name);
|
||||
$this->assertSame(['original'], $data);
|
||||
|
||||
return $data;
|
||||
});
|
||||
|
||||
HookEventBridge::onArrayFilterEvent($event);
|
||||
}
|
||||
|
||||
public static function getHtmlFilterEventData(): array
|
||||
{
|
||||
return [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue