mirror of
https://github.com/flarum/core.git
synced 2025-07-30 21:20:24 +02:00
Add Notification Channel Extender (#2432)
This commit is contained in:
@@ -11,9 +11,12 @@ namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\Driver\NotificationDriverInterface;
|
||||
use Flarum\Notification\Notification;
|
||||
use Flarum\Notification\NotificationSyncer;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
|
||||
class NotificationTest extends \Flarum\Tests\integration\TestCase
|
||||
class NotificationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
@@ -23,6 +26,27 @@ class NotificationTest extends \Flarum\Tests\integration\TestCase
|
||||
$this->assertArrayNotHasKey('customNotificationType', Notification::getSubjectModels());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function notification_serializer_doesnt_exist_by_default()
|
||||
{
|
||||
$this->app();
|
||||
|
||||
$this->assertNotContains(
|
||||
'customNotificationTypeSerializer',
|
||||
$this->app->getContainer()->make('flarum.api.notification_serializers')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function notification_driver_doesnt_exist_by_default()
|
||||
{
|
||||
$this->assertArrayNotHasKey('customNotificationDriver', NotificationSyncer::getNotificationDrivers());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
@@ -37,6 +61,64 @@ class NotificationTest extends \Flarum\Tests\integration\TestCase
|
||||
|
||||
$this->assertArrayHasKey('customNotificationType', Notification::getSubjectModels());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function notification_serializer_exists_if_added()
|
||||
{
|
||||
$this->extend((new Extend\Notification)->type(
|
||||
CustomNotificationType::class,
|
||||
'customNotificationTypeSerializer'
|
||||
));
|
||||
|
||||
$this->app();
|
||||
|
||||
$this->assertContains(
|
||||
'customNotificationTypeSerializer',
|
||||
$this->app->getContainer()->make('flarum.api.notification_serializers')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function notification_driver_exists_if_added()
|
||||
{
|
||||
$this->extend((new Extend\Notification())->driver(
|
||||
'customNotificationDriver',
|
||||
CustomNotificationDriver::class
|
||||
));
|
||||
|
||||
$this->app();
|
||||
|
||||
$this->assertArrayHasKey('customNotificationDriver', NotificationSyncer::getNotificationDrivers());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function notification_driver_enabled_types_exist_if_added()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Notification())
|
||||
->type(CustomNotificationType::class, 'customSerializer')
|
||||
->type(SecondCustomNotificationType::class, 'secondCustomSerializer', ['customDriver'])
|
||||
->type(ThirdCustomNotificationType::class, 'thirdCustomSerializer')
|
||||
->driver('customDriver', CustomNotificationDriver::class, [CustomNotificationType::class])
|
||||
->driver('secondCustomDriver', SecondCustomNotificationDriver::class, [SecondCustomNotificationType::class])
|
||||
);
|
||||
|
||||
$this->app();
|
||||
|
||||
$blueprints = $this->app->getContainer()->make('flarum.notification.blueprints');
|
||||
|
||||
$this->assertContains('customDriver', $blueprints[CustomNotificationType::class]);
|
||||
$this->assertCount(1, $blueprints[CustomNotificationType::class]);
|
||||
$this->assertContains('customDriver', $blueprints[SecondCustomNotificationType::class]);
|
||||
$this->assertContains('secondCustomDriver', $blueprints[SecondCustomNotificationType::class]);
|
||||
$this->assertEmpty($blueprints[ThirdCustomNotificationType::class]);
|
||||
}
|
||||
}
|
||||
|
||||
class CustomNotificationType implements BlueprintInterface
|
||||
@@ -66,3 +148,37 @@ class CustomNotificationType implements BlueprintInterface
|
||||
return 'customNotificationTypeSubjectModel';
|
||||
}
|
||||
}
|
||||
|
||||
class SecondCustomNotificationType extends CustomNotificationType
|
||||
{
|
||||
public static function getType()
|
||||
{
|
||||
return 'secondCustomNotificationType';
|
||||
}
|
||||
}
|
||||
|
||||
class ThirdCustomNotificationType extends CustomNotificationType
|
||||
{
|
||||
public static function getType()
|
||||
{
|
||||
return 'thirdCustomNotificationType';
|
||||
}
|
||||
}
|
||||
|
||||
class CustomNotificationDriver implements NotificationDriverInterface
|
||||
{
|
||||
public function send(BlueprintInterface $blueprint, array $users): void
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
public function registerType(string $blueprintClass, array $driversEnabledByDefault): void
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
class SecondCustomNotificationDriver extends CustomNotificationDriver
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
Reference in New Issue
Block a user