MessageCatalogue example


class TranslatorTest extends TestCase
{
    /** * @dataProvider getCatalogueRequestProvider */
    public function testGetCatalogueIsCachedCorrectly(?string $snippetSetId, ?Request $request, ?string $expectedCacheKey, ?string $injectSalesChannelId = null): void
    {
        $decorated = $this->createMock(SymfonyTranslator::class);
        $originCatalogue = new MessageCatalogue('en-GB', [
            'messages' => [
                'global.title' => 'This is a title',
                'global.summary' => 'This is a summary',
            ],
        ]);

        $decorated->expects(static::any())->method('getCatalogue')->with('en-GB')->willReturn($originCatalogue);
        $decorated->expects(static::any())->method('getLocale')->willReturn('en-GB');

        $requestStack = new RequestStack();

        
'setId' => $snippetSetId,
            ],
            [
                'translationKey' => 'b',
                'value' => '',
                'author' => 'test',
                'setId' => $snippetSetId,
            ],
        ], Context::createDefaultContext());

        $result = $service->getStorefrontSnippets(
            new MessageCatalogue('en-GB', ['messages' => ['a' => 'a', 'b' => 'b']]),
            $snippetSetId
        );

        static::assertSame(['a' => 'test', 'b' => '']$result);
    }

    public function testStorefrontSnippetFallback(): void
    {
        $service = $this->getSnippetService(
            new MockSnippetFile('test-fallback-en', 'en-GB', (string) json_encode([
                'foo' => 'en-foo',
                
$snippetService = new SnippetService(
            $this->connection,
            $this->snippetCollection,
            $this->createMock(EntityRepository::class),
            $this->createMock(EntityRepository::class),
            $this->createMock(EntityRepository::class),
            $this->createMock(SnippetFilterFactory::class),
            $container,
            $themeLoader,
        );

        $catalog = new MessageCatalogue((string) $fetchLocaleResult['messages' => $catalogMessages]);

        $snippets = $snippetService->getStorefrontSnippets($catalog, Uuid::randomHex()$fallbackLocale$salesChannelId);

        static::assertEquals($expected$snippets);
    }

    public function testGetStorefrontSnippetsWithoutThemeRegistry(): void
    {
        $locale = 'de-DE';
        $snippetSetId = Uuid::randomHex();
        $catalog = new MessageCatalogue($locale[]);

        
Home | Imprint | This part of the site doesn't use cookies.