|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) Ibexa AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Ibexa\Tests\Core\Notification\Renderer; |
| 10 | + |
| 11 | +use Ibexa\Contracts\Core\Repository\Values\Notification\Notification; |
| 12 | +use Ibexa\Core\Notification\Renderer\NotificationRenderer; |
| 13 | +use Ibexa\Core\Notification\Renderer\Registry; |
| 14 | +use Ibexa\Core\Notification\Renderer\TypedNotificationRendererInterface; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +final class RegistryTest extends TestCase |
| 18 | +{ |
| 19 | + public function testGetTypeLabelsReturnsSortedLabelsFromTypedRenderers(): void |
| 20 | + { |
| 21 | + $typedRendererA = new class() implements NotificationRenderer, TypedNotificationRendererInterface { |
| 22 | + public function render(Notification $notification): string |
| 23 | + { |
| 24 | + return 'Rendered A'; |
| 25 | + } |
| 26 | + |
| 27 | + public function generateUrl(Notification $notification): ?string |
| 28 | + { |
| 29 | + return null; |
| 30 | + } |
| 31 | + |
| 32 | + public function getTypeLabel(): string |
| 33 | + { |
| 34 | + return 'Label A'; |
| 35 | + } |
| 36 | + }; |
| 37 | + |
| 38 | + $typedRendererB = new class() implements NotificationRenderer, TypedNotificationRendererInterface { |
| 39 | + public function render(Notification $notification): string |
| 40 | + { |
| 41 | + return 'Rendered B'; |
| 42 | + } |
| 43 | + |
| 44 | + public function generateUrl(Notification $notification): ?string |
| 45 | + { |
| 46 | + return null; |
| 47 | + } |
| 48 | + |
| 49 | + public function getTypeLabel(): string |
| 50 | + { |
| 51 | + return 'Label B'; |
| 52 | + } |
| 53 | + }; |
| 54 | + |
| 55 | + $nonTypedRenderer = $this->createMock(NotificationRenderer::class); |
| 56 | + |
| 57 | + $registry = new Registry(); |
| 58 | + $registry->addRenderer('z_type', $typedRendererB); |
| 59 | + $registry->addRenderer('a_type', $typedRendererA); |
| 60 | + $registry->addRenderer('x_type', $nonTypedRenderer); |
| 61 | + |
| 62 | + $expected = [ |
| 63 | + 'a_type' => 'Label A', |
| 64 | + 'z_type' => 'Label B', |
| 65 | + ]; |
| 66 | + |
| 67 | + $this->assertSame($expected, $registry->getTypeLabels()); |
| 68 | + } |
| 69 | +} |
0 commit comments