ReviewFormEvent example

private MockObject&EventDispatcherInterface $dispatcher;

    protected function setUp(): void
    {
        $this->repository = $this->createMock(EntityRepository::class);
        $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
        $this->storer = new ProductStorer($this->repository, $this->dispatcher);
    }

    public function testStoreWithAware(): void
    {
        $event = new ReviewFormEvent(Context::createDefaultContext(), '', new MailRecipientStruct([])new DataBag(), '', '');
        $stored = [];
        $stored = $this->storer->store($event$stored);
        static::assertArrayHasKey(ProductAware::PRODUCT_ID, $stored);
    }

    public function testStoreWithNotAware(): void
    {
        $event = $this->createMock(CustomerRegisterEvent::class);
        $stored = [];
        $stored = $this->storer->store($event$stored);
        static::assertArrayNotHasKey(ProductAware::PRODUCT_ID, $stored);
    }

    private ReviewFormDataStorer $storer;

    protected function setUp(): void
    {
        Feature::skipTestIfActive('v6.6.0.0', $this);
        $this->storer = new ReviewFormDataStorer();
    }

    public function testStoreAware(): void
    {
        $event = new ReviewFormEvent(Context::createDefaultContext(), '', new MailRecipientStruct([])new DataBag(), '', '');
        $stored = [];
        $stored = $this->storer->store($event$stored);
        static::assertArrayHasKey(ReviewFormDataAware::REVIEW_FORM_DATA, $stored);
    }

    public function testStoreNotAware(): void
    {
        $event = $this->createMock(TestFlowBusinessEvent::class);
        $stored = [];
        $stored = $this->storer->store($event$stored);
        static::assertArrayNotHasKey(ReviewFormDataAware::REVIEW_FORM_DATA, $stored);
    }
class ReviewFormEventTest extends TestCase
{
    public function testInstance(): void
    {
        $context = Context::createDefaultContext();
        $salesChannelId = 'foo';
        $mailRecipientStruct = new MailRecipientStruct(['foo' => 'bar']);
        $data = new DataBag(['baz']);
        $productId = 'bar';
        $customerId = 'bar';

        $event = new ReviewFormEvent($context$salesChannelId$mailRecipientStruct$data$productId$customerId);

        static::assertEquals($context$event->getContext());
        static::assertEquals($salesChannelId$event->getSalesChannelId());
        static::assertEquals($mailRecipientStruct$event->getMailStruct());
        static::assertEquals($data->all()$event->getReviewFormData());
        static::assertEquals($productId$event->getProductId());
        static::assertEquals($customerId$event->getCustomerId());
    }

    public function testScalarValuesCorrectly(): void
    {
        
'languageId' => $context->getLanguageId(),
                    'externalUser' => $customer->getFirstName(),
                    'externalEmail' => $customer->getEmail(),
                    'title' => $data->get('title'),
                    'content' => $data->get('content'),
                    'points' => $data->get('points'),
                    'status' => false,
                    'id' => $data->get('id'),
                ],
            ]$context);

        $event = new ReviewFormEvent(
            $context,
            $salesChannel->getId(),
            new MailRecipientStruct(['noreply@example.com' => 'noreply@example.com']),
            new RequestDataBag([
                'title' => 'foo',
                'content' => 'bar',
                'points' => 3,
                'name' => $customer->getFirstName(),
                'lastName' => $customer->getLastName(),
                'email' => $customer->getEmail(),
                'customerId' => $customer->getId(),
                
'status' => false,
        ];

        if ($data->get('id')) {
            $review['id'] = $data->get('id');
        }

        $this->repository->upsert([$review]$context->getContext());

        $mail = $this->config->get('core.basicInformation.email', $context->getSalesChannel()->getId());
        $mail = \is_string($mail) ? $mail : '';
        $event = new ReviewFormEvent(
            $context->getContext(),
            $context->getSalesChannel()->getId(),
            new MailRecipientStruct([$mail => $mail]),
            $data,
            $productId,
            $customerId
        );

        $this->eventDispatcher->dispatch(
            $event,
            ReviewFormEvent::EVENT_NAME
        );
Home | Imprint | This part of the site doesn't use cookies.