AppEntity example

        InstalledVersions::reload($this->packages);
    }

    public function testGetConfigWhenNotExists(): void
    {
        $appLoader = new AppLoader(
            __DIR__,
            __DIR__,
            new ConfigReader()
        );

        $appEntity = new AppEntity();
        $appEntity->setPath('non-existing');

        static::assertNull($appLoader->getConfiguration($appEntity));
    }

    public function testGetConfig(): void
    {
        $appLoader = new AppLoader(
            __DIR__,
            __DIR__,
            new ConfigReader()
        );
public function testLoadFileReturnsNullOnInvalidPath(): void
    {
        $appLoader = $this->getAppLoader(__DIR__ . '/../Manifest/_fixtures/test');
        static::assertNull($appLoader->loadFile(__DIR__ . '/../Manifest/_fixtures/test', 'file/that/dont/exist.png'));
    }

    public function testGetConfigurationReturnsNullIfNoConfigIsProvided(): void
    {
        $appLoader = $this->getAppLoader(__DIR__ . '/../Manifest/_fixtures/test');

        $path = str_replace($this->getContainer()->getParameter('kernel.project_dir') . '/', '', __DIR__ . '/../Manifest/_fixtures/test');
        $app = (new AppEntity())->assign(['path' => $path]);

        static::assertNull($appLoader->getConfiguration($app));
    }

    public function testGetConfigurationReturnsParsedConfig(): void
    {
        $appLoader = $this->getAppLoader(__DIR__ . '/../Manifest/_fixtures/test');

        $path = str_replace($this->getContainer()->getParameter('kernel.project_dir') . '/', '', __DIR__ . '/../Manifest/_fixtures/withConfig');
        $app = (new AppEntity())->assign(['path' => $path]);

        
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Framework\Webhook\AclPrivilegeCollection;

/** * @internal */
class AppDeactivatedEventTest extends TestCase
{
    public function testGetter(): void
    {
        $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());
    }

    
$cart = $this->createCart();
        $salesChannelContext = static::createMock(SalesChannelContext::class);
        $salesChannelContext
            ->method('getTotalRounding')
            ->willReturn(new CashRoundingConfig(2, 0.01, true));

        $taxProvider = new TaxProviderEntity();
        $taxProvider->setId(Uuid::randomHex());
        $taxProvider->setActive(true);
        $taxProvider->setPriority(1);
        $taxProvider->setIdentifier(TestConstantTaxRateProvider::class);
        $taxProvider->setApp(new AppEntity());
        $taxProvider->setProcessUrl('https://example.com');

        $collection = new TaxProviderCollection([$taxProvider]);

        $result = new EntitySearchResult(
            TaxProviderDefinition::ENTITY_NAME,
            1,
            $collection,
            null,
            new Criteria(),
            Context::createDefaultContext()
        );
'https://example.com',
            $this->container,
            $this->eventFactory,
            '0.0.0',
            $this->bus,
            $isAdminWorkerEnabled
        );
    }

    private function getWebhookEntity(string $eventName): WebhookEntity
    {
        $appEntity = new AppEntity();
        $appEntity->setId(Uuid::randomHex());
        $appEntity->setName('Cool App');
        $appEntity->setAclRoleId(Uuid::randomHex());
        $appEntity->setActive(true);
        $appEntity->setVersion('0.0.0');
        $appEntity->setAppSecret('verysecret');

        $webhookEntity = new WebhookEntity();
        $webhookEntity->setId(Uuid::randomHex());
        $webhookEntity->setName('Cool Webhook');
        $webhookEntity->setEventName($eventName);
        
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Framework\Webhook\AclPrivilegeCollection;

/** * @internal */
class AppUpdatedEventTest extends TestCase
{
    public function testGetter(): void
    {
        $app = new AppEntity();
        $context = Context::createDefaultContext();
        $event = new AppUpdatedEvent(
            $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());
        
$shopIdProvider = static::createMock(ShopIdProvider::class);
        $shopIdProvider
            ->method('getShopId')
            ->willReturn($this->ids->get('shop-id'));

        $appPayloadServiceHelper = new AppPayloadServiceHelper(
            static::createMock(DefinitionInstanceRegistry::class),
            static::createMock(JsonEntityEncoder::class),
            $shopIdProvider
        );

        $app = new AppEntity();
        $app->setVersion('1.0.0');

        $source = $appPayloadServiceHelper->buildSource($app, 'https://shopware.com');

        static::assertInstanceOf(Source::class$source);

        static::assertSame('https://shopware.com', $source->getUrl());
        static::assertSame($this->ids->get('shop-id')$source->getShopId());
        static::assertSame('1.0.0', $source->getAppVersion());
    }

    
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Framework\Webhook\AclPrivilegeCollection;

/** * @internal */
class AppInstalledEventTest extends TestCase
{
    public function testGetter(): void
    {
        $app = new AppEntity();
        $context = Context::createDefaultContext();
        $event = new AppInstalledEvent(
            $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());
        

class AppConfirmationDeltaProviderTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testGetDeltas(): void
    {
        $deltas = $this->getAppConfirmationDeltaProvider()
            ->getReports(
                $this->getTestManifest(),
                new AppEntity()
            );

        static::assertCount(2, $deltas);
        static::assertArrayHasKey('permissions', $deltas);
        static::assertCount(6, $deltas['permissions']);
        static::assertArrayHasKey('domains', $deltas);
        static::assertCount(8, $deltas['domains']);
    }

    public function testRequiresRenewedConsent(): void
    {
        
return $repo;
    }

    /** * @param array<int, array<string, mixed>> $appEntities */
    private function getAppCollection(array $appEntities): AppCollection
    {
        $entities = [];

        foreach ($appEntities as $entity) {
            $appEntity = new AppEntity();
            $appEntity->assign($entity);
            $appEntity->setUniqueIdentifier($entity['id']);

            $entities[] = $appEntity;
        }

        return new AppCollection($entities);
    }

    /** * @param array<int, array<string, mixed>> $appEntities * @param array<string, array<string, string>> $expectedSnippets */
self::getAppEntity('appId'),
            [
                'en-GB' => \json_encode(['myCustomSnippetName' => 'newTranslation'], \JSON_THROW_ON_ERROR),
                'foo-bar' => \json_encode(['myCustomSnippetName' => 'newTranslation'], \JSON_THROW_ON_ERROR),
            ],
            'The locale foo-bar does not exists.',
        ];
    }

    private static function getAppEntity(?string $appId = null): AppEntity
    {
        $appEntity = new AppEntity();

        $appEntity->setId($appId ?? Uuid::randomHex());

        return $appEntity;
    }

    /** * @param array<int, array<string, string>> $snippetsFromApp * @param array<int, array<string, string>> $newSnippets * @param array<int, array<string, string>> $deletesSnippetIds */
    
/** * @param array<mixed> $config * * @return array<mixed> */
    public function getConfiguration(array $config): array
    {
        $appLoader = $this->createMock(AppLoader::class);
        $appLoader->method('getConfiguration')->willReturn($config);

        $appCollection = new AppCollection([(new AppEntity())->assign(['name' => 'SwagExampleTest', '_uniqueIdentifier' => 'test'])]);
        $configService = new ConfigurationService(
            [],
            new ConfigReader(),
            $appLoader,
            new StaticEntityRepository([
                $appCollection,
                $appCollection,
            ]),
            new StaticSystemConfigService([])
        );

        
static::assertCount(1, $themes);
        static::assertTrue($themes->first()->isActive());
    }

    public function testHandleUpdateIfNotActivated(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/fixtures/Apps/theme', false);
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/fixtures/Apps/theme/manifest.xml');

        $this->eventDispatcher->dispatch(
            new AppUpdatedEvent(
                (new AppEntity())->assign([
                    'active' => false,
                    'name' => 'SwagTheme',
                    'path' => str_replace(
                        $this->getContainer()->getParameter('kernel.project_dir') . '/',
                        '',
                        $manifest->getPath()
                    ),
                ]),
                $manifest,
                Context::createDefaultContext()
            )
        );
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Framework\Webhook\AclPrivilegeCollection;

/** * @internal */
class AppActivatedEventTest extends TestCase
{
    public function testGetter(): void
    {
        $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 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']);
    }

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