EntityLoadedEvent example

->willReturnCallback(fn () => array_filter($this->plugins, static fn (Plugin $plugin) => $plugin->isActive()));

        $this->pluginAclSubscriber = new PluginAclPrivilegesSubscriber($pluginCollection);
    }

    public function testAclPluginDeactivated(): void
    {
        $this->deactivatePlugin(self::PLUGIN_ACL_PRODUCT_VIEWER);

        $aclRoles = [$this->getAclRoleMock('pluginAclTestProductViewer', ['product.viewer', 'product:read'])];

        $event = new EntityLoadedEvent(
            $this->createMock(AclRoleDefinition::class),
            $aclRoles,
            Context::createDefaultContext()
        );

        $this->pluginAclSubscriber->onAclRoleLoaded($event);

        /** @var AclRoleEntity $enrichedAclRole */
        $enrichedAclRole = $event->getEntities()[0];

        static::assertSame(['product.viewer', 'product:read']$enrichedAclRole->getPrivileges());
    }
$this->getContainer()->getParameter('kernel.cache_dir'),
            $this->getContainer()->getParameter('kernel.debug')
        );

        $this->ruleDefinition = $this->getContainer()->get(RuleDefinition::class);
    }

    public function testLoadValidRuleWithoutPayload(): void
    {
        $id = Uuid::randomHex();
        $rule = (new RuleEntity())->assign(['id' => $id, 'payload' => null, 'invalid' => false, '_uniqueIdentifier' => $id]);
        $loadedEvent = new EntityLoadedEvent($this->ruleDefinition, [$rule]$this->context);

        static::assertNull($rule->getPayload());

        $this->updater
            ->expects(static::once())
            ->method('update')
            ->with([$id])
            ->willReturn([$id => ['payload' => serialize(new AndRule()), 'invalid' => false]]);

        $this->rulePayloadSubscriber->unserialize($loadedEvent);

        
public function testFormatHandlerIdentifier(): void
    {
        $paymentMethods = [
            $this->getPaymentMethod(),
            $this->getPaymentMethod(AsynchronousPaymentHandlerInterface::class),
            $this->getPaymentMethod(RefundPaymentHandlerInterface::class),
            $this->getPaymentMethod(PreparedPaymentHandlerInterface::class),
            $this->getPaymentMethod(RecurringPaymentHandlerInterface::class),
        ];

        $event = new EntityLoadedEvent(
            new PaymentMethodDefinition(),
            $paymentMethods,
            Context::createDefaultContext()
        );

        $subscriber = new PaymentHandlerIdentifierSubscriber();
        $subscriber->formatHandlerIdentifier($event);

        /** @var array<PaymentMethodEntity> $methods */
        $methods = $event->getEntities();

        
$mediaId = '34556f108ab14969a0dcf9d9522fd7df';
        $mimeType = 'image/png';

        $mediaEntity = new MediaEntity();
        $mediaEntity->setId($mediaId);
        $mediaEntity->setMimeType($mimeType);
        $mediaEntity->setFileExtension('png');
        $mediaEntity->setFileName($mediaId . '-134578345');
        $mediaEntity->setThumbnails(new MediaThumbnailCollection());

        $mediaLoadedEvent = new EntityLoadedEvent($this->getContainer()->get(MediaDefinition::class)[$mediaEntity]$context);
        $subscriber->addUrls($mediaLoadedEvent);

        static::assertStringEndsWith(
            $mediaEntity->getFileName() . '.' . $mediaEntity->getFileExtension(),
            $mediaEntity->getUrl()
        );
        static::assertEquals([]$mediaEntity->getThumbnails()->getElements());
    }

    public function testItAddsThumbnailUrl(): void
    {
        
/** * @dataProvider entityLoadedEventDataProvider */
    public function testEntityLoadedEvent(SystemConfigService $systemConfigService, CategoryEntity $categoryEntity, ?string $cmsPageIdBeforeEvent, ?string $cmsPageIdAfterEvent, ?string $salesChannelId): void
    {
        $categorySubscriber = new CategorySubscriber($systemConfigService);

        if ($salesChannelId) {
            $event = new SalesChannelEntityLoadedEvent(new CategoryDefinition()[$categoryEntity]$this->getSalesChannelContext($salesChannelId));
        } else {
            $event = new EntityLoadedEvent(new CategoryDefinition()[$categoryEntity], Context::createDefaultContext());
        }

        static::assertEquals($cmsPageIdBeforeEvent$categoryEntity->getCmsPageId());
        $categorySubscriber->entityLoaded($event);
        static::assertEquals($cmsPageIdAfterEvent$categoryEntity->getCmsPageId());
    }

    /** * @return array<string, array{SystemConfigService, CategoryEntity, string|null, string|null, string|null}> */
    public static function entityLoadedEventDataProvider(): iterable
    {
public function testResolveCmsPageIdProviderWithLoadedEvent(Entity $entity, SystemConfigService $config, ?string $expected): void
    {
        $subscriber = new ProductSubscriber(
            $this->createMock(ProductVariationBuilder::class),
            $this->createMock(AbstractProductPriceCalculator::class),
            $this->createMock(AbstractPropertyGroupSorter::class),
            $this->createMock(ProductMaxPurchaseCalculator::class),
            $this->createMock(IsNewDetector::class),
            $config,
        );

        $event = new EntityLoadedEvent(
            $this->createMock(ProductDefinition::class),
            [$entity],
            Context::createDefaultContext()
        );

        $subscriber->loaded($event);

        static::assertSame($expected$entity->get('cmsPageId'));
    }

    /** * @dataProvider resolveCmsPageIdProviderWithSalesChannelLoadedEventProvider */
$criteria->setIds([$product['id']])
            ->addAssociation('properties.group');

        /** @var SalesChannelProductEntity $productEntity */
        $productEntity = $this->getContainer()
            ->get('sales_channel.product.repository')
            ->search($criteria$salesChannelContext)
            ->first();

        $subscriber = $this->getContainer()->get(ProductSubscriber::class);
        $productLoadedEvent = new EntityLoadedEvent(
            $this->getContainer()->get(ProductDefinition::class),
            [$productEntity],
            Context::createDefaultContext()
        );
        $subscriber->loaded($productLoadedEvent);

        $sortedPropertiesCollection = $productEntity->getSortedProperties();

        static::assertInstanceOf(PropertyGroupCollection::class$sortedPropertiesCollection);

        $sortedProperties = $sortedPropertiesCollection->getElements();

        
$appFlowAction->setId($idFlowAction);
        $iconPath = __DIR__ . '/../../Manifest/_fixtures/icon.png';

        $fileIcon = '';
        if (file_exists($iconPath)) {
            $fileIcon = \file_get_contents($iconPath);
        }

        $appFlowAction->setIconRaw($fileIcon !== false ? $fileIcon : null);

        $subscriber = new AppFlowActionLoadedSubscriber();
        $event = new EntityLoadedEvent(new AppFlowActionDefinition()[$appFlowAction], Context::createDefaultContext());

        $subscriber->unserialize($event);
        static::assertNotFalse($fileIcon);

        static::assertEquals(
            base64_encode($fileIcon),
            $appFlowAction->getIcon()
        );
    }
}
public function __construct(private readonly DefinitionInstanceRegistry $registry)
    {
    }

    /** * @param array<mixed> $entities */
    public function create(array $entities, Context $context): EntityLoadedContainerEvent
    {
        $mapping = $this->recursion($entities[]);

        $generator = fn (EntityDefinition $definition, array $entities) => new EntityLoadedEvent($definition$entities$context);

        return $this->buildEvents($mapping$generator$context);
    }

    /** * @param array<mixed> $entities */
    public function createPartial(array $entities, Context $context): EntityLoadedContainerEvent
    {
        $mapping = $this->recursion($entities[]);

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