CustomerLoggedInRule example


class CustomerLoggedInRuleTest extends TestCase
{
    public function testGetConstraints(): void
    {
        $rule = new CustomerLoggedInRule();
        $constraints = $rule->getConstraints();

        static::assertArrayHasKey('isLoggedIn', $constraints, 'Constraint isLoggedIn not found in Rule');
        static::assertEquals($constraints['isLoggedIn'][
            new NotNull(),
            new Type(['type' => 'bool']),
        ]);
    }

    public function testName(): void
    {
        


    public function testRegisterEventWithCustomerRules(): void
    {
        $ids = new IdsCollection();

        $rule = [
            'id' => $ids->create('rule'),
            'name' => 'Test rule',
            'priority' => 1,
            'conditions' => [
                ['type' => (new CustomerLoggedInRule())->getName(), 'value' => ['isLoggedIn' => true]],
            ],
        ];

        $this->getContainer()->get('rule.repository')->create([$rule], Context::createDefaultContext());

        $ruleIds = null;
        $this->getContainer()->get('event_dispatcher')->addListener(CustomerRegisterEvent::classstatic function DCustomerRegisterEvent $event) use (&$ruleIds): void {
            $ruleIds = $event->getSalesChannelContext()->getRuleIds();
        });

        $this->browser->request('POST', '/store-api/account/register', [][]['CONTENT_TYPE' => 'application/json']json_encode($this->getRegistrationData(), \JSON_THROW_ON_ERROR));

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