StorefrontPluginConfiguration example

$context = Context::createDefaultContext();
        $event = new PluginPostActivateEvent(
            $this->getPlugin(),
            new ActivateContext(
                $this->createMock(Plugin::class),
                $context,
                '6.1.0',
                '1.0.0',
                $this->createMock(MigrationCollection::class)
            )
        );
        $storefrontPluginConfigMock = new StorefrontPluginConfiguration('SwagTest');
        // Plugin storefront config is already added here         $storefrontPluginConfigCollection = new StorefrontPluginConfigurationCollection([$storefrontPluginConfigMock]);

        $pluginConfigurationFactory = $this->createMock(AbstractStorefrontPluginConfigurationFactory::class);
        $pluginConfigurationFactory->method('createFromBundle')->willReturn($storefrontPluginConfigMock);
        $storefrontPluginRegistry = $this->createMock(StorefrontPluginRegistry::class);
        $storefrontPluginRegistry->method('getConfigurations')->willReturn($storefrontPluginConfigCollection);
        $handler = $this->createMock(ThemeLifecycleHandler::class);
        $handler->expects(static::once())->method('handleThemeInstallOrUpdate')->with(
            $storefrontPluginConfigMock,
            // This ensures the plugin storefront config is not added twice
$commandTester = new CommandTester($themeDumpCommand);

        $commandTester->execute([
            'theme-id' => $this->themeId,
        ]);

        static::assertSame(['any' => 'expectedConfig']$themeFileResolverMock->themeConfig->getThemeConfig());
    }

    private function getPluginRegistryMock(): MockObject&StorefrontPluginRegistry
    {
        $storePluginConfiguration1 = new StorefrontPluginConfiguration('parentTheme');
        $storePluginConfiguration1->setThemeConfig([
            'any' => 'expectedConfig',
        ]);
        $storePluginConfiguration1->setBasePath('');

        $storePluginConfiguration2 = new StorefrontPluginConfiguration('childTheme');
        $storePluginConfiguration2->setThemeConfig([
            'any' => 'unexpectedConfig',
        ]);
        $storePluginConfiguration2->setBasePath('');

        
$importer,
            [],
            $this->createMock(CacheInvalidator::class),
            new MD5ThemePathBuilder(),
            $this->getContainer()->getParameter('kernel.project_dir'),
            $this->getContainer()->get(ScssPhpCompiler::class),
            new MessageBus(),
            0,
            false
        );

        $config = new StorefrontPluginConfiguration('test');
        $config->setAssetPaths(['bla']);

        try {
            $compiler->compileTheme(
                TestDefaults::SALES_CHANNEL,
                'test',
                $config,
                new StorefrontPluginConfigurationCollection(),
                true,
                Context::createDefaultContext()
            );
        }
'active' => true,
            'baseConfig' => [
                'fields' => [
                    'media-field' => self::media(self::MEDIA_ID),
                ],
            ],
        ]];

        $this->themeRepository->create($theme, Context::createDefaultContext());

        $collection = new StorefrontPluginConfigurationCollection([
            new StorefrontPluginConfiguration('base'),
        ]);

        $registry = $this->createMock(StorefrontPluginRegistry::class);
        $registry->method('getConfigurations')
            ->willReturn($collection);

        $service = new DatabaseConfigLoader(
            $this->themeRepository,
            $registry,
            $this->mediaRepository,
            'base',
        );

        try {
            if (!$isFullpath) {
                $path = $this->projectDir . \DIRECTORY_SEPARATOR . str_replace(\DIRECTORY_SEPARATOR . 'Resources', '', $path);
            }
            $pathname = $path . \DIRECTORY_SEPARATOR . 'Resources/theme.json';

            $basePath = realpath(pathinfo($pathname, \PATHINFO_DIRNAME)) ?: $pathname;

            $basePath = $this->stripProjectDir($basePath);

            $config = new StorefrontPluginConfiguration($name);

            $config->setThemeJson($data);
            $config->setBasePath($this->stripProjectDir($basePath));
            $config->setStorefrontEntryFilepath($this->getEntryFile($path));
            $config->setIsTheme(true);
            $config->setName($data['name']);
            $config->setAuthor($data['author']);

            if (\array_key_exists('style', $data) && \is_array($data['style'])) {
                $this->resolveStyleFiles($data['style']$basePath$config);
            }

            
$importer,
            [],
            $this->createMock(CacheInvalidator::class),
            new MD5ThemePathBuilder(),
            __DIR__,
            $this->createMock(ScssPhpCompiler::class),
            new MessageBus(),
            0,
            false
        );

        $config = new StorefrontPluginConfiguration('test');
        $config->setAssetPaths(['bla']);

        $pathBuilder = new MD5ThemePathBuilder();
        static::assertEquals('9a11a759d278b4a55cb5e2c3414733c1', $pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'test'));

        try {
            $pathBuilder->getDecorated();
        } catch (DecorationPatternException $e) {
            static::assertInstanceOf(DecorationPatternException::class$e);
        }

        
use Shopware\Storefront\Theme\ConfigLoader\StaticFileConfigDumper;
use Shopware\Storefront\Theme\StorefrontPluginConfiguration\StorefrontPluginConfiguration;

