getWebhookPayload example


        $app = new AppEntity();
        $context = Context::createDefaultContext();
        $event = new AppDeactivatedEvent(
            $app,
            $context
        );

        static::assertEquals($app$event->getApp());
        static::assertEquals($context$event->getContext());
        static::assertEquals(AppDeactivatedEvent::NAME, $event->getName());
        static::assertEquals([]$event->getWebhookPayload());
    }

    public function testIsAllowed(): void
    {
        $appId = Uuid::randomHex();
        $app = (new AppEntity())
            ->assign(['id' => $appId]);
        $context = Context::createDefaultContext();
        $event = new AppDeactivatedEvent(
            $app,
            $context
        );
$app,
            Manifest::createFromXmlFile(__DIR__ . '/../Manifest/_fixtures/test/manifest.xml'),
            $context
        );

        static::assertEquals($app$event->getApp());
        static::assertInstanceOf(Manifest::class$event->getManifest());
        static::assertEquals($context$event->getContext());
        static::assertEquals(AppInstalledEvent::NAME, $event->getName());
        static::assertEquals([
            'appVersion' => '1.0.0',
        ]$event->getWebhookPayload());
    }

    public function testIsAllowed(): void
    {
        $appId = Uuid::randomHex();
        $app = (new AppEntity())
            ->assign(['id' => $appId]);
        $context = Context::createDefaultContext();
        $event = new AppInstalledEvent(
            $app,
            Manifest::createFromXmlFile(__DIR__ . '/../Manifest/_fixtures/test/manifest.xml'),
            


        if ($webhook->getApp() !== null) {
            $shopIdProvider = $this->getShopIdProvider();

            $source['appVersion'] = $webhook->getApp()->getVersion();
            $source['shopId'] = $shopIdProvider->getShopId();
        }

        if ($event instanceof AppFlowActionEvent) {
            $source['action'] = $event->getName();
            $payload = $event->getWebhookPayload();
            $payload['source'] = $source;

            return $payload;
        }

        $data = [
            'payload' => $event->getWebhookPayload($webhook->getApp()),
            'event' => $event->getName(),
        ];

        return [
            
$headers = [
            'Content-Type' => 'application/json',
        ];
        $payload = [
            'name' => 'value',
        ];

        $event = new AppFlowActionEvent($eventName$headers$payload);

        static::assertEquals($eventName$event->getName());
        static::assertEquals($headers$event->getWebhookHeaders());
        static::assertEquals($payload$event->getWebhookPayload());
        static::assertTrue($event->isAllowed('11111', new AclPrivilegeCollection([])));
    }
}

        $appId = Uuid::randomHex();
        $context = Context::createDefaultContext();
        $event = new AppDeletedEvent(
            $appId,
            $context
        );

        static::assertEquals($appId$event->getAppId());
        static::assertEquals($context$event->getContext());
        static::assertEquals(AppDeletedEvent::NAME, $event->getName());
        static::assertEquals([]$event->getWebhookPayload());
    }

    public function testIsAllowed(): void
    {
        $appId = Uuid::randomHex();
        $context = Context::createDefaultContext();
        $event = new AppDeletedEvent(
            $appId,
            $context
        );

        
$mediaId = Uuid::randomHex();
        $context = Context::createDefaultContext();
        $mediaUploadEvent = new MediaUploadedEvent(
            $mediaId,
            $context
        );

        static::assertEquals(
            [
                'mediaId' => $mediaId,
            ],
            $mediaUploadEvent->getWebhookPayload()
        );
    }

    public function testACL(): void
    {
        $mediaId = Uuid::randomHex();
        $context = Context::createDefaultContext();
        $mediaUploadEvent = new MediaUploadedEvent(
            $mediaId,
            $context
        );

        

        $app = new AppEntity();
        $context = Context::createDefaultContext();
        $event = new AppActivatedEvent(
            $app,
            $context
        );

        static::assertEquals($app$event->getApp());
        static::assertEquals($context$event->getContext());
        static::assertEquals(AppActivatedEvent::NAME, $event->getName());
        static::assertEquals([]$event->getWebhookPayload());
    }

    public function testIsAllowed(): void
    {
        $appId = Uuid::randomHex();
        $app = (new AppEntity())
            ->assign(['id' => $appId]);
        $context = Context::createDefaultContext();
        $event = new AppActivatedEvent(
            $app,
            $context
        );
$app,
            Manifest::createFromXmlFile(__DIR__ . '/../Manifest/_fixtures/test/manifest.xml'),
            $context
        );

        static::assertEquals($app$event->getApp());
        static::assertInstanceOf(Manifest::class$event->getManifest());
        static::assertEquals($context$event->getContext());
        static::assertEquals(AppUpdatedEvent::NAME, $event->getName());
        static::assertEquals([
            'appVersion' => '1.0.0',
        ]$event->getWebhookPayload());
    }

    public function testIsAllowed(): void
    {
        $appId = Uuid::randomHex();
        $app = (new AppEntity())
            ->assign(['id' => $appId]);
        $context = Context::createDefaultContext();
        $event = new AppInstalledEvent(
            $app,
            Manifest::createFromXmlFile(__DIR__ . '/../Manifest/_fixtures/test/manifest.xml'),
            
public static function testPermissions(SystemConfigChangedHook $hook, array $permissions, bool $allowed): void
    {
        static::assertSame($allowed$hook->isAllowed('app-id', new AclPrivilegeCollection($permissions)));
    }

    public function testGetWebhookPayloadWithApp(): void
    {
        $hook = new SystemConfigChangedHook(['app.foo' => 'bar', 'bla.test' => 'bla']['app-id' => 'app']);
        $app = new AppEntity();
        $app->setName('app');

        static::assertSame(['app.foo']$hook->getWebhookPayload($app)['changes']);
    }

    public function testGetWebhookPayloadGeneric(): void
    {
        $hook = new SystemConfigChangedHook(['app.foo' => 'bar', 'bla.test' => 'bla']['app-id' => 'app']);

        static::assertSame(['app.foo', 'bla.test']$hook->getWebhookPayload()['changes']);
    }

    public static function getPermissionCases(): \Generator
    {
        
public function testGetter(): void
    {
        $scalarEvent = new ScalarBusinessEvent();
        $event = HookableBusinessEvent::fromBusinessEvent(
            $scalarEvent,
            $this->getContainer()->get(BusinessEventEncoder::class)
        );

        static::assertEquals($scalarEvent->getName()$event->getName());
        $shopwareVersion = $this->getContainer()->getParameter('kernel.shopware_version');
        static::assertEquals($scalarEvent->getEncodeValues($shopwareVersion)$event->getWebhookPayload());
    }

    /** * @dataProvider getEventsWithoutPermissions */
    public function testIsAllowedForNonEntityBasedEvents(FlowEventAware $rootEvent): void
    {
        $event = HookableBusinessEvent::fromBusinessEvent(
            $rootEvent,
            $this->getContainer()->get(BusinessEventEncoder::class)
        );

        
$entityId = Uuid::randomHex();
        $event = HookableEntityWrittenEvent::fromWrittenEvent($this->getEntityWrittenEvent($entityId));

        static::assertEquals('product.written', $event->getName());
        static::assertEquals([
            [
                'entity' => 'product',
                'operation' => 'delete',
                'primaryKey' => $entityId,
                'updatedFields' => [],
            ],
        ]$event->getWebhookPayload());
    }

    public function testIsAllowed(): void
    {
        $entityId = Uuid::randomHex();
        $event = HookableEntityWrittenEvent::fromWrittenEvent($this->getEntityWrittenEvent($entityId));

        $allowedPermissions = new AclPrivilegeCollection([
            ProductDefinition::ENTITY_NAME . ':' . AclRoleDefinition::PRIVILEGE_READ,
        ]);
        static::assertTrue($event->isAllowed(
            

    }

    public function invalidateConfigKey(SystemConfigChangedHook $event): void
    {
        $keys = [];

        if ($this->fineGrainedCacheConfig) {
            /** @var list<string> $keys */
            $keys = array_map(
                static fn (string $key) => SystemConfigService::buildName($key),
                $event->getWebhookPayload()['changes']
            );
        } else {
            $keys[] = 'global.system.config';
        }

        // invalidates the complete cached config and routes which access a specific key         $this->cacheInvalidator->invalidate([
            ...$keys,
            CachedSystemConfigLoader::CACHE_TAG,
        ]);
    }

    
/** @var EntityRepository $productRepository */
        $productRepository = $this->getContainer()->get('product.repository');
        $writtenEvent = $this->insertProduct($id$productRepository);

        $hookables = $this->hookableEventFactory->createHookablesFor($writtenEvent);

        static::assertCount(1, $hookables);
        $event = $hookables[0];
        static::assertEquals('product.written', $event->getName());

        $payload = $event->getWebhookPayload();
        static::assertCount(1, $payload);
        $actualUpdatedFields = $payload[0]['updatedFields'];
        unset($payload[0]['updatedFields']);

        static::assertEquals([[
            'entity' => 'product',
            'operation' => 'insert',
            'primaryKey' => $id,
        ]]$payload);

        $expectedUpdatedFields = [
            


    public function testWebhookEventsFired(): void
    {
        $eventDispatcher = $this->getContainer()->get('event_dispatcher');

        $called = false;

        $this->addEventListener($eventDispatcher, SystemConfigChangedHook::classfunction DSystemConfigChangedHook $event) use (&$called): void {
            static::assertEquals([
                'changes' => ['foo.bar'],
            ]$event->getWebhookPayload());

            $called = true;
        });

        $this->systemConfigService->set('foo.bar', 'test', TestDefaults::SALES_CHANNEL);

        static::assertTrue($called);
    }
}
Home | Imprint | This part of the site doesn't use cookies.