getMailTemplate example



        $eventConfig = $flow->getConfig();
        if (empty($eventConfig['recipient'])) {
            throw new MailEventConfigurationException('The recipient value in the flow action configuration is missing.', $flow::class);
        }

        if (!isset($eventConfig['mailTemplateId'])) {
            return;
        }

        $mailTemplate = $this->getMailTemplate($eventConfig['mailTemplateId']$flow->getContext());

        if ($mailTemplate === null) {
            return;
        }

        $injectedTranslator = $this->injectTranslator($flow->getContext()$flow->getData(MailAware::SALES_CHANNEL_ID));

        $data = new DataBag();

        /** @var MailRecipientStruct $mailStruct */
        $mailStruct = $flow->getData(MailAware::MAIL_STRUCT);

        


        $mail->setMailAttachmentsConfig($mailAttachmentsConfig);

        $this->decorated->expects(static::once())->method('send')->with($mail$envelope);

        $this->attachmentsBuilder
            ->expects(static::once())
            ->method('buildAttachments')
            ->with(
                $mailAttachmentsConfig->getContext(),
                $mailAttachmentsConfig->getMailTemplate(),
                $mailAttachmentsConfig->getExtension(),
                $mailAttachmentsConfig->getEventConfig(),
                $mailAttachmentsConfig->getOrderId()
            )
            ->willReturn([
                ['id' => 'foo', 'content' => 'foo', 'fileName' => 'bar', 'mimeType' => 'baz/asd'],
                ['id' => 'bar', 'content' => 'bar', 'fileName' => 'bar', 'mimeType' => 'baz/asd'],
            ]);

        $this->documentRepository
            ->expects(static::once())
            

class MailEventListener
{
    private array $events = [];

    public function __construct(private readonly array $mapping)
    {
    }

    public function __invoke(FlowSendMailActionEvent $event): void
    {
        $name = $this->mapping[$event->getMailTemplate()->getMailTemplateTypeId()];

        $this->events[$name][] = $event;
    }

    public function assertSent(string $type): void
    {
        TestCase::assertTrue($this->sent($type), \sprintf('Expected to send %s mail', $type));
    }

    public function sent(string $type): bool
    {
        
$orderId = Uuid::randomHex();

        $attachmentsConfig = new MailAttachmentsConfig(
            $context,
            $mailTemplate,
            $extension,
            $evenConfig,
            $orderId
        );

        static::assertEquals($context$attachmentsConfig->getContext());
        static::assertEquals($mailTemplate$attachmentsConfig->getMailTemplate());
        static::assertEquals($extension$attachmentsConfig->getExtension());
        static::assertEquals($evenConfig$attachmentsConfig->getEventConfig());
        static::assertEquals($orderId$attachmentsConfig->getOrderId());

        $attachmentsConfig = $this->getMockBuilder(MailAttachmentsConfig::class)
            ->disableOriginalConstructor()
            ->onlyMethods([])
            ->getMock();

        $attachmentsConfig->setContext($context);
        $attachmentsConfig->setMailTemplate($mailTemplate);
        
$message->attach($this->filesystem->read($url) ?: '', basename($url)$mimeType);
        }

        $config = $message->getMailAttachmentsConfig();

        if (!$config) {
            return $this->decorated->send($message$envelope);
        }

        $attachments = $this->attachmentsBuilder->buildAttachments(
            $config->getContext(),
            $config->getMailTemplate(),
            $config->getExtension(),
            $config->getEventConfig(),
            $config->getOrderId()
        );

        foreach ($attachments as $attachment) {
            $message->attach(
                $attachment['content'],
                $attachment['fileName'],
                $attachment['mimeType']
            );
        }
static::assertEquals($actualDataBag$expectDataBag);
    }

    public function testGetMailTemplate(): void
    {
        $mailTemplate = new MailTemplateEntity();
        $flowEvent = $this->createMock(StorableFlow::class);

        $event = new FlowSendMailActionEvent(new DataBag()$mailTemplate$flowEvent);

        static::assertEquals($mailTemplate$event->getMailTemplate());
    }

    public function testGetStorableFlow(): void
    {
        $event = $this->createMock(StorableFlow::class);

        $mailTemplate = new MailTemplateEntity();

        $mailEvent = new FlowSendMailActionEvent(new DataBag()$mailTemplate$event);

        static::assertEquals($event$mailEvent->getStorableFlow());
    }
Home | Imprint | This part of the site doesn't use cookies.