/** * @internal */
class StaticFileConfigDumperTest extends TestCase
{
    public function testDumping(): void
    {
        $loader = $this->createMock(DatabaseConfigLoader::class);
        $loader->method('load')->willReturn(new StorefrontPluginConfiguration('Test'));

        $fs = $this->createMock(Filesystem::class);
        $fs->expects(static::exactly(4))->method('write');

        $themeProvider = $this->createMock(DatabaseAvailableThemeProvider::class);
        $themeProvider->method('load')->willReturn(['test' => 'test']);

        $dumper = new StaticFileConfigDumper(
            $loader,
            $themeProvider,
            $fs
        );

class ThemeInheritanceBuilderTest extends TestCase
{
    private ThemeInheritanceBuilder $builder;

    protected function setUp(): void
    {
        $this->builder = new ThemeInheritanceBuilder(new TestStorefrontPluginRegistry(
            new StorefrontPluginConfigurationCollection([
                new StorefrontPluginConfiguration('Storefront'),
            ])
        ));
    }

    public function testBuildPreservesThePluginOrder(): void
    {
        $result = $this->builder->build([
            'ExtensionPlugin' => [],
            'BasePlugin' => [],
            'Storefront' => [],
        ][
            
$this->themeServiceMock,
            $this->themeRepositoryMock,
            $this->configurationRegistryMock,
            $this->connectionMock
        );

        $this->context = Context::createDefaultContext();
    }

    public function testThemeUninstallWithoutData(): void
    {
        $themeConfig = new StorefrontPluginConfiguration('SimpleTheme');
        $themeConfig->setStyleFiles(new FileCollection());
        $themeConfig->setScriptFiles(new FileCollection());
        $themeConfig->setName('Simple Theme');
        $themeConfig->setIsTheme(true);

        $collection = new StorefrontPluginConfigurationCollection([
            $themeConfig,
        ]);

        $this->configurationRegistryMock->expects(static::once())->method('getConfigurations')->willReturn(
            $collection
        );
$application->add($themeChangeCommand);

        $commandTester->execute([
            'theme-name' => $themes[0]['technicalName'],
            '--sales-channel' => $salesChannel['id'],
            '--no-compile' => true,
        ]);
    }

    private function getPluginRegistryMock(): MockObject&StorefrontPluginRegistry
    {
        $storePluginConfiguration1 = new StorefrontPluginConfiguration('parentTheme');
        $storePluginConfiguration1->setThemeConfig([
            'any' => 'expectedConfig',
        ]);
        $storePluginConfiguration1->setBasePath('');

        $storePluginConfiguration2 = new StorefrontPluginConfiguration('childTheme');
        $storePluginConfiguration2->setThemeConfig([
            'any' => 'unexpectedConfig',
        ]);
        $storePluginConfiguration2->setBasePath('');

        
$this->themeRepositoryMock->method('search')->willReturn(
            new EntitySearchResult(
                'theme',
                1,
                $themeCollection,
                null,
                new Criteria(),
                $this->context
            )
        );

        $storefrontPlugin = new StorefrontPluginConfiguration('Test');
        $storefrontPlugin->setThemeConfig(ThemeFixtures::getThemeJsonConfig());

        $this->storefrontPluginRegistryMock->method('getConfigurations')->willReturn(
            new StorefrontPluginConfigurationCollection(
                [
                    $storefrontPlugin,
                ]
            )
        );

        $config = $this->themeService->getThemeConfiguration($ids['themeId'], true, $this->context);

        


        $container = $this->createMock(ContainerInterface::class);
        $container->method('has')->with(StorefrontPluginRegistry::class)->willReturn($withThemeRegistry);
        $themeLoader = null;
        $this->connection->expects(static::once())->method('fetchOne')->willReturn($fetchLocaleResult);

        if ($withThemeRegistry) {
            $plugins = new StorefrontPluginConfigurationCollection();

            foreach (['Storefront', 'SwagTheme'] as $technicalName) {
                $theme = new StorefrontPluginConfiguration($technicalName);
                $theme->setIsTheme(true);
                $plugins->add($theme);
            }

            $themeRegistry = $this->createMock(StorefrontPluginRegistry::class);
            $themeRegistry->expects(static::once())->method('getConfigurations')->willReturn($plugins);
            $container->expects(static::exactly(1))->method('get')->with(StorefrontPluginRegistry::class)->willReturn($themeRegistry);
        }

        if ($salesChannelId !== null) {
            $themeLoader = $this->createMock(SalesChannelThemeLoader::class);
            
if (!$this->filesystem->fileExists($path)) {
            throw new \RuntimeException('Cannot find theme configuration. Did you run bin/console theme:dump');
        }

        $fileContent = $this->filesystem->read($path);
        \assert(\is_string($fileContent));
        $fileObject = json_decode($fileContent, true, 512, \JSON_THROW_ON_ERROR);

        $fileObject = $this->prepareCollections($fileObject);

        $config = new StorefrontPluginConfiguration('');
        $config->assign($fileObject);

        return $config;
    }

    private function prepareCollections(array $fileObject): array
    {
        $fileObject['styleFiles'] = array_map(fn (array $file) => (new File(''))->assign($file)$fileObject['styleFiles']);

        $fileObject['scriptFiles'] = array_map(fn (array $file) => (new File(''))->assign($file)$fileObject['scriptFiles']);

        
abstract public function createFromBundle(Bundle $bundle): StorefrontPluginConfiguration;

    abstract public function createFromApp(string $appName, string $appPath): StorefrontPluginConfiguration;

    /** * @decrecated tag:v6.6.0 - will be abstract, implementation has to be in the concrete class * * @param array<string, mixed> $data */
    public function createFromThemeJson(string $name, array $data, string $path, bool $isFullpath = true): StorefrontPluginConfiguration
    {
        return new StorefrontPluginConfiguration($name);
    }
}
Home | Imprint | This part of the site doesn't use cookies.