LanguageEntity example

$this->registry = new ElasticsearchRegistry([$this->createDefinition('product')]);
        $this->indexCreator = $this->createMock(IndexCreator::class);
        $this->iteratorFactory = $this->createMock(IteratorFactory::class);
        $this->client = $this->createMock(Client::class);
        $this->currencyRepository = $this->createMock(EntityRepository::class);
        $this->languageRepository = $this->createMock(EntityRepository::class);
        $this->newEsIndexer = $this->createMock(MultilingualEsIndexer::class);
        $this->bus = new CollectingMessageBus();

        $this->helper->method('allowIndexing')->willReturn(true);

        $this->language1 = new LanguageEntity();
        $this->language1->setId(Defaults::LANGUAGE_SYSTEM);
        $this->language1->setUniqueIdentifier(Defaults::LANGUAGE_SYSTEM);

        $language2 = new LanguageEntity();
        $language2->setId('2');
        $language2->setUniqueIdentifier('2');

        $this->languageRepository
            ->method('search')
            ->willReturn(new EntitySearchResult('language', 1, new LanguageCollection([$this->language1, $language2]), null, new Criteria(), Context::createDefaultContext()));

        


        $this->connection->method('fetchAllKeyValue')->willReturn(
            [
                '' => '{{ product.translated.name }}/{{ product.productNumber }}',
            ]
        );

        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId('testSalsesChannelId');

        $language = new LanguageEntity();
        $language->setId('testLanguageId');

        $seoUrlUpdater = $this->createSeoUrlUpdater(
            [
                new LanguageCollection([
                    $language,
                ]),
            ],
            [
                new SalesChannelCollection([
                    $salesChannel,
                ]),
$criteria = new Criteria();
        $criteria->addAssociations([
            'manufacturer',
            'prices',
            'categories',
        ]);

        /** @var ProductEntity $product */
        $product = $this->productRepository->search($criteria, Context::createDefaultContext())->first();
        $product->addExtension('test', new LanguageCollection([
            (new LanguageEntity())->assign(['id' => $this->ids->create('l1'), '_entityName' => 'language']),
        ]));
        $events = $this->entityLoadedEventFactory->create([$product], Context::createDefaultContext());

        $createdEvents = $events->getEvents()->map(fn (EntityLoadedEvent $event): string => $event->getName());
        sort($createdEvents);

        static::assertEquals([
            'category.loaded',
            'language.loaded',
            'product.loaded',
            'product_manufacturer.loaded',
            
$this->expectException(RoutingException::class);
        $this->expectExceptionMessage('The language "' . $notExistingLang . '" was not found');

        $controller->switchLanguage(
            new Request([]['languageId' => $notExistingLang]),
            $this->createMock(SalesChannelContext::class)
        );
    }

    public function testSwitchCustomerChange(): void
    {
        $language = new LanguageEntity();
        $language->setUniqueIdentifier(Uuid::randomHex());
        $scDomain = new SalesChannelDomainEntity();
        $scDomain->setUniqueIdentifier(Uuid::randomHex());
        $scDomain->setUrl('http://localhost');
        $language->setSalesChannelDomains(new SalesChannelDomainCollection([$scDomain]));

        $changeLangMock = $this->createMock(AbstractChangeLanguageRoute::class);

        $routerMock = $this->createMock(RouterInterface::class);
        $routerMock->expects(static::once())->method('getContext')->willReturn(new RequestContext());
        $routerMock->expects(static::once())->method('generate')->willReturn('http://localhost');
        

    }

    /** * @param array<int, array<string, mixed>> $languageEntities */
    private function getLanguageCollection(array $languageEntities = []): LanguageCollection
    {
        $entities = [];

        foreach ($languageEntities as $entity) {
            $languageEntity = new LanguageEntity();
            $languageEntity->assign($entity);

            $entities[] = $languageEntity;
        }

        return new LanguageCollection($entities);
    }

    /** * @param array<string, mixed> $data */
    
use Shopware\Elasticsearch\Product\ElasticsearchProductDefinition;

/** * @internal * * @covers \Shopware\Elasticsearch\Framework\Indexing\IndexMappingUpdater */
class IndexMappingUpdaterTest extends TestCase
{
    public function testUpdate(): void
    {
        $language = new LanguageEntity();
        $language->setId(Uuid::randomHex());

        $languageProvider = $this->createMock(ElasticsearchLanguageProvider::class);
        $languageProvider
            ->method('getLanguages')
            ->willReturn(new LanguageCollection([$language]));

        $elasticsearchHelper = $this->createMock(ElasticsearchHelper::class);
        $elasticsearchHelper->method('getIndexName')->willReturn('index');

        $registry = new ElasticsearchRegistry([
            

            ]);

        $client = $this->createMock(Client::class);
        $client->method('indices')->willReturn($indices);

        $definition = $this->createMock(ElasticsearchProductDefinition::class);

        $registry = $this->createMock(ElasticsearchRegistry::class);
        $registry->method('getDefinitions')->willReturn([$definition$definition]);

        $makeLanguage = fn () => (new LanguageEntity())->assign(['id' => Uuid::randomHex()]);

        $collection = new EntitySearchResult('test', 1, new LanguageCollection([$makeLanguage()$makeLanguage()$makeLanguage()]), null, new Criteria(), Context::createDefaultContext());

        $repository = $this->createMock(EntityRepository::class);
        $repository
            ->method('search')
            ->willReturn($collection);

        $esHelper = $this->createMock(ElasticsearchHelper::class);

        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            
static::assertSame('foo', $pluginWrite['name']);
        static::assertSame('foo', $pluginWrite['baseClass']);
        static::assertSame('foo', $pluginWrite['composerName']);
        static::assertSame('1.0.0', $pluginWrite['version']);
    }

    /** * @return StaticEntityRepository<LanguageCollection> */
    private function getLanguageRepository(): StaticEntityRepository
    {
        $language = new LanguageEntity();
        $language->setId('foo');

        // @phpstan-ignore-next-line         return new StaticEntityRepository([new LanguageCollection([$language])new LanguageCollection([$language])]);
    }

    private function getComposerPackage(): CompletePackage
    {
        $completePackage = new CompletePackage('foo', '1.0.0', '1.0.0');
        $completePackage->setAutoload([
            'psr-4' => [
                
Home | Imprint | This part of the site doesn't use cookies.