diff --git a/composer.json b/composer.json index 19de5529d6..0cf3ab214d 100644 --- a/composer.json +++ b/composer.json @@ -52,8 +52,9 @@ "sonata-project/intl-bundle": "^2.2", "stof/doctrine-extensions-bundle": "^1.2", "swiftmailer/swiftmailer": "^6.0", - "sylius/fixtures-bundle": "~1.1.15", "sylius-labs/association-hydrator": "^1.0", + "sylius/fixtures-bundle": "~1.1.15", + "sylius/theme-bundle": "~1.1.15", "symfony/monolog-bundle": "^3.0", "symfony/polyfill-iconv": "^1.3", "symfony/polyfill-intl-icu": "^1.3", @@ -144,7 +145,6 @@ "sylius/taxation-bundle": "self.version", "sylius/taxonomy": "self.version", "sylius/taxonomy-bundle": "self.version", - "sylius/theme-bundle": "self.version", "sylius/ui-bundle": "self.version", "sylius/user": "self.version", "sylius/user-bundle": "self.version", diff --git a/phpspec.yml.dist b/phpspec.yml.dist index af5c55316e..533a8e76ab 100644 --- a/phpspec.yml.dist +++ b/phpspec.yml.dist @@ -45,7 +45,6 @@ suites: ShopBundle: { namespace: Sylius\Bundle\ShopBundle, psr4_prefix: Sylius\Bundle\ShopBundle, spec_path: src/Sylius/Bundle/ShopBundle, src_path: src/Sylius/Bundle/ShopBundle } TaxationBundle: { namespace: Sylius\Bundle\TaxationBundle, psr4_prefix: Sylius\Bundle\TaxationBundle, spec_path: src/Sylius/Bundle/TaxationBundle, src_path: src/Sylius/Bundle/TaxationBundle } TaxonomyBundle: { namespace: Sylius\Bundle\TaxonomyBundle, psr4_prefix: Sylius\Bundle\TaxonomyBundle, spec_path: src/Sylius/Bundle/TaxonomyBundle, src_path: src/Sylius/Bundle/TaxonomyBundle } - ThemeBundle: { namespace: Sylius\Bundle\ThemeBundle, psr4_prefix: Sylius\Bundle\ThemeBundle , spec_path: src/Sylius/Bundle/ThemeBundle, src_path: src/Sylius/Bundle/ThemeBundle } UiBundle: { namespace: Sylius\Bundle\UiBundle, psr4_prefix: Sylius\Bundle\UiBundle, spec_path: src/Sylius/Bundle/UiBundle, src_path: src/Sylius/Bundle/UiBundle } UserBundle: { namespace: Sylius\Bundle\UserBundle, psr4_prefix: Sylius\Bundle\UserBundle, spec_path: src/Sylius/Bundle/UserBundle, src_path: src/Sylius/Bundle/UserBundle } diff --git a/src/Sylius/Bundle/ThemeBundle/.gitignore b/src/Sylius/Bundle/ThemeBundle/.gitignore deleted file mode 100644 index dd3906cf2b..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/vendor/ -/bin/ - -/composer.phar -/composer.lock - -/phpspec.yml -/phpunit.xml diff --git a/src/Sylius/Bundle/ThemeBundle/Asset/Installer/AssetsInstaller.php b/src/Sylius/Bundle/ThemeBundle/Asset/Installer/AssetsInstaller.php deleted file mode 100644 index ac1bb9fb54..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Asset/Installer/AssetsInstaller.php +++ /dev/null @@ -1,280 +0,0 @@ -filesystem = $filesystem; - $this->kernel = $kernel; - $this->themeRepository = $themeRepository; - $this->themeHierarchyProvider = $themeHierarchyProvider; - $this->pathResolver = $pathResolver; - } - - /** - * {@inheritdoc} - */ - public function installAssets(string $targetDir, int $symlinkMask): int - { - // Create the bundles directory otherwise symlink will fail. - $targetDir = rtrim($targetDir, '/') . '/bundles/'; - $this->filesystem->mkdir($targetDir); - - $effectiveSymlinkMask = $symlinkMask; - foreach ($this->kernel->getBundles() as $bundle) { - $effectiveSymlinkMask = min($effectiveSymlinkMask, $this->installBundleAssets($bundle, $targetDir, $symlinkMask)); - } - - return $effectiveSymlinkMask; - } - - /** - * {@inheritdoc} - */ - public function installBundleAssets(BundleInterface $bundle, string $targetDir, int $symlinkMask): int - { - $targetDir .= preg_replace('/bundle$/', '', strtolower($bundle->getName())); - - $this->filesystem->remove($targetDir); - - $effectiveSymlinkMask = $symlinkMask; - foreach ($this->findAssetsPaths($bundle) as $originDir) { - $effectiveSymlinkMask = min( - $effectiveSymlinkMask, - $this->installVanillaBundleAssets($originDir, $targetDir, $symlinkMask) - ); - } - - foreach ($this->themeRepository->findAll() as $theme) { - $themes = $this->themeHierarchyProvider->getThemeHierarchy($theme); - - foreach ($this->findAssetsPaths($bundle, $themes) as $originDir) { - $effectiveSymlinkMask = min( - $effectiveSymlinkMask, - $this->installThemedBundleAssets($theme, $originDir, $targetDir, $symlinkMask) - ); - } - } - - return $effectiveSymlinkMask; - } - - /** - * @param ThemeInterface $theme - * @param string $originDir - * @param string $targetDir - * @param int $symlinkMask - * - * @return int - */ - private function installThemedBundleAssets(ThemeInterface $theme, string $originDir, string $targetDir, int $symlinkMask): int - { - $effectiveSymlinkMask = $symlinkMask; - - $finder = new Finder(); - $finder->sortByName()->ignoreDotFiles(false)->in($originDir); - - /** @var SplFileInfo[] $finder */ - foreach ($finder as $originFile) { - $targetFile = $targetDir . '/' . $originFile->getRelativePathname(); - $targetFile = $this->pathResolver->resolve($targetFile, $theme); - - if (file_exists($targetFile) && AssetsInstallerInterface::HARD_COPY !== $symlinkMask) { - continue; - } - - $this->filesystem->mkdir(dirname($targetFile)); - - $effectiveSymlinkMask = min( - $effectiveSymlinkMask, - $this->installAsset($originFile->getPathname(), $targetFile, $symlinkMask) - ); - } - - return $effectiveSymlinkMask; - } - - /** - * @param string $originDir - * @param string $targetDir - * @param int $symlinkMask - * - * @return int - */ - private function installVanillaBundleAssets(string $originDir, string $targetDir, int $symlinkMask): int - { - return $this->installAsset($originDir, $targetDir, $symlinkMask); - } - - /** - * @param string $origin - * @param string $target - * @param int $symlinkMask - * - * @return int - */ - private function installAsset(string $origin, string $target, int $symlinkMask): int - { - if (AssetsInstallerInterface::RELATIVE_SYMLINK === $symlinkMask) { - try { - $targetDirname = realpath(is_dir($target) ? $target : dirname($target)); - $relativeOrigin = rtrim($this->filesystem->makePathRelative($origin, $targetDirname), '/'); - - $this->doInstallAsset($relativeOrigin, $target, true); - - return AssetsInstallerInterface::RELATIVE_SYMLINK; - } catch (IOException $exception) { - // Do nothing, trying to create non-relative symlinks later. - } - } - - if (AssetsInstallerInterface::HARD_COPY !== $symlinkMask) { - try { - $this->doInstallAsset($origin, $target, true); - - return AssetsInstallerInterface::SYMLINK; - } catch (IOException $exception) { - // Do nothing, hard copy later. - } - } - - $this->doInstallAsset($origin, $target, false); - - return AssetsInstallerInterface::HARD_COPY; - } - - /** - * @param string $origin - * @param string $target - * @param bool $symlink - * - * @throws IOException When failed to make symbolic link, if requested. - */ - private function doInstallAsset(string $origin, string $target, bool $symlink): void - { - if ($symlink) { - $this->doSymlinkAsset($origin, $target); - - return; - } - - $this->doCopyAsset($origin, $target); - } - - /** - * @param BundleInterface $bundle - * @param array|ThemeInterface[] $themes - * - * @return array - */ - private function findAssetsPaths(BundleInterface $bundle, array $themes = []): array - { - $sources = []; - - foreach ($themes as $theme) { - $sourceDir = $theme->getPath() . '/' . $bundle->getName() . '/public'; - if (is_dir($sourceDir)) { - $sources[] = $sourceDir; - } - } - - $sourceDir = $bundle->getPath() . '/Resources/public'; - if (is_dir($sourceDir)) { - $sources[] = $sourceDir; - } - - return $sources; - } - - /** - * @param string $origin - * @param string $target - * - * @throws IOException If symbolic link is broken - */ - private function doSymlinkAsset(string $origin, string $target): void - { - $this->filesystem->symlink($origin, $target); - - if (!file_exists($target)) { - throw new IOException('Symbolic link is broken'); - } - } - - /** - * @param string $origin - * @param string $target - */ - private function doCopyAsset(string $origin, string $target): void - { - if (is_dir($origin)) { - $this->filesystem->mkdir($target, 0777); - $this->filesystem->mirror($origin, $target, Finder::create()->ignoreDotFiles(false)->in($origin)); - - return; - } - - $this->filesystem->copy($origin, $target); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Asset/Installer/AssetsInstallerInterface.php b/src/Sylius/Bundle/ThemeBundle/Asset/Installer/AssetsInstallerInterface.php deleted file mode 100644 index e6271a5c81..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Asset/Installer/AssetsInstallerInterface.php +++ /dev/null @@ -1,63 +0,0 @@ -assetsInstaller = $assetsInstaller; - $this->output = new NullOutput(); - } - - /** - * {@inheritdoc} - */ - public function setOutput(OutputInterface $output): void - { - $this->output = $output; - } - - /** - * {@inheritdoc} - */ - public function installAssets(string $targetDir, int $symlinkMask): int - { - $this->output->writeln($this->provideExpectationComment($symlinkMask)); - - return $this->assetsInstaller->installAssets($targetDir, $symlinkMask); - } - - /** - * {@inheritdoc} - */ - public function installBundleAssets(BundleInterface $bundle, string $targetDir, int $symlinkMask): int - { - $this->output->writeln(sprintf( - 'Installing assets for %s into %s', - $bundle->getNamespace(), - $targetDir - )); - - $effectiveSymlinkMask = $this->assetsInstaller->installBundleAssets($bundle, $targetDir, $symlinkMask); - - $this->output->writeln($this->provideResultComment($symlinkMask, $effectiveSymlinkMask)); - - return $effectiveSymlinkMask; - } - - /** - * @param int $symlinkMask - * @param int $effectiveSymlinkMask - * - * @return string - */ - private function provideResultComment(int $symlinkMask, int $effectiveSymlinkMask): string - { - if ($effectiveSymlinkMask === $symlinkMask) { - switch ($symlinkMask) { - case AssetsInstallerInterface::HARD_COPY: - return 'The assets were copied.'; - case AssetsInstallerInterface::SYMLINK: - return 'The assets were installed using symbolic links.'; - case AssetsInstallerInterface::RELATIVE_SYMLINK: - return 'The assets were installed using relative symbolic links.'; - } - } - - switch ($symlinkMask + $effectiveSymlinkMask) { - case AssetsInstallerInterface::SYMLINK: - case AssetsInstallerInterface::RELATIVE_SYMLINK: - return 'It looks like your system doesn\'t support symbolic links, so the assets were copied.'; - case AssetsInstallerInterface::RELATIVE_SYMLINK + AssetsInstallerInterface::SYMLINK: - return 'It looks like your system doesn\'t support relative symbolic links, so the assets were installed by using absolute symbolic links.'; - } - - return 'Something gone bad, can\'t provide the result of assets installing!'; - } - - /** - * @param int $symlinkMask - * - * @return string - */ - private function provideExpectationComment(int $symlinkMask): string - { - if (AssetsInstallerInterface::HARD_COPY === $symlinkMask) { - return 'Installing assets as hard copies.'; - } - - return 'Trying to install assets as symbolic links.'; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Asset/Installer/OutputAwareInterface.php b/src/Sylius/Bundle/ThemeBundle/Asset/Installer/OutputAwareInterface.php deleted file mode 100644 index 7a9bd946c8..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Asset/Installer/OutputAwareInterface.php +++ /dev/null @@ -1,24 +0,0 @@ -themeContext = $themeContext; - $this->pathResolver = $pathResolver; - } - - /** - * {@inheritdoc} - */ - public function getUrl($path): string - { - if ($this->isAbsoluteUrl($path)) { - return $path; - } - - $theme = $this->themeContext->getTheme(); - if (null !== $theme) { - $path = $this->pathResolver->resolve($path, $theme); - } - - $versionedPath = $this->getVersionStrategy()->applyVersion($path); - - // if absolute or begins with /, we're done - if ($this->isAbsoluteUrl($versionedPath) || ($versionedPath && '/' === $versionedPath[0])) { - return $versionedPath; - } - - return $this->getBasePath() . ltrim($versionedPath, '/'); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Asset/Package/UrlPackage.php b/src/Sylius/Bundle/ThemeBundle/Asset/Package/UrlPackage.php deleted file mode 100644 index acb94bc2af..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Asset/Package/UrlPackage.php +++ /dev/null @@ -1,132 +0,0 @@ -baseUrls[] = rtrim($baseUrl, '/'); - } - - $sslUrls = $this->getSslUrls($baseUrls); - - if ($sslUrls && $baseUrls !== $sslUrls) { - $this->sslPackage = new self($sslUrls, $versionStrategy, $themeContext, $pathResolver); - } - - $this->themeContext = $themeContext; - $this->pathResolver = $pathResolver; - } - - /** - * {@inheritdoc} - */ - public function getUrl($path): string - { - if ($this->isAbsoluteUrl($path)) { - return $path; - } - - if (null !== $this->sslPackage && $this->getContext()->isSecure()) { - return $this->sslPackage->getUrl($path); - } - - $theme = $this->themeContext->getTheme(); - if (null !== $theme) { - $path = $this->pathResolver->resolve($path, $theme); - } - - $url = $this->getVersionStrategy()->applyVersion($path); - - if ($this->isAbsoluteUrl($url)) { - return $url; - } - - if ($url && '/' != $url[0]) { - $url = '/' . $url; - } - - return $this->getBaseUrl($path) . $url; - } - - /** - * @param array $urls - * - * @return array - */ - private function getSslUrls(array $urls): array - { - $sslUrls = []; - - foreach ($urls as $url) { - if ('https://' === substr($url, 0, 8) || '//' === substr($url, 0, 2)) { - $sslUrls[] = $url; - } elseif ('http://' !== substr($url, 0, 7)) { - throw new InvalidArgumentException(sprintf('"%s" is not a valid URL', $url)); - } - } - - return $sslUrls; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Asset/PathResolver.php b/src/Sylius/Bundle/ThemeBundle/Asset/PathResolver.php deleted file mode 100644 index d6166db530..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Asset/PathResolver.php +++ /dev/null @@ -1,27 +0,0 @@ -getName() . '/', $path); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Asset/PathResolverInterface.php b/src/Sylius/Bundle/ThemeBundle/Asset/PathResolverInterface.php deleted file mode 100644 index 24703e8d97..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Asset/PathResolverInterface.php +++ /dev/null @@ -1,30 +0,0 @@ -themeRepository = $themeRepository; - $this->themeContext = $themeContext; - $this->themeHierarchyProvider = $themeHierarchyProvider; - - $this->data = [ - 'used_theme' => null, - 'used_themes' => [], - 'themes' => [], - ]; - } - - /** - * @return ThemeInterface|null - */ - public function getUsedTheme(): ?ThemeInterface - { - return $this->data['used_theme']; - } - - /** - * @return array|ThemeInterface[] - */ - public function getUsedThemes(): array - { - return $this->data['used_themes']; - } - - /** - * @return ThemeInterface[] - */ - public function getThemes(): array - { - return $this->data['themes']; - } - - /** - * {@inheritdoc} - */ - public function collect(Request $request, Response $response, ?\Exception $exception = null): void - { - $usedTheme = $this->themeContext->getTheme(); - - $this->data['used_theme'] = $usedTheme; - $this->data['used_themes'] = null !== $usedTheme ? $this->themeHierarchyProvider->getThemeHierarchy($usedTheme) : []; - $this->data['themes'] = $this->themeRepository->findAll(); - } - - /** - * {@inheritdoc} - */ - public function reset(): void - { - $this->data['used_theme'] = null; - $this->data['used_themes'] = []; - $this->data['themes'] = []; - } - - /** - * {@inheritdoc} - */ - public function getName(): string - { - return 'sylius_theme'; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Command/AssetsInstallCommand.php b/src/Sylius/Bundle/ThemeBundle/Command/AssetsInstallCommand.php deleted file mode 100644 index 1d3567400e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Command/AssetsInstallCommand.php +++ /dev/null @@ -1,95 +0,0 @@ -setName('sylius:theme:assets:install') - ->setDefinition([ - new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'web'), - ]) - ->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it') - ->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks') - ->setDescription('Installs themes web assets under a public web directory') - ->setHelp($this->getHelpMessage()) - ; - } - - /** - * {@inheritdoc} - * - * @throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used - */ - protected function execute(InputInterface $input, OutputInterface $output): void - { - $assetsInstaller = $this->getContainer()->get('sylius.theme.asset.assets_installer'); - if ($assetsInstaller instanceof OutputAwareInterface) { - $assetsInstaller->setOutput($output); - } - - $symlinkMask = AssetsInstallerInterface::HARD_COPY; - - if ($input->getOption('symlink')) { - $symlinkMask = max($symlinkMask, AssetsInstallerInterface::SYMLINK); - } - - if ($input->getOption('relative')) { - $symlinkMask = max($symlinkMask, AssetsInstallerInterface::RELATIVE_SYMLINK); - } - - $assetsInstaller->installAssets($input->getArgument('target'), $symlinkMask); - } - - /** - * @return string - */ - private function getHelpMessage(): string - { - return <<%command.name% command installs theme assets into a given -directory (e.g. the web directory). - - php %command.full_name% web - -A "themes" directory will be created inside the target directory. - -To create a symlink to each theme instead of copying its assets, use the ---symlink option (will fall back to hard copies when symbolic links aren't possible): - - php %command.full_name% web --symlink - -To make symlink relative, add the --relative option: - - php %command.full_name% web --symlink --relative - -EOT; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Command/ListCommand.php b/src/Sylius/Bundle/ThemeBundle/Command/ListCommand.php deleted file mode 100644 index 82185bad7e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Command/ListCommand.php +++ /dev/null @@ -1,61 +0,0 @@ -setName('sylius:theme:list') - ->setDescription('Shows list of detected themes.') - ; - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output): void - { - /** @var ThemeInterface[] $themes */ - $themes = $this->getContainer()->get('sylius.repository.theme')->findAll(); - - if (0 === count($themes)) { - $output->writeln('There are no themes.'); - - return; - } - - $output->writeln('Successfully loaded themes:'); - - $table = new Table($output); - $table->setHeaders(['Title', 'Name', 'Path']); - - foreach ($themes as $theme) { - $table->addRow([$theme->getTitle(), $theme->getName(), $theme->getPath()]); - } - - $table->setStyle('borderless'); - $table->render(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/CompositeConfigurationProvider.php b/src/Sylius/Bundle/ThemeBundle/Configuration/CompositeConfigurationProvider.php deleted file mode 100644 index 69c53a7775..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/CompositeConfigurationProvider.php +++ /dev/null @@ -1,46 +0,0 @@ -configurationProviders = $configurationProviders; - } - - /** - * {@inheritdoc} - */ - public function getConfigurations(): array - { - $configurations = []; - foreach ($this->configurationProviders as $configurationProvider) { - $configurations = array_merge( - $configurations, - $configurationProvider->getConfigurations() - ); - } - - return $configurations; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/ConfigurationProcessorInterface.php b/src/Sylius/Bundle/ThemeBundle/Configuration/ConfigurationProcessorInterface.php deleted file mode 100644 index 13bcee76db..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/ConfigurationProcessorInterface.php +++ /dev/null @@ -1,24 +0,0 @@ -fileLocator = $fileLocator; - $this->loader = $loader; - $this->configurationFilename = $configurationFilename; - } - - /** - * {@inheritdoc} - */ - public function getConfigurations(): array - { - try { - return array_map( - [$this->loader, 'load'], - $this->fileLocator->locateFilesNamed($this->configurationFilename) - ); - } catch (\InvalidArgumentException $exception) { - return []; - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/FilesystemConfigurationSourceFactory.php b/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/FilesystemConfigurationSourceFactory.php deleted file mode 100644 index b6a6648242..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/FilesystemConfigurationSourceFactory.php +++ /dev/null @@ -1,78 +0,0 @@ -fixXmlConfig('directory', 'directories') - ->children() - ->scalarNode('filename')->defaultValue('composer.json')->cannotBeEmpty()->end() - ->integerNode('scan_depth')->info('Restrict depth to scan for configuration file inside theme folder')->defaultNull()->end() - ->arrayNode('directories') - ->defaultValue(['%kernel.root_dir%/themes']) - ->requiresAtLeastOneElement() - ->performNoDeepMerging() - ->prototype('scalar') - ->end() - ; - } - - /** - * {@inheritdoc} - */ - public function initializeSource(ContainerBuilder $container, array $config): Definition - { - $recursiveFileLocator = new Definition(RecursiveFileLocator::class, [ - new Reference('sylius.theme.finder_factory'), - $config['directories'], - $config['scan_depth'], - ]); - - $configurationLoader = new Definition(ProcessingConfigurationLoader::class, [ - new Definition(JsonFileConfigurationLoader::class, [ - new Reference('sylius.theme.filesystem'), - ]), - new Reference('sylius.theme.configuration.processor'), - ]); - - $configurationProvider = new Definition(FilesystemConfigurationProvider::class, [ - $recursiveFileLocator, - $configurationLoader, - $config['filename'], - ]); - - return $configurationProvider; - } - - /** - * {@inheritdoc} - */ - public function getName(): string - { - return 'filesystem'; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/JsonFileConfigurationLoader.php b/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/JsonFileConfigurationLoader.php deleted file mode 100644 index 8681d93380..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/JsonFileConfigurationLoader.php +++ /dev/null @@ -1,60 +0,0 @@ -filesystem = $filesystem; - } - - /** - * {@inheritdoc} - */ - public function load(string $identifier): array - { - $this->assertFileExists($identifier); - - $contents = $this->filesystem->getFileContents($identifier); - - return array_merge( - ['path' => dirname($identifier)], - json_decode($contents, true) - ); - } - - /** - * @param string $path - */ - private function assertFileExists(string $path): void - { - if (!$this->filesystem->exists($path)) { - throw new \InvalidArgumentException(sprintf( - 'Given file "%s" does not exist!', - $path - )); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/ProcessingConfigurationLoader.php b/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/ProcessingConfigurationLoader.php deleted file mode 100644 index 89a210d211..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/Filesystem/ProcessingConfigurationLoader.php +++ /dev/null @@ -1,54 +0,0 @@ -decoratedLoader = $decoratedLoader; - $this->configurationProcessor = $configurationProcessor; - } - - /** - * {@inheritdoc} - */ - public function load(string $identifier): array - { - $rawConfiguration = $this->decoratedLoader->load($identifier); - - $configurations = [$rawConfiguration]; - if (isset($rawConfiguration['extra']['sylius-theme'])) { - $configurations[] = $rawConfiguration['extra']['sylius-theme']; - } - - return $this->configurationProcessor->process($configurations); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/SymfonyConfigurationProcessor.php b/src/Sylius/Bundle/ThemeBundle/Configuration/SymfonyConfigurationProcessor.php deleted file mode 100644 index 9130a7a78f..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/SymfonyConfigurationProcessor.php +++ /dev/null @@ -1,48 +0,0 @@ -configuration = $configuration; - $this->processor = $processor; - } - - /** - * {@inheritdoc} - */ - public function process(array $configs): array - { - return $this->processor->processConfiguration($this->configuration, $configs); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestConfigurationProvider.php b/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestConfigurationProvider.php deleted file mode 100644 index f970fb50c5..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestConfigurationProvider.php +++ /dev/null @@ -1,40 +0,0 @@ -testThemeConfigurationManager = $testThemeConfigurationManager; - } - - /** - * {@inheritdoc} - */ - public function getConfigurations(): array - { - return $this->testThemeConfigurationManager->findAll(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestConfigurationSourceFactory.php b/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestConfigurationSourceFactory.php deleted file mode 100644 index ef4296aa86..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestConfigurationSourceFactory.php +++ /dev/null @@ -1,58 +0,0 @@ -setDefinition( - 'sylius.theme.test_theme_configuration_manager', - new Definition(TestThemeConfigurationManager::class, [ - new Reference('sylius.theme.configuration.processor'), - new Parameter('kernel.cache_dir'), - ]) - ); - - return new Definition(TestConfigurationProvider::class, [ - new Reference('sylius.theme.test_theme_configuration_manager'), - ]); - } - - /** - * {@inheritdoc} - */ - public function getName(): string - { - return 'test'; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestThemeConfigurationManager.php b/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestThemeConfigurationManager.php deleted file mode 100644 index 0cb27a1a6d..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestThemeConfigurationManager.php +++ /dev/null @@ -1,169 +0,0 @@ -configurationProcessor = $configurationProcessor; - $this->filesystem = new Filesystem(); - $this->configurationsFile = rtrim($cacheDir, '/') . '/_test_themes/data.serialized'; - } - - /** - * {@inheritdoc} - */ - public function findAll(): array - { - $this->initializeIfNeeded(); - - return $this->load(); - } - - /** - * {@inheritdoc} - */ - public function add(array $configuration): void - { - $this->initializeIfNeeded(); - - $configuration = $this->configurationProcessor->process([$configuration]); - $configuration['path'] = $this->getThemeDirectory($configuration['name']); - - $this->initializeTheme($configuration['name']); - - $configurations = $this->load(); - $configurations[] = $configuration; - $this->save($configurations); - } - - /** - * {@inheritdoc} - */ - public function remove(string $themeName): void - { - $this->initializeIfNeeded(); - - $this->clearTheme($themeName); - - $configurations = $this->load(); - $configurations = array_filter($configurations, function ($configuration) use ($themeName) { - return isset($configuration['name']) && $configuration['name'] !== $themeName; - }); - $this->save($configurations); - } - - /** - * {@inheritdoc} - */ - public function clear(): void - { - $configurationsDirectory = dirname($this->configurationsFile); - - if ($this->filesystem->exists($configurationsDirectory)) { - $this->filesystem->remove($configurationsDirectory); - } - } - - /** - * @return array - */ - private function load(): array - { - return unserialize(file_get_contents($this->configurationsFile)); - } - - /** - * @param array $configurations - */ - private function save(array $configurations): void - { - file_put_contents($this->configurationsFile, serialize($configurations)); - } - - private function initializeIfNeeded(): void - { - if ($this->filesystem->exists($this->configurationsFile)) { - return; - } - - $this->initialize(); - } - - private function initialize(): void - { - $configurationsDirectory = dirname($this->configurationsFile); - - $this->filesystem->mkdir($configurationsDirectory); - - $this->save([]); - } - - /** - * @param string $themeName - */ - private function initializeTheme(string $themeName): void - { - $themeDirectory = $this->getThemeDirectory($themeName); - - $this->filesystem->mkdir($themeDirectory); - } - - /** - * @param string $themeName - */ - private function clearTheme(string $themeName): void - { - $themeDirectory = $this->getThemeDirectory($themeName); - - if (!$this->filesystem->exists($themeDirectory)) { - return; - } - - $this->filesystem->remove($themeDirectory); - } - - /** - * @param string $themeName - * - * @return string - */ - private function getThemeDirectory(string $themeName): string - { - return rtrim(dirname($this->configurationsFile), '/') . '/' . $themeName; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestThemeConfigurationManagerInterface.php b/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestThemeConfigurationManagerInterface.php deleted file mode 100644 index f64af8baa3..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Configuration/Test/TestThemeConfigurationManagerInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -root('sylius_theme'); - $rootNodeDefinition->ignoreExtraKeys(); - - $this->addRequiredNameField($rootNodeDefinition); - $this->addOptionalTitleField($rootNodeDefinition); - $this->addOptionalDescriptionField($rootNodeDefinition); - $this->addOptionalPathField($rootNodeDefinition); - $this->addOptionalParentsList($rootNodeDefinition); - $this->addOptionalScreenshotsList($rootNodeDefinition); - $this->addOptionalAuthorsList($rootNodeDefinition); - - return $treeBuilder; - } - - /** - * @param ArrayNodeDefinition $rootNodeDefinition - */ - private function addRequiredNameField(ArrayNodeDefinition $rootNodeDefinition): void - { - $rootNodeDefinition->children()->scalarNode('name')->isRequired()->cannotBeEmpty(); - } - - /** - * @param ArrayNodeDefinition $rootNodeDefinition - */ - private function addOptionalTitleField(ArrayNodeDefinition $rootNodeDefinition): void - { - $rootNodeDefinition->children()->scalarNode('title')->cannotBeEmpty(); - } - - /** - * @param ArrayNodeDefinition $rootNodeDefinition - */ - private function addOptionalDescriptionField(ArrayNodeDefinition $rootNodeDefinition): void - { - $rootNodeDefinition->children()->scalarNode('description')->cannotBeEmpty(); - } - - /** - * @param ArrayNodeDefinition $rootNodeDefinition - */ - private function addOptionalPathField(ArrayNodeDefinition $rootNodeDefinition): void - { - $rootNodeDefinition->children()->scalarNode('path')->cannotBeEmpty(); - } - - /** - * @param ArrayNodeDefinition $rootNodeDefinition - */ - private function addOptionalParentsList(ArrayNodeDefinition $rootNodeDefinition): void - { - $parentsNodeDefinition = $rootNodeDefinition->children()->arrayNode('parents'); - $parentsNodeDefinition - ->requiresAtLeastOneElement() - ->performNoDeepMerging() - ->scalarPrototype() - ->cannotBeEmpty() - ; - } - - /** - * @param ArrayNodeDefinition $rootNodeDefinition - */ - private function addOptionalScreenshotsList(ArrayNodeDefinition $rootNodeDefinition): void - { - $screenshotsNodeDefinition = $rootNodeDefinition->children()->arrayNode('screenshots'); - $screenshotsNodeDefinition - ->requiresAtLeastOneElement() - ->performNoDeepMerging() - ; - - /** @var ArrayNodeDefinition $screenshotNodeDefinition */ - $screenshotNodeDefinition = $screenshotsNodeDefinition->arrayPrototype(); - - $screenshotNodeDefinition - ->validate() - ->ifTrue(function ($screenshot) { - return [] === $screenshot || ['path' => ''] === $screenshot; - }) - ->thenInvalid('Screenshot cannot be empty!') - ; - $screenshotNodeDefinition - ->beforeNormalization() - ->ifString() - ->then(function ($value) { - return ['path' => $value]; - }) - ; - - $screenshotNodeBuilder = $screenshotNodeDefinition->children(); - $screenshotNodeBuilder->scalarNode('path')->isRequired(); - $screenshotNodeBuilder->scalarNode('title')->cannotBeEmpty(); - $screenshotNodeBuilder->scalarNode('description')->cannotBeEmpty(); - } - - /** - * @param ArrayNodeDefinition $rootNodeDefinition - */ - private function addOptionalAuthorsList(ArrayNodeDefinition $rootNodeDefinition): void - { - $authorsNodeDefinition = $rootNodeDefinition->children()->arrayNode('authors'); - $authorsNodeDefinition - ->requiresAtLeastOneElement() - ->performNoDeepMerging() - ; - - /** @var ArrayNodeDefinition $authorNodeDefinition */ - $authorNodeDefinition = $authorsNodeDefinition->arrayPrototype(); - $authorNodeDefinition - ->validate() - ->ifTrue(function ($author) { - return [] === $author; - }) - ->thenInvalid('Author cannot be empty!') - ; - - $authorNodeBuilder = $authorNodeDefinition->children(); - $authorNodeBuilder->scalarNode('name')->cannotBeEmpty(); - $authorNodeBuilder->scalarNode('email')->cannotBeEmpty(); - $authorNodeBuilder->scalarNode('homepage')->cannotBeEmpty(); - $authorNodeBuilder->scalarNode('role')->cannotBeEmpty(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Context/EmptyThemeContext.php b/src/Sylius/Bundle/ThemeBundle/Context/EmptyThemeContext.php deleted file mode 100644 index 760be126cb..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Context/EmptyThemeContext.php +++ /dev/null @@ -1,27 +0,0 @@ -theme = $theme; - } - - /** - * {@inheritdoc} - */ - public function getTheme(): ?ThemeInterface - { - return $this->theme; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Context/ThemeContextInterface.php b/src/Sylius/Bundle/ThemeBundle/Context/ThemeContextInterface.php deleted file mode 100644 index 7a6db5eefb..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Context/ThemeContextInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -themeRepository = $themeRepository; - } - - /** - * @param string $themeName - * @param int $screenshotNumber - * - * @return Response - */ - public function streamScreenshotAction(string $themeName, int $screenshotNumber): Response - { - $screenshotPath = $this->getScreenshotPath($this->getTheme($themeName), $screenshotNumber); - - try { - return new BinaryFileResponse($screenshotPath); - } catch (FileNotFoundException $exception) { - throw new NotFoundHttpException(sprintf('Screenshot "%s" does not exist', $screenshotPath), $exception); - } - } - - /** - * @param ThemeInterface $theme - * @param int $screenshotNumber - * - * @return string - */ - private function getScreenshotPath(ThemeInterface $theme, int $screenshotNumber): string - { - $screenshots = $theme->getScreenshots(); - - if (!isset($screenshots[$screenshotNumber])) { - throw new NotFoundHttpException(sprintf('Theme "%s" does not have screenshot #%d', $theme->getTitle(), $screenshotNumber)); - } - - $screenshotRelativePath = $screenshots[$screenshotNumber]->getPath(); - - return rtrim($theme->getPath(), \DIRECTORY_SEPARATOR) . \DIRECTORY_SEPARATOR . $screenshotRelativePath; - } - - /** - * @param string $themeName - * - * @return ThemeInterface - */ - private function getTheme(string $themeName): ThemeInterface - { - $theme = $this->themeRepository->findOneByName($themeName); - if (null === $theme) { - throw new NotFoundHttpException(sprintf('Theme with name "%s" not found', $themeName)); - } - - return $theme; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/ThemeBundle/DependencyInjection/Configuration.php deleted file mode 100644 index 81fd81dbeb..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/DependencyInjection/Configuration.php +++ /dev/null @@ -1,87 +0,0 @@ -configurationSourceFactories = $configurationSourceFactories; - } - - /** - * {@inheritdoc} - */ - public function getConfigTreeBuilder(): TreeBuilder - { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('sylius_theme'); - - $this->addSourcesConfiguration($rootNode); - - $rootNode - ->children() - ->arrayNode('assets') - ->canBeDisabled() - ->end() - ->arrayNode('templating') - ->canBeDisabled() - ->end() - ->arrayNode('translations') - ->canBeDisabled() - ->end() - ->scalarNode('context') - ->defaultValue('sylius.theme.context.settable') - ->cannotBeEmpty() - ->end() - ; - - return $treeBuilder; - } - - /** - * @param ArrayNodeDefinition $rootNode - */ - private function addSourcesConfiguration(ArrayNodeDefinition $rootNode): void - { - $sourcesNodeBuilder = $rootNode - ->fixXmlConfig('source') - ->children() - ->arrayNode('sources') - ->children() - ; - - foreach ($this->configurationSourceFactories as $sourceFactory) { - $sourceNode = $sourcesNodeBuilder - ->arrayNode($sourceFactory->getName()) - ->canBeEnabled() - ; - - $sourceFactory->buildConfiguration($sourceNode); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/DependencyInjection/SyliusThemeExtension.php b/src/Sylius/Bundle/ThemeBundle/DependencyInjection/SyliusThemeExtension.php deleted file mode 100644 index 4688bb0071..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/DependencyInjection/SyliusThemeExtension.php +++ /dev/null @@ -1,143 +0,0 @@ -processConfiguration($this->getConfiguration([], $container), $config); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('services.xml'); - - if ($config['assets']['enabled']) { - $loader->load('services/integrations/assets.xml'); - } - - if ($config['templating']['enabled']) { - $loader->load('services/integrations/templating.xml'); - } - - if ($config['translations']['enabled']) { - $loader->load('services/integrations/translations.xml'); - } - - $this->resolveConfigurationSources($container, $config); - - $container->setAlias('sylius.context.theme', $config['context']); - } - - /** - * @internal - * - * {@inheritdoc} - */ - public function prepend(ContainerBuilder $container): void - { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - - $this->prependTwig($container, $loader); - } - - /** - * @api - * - * @param ConfigurationSourceFactoryInterface $configurationSourceFactory - */ - public function addConfigurationSourceFactory(ConfigurationSourceFactoryInterface $configurationSourceFactory): void - { - $this->configurationSourceFactories[$configurationSourceFactory->getName()] = $configurationSourceFactory; - } - - /** - * {@inheritdoc} - */ - public function getConfiguration(array $config, ContainerBuilder $container): Configuration - { - $configuration = new Configuration($this->configurationSourceFactories); - - $container->addObjectResource($configuration); - - return $configuration; - } - - /** - * @param ContainerBuilder $container - * @param LoaderInterface $loader - */ - private function prependTwig(ContainerBuilder $container, LoaderInterface $loader): void - { - if (!$container->hasExtension('twig')) { - return; - } - - $loader->load('services/integrations/twig.xml'); - } - - /** - * @param ContainerBuilder $container - * @param array $config - */ - private function resolveConfigurationSources(ContainerBuilder $container, array $config): void - { - $configurationProviders = []; - foreach ($this->configurationSourceFactories as $configurationSourceFactory) { - $sourceName = $configurationSourceFactory->getName(); - if (isset($config['sources'][$sourceName]) && $config['sources'][$sourceName]['enabled']) { - $sourceConfig = $config['sources'][$sourceName]; - - $configurationProvider = $configurationSourceFactory->initializeSource($container, $sourceConfig); - - if (!$configurationProvider instanceof Reference && !$configurationProvider instanceof Definition) { - throw new \InvalidArgumentException(sprintf( - 'Source factory "%s" was expected to return an instance of "%s" or "%s", "%s" found', - $configurationSourceFactory->getName(), - Reference::class, - Definition::class, - is_object($configurationProvider) ? get_class($configurationProvider) : gettype($configurationProvider) - )); - } - - $configurationProviders[] = $configurationProvider; - } - } - - $compositeConfigurationProvider = $container->getDefinition('sylius.theme.configuration.provider'); - $compositeConfigurationProvider->replaceArgument(0, $configurationProviders); - - foreach ($this->configurationSourceFactories as $configurationSourceFactory) { - $container->addObjectResource($configurationSourceFactory); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Factory/FinderFactory.php b/src/Sylius/Bundle/ThemeBundle/Factory/FinderFactory.php deleted file mode 100644 index d6ed80f212..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Factory/FinderFactory.php +++ /dev/null @@ -1,27 +0,0 @@ -setName($data['name'] ?? null); - $author->setEmail($data['email'] ?? null); - $author->setHomepage($data['homepage'] ?? null); - $author->setRole($data['role'] ?? null); - - return $author; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Factory/ThemeAuthorFactoryInterface.php b/src/Sylius/Bundle/ThemeBundle/Factory/ThemeAuthorFactoryInterface.php deleted file mode 100644 index f2dd2dc1c5..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Factory/ThemeAuthorFactoryInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -setTitle($data['title'] ?? null); - $themeScreenshot->setDescription($data['description'] ?? null); - - return $themeScreenshot; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Factory/ThemeScreenshotFactoryInterface.php b/src/Sylius/Bundle/ThemeBundle/Factory/ThemeScreenshotFactoryInterface.php deleted file mode 100644 index 2848d5622e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Factory/ThemeScreenshotFactoryInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -themeRepository = $themeRepository; - } - - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'choices' => function (Options $options): array { - return $this->themeRepository->findAll(); - }, - 'choice_label' => function (ThemeInterface $theme): string { - return $theme->getTitle() ?: $theme->getName(); - }, - ]); - } - - /** - * {@inheritdoc} - */ - public function getParent(): string - { - return ChoiceType::class; - } - - /** - * {@inheritdoc} - */ - public function getBlockPrefix(): string - { - return 'sylius_theme_choice'; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Form/Type/ThemeNameChoiceType.php b/src/Sylius/Bundle/ThemeBundle/Form/Type/ThemeNameChoiceType.php deleted file mode 100644 index 3a4e516313..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Form/Type/ThemeNameChoiceType.php +++ /dev/null @@ -1,71 +0,0 @@ -themeRepository = $themeRepository; - } - - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'choices' => function (Options $options): array { - $themes = $this->themeRepository->findAll(); - - $choices = []; - foreach ($themes as $theme) { - $choices[$theme->getTitle() ?: $theme->getName()] = $theme->getName(); - } - - return $choices; - }, - ]); - } - - /** - * {@inheritdoc} - */ - public function getParent(): string - { - return ChoiceType::class; - } - - /** - * {@inheritdoc} - */ - public function getBlockPrefix(): string - { - return 'sylius_theme_name_choice'; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/HierarchyProvider/NoopThemeHierarchyProvider.php b/src/Sylius/Bundle/ThemeBundle/HierarchyProvider/NoopThemeHierarchyProvider.php deleted file mode 100644 index 1752a50b8b..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/HierarchyProvider/NoopThemeHierarchyProvider.php +++ /dev/null @@ -1,27 +0,0 @@ -getParents() as $parent) { - $parents = array_merge( - $parents, - $this->getThemeHierarchy($parent) - ); - } - - return array_merge([$theme], $parents); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/HierarchyProvider/ThemeHierarchyProviderInterface.php b/src/Sylius/Bundle/ThemeBundle/HierarchyProvider/ThemeHierarchyProviderInterface.php deleted file mode 100644 index 564484a3f5..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/HierarchyProvider/ThemeHierarchyProviderInterface.php +++ /dev/null @@ -1,28 +0,0 @@ -getParents())) { - return; - } - - $previousThemes[] = $theme; - foreach ($theme->getParents() as $parent) { - if (in_array($parent, $previousThemes, true)) { - throw new CircularDependencyFoundException(array_merge($previousThemes, [$parent])); - } - - $this->check($parent, $previousThemes); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Loader/CircularDependencyCheckerInterface.php b/src/Sylius/Bundle/ThemeBundle/Loader/CircularDependencyCheckerInterface.php deleted file mode 100644 index 2b9b3ceff2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Loader/CircularDependencyCheckerInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -getCycleFromArray($themes); - - $message = sprintf( - 'Circular dependency was found while resolving theme "%s", caused by cycle "%s".', - reset($themes)->getName(), - $this->formatCycleToString($cycle) - ); - - parent::__construct($message, 0, $previous); - } - - /** - * @param array $themes - * - * @return array - */ - private function getCycleFromArray(array $themes): array - { - while (reset($themes) !== end($themes) || 1 === count($themes)) { - array_shift($themes); - } - - if (0 === count($themes)) { - throw new \InvalidArgumentException('There is no cycle within given themes.'); - } - - return $themes; - } - - /** - * @param array $themes - * - * @return string - */ - private function formatCycleToString(array $themes): string - { - $themesNames = array_map(function (ThemeInterface $theme) { - return $theme->getName(); - }, $themes); - - return implode(' -> ', $themesNames); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Loader/ThemeLoader.php b/src/Sylius/Bundle/ThemeBundle/Loader/ThemeLoader.php deleted file mode 100644 index d70f416c28..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Loader/ThemeLoader.php +++ /dev/null @@ -1,192 +0,0 @@ -configurationProvider = $configurationProvider; - $this->themeFactory = $themeFactory; - $this->themeAuthorFactory = $themeAuthorFactory; - $this->themeScreenshotFactory = $themeScreenshotFactory; - $this->themeHydrator = $themeHydrator; - $this->circularDependencyChecker = $circularDependencyChecker; - } - - /** - * {@inheritdoc} - */ - public function load(): array - { - $configurations = $this->configurationProvider->getConfigurations(); - - $themes = $this->initializeThemes($configurations); - $themes = $this->hydrateThemes($configurations, $themes); - - $this->checkForCircularDependencies($themes); - - return array_values($themes); - } - - /** - * @param array $configurations - * - * @return array|ThemeInterface[] - */ - private function initializeThemes(array $configurations): array - { - $themes = []; - foreach ($configurations as $configuration) { - /** @var ThemeInterface $theme */ - $themes[$configuration['name']] = $this->themeFactory->create($configuration['name'], $configuration['path']); - } - - return $themes; - } - - /** - * @param array $configurations - * @param array|ThemeInterface[] $themes - * - * @return array|ThemeInterface[] - */ - private function hydrateThemes(array $configurations, array $themes): array - { - foreach ($configurations as $configuration) { - $themeName = $configuration['name']; - - $configuration['parents'] = $this->convertParentsNamesToParentsObjects($themeName, $configuration['parents'], $themes); - $configuration['authors'] = $this->convertAuthorsArraysToAuthorsObjects($configuration['authors']); - $configuration['screenshots'] = $this->convertScreenshotsArraysToScreenshotsObjects($configuration['screenshots']); - - $themes[$themeName] = $this->themeHydrator->hydrate($configuration, $themes[$themeName]); - } - - return $themes; - } - - /** - * @param array|ThemeInterface[] $themes - */ - private function checkForCircularDependencies(array $themes): void - { - try { - foreach ($themes as $theme) { - $this->circularDependencyChecker->check($theme); - } - } catch (CircularDependencyFoundException $exception) { - throw new ThemeLoadingFailedException('Circular dependency found.', 0, $exception); - } - } - - /** - * @param string $themeName - * @param array $parentsNames - * @param array $existingThemes - * - * @return array|ThemeInterface[] - */ - private function convertParentsNamesToParentsObjects(string $themeName, array $parentsNames, array $existingThemes): array - { - return array_map(function ($parentName) use ($themeName, $existingThemes) { - if (!isset($existingThemes[$parentName])) { - throw new ThemeLoadingFailedException(sprintf( - 'Unexisting theme "%s" is required by "%s".', - $parentName, - $themeName - )); - } - - return $existingThemes[$parentName]; - }, $parentsNames); - } - - /** - * @param array $authorsArrays - * - * @return array|ThemeAuthor[] - */ - private function convertAuthorsArraysToAuthorsObjects(array $authorsArrays): array - { - return array_map(function (array $authorArray) { - return $this->themeAuthorFactory->createFromArray($authorArray); - }, $authorsArrays); - } - - /** - * @param array $screenshotsArrays - * - * @return array|ThemeScreenshot[] - */ - private function convertScreenshotsArraysToScreenshotsObjects(array $screenshotsArrays): array - { - return array_map(function (array $screenshotArray) { - return $this->themeScreenshotFactory->createFromArray($screenshotArray); - }, $screenshotsArrays); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Loader/ThemeLoaderInterface.php b/src/Sylius/Bundle/ThemeBundle/Loader/ThemeLoaderInterface.php deleted file mode 100644 index 855fbc9438..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Loader/ThemeLoaderInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -filesystem = $filesystem; - } - - /** - * {@inheritdoc} - */ - public function locateResource(string $resourceName, ThemeInterface $theme): string - { - $path = sprintf('%s/%s', $theme->getPath(), $resourceName); - if (!$this->filesystem->exists($path)) { - throw new ResourceNotFoundException($resourceName, $theme); - } - - return $path; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Locator/BundleResourceLocator.php b/src/Sylius/Bundle/ThemeBundle/Locator/BundleResourceLocator.php deleted file mode 100644 index 725c9ef502..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Locator/BundleResourceLocator.php +++ /dev/null @@ -1,103 +0,0 @@ -filesystem = $filesystem; - $this->kernel = $kernel; - } - - /** - * {@inheritdoc} - * - * @param string $resourcePath Eg. "@AcmeBundle/Resources/views/template.html.twig" - */ - public function locateResource(string $resourcePath, ThemeInterface $theme): string - { - $this->assertResourcePathIsValid($resourcePath); - - $bundleName = $this->getBundleNameFromResourcePath($resourcePath); - $resourceName = $this->getResourceNameFromResourcePath($resourcePath); - - $bundles = $this->kernel->getBundle($bundleName, false); - foreach ($bundles as $bundle) { - $path = sprintf('%s/%s/%s', $theme->getPath(), $bundle->getName(), $resourceName); - - if ($this->filesystem->exists($path)) { - return $path; - } - } - - throw new ResourceNotFoundException($resourcePath, $theme); - } - - /** - * @param string $resourcePath - */ - private function assertResourcePathIsValid(string $resourcePath): void - { - if (0 !== strpos($resourcePath, '@')) { - throw new \InvalidArgumentException(sprintf('Bundle resource path (given "%s") should start with an "@".', $resourcePath)); - } - - if (false !== strpos($resourcePath, '..')) { - throw new \InvalidArgumentException(sprintf('File name "%s" contains invalid characters (..).', $resourcePath)); - } - - if (false === strpos($resourcePath, 'Resources/')) { - throw new \InvalidArgumentException(sprintf('Resource path "%s" should be in bundles\' "Resources/" directory.', $resourcePath)); - } - } - - /** - * @param string $resourcePath - * - * @return string - */ - private function getBundleNameFromResourcePath(string $resourcePath): string - { - return substr($resourcePath, 1, strpos($resourcePath, '/') - 1); - } - - /** - * @param string $resourcePath - * - * @return string - */ - private function getResourceNameFromResourcePath(string $resourcePath): string - { - return substr($resourcePath, strpos($resourcePath, 'Resources/') + strlen('Resources/')); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Locator/FileLocatorInterface.php b/src/Sylius/Bundle/ThemeBundle/Locator/FileLocatorInterface.php deleted file mode 100644 index b900abcc20..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Locator/FileLocatorInterface.php +++ /dev/null @@ -1,35 +0,0 @@ -finderFactory = $finderFactory; - $this->paths = $paths; - $this->depth = $depth; - } - - /** - * {@inheritdoc} - */ - public function locateFileNamed(string $name): string - { - return $this->doLocateFilesNamed($name)->current(); - } - - /** - * {@inheritdoc} - */ - public function locateFilesNamed(string $name): array - { - return iterator_to_array($this->doLocateFilesNamed($name)); - } - - /** - * @param string $name - * - * @return \Generator - */ - private function doLocateFilesNamed(string $name): \Generator - { - $this->assertNameIsNotEmpty($name); - - $found = false; - foreach ($this->paths as $path) { - try { - $finder = $this->finderFactory->create(); - - if ($this->depth !== null) { - $finder->depth(sprintf('<= %d', $this->depth)); - } - - $finder - ->files() - ->name($name) - ->ignoreUnreadableDirs() - ->in($path); - - /** @var SplFileInfo $file */ - foreach ($finder as $file) { - $found = true; - - yield $file->getPathname(); - } - } catch (\InvalidArgumentException $exception) { - } - } - - if (false === $found) { - throw new \InvalidArgumentException(sprintf( - 'The file "%s" does not exist (searched in the following directories: %s).', - $name, - implode(', ', $this->paths) - )); - } - } - - /** - * @param string $name - */ - private function assertNameIsNotEmpty(string $name): void - { - if (null === $name || '' === $name) { - throw new \InvalidArgumentException( - 'An empty file name is not valid to be located.' - ); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Locator/ResourceLocator.php b/src/Sylius/Bundle/ThemeBundle/Locator/ResourceLocator.php deleted file mode 100644 index 4af778c689..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Locator/ResourceLocator.php +++ /dev/null @@ -1,53 +0,0 @@ -applicationResourceLocator = $applicationResourceLocator; - $this->bundleResourceLocator = $bundleResourceLocator; - } - - /** - * {@inheritdoc} - */ - public function locateResource(string $resourcePath, ThemeInterface $theme): string - { - if (0 === strpos($resourcePath, '@')) { - return $this->bundleResourceLocator->locateResource($resourcePath, $theme); - } - - return $this->applicationResourceLocator->locateResource($resourcePath, $theme); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Locator/ResourceLocatorInterface.php b/src/Sylius/Bundle/ThemeBundle/Locator/ResourceLocatorInterface.php deleted file mode 100644 index b7a67408d9..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Locator/ResourceLocatorInterface.php +++ /dev/null @@ -1,29 +0,0 @@ -getName() - )); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Model/Theme.php b/src/Sylius/Bundle/ThemeBundle/Model/Theme.php deleted file mode 100644 index 0e7dc9d060..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Model/Theme.php +++ /dev/null @@ -1,213 +0,0 @@ -assertNameIsValid($name); - - $this->name = $name; - $this->path = $path; - } - - /** - * @return string - */ - public function __toString(): string - { - return (string) ($this->title ?: $this->name); - } - - /** - * {@inheritdoc} - */ - public function getName(): string - { - return $this->name; - } - - /** - * {@inheritdoc} - */ - public function getPath(): string - { - return $this->path; - } - - /** - * {@inheritdoc} - */ - public function getTitle(): ?string - { - return $this->title; - } - - /** - * {@inheritdoc} - */ - public function setTitle(?string $title): void - { - $this->title = $title; - } - - /** - * {@inheritdoc} - */ - public function getDescription(): ?string - { - return $this->description; - } - - /** - * {@inheritdoc} - */ - public function setDescription(?string $description): void - { - $this->description = $description; - } - - /** - * {@inheritdoc} - */ - public function getAuthors(): array - { - return $this->authors; - } - - /** - * {@inheritdoc} - */ - public function addAuthor(ThemeAuthor $author): void - { - $this->authors[] = $author; - } - - /** - * {@inheritdoc} - */ - public function removeAuthor(ThemeAuthor $author): void - { - $this->authors = array_filter($this->authors, function ($currentAuthor) use ($author) { - return $currentAuthor !== $author; - }); - } - - /** - * {@inheritdoc} - */ - public function getParents(): array - { - return $this->parents; - } - - /** - * {@inheritdoc} - */ - public function addParent(ThemeInterface $theme): void - { - $this->parents[] = $theme; - } - - /** - * {@inheritdoc} - */ - public function removeParent(ThemeInterface $theme): void - { - $this->parents = array_filter($this->parents, function ($currentTheme) use ($theme) { - return $currentTheme !== $theme; - }); - } - - /** - * {@inheritdoc} - */ - public function getScreenshots(): array - { - return $this->screenshots; - } - - /** - * {@inheritdoc} - */ - public function addScreenshot(ThemeScreenshot $screenshot): void - { - $this->screenshots[] = $screenshot; - } - - /** - * {@inheritdoc} - */ - public function removeScreenshot(ThemeScreenshot $screenshot): void - { - $this->screenshots = array_filter($this->screenshots, function ($currentScreenshot) use ($screenshot) { - return $currentScreenshot !== $screenshot; - }); - } - - /** - * @param string $name - */ - private function assertNameIsValid(string $name): void - { - $pattern = '/^[a-zA-Z0-9\-]+\/[a-zA-Z0-9\-]+$/'; - if (false === (bool) preg_match($pattern, $name)) { - throw new \InvalidArgumentException(sprintf( - 'Given name "%s" does not match regular expression "%s".', - $name, - $pattern - )); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Model/ThemeAuthor.php b/src/Sylius/Bundle/ThemeBundle/Model/ThemeAuthor.php deleted file mode 100644 index 9f1b03ca18..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Model/ThemeAuthor.php +++ /dev/null @@ -1,77 +0,0 @@ -name; - } - - public function setName(?string $name): void - { - $this->name = $name; - } - - public function getEmail(): ?string - { - return $this->email; - } - - public function setEmail(?string $email): void - { - $this->email = $email; - } - - public function getHomepage(): ?string - { - return $this->homepage; - } - - public function setHomepage(?string $homepage): void - { - $this->homepage = $homepage; - } - - public function getRole(): ?string - { - return $this->role; - } - - public function setRole(?string $role): void - { - $this->role = $role; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Model/ThemeInterface.php b/src/Sylius/Bundle/ThemeBundle/Model/ThemeInterface.php deleted file mode 100644 index 1e9bea1e44..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Model/ThemeInterface.php +++ /dev/null @@ -1,92 +0,0 @@ -path = $path; - } - - /** - * @return string - */ - public function getPath(): string - { - return $this->path; - } - - /** - * @return string|null - */ - public function getTitle(): ?string - { - return $this->title; - } - - /** - * @param string|null $title - */ - public function setTitle(?string $title): void - { - $this->title = $title; - } - - /** - * @return string|null - */ - public function getDescription(): ?string - { - return $this->description; - } - - /** - * @param string|null $description - */ - public function setDescription(?string $description): void - { - $this->description = $description; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/README.md b/src/Sylius/Bundle/ThemeBundle/README.md deleted file mode 100644 index a43f77db02..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/README.md +++ /dev/null @@ -1,47 +0,0 @@ -SyliusThemeBundle [![Build status...](https://secure.travis-ci.org/Sylius/SyliusThemeBundle.png?branch=master)](http://travis-ci.org/Sylius/SyliusThemeBundle) -================== - -Theme management for [**Symfony2**](http://symfony.com). - -Sylius ------- - -![Sylius](https://demo.sylius.com/assets/shop/img/logo.png) - -Sylius is an Open Source eCommerce solution built from decoupled components with powerful API and the highest quality code. [Read more on sylius.com](http://sylius.com). - -Documentation -------------- - -Documentation is available on [**docs.sylius.com**](http://docs.sylius.com/en/latest/components_and_bundles/bundles/SyliusThemeBundle/index.html). - -Contributing ------------- - -[This page](http://docs.sylius.com/en/latest/contributing/index.html) contains all the information about contributing to Sylius. - -Follow Sylius' Development --------------------------- - -If you want to keep up with the updates and latest features, follow us on the following channels: - -* [Official Blog](https://sylius.com/blog) -* [Sylius on Twitter](https://twitter.com/Sylius) -* [Sylius on Facebook](https://facebook.com/SyliusEcommerce) - -Bug tracking ------------- - -Sylius uses [GitHub issues](https://github.com/Sylius/Sylius/issues). -If you have found bug, please create an issue. - -MIT License ------------ - -License can be found [here](https://github.com/Sylius/Sylius/blob/master/LICENSE). - -Authors -------- - -The bundle was originally created by [Kamil Kokot](http://kamil.kokot.me). -See the list of [contributors](https://github.com/Sylius/SyliusThemeBundle/contributors). diff --git a/src/Sylius/Bundle/ThemeBundle/Repository/InMemoryThemeRepository.php b/src/Sylius/Bundle/ThemeBundle/Repository/InMemoryThemeRepository.php deleted file mode 100644 index ba35e34518..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Repository/InMemoryThemeRepository.php +++ /dev/null @@ -1,93 +0,0 @@ -themeLoader = $themeLoader; - } - - /** - * {@inheritdoc} - */ - public function findAll(): array - { - $this->loadThemesIfNeeded(); - - return $this->themes; - } - - /** - * {@inheritdoc} - */ - public function findOneByName(string $name): ?ThemeInterface - { - $this->loadThemesIfNeeded(); - - return $this->themes[$name] ?? null; - } - - /** - * {@inheritdoc} - */ - public function findOneByTitle(string $title): ?ThemeInterface - { - $this->loadThemesIfNeeded(); - - foreach ($this->themes as $theme) { - if ($theme->getTitle() === $title) { - return $theme; - } - } - - return null; - } - - private function loadThemesIfNeeded(): void - { - if ($this->themesLoaded) { - return; - } - - $themes = $this->themeLoader->load(); - foreach ($themes as $theme) { - $this->themes[$theme->getName()] = $theme; - } - - $this->themesLoaded = true; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Repository/ThemeRepositoryInterface.php b/src/Sylius/Bundle/ThemeBundle/Repository/ThemeRepositoryInterface.php deleted file mode 100644 index e504a874a6..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Repository/ThemeRepositoryInterface.php +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/assets.xml b/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/assets.xml deleted file mode 100644 index 7e7cd57662..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/assets.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/templating.xml b/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/templating.xml deleted file mode 100644 index e57a4bb66a..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/templating.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %kernel.cache_dir% - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/translations.xml b/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/translations.xml deleted file mode 100644 index d270113237..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/translations.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - %kernel.default_locale% - - %kernel.cache_dir%/translations - %kernel.debug% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/twig.xml b/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/twig.xml deleted file mode 100644 index 57e4686417..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Resources/config/services/integrations/twig.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ThemeBundle/Resources/views/Collector/Icon/theme.svg b/src/Sylius/Bundle/ThemeBundle/Resources/views/Collector/Icon/theme.svg deleted file mode 100644 index 98faf157d2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Resources/views/Collector/Icon/theme.svg +++ /dev/null @@ -1,3 +0,0 @@ -> - - diff --git a/src/Sylius/Bundle/ThemeBundle/Resources/views/Collector/theme.html.twig b/src/Sylius/Bundle/ThemeBundle/Resources/views/Collector/theme.html.twig deleted file mode 100644 index c2df17c369..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Resources/views/Collector/theme.html.twig +++ /dev/null @@ -1,113 +0,0 @@ -{% extends '@WebProfiler/Profiler/layout.html.twig' %} - -{% import _self as helper %} - -{% block toolbar %} - {% if collector.themes is not empty %} - {% set icon %} - {{ include('@SyliusTheme/Collector/Icon/theme.svg') }} - {{ collector.usedTheme|default(collector.themes|length) }} - {% endset %} - - {% set text %} -
- All themes - {{ collector.themes|length }} -
- -
- Used themes - {{ collector.usedThemes|length }} -
- {% endset %} - - {{ include('@WebProfiler/Profiler/toolbar_item.html.twig') }} - {% endif %} -{% endblock %} - -{% block menu %} - - {{ include('@SyliusTheme/Collector/Icon/theme.svg') }} - Themes - - {{ collector.usedThemes|length }} - - -{% endblock %} - -{% block panel %} -

Theme Metrics

- -
-
- {{ collector.usedThemes|length }} - Used themes -
- -
- {{ collector.themes|length }} - All themes -
-
- -

Themes List

- -
-
-

Used {{ collector.usedThemes|length }}

- -
-

- These are themes used. -

- - {% if collector.usedThemes is empty %} -
-

No themes were used.

-
- {% else %} - {{ helper.render_table(collector.usedThemes) }} - {% endif %} -
-
- -
-

All {{ collector.themes|length }}

- -
-

- These are themes found. -

- - {% if collector.themes is empty %} -
-

No themes were found.

-
- {% else %} - {{ helper.render_table(collector.themes) }} - {% endif %} -
-
-
-{% endblock %} - -{% macro render_table(themes) %} - - - - - - - - - - {% for theme in themes %} - - - - - - {% endfor %} - -
NamePathDescription
{{ theme.name }}{{ theme.path }}{{ theme.description }}
-{% endmacro %} diff --git a/src/Sylius/Bundle/ThemeBundle/SyliusThemeBundle.php b/src/Sylius/Bundle/ThemeBundle/SyliusThemeBundle.php deleted file mode 100644 index 36872094b5..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/SyliusThemeBundle.php +++ /dev/null @@ -1,41 +0,0 @@ -getExtension('sylius_theme'); - $themeExtension->addConfigurationSourceFactory(new FilesystemConfigurationSourceFactory()); - $themeExtension->addConfigurationSourceFactory(new TestConfigurationSourceFactory()); - - $container->addCompilerPass(new TranslatorFallbackLocalesPass()); - $container->addCompilerPass(new TranslatorLoaderProviderPass()); - $container->addCompilerPass(new TranslatorResourceProviderPass()); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Templating/Cache/Clearer/TemplatePathsCacheClearer.php b/src/Sylius/Bundle/ThemeBundle/Templating/Cache/Clearer/TemplatePathsCacheClearer.php deleted file mode 100644 index efa0daed6b..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Templating/Cache/Clearer/TemplatePathsCacheClearer.php +++ /dev/null @@ -1,46 +0,0 @@ -cache = $cache; - } - - /** - * {@inheritdoc} - */ - public function clear($cacheDir): void - { - if (!$this->cache instanceof ClearableCache) { - return; - } - - $this->cache->deleteAll(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Templating/Cache/Warmer/TemplatePathsCacheWarmer.php b/src/Sylius/Bundle/ThemeBundle/Templating/Cache/Warmer/TemplatePathsCacheWarmer.php deleted file mode 100644 index e6ef0a1295..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Templating/Cache/Warmer/TemplatePathsCacheWarmer.php +++ /dev/null @@ -1,122 +0,0 @@ -templateFinder = $templateFinder; - $this->templateLocator = $templateLocator; - $this->themeRepository = $themeRepository; - $this->cache = $cache; - } - - /** - * {@inheritdoc} - */ - public function warmUp($cacheDir): void - { - $templates = $this->templateFinder->findAllTemplates(); - - /** @var TemplateReferenceInterface $template */ - foreach ($templates as $template) { - $this->warmUpTemplate($template); - } - } - - /** - * {@inheritdoc} - */ - public function isOptional(): bool - { - return true; - } - - /** - * @param TemplateReferenceInterface $template - */ - private function warmUpTemplate(TemplateReferenceInterface $template): void - { - /** @var ThemeInterface $theme */ - foreach ($this->themeRepository->findAll() as $theme) { - $this->warmUpThemeTemplate($template, $theme); - } - } - - /** - * @param TemplateReferenceInterface $template - * @param ThemeInterface $theme - */ - private function warmUpThemeTemplate(TemplateReferenceInterface $template, ThemeInterface $theme): void - { - try { - $location = $this->templateLocator->locateTemplate($template, $theme); - } catch (ResourceNotFoundException $exception) { - $location = null; - } - - $this->cache->save($this->getCacheKey($template, $theme), $location); - } - - /** - * @param TemplateReferenceInterface $template - * @param ThemeInterface $theme - * - * @return string - */ - private function getCacheKey(TemplateReferenceInterface $template, ThemeInterface $theme): string - { - return $template->getLogicalName() . '|' . $theme->getName(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Templating/Locator/CachedTemplateLocator.php b/src/Sylius/Bundle/ThemeBundle/Templating/Locator/CachedTemplateLocator.php deleted file mode 100644 index 5421d68613..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Templating/Locator/CachedTemplateLocator.php +++ /dev/null @@ -1,72 +0,0 @@ -decoratedTemplateLocator = $decoratedTemplateLocator; - $this->cache = $cache; - } - - /** - * {@inheritdoc} - */ - public function locateTemplate(TemplateReferenceInterface $template, ThemeInterface $theme): string - { - $cacheKey = $this->getCacheKey($template, $theme); - if ($this->cache->contains($cacheKey)) { - $location = $this->cache->fetch($cacheKey); - - if (null === $location) { - throw new ResourceNotFoundException($template->getPath(), $theme); - } - - return $location; - } - - return $this->decoratedTemplateLocator->locateTemplate($template, $theme); - } - - /** - * @param TemplateReferenceInterface $template - * @param ThemeInterface $theme - * - * @return string - */ - private function getCacheKey(TemplateReferenceInterface $template, ThemeInterface $theme): string - { - return $template->getLogicalName() . '|' . $theme->getName(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateFileLocator.php b/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateFileLocator.php deleted file mode 100644 index 825f92766a..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateFileLocator.php +++ /dev/null @@ -1,107 +0,0 @@ -decoratedFileLocator = $decoratedFileLocator; - $this->themeContext = $themeContext; - $this->themeHierarchyProvider = $themeHierarchyProvider; - $this->templateLocator = $templateLocator; - } - - /** - * {@inheritdoc} - */ - public function locate($template, $currentPath = null, $first = true): string - { - if (!$template instanceof TemplateReferenceInterface) { - throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.'); - } - - $theme = $this->themeContext->getTheme(); - $themes = $theme !== null ? $this->themeHierarchyProvider->getThemeHierarchy($theme) : []; - foreach ($themes as $theme) { - try { - return $this->templateLocator->locateTemplate($template, $theme); - } catch (ResourceNotFoundException $exception) { - // Ignore if resource cannot be found in given theme. - } - } - - return $this->decoratedFileLocator->locate($template, $currentPath, $first); - } - - /** - * {@inheritdoc} - */ - public function serialize(): string - { - return serialize($this->decoratedFileLocator); - } - - /** - * {@inheritdoc} - */ - public function unserialize($serialized): void - { - $this->decoratedFileLocator = unserialize($serialized); - - $this->themeContext = new EmptyThemeContext(); - $this->themeHierarchyProvider = new NoopThemeHierarchyProvider(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateLocator.php b/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateLocator.php deleted file mode 100644 index 03a7deebef..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateLocator.php +++ /dev/null @@ -1,42 +0,0 @@ -resourceLocator = $resourceLocator; - } - - /** - * {@inheritdoc} - */ - public function locateTemplate(TemplateReferenceInterface $template, ThemeInterface $theme): string - { - return $this->resourceLocator->locateResource($template->getPath(), $theme); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateLocatorInterface.php b/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateLocatorInterface.php deleted file mode 100644 index 761b34ccc3..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Templating/Locator/TemplateLocatorInterface.php +++ /dev/null @@ -1,31 +0,0 @@ -decoratedParser = $decoratedParser; - $this->kernel = $kernel; - } - - /** - * {@inheritdoc} - */ - public function parse($name): TemplateReferenceInterface - { - if ($name instanceof TemplateReferenceInterface) { - return $name; - } - - if (isset($this->cache[$name])) { - return $this->cache[$name]; - } - - if (!preg_match('/^(?:@([^\/]*)|)(?:\/(.+))?\/(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) { - return $this->decoratedParser->parse($name); - } - - $template = new TemplateReference( - $matches[1] ? $matches[1] . 'Bundle' : '', - $matches[2], - $matches[3], - $matches[4], - $matches[5] - ); - - if ($template->get('bundle')) { - try { - $this->kernel->getBundle($template->get('bundle')); - } catch (\Exception $e) { - return $this->decoratedParser->parse($name); - } - } - - return $this->cache[$name] = $template; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Configuration/ThemeConfigurationTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/Configuration/ThemeConfigurationTest.php deleted file mode 100644 index 9ac439dc9d..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Configuration/ThemeConfigurationTest.php +++ /dev/null @@ -1,392 +0,0 @@ -assertProcessedConfigurationEquals( - [ - ['name' => 'example/sylius-theme'], - ], - ['name' => 'example/sylius-theme'], - 'name' - ); - } - - /** - * @test - */ - public function its_name_is_required_and_cannot_be_empty(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - [/* no name defined */], - ], - 'name' - ); - - $this->assertPartialConfigurationIsInvalid( - [ - ['name' => ''], - ], - 'name' - ); - } - - /** - * @test - */ - public function its_title_is_optional_but_cannot_be_empty(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['title' => ''], - ], - 'title' - ); - - $this->assertConfigurationIsValid( - [ - ['title' => 'Lorem ipsum'], - ], - 'title' - ); - } - - /** - * @test - */ - public function its_description_is_optional_but_cannot_be_empty(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['description' => ''], - ], - 'description' - ); - - $this->assertConfigurationIsValid( - [ - ['description' => 'Lorem ipsum dolor sit amet'], - ], - 'description' - ); - } - - /** - * @test - */ - public function its_path_is_optional_but_cannot_be_empty(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['path' => ''], - ], - 'path' - ); - - $this->assertConfigurationIsValid( - [ - ['path' => '/theme/path'], - ], - 'path' - ); - } - - /** - * @test - */ - public function its_authors_are_optional(): void - { - $this->assertConfigurationIsValid( - [ - [/* no authors defined */], - ], - 'authors' - ); - } - - /** - * @test - */ - public function its_author_can_have_only_name_email_homepage_and_role_properties(): void - { - $this->assertConfigurationIsValid( - [ - ['authors' => [['name' => 'Kamil Kokot']]], - ], - 'authors' - ); - - $this->assertConfigurationIsValid( - [ - ['authors' => [['email' => 'kamil@kokot.me']]], - ], - 'authors' - ); - - $this->assertConfigurationIsValid( - [ - ['authors' => [['homepage' => 'http://kamil.kokot.me']]], - ], - 'authors' - ); - - $this->assertConfigurationIsValid( - [ - ['authors' => [['role' => 'Developer']]], - ], - 'authors' - ); - - $this->assertPartialConfigurationIsInvalid( - [ - ['authors' => [['undefined' => '42']]], - ], - 'authors' - ); - } - - /** - * @test - */ - public function its_author_must_have_at_least_one_property(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['authors' => [[/* empty author */]]], - ], - 'authors', - 'Author cannot be empty' - ); - } - - /** - * @test - */ - public function its_authors_replaces_other_authors_defined_elsewhere(): void - { - $this->assertProcessedConfigurationEquals( - [ - ['authors' => [['name' => 'Kamil Kokot']]], - ['authors' => [['name' => 'Krzysztof Krawczyk']]], - ], - ['authors' => [['name' => 'Krzysztof Krawczyk']]], - 'authors' - ); - } - - /** - * @test - */ - public function it_ignores_undefined_root_level_fields(): void - { - $this->assertConfigurationIsValid( - [ - ['name' => 'example/sylius-theme', 'undefined_variable' => '42'], - ] - ); - } - - /** - * @test - */ - public function its_parents_are_optional_but_has_to_have_at_least_one_element(): void - { - $this->assertConfigurationIsValid( - [ - [], - ], - 'parents' - ); - - $this->assertPartialConfigurationIsInvalid( - [ - ['parents' => [/* no elements */]], - ], - 'parents' - ); - } - - /** - * @test - */ - public function its_parent_is_strings(): void - { - $this->assertConfigurationIsValid( - [ - ['parents' => ['example/parent-theme', 'example/parent-theme-2']], - ], - 'parents' - ); - } - - /** - * @test - */ - public function its_parent_cannot_be_empty(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['parents' => ['']], - ], - 'parents' - ); - } - - /** - * @test - */ - public function its_parents_replaces_other_parents_defined_elsewhere(): void - { - $this->assertProcessedConfigurationEquals( - [ - ['parents' => ['example/first-theme']], - ['parents' => ['example/second-theme']], - ], - ['parents' => ['example/second-theme']], - 'parents' - ); - } - - /** - * @test - */ - public function its_screenshots_are_strings(): void - { - $this->assertConfigurationIsValid( - [ - ['screenshots' => ['screenshot/krzysztof-krawczyk.jpg', 'screenshot/ryszard-rynkowski.jpg']], - ], - 'screenshots' - ); - } - - /** - * @test - */ - public function its_screenshots_are_optional(): void - { - $this->assertConfigurationIsValid( - [ - [/* no screenshots defined */], - ], - 'screenshots' - ); - } - - /** - * @test - */ - public function its_screenshots_must_have_at_least_one_element(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['screenshots' => [/* no elements */]], - ], - 'screenshots' - ); - } - - /** - * @test - */ - public function its_screenshots_cannot_be_empty(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['screenshots' => ['']], - ], - 'screenshots' - ); - } - - /** - * @test - */ - public function its_screenshots_replaces_other_screenshots_defined_elsewhere(): void - { - $this->assertProcessedConfigurationEquals( - [ - ['screenshots' => ['screenshot/zbigniew-holdys.jpg']], - ['screenshots' => ['screenshot/maryla-rodowicz.jpg']], - ], - ['screenshots' => [['path' => 'screenshot/maryla-rodowicz.jpg']]], - 'screenshots' - ); - } - - /** - * @test - */ - public function its_screenshots_are_an_array(): void - { - $this->assertConfigurationIsValid( - [ - ['screenshots' => [['path' => 'screenshot/rick-astley.jpg']]], - ], - 'screenshots' - ); - } - - /** - * @test - */ - public function its_screenshots_must_have_a_path(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['screenshots' => [['title' => 'Candy shop']]], - ], - 'screenshots' - ); - } - - /** - * @test - */ - public function its_screenshots_have_optional_title_and_description(): void - { - $this->assertConfigurationIsValid( - [ - ['screenshots' => [[ - 'path' => 'screenshot/rick-astley.jpg', - 'title' => 'Rick Astley', - 'description' => 'He\'ll never gonna give you up or let you down', - ]]], - ], - 'screenshots' - ); - } - - /** - * {@inheritdoc} - */ - protected function getConfiguration(): ConfigurationInterface - { - return new ThemeConfiguration(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index 76e276dc7c..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,136 +0,0 @@ -assertProcessedConfigurationEquals( - [ - [], - ], - ['context' => 'sylius.theme.context.settable'], - 'context' - ); - } - - /** - * @test - */ - public function its_context_cannot_be_empty(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - [''], - ], - 'context' - ); - } - - /** - * @test - */ - public function its_context_can_be_overridden(): void - { - $this->assertProcessedConfigurationEquals( - [ - ['context' => 'sylius.theme.context.custom'], - ], - ['context' => 'sylius.theme.context.custom'], - 'context' - ); - } - - /** - * @test - */ - public function assets_support_is_enabled_by_default() - { - $this->assertProcessedConfigurationEquals([[]], ['assets' => ['enabled' => true]], 'assets'); - } - - /** - * @test - */ - public function assets_support_may_be_toggled() - { - $this->assertProcessedConfigurationEquals([['assets' => ['enabled' => true]]], ['assets' => ['enabled' => true]], 'assets'); - $this->assertProcessedConfigurationEquals([['assets' => []]], ['assets' => ['enabled' => true]], 'assets'); - $this->assertProcessedConfigurationEquals([['assets' => null]], ['assets' => ['enabled' => true]], 'assets'); - - $this->assertProcessedConfigurationEquals([['assets' => ['enabled' => false]]], ['assets' => ['enabled' => false]], 'assets'); - $this->assertProcessedConfigurationEquals([['assets' => false]], ['assets' => ['enabled' => false]], 'assets'); - } - - /** - * @test - */ - public function templating_support_is_enabled_by_default() - { - $this->assertProcessedConfigurationEquals([[]], ['templating' => ['enabled' => true]], 'templating'); - } - - /** - * @test - */ - public function templating_support_may_be_toggled() - { - $this->assertProcessedConfigurationEquals([['templating' => ['enabled' => true]]], ['templating' => ['enabled' => true]], 'templating'); - $this->assertProcessedConfigurationEquals([['templating' => []]], ['templating' => ['enabled' => true]], 'templating'); - $this->assertProcessedConfigurationEquals([['templating' => null]], ['templating' => ['enabled' => true]], 'templating'); - - $this->assertProcessedConfigurationEquals([['templating' => ['enabled' => false]]], ['templating' => ['enabled' => false]], 'templating'); - $this->assertProcessedConfigurationEquals([['templating' => false]], ['templating' => ['enabled' => false]], 'templating'); - } - - /** - * @test - */ - public function translations_support_is_enabled_by_default() - { - $this->assertProcessedConfigurationEquals([[]], ['translations' => ['enabled' => true]], 'translations'); - } - - /** - * @test - */ - public function translations_support_may_be_toggled() - { - $this->assertProcessedConfigurationEquals([['translations' => ['enabled' => true]]], ['translations' => ['enabled' => true]], 'translations'); - $this->assertProcessedConfigurationEquals([['translations' => []]], ['translations' => ['enabled' => true]], 'translations'); - $this->assertProcessedConfigurationEquals([['translations' => null]], ['translations' => ['enabled' => true]], 'translations'); - - $this->assertProcessedConfigurationEquals([['translations' => ['enabled' => false]]], ['translations' => ['enabled' => false]], 'translations'); - $this->assertProcessedConfigurationEquals([['translations' => false]], ['translations' => ['enabled' => false]], 'translations'); - } - - /** - * {@inheritdoc} - */ - protected function getConfiguration(): ConfigurationInterface - { - return new Configuration(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/FilesystemSource/ConfigurationTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/FilesystemSource/ConfigurationTest.php deleted file mode 100644 index 0279fc1a63..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/FilesystemSource/ConfigurationTest.php +++ /dev/null @@ -1,151 +0,0 @@ -assertProcessedConfigurationEquals( - [ - ['sources' => ['filesystem' => null]], - ], - ['sources' => ['filesystem' => [ - 'directories' => ['%kernel.root_dir%/themes'], - 'filename' => 'composer.json', - 'enabled' => true, - 'scan_depth' => null, - ]]], - 'sources' - ); - } - - /** - * @test - */ - public function it_allows_an_integer_for_scan_depth(): void - { - $this->assertProcessedConfigurationEquals( - [ - ['sources' => ['filesystem' => ['scan_depth' => 1]]], - ], - ['sources' => ['filesystem' => [ - 'directories' => ['%kernel.root_dir%/themes'], - 'filename' => 'composer.json', - 'enabled' => true, - 'scan_depth' => 1, - ]]], - 'sources' - ); - } - - /** - * @test - */ - public function it_does_not_add_default_theme_directories_if_there_are_some_defined_by_user(): void - { - $this->assertProcessedConfigurationEquals( - [ - ['sources' => ['filesystem' => ['directories' => ['/custom/path', '/custom/path2']]]], - ], - ['sources' => ['filesystem' => [ - 'directories' => ['/custom/path', '/custom/path2'], - 'filename' => 'composer.json', - 'enabled' => true, - 'scan_depth' => null, - ]]], - 'sources.filesystem' - ); - } - - /** - * @test - */ - public function it_uses_the_last_theme_directories_passed_and_rejects_the_other_ones(): void - { - $this->assertProcessedConfigurationEquals( - [ - ['sources' => ['filesystem' => ['directories' => ['/custom/path', '/custom/path2']]]], - ['sources' => ['filesystem' => ['directories' => ['/last/custom/path']]]], - ], - ['sources' => ['filesystem' => [ - 'directories' => ['/last/custom/path'], - 'filename' => 'composer.json', - 'enabled' => true, - 'scan_depth' => null, - ]]], - 'sources.filesystem' - ); - } - - /** - * @test - */ - public function it_is_invalid_to_pass_a_string_as_theme_directories(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['directories' => '/string/not/array'], - ], - 'sources.filesystem' - ); - } - - /** - * @test - */ - public function it_is_invalid_to_pass_a_string_as_scan_depth(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['sources' => ['filesystem' => ['directories' => ['/custom/path', '/custom/path2'], 'scan_depth' => 'test']]], - ], - 'sources.filesystem' - ); - } - - /** - * @test - */ - public function it_throws_an_error_if_trying_to_set_theme_directories_to_an_empty_array(): void - { - $this->assertPartialConfigurationIsInvalid( - [ - ['directories' => []], - ], - 'sources.filesystem' - ); - } - - /** - * {@inheritdoc} - */ - protected function getConfiguration(): ConfigurationInterface - { - return new Configuration([ - new FilesystemConfigurationSourceFactory(), - ]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/FilesystemSource/SyliusThemeExtensionTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/FilesystemSource/SyliusThemeExtensionTest.php deleted file mode 100644 index 2f674d3cab..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/FilesystemSource/SyliusThemeExtensionTest.php +++ /dev/null @@ -1,46 +0,0 @@ -load(['sources' => ['filesystem' => false]]); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.configuration.provider', - 0, - [] - ); - } - - /** - * {@inheritdoc} - */ - protected function getContainerExtensions(): array - { - $themeExtension = new SyliusThemeExtension(); - $themeExtension->addConfigurationSourceFactory(new FilesystemConfigurationSourceFactory()); - - return [$themeExtension]; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/SyliusThemeExtensionTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/SyliusThemeExtensionTest.php deleted file mode 100644 index c86f7c0ff9..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/DependencyInjection/SyliusThemeExtensionTest.php +++ /dev/null @@ -1,82 +0,0 @@ -load(['context' => 'sylius.theme.context.custom']); - - $this->assertContainerBuilderHasAlias('sylius.context.theme', 'sylius.theme.context.custom'); - } - - /** - * @test - */ - public function it_loads_all_the_supported_features_by_default(): void - { - $this->load([]); - - $this->assertContainerBuilderHasService('sylius.theme.asset.assets_installer'); - $this->assertContainerBuilderHasService('sylius.theme.templating.locator'); - $this->assertContainerBuilderHasService('sylius.theme.translation.translator'); - } - - /** - * @test - */ - public function it_does_not_load_assets_support_if_its_disabled(): void - { - $this->load(['assets' => ['enabled' => false]]); - - $this->assertContainerBuilderNotHasService('sylius.theme.asset.assets_installer'); - } - - /** - * @test - */ - public function it_does_not_load_templating_support_if_its_disabled(): void - { - $this->load(['templating' => ['enabled' => false]]); - - $this->assertContainerBuilderNotHasService('sylius.theme.templating.locator'); - } - - /** - * @test - */ - public function it_does_not_load_translations_support_if_its_disabled(): void - { - $this->load(['translations' => ['enabled' => false]]); - - $this->assertContainerBuilderNotHasService('sylius.theme.translation.translator'); - } - - /** - * {@inheritdoc} - */ - protected function getContainerExtensions(): array - { - return [ - new SyliusThemeExtension(), - ]; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/public/theme_asset.txt b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/public/theme_asset.txt deleted file mode 100644 index 85b065e600..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/public/theme_asset.txt +++ /dev/null @@ -1 +0,0 @@ -Theme asset diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/translations/messages.en.yml deleted file mode 100644 index fd42685129..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/translations/messages.en.yml +++ /dev/null @@ -1,3 +0,0 @@ -test: - theme_bundle: 'THEME/BUNDLE_NAME/translations' - theme: 'THEME/BUNDLE_NAME/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig deleted file mode 100644 index 9514eb2622..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:bothThemesTemplate.txt.twig|sylius/first-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/views/Templating/vanillaOverriddenThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/views/Templating/vanillaOverriddenThemeTemplate.txt.twig deleted file mode 100644 index db26b2de7c..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/TestBundle/views/Templating/vanillaOverriddenThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:vanillaOverriddenThemeTemplate.txt.twig|sylius/first-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/composer.json b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/composer.json deleted file mode 100644 index 895b3edcff..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/composer.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "sylius/first-test-theme", - "authors": [ - { - "name": "Krzysztof Krawczyk", - "email": "krzysztof.krawczyk@example.com" - } - ], - "extra": { - "sylius-theme": { - "title": "Sylius First Theme", - "parents": [ - "sylius/second-test-theme" - ] - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/translations/messages.en.yml deleted file mode 100644 index f415ad2a25..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/translations/messages.en.yml +++ /dev/null @@ -1,2 +0,0 @@ -test: - theme: 'THEME/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/views/Templating/bothThemesTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/views/Templating/bothThemesTemplate.txt.twig deleted file mode 100644 index eca6e7083a..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/FirstTestTheme/views/Templating/bothThemesTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -:Templating:bothThemesTemplate.txt.twig|sylius/first-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/public/theme_asset.txt b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/public/theme_asset.txt deleted file mode 100644 index f87523d374..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/public/theme_asset.txt +++ /dev/null @@ -1 +0,0 @@ -This should be overridden by first theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/translations/messages.en.yml deleted file mode 100644 index cb1eab01b9..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/translations/messages.en.yml +++ /dev/null @@ -1,5 +0,0 @@ -test: - theme_bundle: 'That should be overridden by first test theme.' - theme: 'That should be overridden by first test theme.' - parent_theme_bundle: 'PARENT_THEME/BUNDLE_NAME/translations' - parent_theme: 'PARENT_THEME/BUNDLE_NAME/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig deleted file mode 100644 index 6404b84d58..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:bothThemesTemplate.txt.twig|sylius/second-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/views/Templating/lastThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/views/Templating/lastThemeTemplate.txt.twig deleted file mode 100644 index 2cab431fa0..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/TestBundle/views/Templating/lastThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:lastThemeTemplate.txt.twig|sylius/second-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/composer.json b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/composer.json deleted file mode 100644 index 455a0cbd21..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/composer.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "sylius/second-test-theme", - "extra": { - "sylius-theme": { - "title": "Sylius Second Theme" - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/translations/messages.en.yml deleted file mode 100644 index ac3f575a95..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/translations/messages.en.yml +++ /dev/null @@ -1,3 +0,0 @@ -test: - theme: 'That should be overridden by first test theme.' - parent_theme: 'PARENT_THEME/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/views/Templating/bothThemesTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/views/Templating/bothThemesTemplate.txt.twig deleted file mode 100644 index ee9f4a8880..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/views/Templating/bothThemesTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -:Templating:bothThemesTemplate.txt.twig|sylius/second-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/views/Templating/lastThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/views/Templating/lastThemeTemplate.txt.twig deleted file mode 100644 index 72fadc91f2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/SecondTestTheme/views/Templating/lastThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -:Templating:lastThemeTemplate.txt.twig|sylius/second-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/public/theme_asset.txt b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/public/theme_asset.txt deleted file mode 100644 index a1a93f78ee..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/public/theme_asset.txt +++ /dev/null @@ -1 +0,0 @@ -This should not be overridden by first theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/translations/messages.en.yml deleted file mode 100644 index 7cc8b71986..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/translations/messages.en.yml +++ /dev/null @@ -1,5 +0,0 @@ -test: - theme_bundle: 'That should not be overridden by first test theme.' - theme: 'That should not be overridden by first test theme.' - parent_theme_bundle: 'PARENT_THEME/BUNDLE_NAME/translations' - parent_theme: 'PARENT_THEME/BUNDLE_NAME/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig deleted file mode 100644 index 553e549e52..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/views/Templating/bothThemesTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:bothThemesTemplate.txt.twig|sylius/third-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/views/Templating/lastThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/views/Templating/lastThemeTemplate.txt.twig deleted file mode 100644 index a9dae5cecb..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/TestBundle/views/Templating/lastThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:lastThemeTemplate.txt.twig|sylius/third-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/composer.json b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/composer.json deleted file mode 100644 index 6e0e4ad08f..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/composer.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "sylius/third-test-theme", - "extra": { - "sylius-theme": { - "title": "Sylius Third Theme", - "parents": [ - "sylius/first-test-theme" - ] - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/translations/messages.en.yml deleted file mode 100644 index 4396d58962..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/translations/messages.en.yml +++ /dev/null @@ -1,3 +0,0 @@ -test: - theme: 'That should not be overridden by first test theme.' - parent_theme: 'PARENT_THEME/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/views/Templating/bothThemesTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/views/Templating/bothThemesTemplate.txt.twig deleted file mode 100644 index 7d045eca63..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/views/Templating/bothThemesTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -:Templating:bothThemesTemplate.txt.twig|sylius/third-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/views/Templating/lastThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/views/Templating/lastThemeTemplate.txt.twig deleted file mode 100644 index 36c8bf4e9d..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Fixtures/themes/YetAnotherTheme/TestTheme/views/Templating/lastThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -:Templating:lastThemeTemplate.txt.twig|sylius/third-test-theme diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/AssetTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/AssetTest.php deleted file mode 100644 index bdc671b87c..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/AssetTest.php +++ /dev/null @@ -1,133 +0,0 @@ -createWebDirectory(); - - $client->getContainer()->get('sylius.theme.asset.assets_installer')->installAssets($webDirectory, $symlinkMask); - - $crawler = $client->request('GET', '/template/:Asset:assetsTest.txt.twig'); - $lines = explode("\n", $crawler->text()); - - $this->assertFileContent($lines, $webDirectory); - } - - /** - * @test - * @dataProvider getSymlinkMasks - * - * @param int $symlinkMask - */ - public function it_updates_dumped_assets_if_they_are_modified($symlinkMask): void - { - $client = self::createClient(); - - $webDirectory = $this->createWebDirectory(); - - $client->getContainer()->get('sylius.theme.asset.assets_installer')->installAssets($webDirectory, $symlinkMask); - - sleep(1); - file_put_contents(__DIR__ . '/../Fixtures/themes/FirstTestTheme/TestBundle/public/theme_asset.txt', 'Theme asset modified'); - clearstatcache(); - - $client->getContainer()->get('sylius.theme.asset.assets_installer')->installAssets($webDirectory, $symlinkMask); - - $crawler = $client->request('GET', '/template/:Asset:modifiedAssetsTest.txt.twig'); - $lines = explode("\n", $crawler->text()); - - $this->assertFileContent($lines, $webDirectory); - } - - /** - * @test - * @dataProvider getSymlinkMasks - * - * @param int $symlinkMask - */ - public function it_dumps_assets_correctly_even_if_nothing_has_changed($symlinkMask): void - { - $client = self::createClient(); - - $webDirectory = $this->createWebDirectory(); - - $client->getContainer()->get('sylius.theme.asset.assets_installer')->installAssets($webDirectory, $symlinkMask); - $client->getContainer()->get('sylius.theme.asset.assets_installer')->installAssets($webDirectory, $symlinkMask); - - $crawler = $client->request('GET', '/template/:Asset:assetsTest.txt.twig'); - $lines = explode("\n", $crawler->text()); - - $this->assertFileContent($lines, $webDirectory); - } - - private function createWebDirectory() - { - $webDirectory = self::$kernel->getCacheDir() . '/web'; - if (!is_dir($webDirectory)) { - mkdir($webDirectory, 0777, true); - } - - chdir($webDirectory); - - return $webDirectory; - } - - private function assertFileContent($lines, $webDirectory): void - { - foreach ($lines as $line) { - if (empty($line)) { - continue; - } - - [$expectedText, $assetFile] = explode(': ', $line); - - $contents = file_get_contents($webDirectory . $assetFile); - - $this->assertEquals($expectedText, trim($contents)); - } - } - - /** - * @return array - */ - public function getSymlinkMasks() - { - return [ - [AssetsInstallerInterface::RELATIVE_SYMLINK], - [AssetsInstallerInterface::SYMLINK], - [AssetsInstallerInterface::HARD_COPY], - ]; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/SyliusThemeBundleTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/SyliusThemeBundleTest.php deleted file mode 100644 index 4ce8988c5c..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/SyliusThemeBundleTest.php +++ /dev/null @@ -1,40 +0,0 @@ -getContainer(); - - $serviceIds = array_filter($container->getServiceIds(), function ($serviceId) { - return 0 === strpos($serviceId, 'sylius.'); - }); - - foreach ($serviceIds as $serviceId) { - Assert::assertNotNull($container->get($serviceId)); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TemplatingTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TemplatingTest.php deleted file mode 100644 index fdb246936e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TemplatingTest.php +++ /dev/null @@ -1,131 +0,0 @@ -request('GET', '/template/' . $templateName); - $this->assertEquals($contents, trim($crawler->text())); - } - - /** - * @return array - */ - public function getBundleTemplates() - { - return [ - ['TestBundle:Templating:vanillaTemplate.txt.twig', 'TestBundle:Templating:vanillaTemplate.txt.twig'], - ['TestBundle:Templating:vanillaOverriddenTemplate.txt.twig', 'TestBundle:Templating:vanillaOverriddenTemplate.txt.twig (app overridden)'], - ['TestBundle:Templating:vanillaOverriddenThemeTemplate.txt.twig', 'TestBundle:Templating:vanillaOverriddenThemeTemplate.txt.twig|sylius/first-test-theme'], - ['TestBundle:Templating:bothThemesTemplate.txt.twig', 'TestBundle:Templating:bothThemesTemplate.txt.twig|sylius/first-test-theme'], - ['TestBundle:Templating:lastThemeTemplate.txt.twig', 'TestBundle:Templating:lastThemeTemplate.txt.twig|sylius/second-test-theme'], - ]; - } - - /** - * @test - * @dataProvider getBundleTemplatesUsingNamespacedPaths - * - * @param string $templateName - * @param string $contents - */ - public function it_renders_bundle_templates_using_namespaced_paths($templateName, $contents): void - { - $client = self::createClient(); - - $crawler = $client->request('GET', '/template/' . $templateName); - $this->assertEquals($contents, trim($crawler->text())); - } - - /** - * @return array - */ - public function getBundleTemplatesUsingNamespacedPaths() - { - return [ - ['@Test/Templating/vanillaTemplate.txt.twig', 'TestBundle:Templating:vanillaTemplate.txt.twig'], - ['@Test/Templating/vanillaOverriddenTemplate.txt.twig', 'TestBundle:Templating:vanillaOverriddenTemplate.txt.twig (app overridden)'], - ['@Test/Templating/vanillaOverriddenThemeTemplate.txt.twig', 'TestBundle:Templating:vanillaOverriddenThemeTemplate.txt.twig|sylius/first-test-theme'], - ['@Test/Templating/bothThemesTemplate.txt.twig', 'TestBundle:Templating:bothThemesTemplate.txt.twig|sylius/first-test-theme'], - ['@Test/Templating/lastThemeTemplate.txt.twig', 'TestBundle:Templating:lastThemeTemplate.txt.twig|sylius/second-test-theme'], - ]; - } - - /** - * @test - * @dataProvider getAppTemplates - * - * @param string $templateName - * @param string $contents - */ - public function it_renders_application_templates($templateName, $contents): void - { - $client = self::createClient(); - - $crawler = $client->request('GET', '/template/' . $templateName); - $this->assertEquals($contents, trim($crawler->text())); - } - - /** - * @return array - */ - public function getAppTemplates() - { - return [ - [':Templating:vanillaTemplate.txt.twig', ':Templating:vanillaTemplate.txt.twig'], - [':Templating:bothThemesTemplate.txt.twig', ':Templating:bothThemesTemplate.txt.twig|sylius/first-test-theme'], - [':Templating:lastThemeTemplate.txt.twig', ':Templating:lastThemeTemplate.txt.twig|sylius/second-test-theme'], - ]; - } - - /** - * @test - * @dataProvider getAppTemplatesUsingNamespacedPaths - * - * @param string $templateName - * @param string $contents - */ - public function it_renders_application_templates_using_namespaced_paths($templateName, $contents): void - { - $client = self::createClient(); - - $crawler = $client->request('GET', '/template/' . $templateName); - $this->assertEquals($contents, trim($crawler->text())); - } - - /** - * @return array - */ - public function getAppTemplatesUsingNamespacedPaths() - { - return [ - ['/Templating/vanillaTemplate.txt.twig', ':Templating:vanillaTemplate.txt.twig'], - ['/Templating/bothThemesTemplate.txt.twig', ':Templating:bothThemesTemplate.txt.twig|sylius/first-test-theme'], - ['/Templating/lastThemeTemplate.txt.twig', ':Templating:lastThemeTemplate.txt.twig|sylius/second-test-theme'], - ]; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Controller/TemplatingController.php b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Controller/TemplatingController.php deleted file mode 100644 index e08accb58b..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Controller/TemplatingController.php +++ /dev/null @@ -1,33 +0,0 @@ -container->get('templating')->renderResponse($templateName); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/DependencyInjection/TestExtension.php b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/DependencyInjection/TestExtension.php deleted file mode 100644 index 6eea0ad512..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/DependencyInjection/TestExtension.php +++ /dev/null @@ -1,31 +0,0 @@ -load('services.xml'); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Listener/RequestListener.php b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Listener/RequestListener.php deleted file mode 100644 index 0d59e788a6..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Listener/RequestListener.php +++ /dev/null @@ -1,55 +0,0 @@ -themeRepository = $themeRepository; - $this->themeContext = $themeContext; - } - - /** - * @param GetResponseEvent $event - */ - public function onKernelRequest(GetResponseEvent $event) - { - if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { - // don't do anything if it's not the master request - return; - } - - $this->themeContext->setTheme($this->themeRepository->findOneByName('sylius/first-test-theme')); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/config/routing.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/config/routing.yml deleted file mode 100644 index 630dd3b10f..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/config/routing.yml +++ /dev/null @@ -1,5 +0,0 @@ -template: - path: /template/{templateName} - defaults: { _controller: TestBundle:Templating:renderTemplate } - requirements: - templateName: .+ diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/config/services.xml b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/config/services.xml deleted file mode 100644 index 9df4eb91f8..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/config/services.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/public/asset.txt b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/public/asset.txt deleted file mode 100644 index b1118f9476..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/public/asset.txt +++ /dev/null @@ -1 +0,0 @@ -Vanilla asset diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/public/theme_asset.txt b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/public/theme_asset.txt deleted file mode 100644 index b1118f9476..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/public/theme_asset.txt +++ /dev/null @@ -1 +0,0 @@ -Vanilla asset diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/translations/messages.en.yml deleted file mode 100644 index eae50e3095..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/translations/messages.en.yml +++ /dev/null @@ -1,8 +0,0 @@ -test: - bundle: 'BUNDLE/Resources/translations' - app_bundle: 'BUNDLE/Resources/translations' - app: 'BUNDLE/Resources/translations' - theme_bundle: 'BUNDLE/Resources/translations' - theme: 'BUNDLE/Resources/translations' - parent_theme_bundle: 'BUNDLE/Resources/translations' - parent_theme: 'BUNDLE/Resources/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/bothThemesTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/bothThemesTemplate.txt.twig deleted file mode 100644 index a37e0d0fe9..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/bothThemesTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:firstOverriddenTemplate.txt.twig diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/lastThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/lastThemeTemplate.txt.twig deleted file mode 100644 index e8cd6e8f3e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/lastThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:lastOverriddenTemplate.txt.twig diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaOverriddenTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaOverriddenTemplate.txt.twig deleted file mode 100644 index 79f2f4ffe8..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaOverriddenTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:vanillaOverriddenTemplate.txt.twig diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaOverriddenThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaOverriddenThemeTemplate.txt.twig deleted file mode 100644 index 68c971ee51..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaOverriddenThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:vanillaOverriddenThemeTemplate.txt.twig diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaTemplate.txt.twig deleted file mode 100644 index f3e3912472..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/Resources/views/Templating/vanillaTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:vanillaTemplate.txt.twig diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/TestBundle.php b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/TestBundle.php deleted file mode 100644 index 7cb53e36ed..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/TestBundle/TestBundle.php +++ /dev/null @@ -1,20 +0,0 @@ -request('GET', '/template/:Translation:translationsTest.txt.twig'); - - foreach ($this->getTranslationsLines() as $expectedContent) { - $this->assertContains($expectedContent, $crawler->text()); - } - } - - /** - * @return array - */ - protected function getTranslationsLines() - { - return [ - 'BUNDLE/Resources/translations: BUNDLE/Resources/translations', - 'app/Resources/BUNDLE_NAME/translations: app/Resources/BUNDLE_NAME/translations', - 'app/Resources/translations: app/Resources/translations', - 'THEME/BUNDLE_NAME/translations: THEME/BUNDLE_NAME/translations', - 'THEME/translations: THEME/translations', - 'PARENT_THEME/BUNDLE_NAME/translations: PARENT_THEME/BUNDLE_NAME/translations', - 'PARENT_THEME/translations: PARENT_THEME/translations', - ]; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/.gitignore b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/.gitignore deleted file mode 100644 index 4b11edd3eb..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/config/parameters.yml diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/AppKernel.php b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/AppKernel.php deleted file mode 100644 index 4eccf98d2c..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/AppKernel.php +++ /dev/null @@ -1,63 +0,0 @@ -load(__DIR__ . '/config/config.yml'); - } - - /** - * {@inheritdoc} - */ - public function getCacheDir() - { - return sys_get_temp_dir() . '/SyliusThemeBundle/cache/' . $this->getEnvironment(); - } - - /** - * {@inheritdoc} - */ - public function getLogDir() - { - return sys_get_temp_dir() . '/SyliusThemeBundle/logs'; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/translations/messages.en.yml deleted file mode 100644 index bb78b82433..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/translations/messages.en.yml +++ /dev/null @@ -1,7 +0,0 @@ -test: - app_bundle: 'app/Resources/BUNDLE_NAME/translations' - app: 'app/Resources/BUNDLE_NAME/translations' - theme_bundle: 'app/Resources/BUNDLE_NAME/translations' - theme: 'app/Resources/BUNDLE_NAME/translations' - parent_theme_bundle: 'app/Resources/BUNDLE_NAME/translations' - parent_theme: 'app/Resources/BUNDLE_NAME/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/views/Templating/vanillaOverriddenTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/views/Templating/vanillaOverriddenTemplate.txt.twig deleted file mode 100644 index ebb9a1e075..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/views/Templating/vanillaOverriddenTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:vanillaOverriddenTemplate.txt.twig (app overridden) diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/views/Templating/vanillaOverriddenThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/views/Templating/vanillaOverriddenThemeTemplate.txt.twig deleted file mode 100644 index 1545eccfe2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/TestBundle/views/Templating/vanillaOverriddenThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -TestBundle:Templating:vanillaOverriddenThemeTemplate.txt.twig (app overridden) diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/translations/messages.en.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/translations/messages.en.yml deleted file mode 100644 index b1548ca81e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/translations/messages.en.yml +++ /dev/null @@ -1,6 +0,0 @@ -test: - app: 'app/Resources/translations' - theme_bundle: 'app/Resources/translations' - theme: 'app/Resources/translations' - parent_theme_bundle: 'app/Resources/translations' - parent_theme: 'app/Resources/translations' diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Asset/assetsTest.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Asset/assetsTest.txt.twig deleted file mode 100644 index f3402d25d1..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Asset/assetsTest.txt.twig +++ /dev/null @@ -1,2 +0,0 @@ -Vanilla asset: {{ asset('bundles/test/asset.txt') }} -Theme asset: {{ asset('bundles/test/theme_asset.txt') }} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Asset/modifiedAssetsTest.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Asset/modifiedAssetsTest.txt.twig deleted file mode 100644 index a588f23aa2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Asset/modifiedAssetsTest.txt.twig +++ /dev/null @@ -1 +0,0 @@ -Theme asset modified: {{ asset('bundles/test/theme_asset.txt') }} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/bothThemesTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/bothThemesTemplate.txt.twig deleted file mode 100644 index 16326527a6..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/bothThemesTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -:Templating:firstOverriddenTemplate.txt.twig diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/lastThemeTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/lastThemeTemplate.txt.twig deleted file mode 100644 index 0275795599..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/lastThemeTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -:Templating:lastOverriddenTemplate.txt.twig diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/vanillaTemplate.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/vanillaTemplate.txt.twig deleted file mode 100644 index 996a1be7ff..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Templating/vanillaTemplate.txt.twig +++ /dev/null @@ -1 +0,0 @@ -:Templating:vanillaTemplate.txt.twig diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Translation/translationsTest.txt.twig b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Translation/translationsTest.txt.twig deleted file mode 100644 index 46f7b7223d..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/Resources/views/Translation/translationsTest.txt.twig +++ /dev/null @@ -1,7 +0,0 @@ -BUNDLE/Resources/translations: {{ 'test.bundle'|trans }} -app/Resources/BUNDLE_NAME/translations: {{ 'test.app_bundle'|trans }} -app/Resources/translations: {{ 'test.app'|trans }} -THEME/BUNDLE_NAME/translations: {{ 'test.theme_bundle'|trans }} -THEME/translations: {{ 'test.theme'|trans }} -PARENT_THEME/BUNDLE_NAME/translations: {{ 'test.parent_theme_bundle'|trans }} -PARENT_THEME/translations: {{ 'test.parent_theme'|trans }} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/config/config.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/config/config.yml deleted file mode 100644 index 4ad8d1f7b9..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/config/config.yml +++ /dev/null @@ -1,30 +0,0 @@ -parameters: - locale: en - secret: "Three can keep a secret, if two of them are dead." - -framework: - translator: { fallbacks: ["%locale%"] } - secret: "%secret%" - router: - resource: "%kernel.root_dir%/config/routing.yml" - form: ~ - csrf_protection: true - templating: - engines: ['twig'] - default_locale: "%locale%" - session: - handler_id: ~ - storage_id: session.storage.mock_file - http_method_override: true - test: ~ - -twig: - debug: "%kernel.debug%" - strict_variables: "%kernel.debug%" - -sylius_theme: - sources: - filesystem: - scan_depth: 1 - directories: - - "%kernel.root_dir%/../../Fixtures/themes" diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/config/routing.yml b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/config/routing.yml deleted file mode 100644 index ede3460e61..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/app/config/routing.yml +++ /dev/null @@ -1,2 +0,0 @@ -_templatetest_bundle: - resource: "@TestBundle/Resources/config/routing.yml" diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/bin/console b/src/Sylius/Bundle/ThemeBundle/Tests/Functional/bin/console deleted file mode 100755 index da68d7d568..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Functional/bin/console +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env php -run(new ArgvInput()); diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPassTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPassTest.php deleted file mode 100644 index 8a85b14656..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPassTest.php +++ /dev/null @@ -1,110 +0,0 @@ -addMethodCall('setFallbackLocales', ['pl_PL']); - $this->setDefinition('translator.default', $symfonyTranslatorDefinition); - - $this->setDefinition('sylius.theme.translation.translator', new Definition()); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - 'sylius.theme.translation.translator', - 'setFallbackLocales', - ['pl_PL'] - ); - } - - /** - * @test - */ - public function it_filters_out_other_method_calls_to_symfony_translator(): void - { - $symfonyTranslatorDefinition = new Definition(); - $symfonyTranslatorDefinition->addMethodCall('doFooAndBar', ['argument1', 'argument2']); - $symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['pl_PL']); - $symfonyTranslatorDefinition->addMethodCall('doFoo', ['argument1']); - $this->setDefinition('translator.default', $symfonyTranslatorDefinition); - - $this->setDefinition('sylius.theme.translation.translator', new Definition()); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - 'sylius.theme.translation.translator', - 'setFallbackLocales', - ['pl_PL'] - ); - } - - /** - * @test - */ - public function it_copies_method_calls_that_set_fallback_locales_to_theme_translator(): void - { - $symfonyTranslatorDefinition = new Definition(); - $symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['pl_PL']); - $symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['en_US']); - $this->setDefinition('translator.default', $symfonyTranslatorDefinition); - - $this->setDefinition('sylius.theme.translation.translator', new Definition()); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - 'sylius.theme.translation.translator', - 'setFallbackLocales', - ['pl_PL'] - ); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - 'sylius.theme.translation.translator', - 'setFallbackLocales', - ['en_US'] - ); - } - - /** - * @test - */ - public function it_does_not_force_symfony_translator_to_have_any_method_calls(): void - { - $this->setDefinition('translator.default', new Definition()); - $this->setDefinition('sylius.theme.translation.translator', new Definition()); - - $this->compile(); - } - - /** - * {@inheritdoc} - */ - protected function registerCompilerPass(ContainerBuilder $container) - { - $container->addCompilerPass(new TranslatorFallbackLocalesPass()); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPassTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPassTest.php deleted file mode 100644 index 7f5ae43e9a..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPassTest.php +++ /dev/null @@ -1,108 +0,0 @@ -setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]])); - - $translationLoaderDefinition = new Definition(); - $translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yml']); - $this->setDefinition('translation.loader.yml', $translationLoaderDefinition); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.loader_provider', - 0, - ['yml' => new Reference('translation.loader.yml')] - ); - } - - /** - * @test - */ - public function it_adds_translation_loaders_with_its_legacy_alias_to_sylius_loader_provider(): void - { - $this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]])); - - $translationLoaderDefinition = new Definition(); - $translationLoaderDefinition->addTag('translation.loader', ['alias' => 'xlf', 'legacy-alias' => 'xliff']); - $this->setDefinition('translation.loader.xliff', $translationLoaderDefinition); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.loader_provider', - 0, - ['xlf' => new Reference('translation.loader.xliff'), 'xliff' => new Reference('translation.loader.xliff')] - ); - } - - /** - * @test - */ - public function it_adds_translation_loaders_using_only_the_first_tag_alias(): void - { - $this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]])); - - $translationLoaderDefinition = new Definition(); - $translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yml']); - $translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yaml']); - $this->setDefinition('translation.loader.yml', $translationLoaderDefinition); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.loader_provider', - 0, - ['yml' => new Reference('translation.loader.yml')] - ); - } - - /** - * @test - */ - public function it_does_not_force_the_existence_of_translation_loaders(): void - { - $this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]])); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.loader_provider', - 0, - [] - ); - } - - /** - * {@inheritdoc} - */ - protected function registerCompilerPass(ContainerBuilder $container) - { - $container->addCompilerPass(new TranslatorLoaderProviderPass()); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPassTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPassTest.php deleted file mode 100644 index f8f36dbfee..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPassTest.php +++ /dev/null @@ -1,154 +0,0 @@ - [ - 'en' => ['/resources/messages.en.yml', '/resources/alerts.en.yml'], - 'es' => ['/resources/messages.es.yml'], - ]], - ]); - $this->setDefinition('translator.default', $symfonyTranslatorDefinition); - - $this->setDefinition('sylius.theme.translation.resource_provider.default', new Definition(null, [[]])); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.resource_provider.default', - 0, - ['/resources/messages.en.yml', '/resources/alerts.en.yml', '/resources/messages.es.yml'] - ); - } - - /** - * @test - */ - public function it_merges_copied_resource_files_from_symfony_translator_with_existing_resource_files_from_sylius_resource_provider(): void - { - $symfonyTranslatorDefinition = new Definition(null, [ - null, - null, - [], - ['resource_files' => ['en' => ['/resources/messages.en.yml']]], - ]); - $this->setDefinition('translator.default', $symfonyTranslatorDefinition); - - $this->setDefinition('sylius.theme.translation.resource_provider.default', new Definition(null, [ - ['/resources/alerts.en.yml'], - ])); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.resource_provider.default', - 0, - ['/resources/alerts.en.yml', '/resources/messages.en.yml'] - ); - } - - /** - * @test - */ - public function it_does_not_copy_anything_if_symfony_translator_does_not_have_resource_files(): void - { - $symfonyTranslatorDefinition = new Definition(null, [ - null, - null, - [], - ['cache_dir' => '/foo/bar'], - ]); - $this->setDefinition('translator.default', $symfonyTranslatorDefinition); - - $this->setDefinition('sylius.theme.translation.resource_provider.default', new Definition(null, [[]])); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.resource_provider.default', - 0, - [] - ); - } - - /** - * @test - */ - public function it_copies_resource_files_from_symfony_translator_33_to_sylius_resource_provider(): void - { - $symfonyTranslatorDefinition = new Definition(null, [ - null, - null, - [], - [], - ['resource_files' => [ - 'en' => ['/resources/messages.en.yml', '/resources/alerts.en.yml'], - 'es' => ['/resources/messages.es.yml'], - ]], - ]); - $this->setDefinition('translator.default', $symfonyTranslatorDefinition); - - $this->setDefinition('sylius.theme.translation.resource_provider.default', new Definition(null, [[]])); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.resource_provider.default', - 0, - ['/resources/messages.en.yml', '/resources/alerts.en.yml', '/resources/messages.es.yml'] - ); - } - - /** - * @test - */ - public function it_does_not_crash_if_definition_does_not_have_resource_files_at_all(): void - { - $symfonyTranslatorDefinition = new Definition(null, [null, null]); - $this->setDefinition('translator.default', $symfonyTranslatorDefinition); - - $this->setDefinition('sylius.theme.translation.resource_provider.default', new Definition(null, [[]])); - - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithArgument( - 'sylius.theme.translation.resource_provider.default', - 0, - [] - ); - } - - /** - * {@inheritdoc} - */ - protected function registerCompilerPass(ContainerBuilder $container) - { - $container->addCompilerPass(new TranslatorResourceProviderPass()); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Tests/Translation/TranslatorTest.php b/src/Sylius/Bundle/ThemeBundle/Tests/Translation/TranslatorTest.php deleted file mode 100644 index 710e0358a2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Tests/Translation/TranslatorTest.php +++ /dev/null @@ -1,370 +0,0 @@ -createTranslator('en', $options); - } - - /** - * @test - * @dataProvider getValidOptionsTests - */ - public function it_instantiates_with_valid_options(array $options): void - { - $this->createTranslator('en', $options); - } - - /** - * @test - * @dataProvider getInvalidLocalesTests - * @expectedException \InvalidArgumentException - */ - public function it_throws_exception_on_instantiating_with_invalid_locale($locale): void - { - $this->createTranslator($locale); - } - - /** - * @test - * @dataProvider getAllValidLocalesTests - */ - public function it_instantiates_with_valid_locale($locale): void - { - $translator = $this->createTranslator($locale); - - $this->assertEquals($locale, $translator->getLocale()); - } - - /** - * @test - * @dataProvider getInvalidLocalesTests - * @expectedException \InvalidArgumentException - */ - public function its_throws_exception_on_setting_invalid_fallback_locales($locale): void - { - $translator = $this->createTranslator('fr'); - $translator->setFallbackLocales(['fr', $locale]); - } - - /** - * @test - * @dataProvider getAllValidLocalesTests - */ - public function its_fallback_locales_can_be_set_only_if_valid($locale): void - { - $translator = $this->createTranslator('fr'); - $translator->setFallbackLocales(['fr', $locale]); - } - - /** - * @test - * @dataProvider getAllValidLocalesTests - */ - public function it_adds_resources_with_valid_locales($locale): void - { - $translator = $this->createTranslator('fr'); - $translator->addResource('array', ['foo' => 'foofoo'], $locale); - } - - /** - * @test - * @dataProvider getAllValidLocalesTests - */ - public function it_translates_valid_locales($locale): void - { - $translator = $this->createTranslator($locale); - $translator->addLoader('array', new ArrayLoader()); - $translator->addResource('array', ['test' => 'OK'], $locale); - - $this->assertEquals('OK', $translator->trans('test')); - $this->assertEquals('OK', $translator->trans('test', [], null, $locale)); - } - - /** - * @test - */ - public function it_translates_to_a_fallback_locale(): void - { - $translator = $this->createTranslator('en'); - $translator->setFallbackLocales(['fr']); - - $translator->addLoader('array', new ArrayLoader()); - $translator->addResource('array', ['foo' => 'foofoo'], 'en'); - $translator->addResource('array', ['bar' => 'foobar'], 'fr'); - - $this->assertEquals('foobar', $translator->trans('bar')); - } - - /** - * @test - */ - public function it_can_have_multiple_fallback_locales(): void - { - $translator = $this->createTranslator('en'); - $translator->setFallbackLocales(['de', 'fr']); - - $translator->addLoader('array', new ArrayLoader()); - $translator->addResource('array', ['foo' => 'foo (en)'], 'en'); - $translator->addResource('array', ['bar' => 'bar (fr)'], 'fr'); - $translator->addResource('array', ['foobar' => 'foobar (de)'], 'de'); - - $this->assertEquals('bar (fr)', $translator->trans('bar')); - $this->assertEquals('foobar (de)', $translator->trans('foobar')); - } - - /** - * @test - * @dataProvider getThemelessLocalesTests - */ - public function it_gets_catalogue_with_fallback_catalogues_of_a_simple_locale($locale): void - { - $translator = $this->createTranslator($locale); - $catalogue = new MessageCatalogue($locale); - - $this->assertEquals($catalogue, $translator->getCatalogue()); - } - - /** - * @test - * @dataProvider getThemedLocalesTests - */ - public function it_gets_catalogue_with_fallback_catalogues_of_a_themed_locale($locale): void - { - $translator = $this->createTranslator($locale); - - $catalogue = new MessageCatalogue($locale); - $themeDelimiter = strrpos($locale, '@'); - - $catalogue->addFallbackCatalogue(new MessageCatalogue(substr($locale, 0, $themeDelimiter))); - - $this->assertEquals($catalogue, $translator->getCatalogue()); - } - - /** - * @test - */ - public function it_creates_a_nested_catalogue_with_fallback_translations_of_a_territorial_locale(): void - { - $translator = $this->createTranslator('fr_FR'); - - $catalogue = new MessageCatalogue('fr_FR'); - - $fallback = new MessageCatalogue('fr'); - $catalogue->addFallbackCatalogue($fallback); - - $this->assertEquals($catalogue, $translator->getCatalogue()); - } - - /** - * @test - */ - public function it_creates_a_nested_catalogue_with_fallback_translations_of_a_themed_locale(): void - { - $translator = $this->createTranslator('fr_FR@heron'); - - $catalogue = new MessageCatalogue('fr_FR@heron'); - - $firstFallback = new MessageCatalogue('fr_FR'); - $catalogue->addFallbackCatalogue($firstFallback); - - $secondFallback = new MessageCatalogue('fr@heron'); - $firstFallback->addFallbackCatalogue($secondFallback); - - $thirdFallback = new MessageCatalogue('fr'); - $secondFallback->addFallbackCatalogue($thirdFallback); - - $this->assertEquals($catalogue, $translator->getCatalogue()); - } - - /** - * @test - */ - public function it_creates_a_nested_catalogue_with_fallback_translations_with_duplicated_additional_fallbacks(): void - { - $translator = $this->createTranslator('fr_FR@heron'); - $translator->setFallbackLocales(['fr_FR', 'fr']); - - $catalogue = new MessageCatalogue('fr_FR@heron'); - - $firstFallback = new MessageCatalogue('fr_FR'); - $catalogue->addFallbackCatalogue($firstFallback); - - $secondFallback = new MessageCatalogue('fr@heron'); - $firstFallback->addFallbackCatalogue($secondFallback); - - $thirdFallback = new MessageCatalogue('fr'); - $secondFallback->addFallbackCatalogue($thirdFallback); - - $this->assertEquals($catalogue, $translator->getCatalogue()); - } - - /** - * @test - */ - public function it_creates_a_nested_catalogue_with_fallback_translations(): void - { - $translator = $this->createTranslator('fr_FR@heron'); - $translator->setFallbackLocales(['en_US', 'en']); - - $catalogue = new MessageCatalogue('fr_FR@heron'); - - $firstFallback = new MessageCatalogue('fr_FR'); - $catalogue->addFallbackCatalogue($firstFallback); - - $secondFallback = new MessageCatalogue('fr@heron'); - $firstFallback->addFallbackCatalogue($secondFallback); - - $thirdFallback = new MessageCatalogue('fr'); - $secondFallback->addFallbackCatalogue($thirdFallback); - - $fourthFallback = new MessageCatalogue('en_US@heron'); - $thirdFallback->addFallbackCatalogue($fourthFallback); - - $fifthFallback = new MessageCatalogue('en_US'); - $fourthFallback->addFallbackCatalogue($fifthFallback); - - $sixthFallback = new MessageCatalogue('en@heron'); - $fifthFallback->addFallbackCatalogue($sixthFallback); - - $seventhFallback = new MessageCatalogue('en'); - $sixthFallback->addFallbackCatalogue($seventhFallback); - - $this->assertEquals($catalogue, $translator->getCatalogue()); - } - - /** - * @return array - */ - public function getInvalidLocalesTests() - { - return [ - ['fr FR'], - ['français'], - ['fr+en'], - ['utf#8'], - ['fr&en'], - ['fr~FR'], - [' fr'], - ['fr '], - ['fr*'], - ['fr/FR'], - ['fr\\FR'], - ]; - } - - /** - * @return array - */ - public function getAllValidLocalesTests() - { - return array_merge( - $this->getThemedLocalesTests(), - $this->getThemelessLocalesTests() - ); - } - - /** - * @return array - */ - public function getThemedLocalesTests() - { - return [ - ['fr@heron'], - ['francais@heron'], - ['FR@heron'], - ['frFR@heron'], - ['fr-FR@heron'], - ['fr.FR@heron'], - ['fr-FR.UTF8@heron'], - ]; - } - - /** - * @return array - */ - public function getThemelessLocalesTests() - { - return [ - [''], - ['fr'], - ['francais'], - ['FR'], - ['frFR'], - ['fr-FR'], - ['fr.FR'], - ['fr-FR.UTF8'], - ]; - } - - /** - * @return array - */ - public function getValidOptionsTests() - { - return [ - [['cache_dir' => null, 'debug' => false]], - [['cache_dir' => 'someDirectory', 'debug' => false]], - [['debug' => false]], - [['cache_dir' => 'yup']], - [[]], - ]; - } - - /** - * @return array - */ - public function getInvalidOptionsTests() - { - return [ - [['heron' => '']], - [['cache_dir' => null, 'pugs' => 'yes']], - [['cache_dir' => null, 'debug' => false, 'pug' => 'heron']], - ]; - } - - /** - * @param string $locale - * @param string[] $options - * - * @return Translator - */ - private function createTranslator($locale = 'en', $options = []): Translator - { - $loaderProvider = new TranslatorLoaderProvider(); - $resourceProvider = new TranslatorResourceProvider(); - $messageSelector = $this->getMockBuilder(MessageSelector::class)->getMock(); - - return new Translator($loaderProvider, $resourceProvider, $messageSelector, $locale, $options); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPass.php b/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPass.php deleted file mode 100644 index 93b6fd1982..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPass.php +++ /dev/null @@ -1,41 +0,0 @@ -findDefinition('translator.default'); - $syliusTranslator = $container->findDefinition('sylius.theme.translation.translator'); - } catch (\InvalidArgumentException $exception) { - return; - } - - $methodCalls = array_filter($symfonyTranslator->getMethodCalls(), function (array $methodCall): bool { - return 'setFallbackLocales' === $methodCall[0]; - }); - - foreach ($methodCalls as $methodCall) { - $syliusTranslator->addMethodCall($methodCall[0], $methodCall[1]); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPass.php b/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPass.php deleted file mode 100644 index 51b28c385e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPass.php +++ /dev/null @@ -1,48 +0,0 @@ -findDefinition('sylius.theme.translation.loader_provider'); - } catch (\InvalidArgumentException $exception) { - return; - } - - $taggedServices = $container->findTaggedServiceIds('translation.loader'); - $loaders = []; - foreach ($taggedServices as $id => $attributes) { - $loader = $container->findDefinition($id); - $loader->setLazy(true); - - $loaders[$attributes[0]['alias']] = new Reference($id); - - if (isset($attributes[0]['legacy-alias'])) { - $loaders[$attributes[0]['legacy-alias']] = new Reference($id); - } - } - - $loaderProvider->replaceArgument(0, $loaders); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPass.php b/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPass.php deleted file mode 100644 index 1756e69a90..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPass.php +++ /dev/null @@ -1,71 +0,0 @@ -findDefinition('translator.default'); - $syliusResourceProvider = $container->findDefinition('sylius.theme.translation.resource_provider.default'); - } catch (\InvalidArgumentException $exception) { - return; - } - - $symfonyResourcesFiles = $this->extractResourcesFilesFromSymfonyTranslator($symfonyTranslator); - - $syliusResourceProvider->replaceArgument(0, array_merge( - $syliusResourceProvider->getArgument(0), - $symfonyResourcesFiles - )); - } - - /** - * @param Definition $symfonyTranslator - * - * @return array - */ - private function extractResourcesFilesFromSymfonyTranslator(Definition $symfonyTranslator): array - { - try { - $options = $symfonyTranslator->getArgument(3); - - if (!array_key_exists('resource_files', $options)) { - $options = $symfonyTranslator->getArgument(4); - } - } catch (OutOfBoundsException $exception) { - $options = []; - } - - $languagesFiles = $options['resource_files'] ?? []; - - $resourceFiles = []; - foreach ($languagesFiles as $language => $files) { - foreach ($files as $file) { - $resourceFiles[] = $file; - } - } - - return $resourceFiles; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Finder/OrderingTranslationFilesFinder.php b/src/Sylius/Bundle/ThemeBundle/Translation/Finder/OrderingTranslationFilesFinder.php deleted file mode 100644 index dd6aae5a7b..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Finder/OrderingTranslationFilesFinder.php +++ /dev/null @@ -1,44 +0,0 @@ -translationFilesFinder = $translationFilesFinder; - } - - public function findTranslationFiles(string $path): array - { - $files = $this->translationFilesFinder->findTranslationFiles($path); - - usort($files, function (string $firstFile, string $secondFile) use ($path): int { - $firstFile = str_replace($path, '', $firstFile); - $secondFile = str_replace($path, '', $secondFile); - - return strpos($secondFile, 'translations') - strpos($firstFile, 'translations'); - }); - - return $files; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Finder/TranslationFilesFinder.php b/src/Sylius/Bundle/ThemeBundle/Translation/Finder/TranslationFilesFinder.php deleted file mode 100644 index e46f3db50f..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Finder/TranslationFilesFinder.php +++ /dev/null @@ -1,82 +0,0 @@ -finderFactory = $finderFactory; - } - - /** - * {@inheritdoc} - */ - public function findTranslationFiles(string $path): array - { - $themeFiles = $this->getFiles($path); - - $translationsFiles = []; - foreach ($themeFiles as $themeFile) { - $themeFilepath = (string) $themeFile; - - if (!$this->isTranslationFile($themeFilepath)) { - continue; - } - - $translationsFiles[] = $themeFilepath; - } - - return $translationsFiles; - } - - /** - * @param string $path - * - * @return iterable|SplFileInfo[] - */ - private function getFiles(string $path): iterable - { - $finder = $this->finderFactory->create(); - - $finder - ->ignoreUnreadableDirs() - ->in($path) - ; - - return $finder; - } - - /** - * @param string $file - * - * @return bool - */ - private function isTranslationFile(string $file): bool - { - return false !== strpos($file, 'translations' . DIRECTORY_SEPARATOR) - && (bool) preg_match('/^[^\.]+?\.[a-zA-Z_]{2,}?\.[a-z0-9]{2,}?$/', basename($file)); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Finder/TranslationFilesFinderInterface.php b/src/Sylius/Bundle/ThemeBundle/Translation/Finder/TranslationFilesFinderInterface.php deleted file mode 100644 index 5124ac951c..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Finder/TranslationFilesFinderInterface.php +++ /dev/null @@ -1,24 +0,0 @@ -loaders = $loaders; - } - - /** - * {@inheritdoc} - */ - public function getLoaders(): array - { - return $this->loaders; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Loader/TranslatorLoaderProviderInterface.php b/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Loader/TranslatorLoaderProviderInterface.php deleted file mode 100644 index 9d83764f24..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Loader/TranslatorLoaderProviderInterface.php +++ /dev/null @@ -1,22 +0,0 @@ - Loader - */ - public function getLoaders(): array; -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/CompositeTranslatorResourceProvider.php b/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/CompositeTranslatorResourceProvider.php deleted file mode 100644 index 23c37b9061..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/CompositeTranslatorResourceProvider.php +++ /dev/null @@ -1,58 +0,0 @@ -resourceProviders = $resourceProviders; - } - - /** - * {@inheritdoc} - */ - public function getResources(): array - { - $resources = []; - - foreach ($this->resourceProviders as $resourceProvider) { - $resources = array_merge($resources, $resourceProvider->getResources()); - } - - return $resources; - } - - /** - * {@inheritdoc} - */ - public function getResourcesLocales(): array - { - $resourcesLocales = []; - - foreach ($this->resourceProviders as $resourceProvider) { - $resourcesLocales = array_merge($resourcesLocales, $resourceProvider->getResourcesLocales()); - } - - return array_values(array_unique($resourcesLocales)); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/ThemeTranslatorResourceProvider.php b/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/ThemeTranslatorResourceProvider.php deleted file mode 100644 index a97be14e8b..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/ThemeTranslatorResourceProvider.php +++ /dev/null @@ -1,102 +0,0 @@ -translationFilesFinder = $translationFilesFinder; - $this->themeRepository = $themeRepository; - $this->themeHierarchyProvider = $themeHierarchyProvider; - } - - /** - * {@inheritdoc} - */ - public function getResources(): array - { - /** @var ThemeInterface[] $themes */ - $themes = $this->themeRepository->findAll(); - - $resources = []; - foreach ($themes as $theme) { - $resources = array_merge($resources, $this->extractResourcesFromTheme($theme)); - } - - return $resources; - } - - /** - * {@inheritdoc} - */ - public function getResourcesLocales(): array - { - return array_values(array_unique(array_map(function (TranslationResourceInterface $translationResource): string { - return $translationResource->getLocale(); - }, $this->getResources()))); - } - - /** - * @param ThemeInterface $mainTheme - * - * @return array - */ - private function extractResourcesFromTheme(ThemeInterface $mainTheme): array - { - /** @var ThemeInterface[] $themes */ - $themes = array_reverse($this->themeHierarchyProvider->getThemeHierarchy($mainTheme)); - - $resources = []; - foreach ($themes as $theme) { - $paths = $this->translationFilesFinder->findTranslationFiles($theme->getPath()); - - foreach ($paths as $path) { - $resources[] = new ThemeTranslationResource($mainTheme, $path); - } - } - - return $resources; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/TranslatorResourceProvider.php b/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/TranslatorResourceProvider.php deleted file mode 100644 index 40fe950cf2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/TranslatorResourceProvider.php +++ /dev/null @@ -1,76 +0,0 @@ -filepaths = $filepaths; - } - - /** - * {@inheritdoc} - */ - public function getResources(): array - { - $this->initializeIfNeeded(); - - return $this->resources; - } - - /** - * {@inheritdoc} - */ - public function getResourcesLocales(): array - { - $this->initializeIfNeeded(); - - return $this->resourcesLocales; - } - - private function initializeIfNeeded(): void - { - foreach ($this->filepaths as $key => $filepath) { - $resource = new TranslationResource($filepath); - - $this->resources[] = $resource; - $this->resourcesLocales[] = $resource->getLocale(); - } - - $this->resourcesLocales = array_unique($this->resourcesLocales); - $this->filepaths = []; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/TranslatorResourceProviderInterface.php b/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/TranslatorResourceProviderInterface.php deleted file mode 100644 index 1c4db21990..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Provider/Resource/TranslatorResourceProviderInterface.php +++ /dev/null @@ -1,29 +0,0 @@ -name = $filepath; - - $parts = explode('.', basename($filepath), 3); - if (3 !== count($parts)) { - throw new \InvalidArgumentException(sprintf( - 'Could not create a translation resource with filepath "%s".', - $filepath - )); - } - - $this->domain = $parts[0]; - $this->locale = $parts[1] . '@' . str_replace('/', '-', $theme->getName()); - $this->format = $parts[2]; - } - - /** - * {@inheritdoc} - */ - public function getName(): string - { - return $this->name; - } - - /** - * {@inheritdoc} - */ - public function getLocale(): string - { - return $this->locale; - } - - /** - * {@inheritdoc} - */ - public function getFormat(): string - { - return $this->format; - } - - /** - * {@inheritdoc} - */ - public function getDomain(): string - { - return $this->domain; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Resource/TranslationResource.php b/src/Sylius/Bundle/ThemeBundle/Translation/Resource/TranslationResource.php deleted file mode 100644 index 112ab6268c..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Resource/TranslationResource.php +++ /dev/null @@ -1,89 +0,0 @@ -name = $filepath; - - $parts = explode('.', basename($filepath), 3); - if (3 !== count($parts)) { - throw new \InvalidArgumentException(sprintf( - 'Could not create a translation resource with filepath "%s".', - $filepath - )); - } - - $this->domain = $parts[0]; - $this->locale = $parts[1]; - $this->format = $parts[2]; - } - - /** - * {@inheritdoc} - */ - public function getName(): string - { - return $this->name; - } - - /** - * {@inheritdoc} - */ - public function getLocale(): string - { - return $this->locale; - } - - /** - * {@inheritdoc} - */ - public function getFormat(): string - { - return $this->format; - } - - /** - * {@inheritdoc} - */ - public function getDomain(): string - { - return $this->domain; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Resource/TranslationResourceInterface.php b/src/Sylius/Bundle/ThemeBundle/Translation/Resource/TranslationResourceInterface.php deleted file mode 100644 index 1e8f1e4155..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Resource/TranslationResourceInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -translator = $translator; - $this->themeContext = $themeContext; - } - - /** - * Passes through all unknown calls onto the translator object. - * - * @param string $method - * @param array $arguments - * - * @return mixed - */ - public function __call(string $method, array $arguments) - { - $translator = $this->translator; - $arguments = array_values($arguments); - - return $translator->$method(...$arguments); - } - - /** - * {@inheritdoc} - */ - public function trans($id, array $parameters = [], $domain = null, $locale = null): string - { - return $this->translator->trans($id, $parameters, $domain, $this->transformLocale($locale)); - } - - /** - * {@inheritdoc} - */ - public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null): string - { - return $this->translator->transChoice($id, $number, $parameters, $domain, $this->transformLocale($locale)); - } - - /** - * {@inheritdoc} - */ - public function getLocale(): string - { - return $this->translator->getLocale(); - } - - /** - * {@inheritdoc} - */ - public function setLocale($locale): void - { - $this->translator->setLocale($this->transformLocale($locale)); - } - - /** - * {@inheritdoc} - */ - public function getCatalogue($locale = null): MessageCatalogueInterface - { - return $this->translator->getCatalogue($locale); - } - - /** - * {@inheritdoc} - */ - public function warmUp($cacheDir): void - { - if ($this->translator instanceof WarmableInterface) { - $this->translator->warmUp($cacheDir); - } - } - - /** - * @param string|null $locale - * - * @return string|null - */ - private function transformLocale(?string $locale): ?string - { - $theme = $this->themeContext->getTheme(); - - if (null === $theme) { - return $locale; - } - - if (null === $locale) { - $locale = $this->getLocale(); - } - - return $locale . '@' . str_replace('/', '-', $theme->getName()); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Translation/Translator.php b/src/Sylius/Bundle/ThemeBundle/Translation/Translator.php deleted file mode 100644 index 22d0c6aaac..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Translation/Translator.php +++ /dev/null @@ -1,198 +0,0 @@ - null, - 'debug' => false, - ]; - - /** - * @var TranslatorLoaderProviderInterface - */ - private $loaderProvider; - - /** - * @var TranslatorResourceProviderInterface - */ - private $resourceProvider; - - /** - * @var bool - */ - private $resourcesLoaded = false; - - /** - * @param TranslatorLoaderProviderInterface $loaderProvider - * @param TranslatorResourceProviderInterface $resourceProvider - * @param MessageSelector $messageSelector - * @param string $locale - * @param array $options - */ - public function __construct( - TranslatorLoaderProviderInterface $loaderProvider, - TranslatorResourceProviderInterface $resourceProvider, - MessageSelector $messageSelector, - string $locale, - array $options = [] - ) { - $this->assertOptionsAreKnown($options); - - $this->loaderProvider = $loaderProvider; - $this->resourceProvider = $resourceProvider; - - $this->options = array_merge($this->options, $options); - if (null !== $this->options['cache_dir'] && $this->options['debug']) { - $this->addResources(); - } - - parent::__construct($locale, $messageSelector, $this->options['cache_dir'], $this->options['debug']); - } - - /** - * {@inheritdoc} - */ - public function warmUp($cacheDir): void - { - // skip warmUp when translator doesn't use cache - if (null === $this->options['cache_dir']) { - return; - } - - $locales = array_merge( - $this->getFallbackLocales(), - [$this->getLocale()], - $this->resourceProvider->getResourcesLocales() - ); - foreach (array_unique($locales) as $locale) { - // reset catalogue in case it's already loaded during the dump of the other locales. - if (isset($this->catalogues[$locale])) { - unset($this->catalogues[$locale]); - } - - $this->loadCatalogue($locale); - } - } - - /** - * {@inheritdoc} - */ - protected function initializeCatalogue($locale): void - { - $this->initialize(); - - parent::initializeCatalogue($locale); - } - - /** - * {@inheritdoc} - */ - protected function computeFallbackLocales($locale): array - { - $themeModifier = $this->getLocaleModifier($locale); - $localeWithoutModifier = $this->getLocaleWithoutModifier($locale, $themeModifier); - - $computedFallbackLocales = parent::computeFallbackLocales($locale); - array_unshift($computedFallbackLocales, $localeWithoutModifier); - - $fallbackLocales = []; - foreach (array_diff($computedFallbackLocales, [$locale]) as $computedFallback) { - $fallback = $computedFallback . $themeModifier; - if (null !== $themeModifier && $locale !== $fallback) { - $fallbackLocales[] = $fallback; - } - - $fallbackLocales[] = $computedFallback; - } - - return array_unique($fallbackLocales); - } - - /** - * @param string $locale - * - * @return string - */ - private function getLocaleModifier(string $locale): string - { - $modifier = strrchr($locale, '@'); - - return $modifier ?: ''; - } - - /** - * @param string $locale - * @param string $modifier - * - * @return string - */ - private function getLocaleWithoutModifier(string $locale, string $modifier): string - { - return str_replace($modifier, '', $locale); - } - - private function initialize(): void - { - $this->addResources(); - $this->addLoaders(); - } - - private function addResources(): void - { - if ($this->resourcesLoaded) { - return; - } - - $resources = $this->resourceProvider->getResources(); - foreach ($resources as $resource) { - $this->addResource( - $resource->getFormat(), - $resource->getName(), - $resource->getLocale(), - $resource->getDomain() - ); - } - - $this->resourcesLoaded = true; - } - - private function addLoaders(): void - { - $loaders = $this->loaderProvider->getLoaders(); - foreach ($loaders as $alias => $loader) { - $this->addLoader($alias, $loader); - } - } - - /** - * @param array $options - */ - private function assertOptionsAreKnown(array $options): void - { - if ($diff = array_diff(array_keys($options), array_keys($this->options))) { - throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff))); - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/Twig/ThemeFilesystemLoader.php b/src/Sylius/Bundle/ThemeBundle/Twig/ThemeFilesystemLoader.php deleted file mode 100644 index 60d6332046..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/Twig/ThemeFilesystemLoader.php +++ /dev/null @@ -1,124 +0,0 @@ -decoratedLoader = $decoratedLoader; - $this->templateLocator = $templateLocator; - $this->templateNameParser = $templateNameParser; - } - - /** - * {@inheritdoc} - */ - public function getSourceContext($name): \Twig_Source - { - try { - $path = $this->findTemplate((string) $name); - - return new \Twig_Source(file_get_contents($path), $name, $path); - } catch (\Exception $exception) { - return $this->decoratedLoader->getSourceContext((string) $name); - } - } - - /** - * {@inheritdoc} - */ - public function getCacheKey($name): string - { - try { - return $this->findTemplate((string) $name); - } catch (\Exception $exception) { - return $this->decoratedLoader->getCacheKey((string) $name); - } - } - - /** - * {@inheritdoc} - */ - public function isFresh($name, $time): bool - { - try { - return filemtime($this->findTemplate((string) $name)) <= $time; - } catch (\Exception $exception) { - return $this->decoratedLoader->isFresh((string) $name, $time); - } - } - - /** - * {@inheritdoc} - */ - public function exists($name): bool - { - try { - return stat($this->findTemplate((string) $name)) !== false; - } catch (\Exception $exception) { - return $this->decoratedLoader->exists((string) $name); - } - } - - /** - * @param string $logicalName - * - * @return string - */ - private function findTemplate(string $logicalName): string - { - if (isset($this->cache[$logicalName])) { - return (string) $this->cache[$logicalName]; - } - - $template = $this->templateNameParser->parse($logicalName); - - /** @var string $file */ - $file = $this->templateLocator->locate($template); - - return $this->cache[$logicalName] = $file; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/composer.json b/src/Sylius/Bundle/ThemeBundle/composer.json deleted file mode 100644 index c03d4da3fb..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/composer.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "name": "sylius/theme-bundle", - "type": "symfony-bundle", - "description": "Themes management for Symfony projects.", - "keywords": ["themes", "theming"], - "homepage": "http://sylius.com", - "license": "MIT", - "authors": [ - { - "name": "Kamil Kokot", - "homepage": "http://kamil.kokot.me" - }, - { - "name": "Sylius project", - "homepage": "http://sylius.com" - }, - { - "name": "Community contributions", - "homepage": "http://github.com/Sylius/Sylius/contributors" - } - ], - "require": { - "php": "^7.1", - - "doctrine/common": "^2.5", - "symfony/asset": "^3.4", - "symfony/config": "^3.4", - "symfony/console": "^3.4", - "symfony/dependency-injection": "^3.4", - "symfony/filesystem": "^3.4", - "symfony/finder": "^3.4", - "symfony/form": "^3.4", - "symfony/framework-bundle": "^3.4", - "symfony/http-foundation": "^3.4", - "symfony/http-kernel": "^3.4", - "symfony/options-resolver": "^3.4", - "symfony/templating": "^3.4", - "symfony/translation": "^3.4", - "zendframework/zend-hydrator": "^2.2" - }, - "require-dev": { - "matthiasnoback/symfony-config-test": "^3.0", - "matthiasnoback/symfony-dependency-injection-test": "^2.0", - "mikey179/vfsStream": "^1.6", - "phpspec/phpspec": "^4.0", - "phpunit/phpunit": "^6.5", - "sylius/registry": "^1.1", - "symfony/browser-kit": "^3.4", - "symfony/security-csrf": "^3.4", - "symfony/twig-bundle": "^3.4", - "twig/twig": "^2.0" - }, - "conflict": { - "twig/twig": "^1.0" - }, - "config": { - "bin-dir": "bin" - }, - "autoload": { - "psr-4": { "Sylius\\Bundle\\ThemeBundle\\": "" }, - "exclude-from-classmap": ["/Tests/"] - }, - "autoload-dev": { - "psr-4": { - "Sylius\\Bundle\\ThemeBundle\\Tests\\": "tests/" - }, - "files": ["Tests/Functional/app/AppKernel.php"] - }, - "minimum-stability": "dev", - "prefer-stable": true, - "repositories": [ - { - "type": "path", - "url": "../../*/*" - } - ], - "scripts": { - "test": [ - "@composer validate --strict", - "Tests/Functional/bin/console cache:clear --no-warmup --ansi --no-interaction", - "bin/phpunit --colors=always", - "bin/phpspec run --ansi --no-interaction" - ] - }, - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/phpspec.yml.dist b/src/Sylius/Bundle/ThemeBundle/phpspec.yml.dist deleted file mode 100644 index 011d8746ed..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/phpspec.yml.dist +++ /dev/null @@ -1,5 +0,0 @@ -suites: - main: - namespace: Sylius\Bundle\ThemeBundle - psr4_prefix: Sylius\Bundle\ThemeBundle - src_path: . diff --git a/src/Sylius/Bundle/ThemeBundle/phpunit.xml.dist b/src/Sylius/Bundle/ThemeBundle/phpunit.xml.dist deleted file mode 100644 index bc705031ac..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/phpunit.xml.dist +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - ./Tests/ - - - diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Asset/Package/PathPackageSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Asset/Package/PathPackageSpec.php deleted file mode 100644 index e4586eb0fb..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Asset/Package/PathPackageSpec.php +++ /dev/null @@ -1,107 +0,0 @@ -beConstructedWith('/', $versionStrategy, $themeContext, $pathResolver); - } - - function it_implements_package_interface_interface(): void - { - $this->shouldImplement(PackageInterface::class); - } - - function it_returns_vanilla_path_if_there_are_no_active_themes( - ThemeContextInterface $themeContext, - VersionStrategyInterface $versionStrategy - ): void { - $path = 'bundles/sample/asset.js'; - $versionedPath = 'bundles/sample/asset.js?v=42'; - - $themeContext->getTheme()->shouldBeCalled()->willReturn(null); - $versionStrategy->applyVersion($path)->shouldBeCalled()->willReturn($versionedPath); - - $this->getUrl($path)->shouldReturn('/' . $versionedPath); - } - - function it_returns_modified_path_if_there_is_active_theme( - ThemeContextInterface $themeContext, - VersionStrategyInterface $versionStrategy, - PathResolverInterface $pathResolver, - ThemeInterface $theme - ): void { - $path = 'bundles/sample/asset.js'; - $themedPath = 'bundles/theme/foo/bar/sample/asset.js'; - $versionedThemedPath = 'bundles/theme/foo/bar/sample/asset.js?v=42'; - - $themeContext->getTheme()->shouldBeCalled()->willReturn($theme); - $pathResolver->resolve($path, $theme)->shouldBeCalled()->willReturn($themedPath); - $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath); - - $this->getUrl($path)->shouldReturn('/' . $versionedThemedPath); - } - - function it_returns_path_without_changes_if_it_is_absolute(): void - { - $this->getUrl('//localhost/asset.js')->shouldReturn('//localhost/asset.js'); - $this->getUrl('https://localhost/asset.js')->shouldReturn('https://localhost/asset.js'); - } - - function it_does_not_prepend_it_with_base_path_if_modified_path_is_an_absolute_one( - ThemeContextInterface $themeContext, - VersionStrategyInterface $versionStrategy, - PathResolverInterface $pathResolver, - ThemeInterface $theme - ): void { - $path = 'bundles/sample/asset.js'; - $themedPath = 'bundles/theme/foo/bar/sample/asset.js'; - $versionedThemedPath = '/bundles/theme/foo/bar/sample/asset.js?v=42'; - - $themeContext->getTheme()->shouldBeCalled()->willReturn($theme); - $pathResolver->resolve($path, $theme)->shouldBeCalled()->willReturn($themedPath); - $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath); - - $this->getUrl($path)->shouldReturn($versionedThemedPath); - } - - function it_does_not_prepend_it_with_base_path_if_modified_path_is_an_absolute_url( - ThemeContextInterface $themeContext, - VersionStrategyInterface $versionStrategy, - PathResolverInterface $pathResolver, - ThemeInterface $theme - ): void { - $path = 'bundles/sample/asset.js'; - $themedPath = 'bundles/theme/foo/bar/sample/asset.js'; - $versionedThemedPath = 'https://bundles/theme/foo/bar/sample/asset.js?v=42'; - - $themeContext->getTheme()->shouldBeCalled()->willReturn($theme); - $pathResolver->resolve($path, $theme)->shouldBeCalled()->willReturn($themedPath); - $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath); - - $this->getUrl($path)->shouldReturn($versionedThemedPath); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Asset/Package/UrlPackageSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Asset/Package/UrlPackageSpec.php deleted file mode 100644 index 05398e3555..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Asset/Package/UrlPackageSpec.php +++ /dev/null @@ -1,116 +0,0 @@ -beConstructedWith(['https://cdn-url.com/'], $versionStrategy, $themeContext, $urlResolver); - } - - function it_implements_package_interface(): void - { - $this->shouldImplement(PackageInterface::class); - } - - function it_extends_symfony_url_package(): void - { - $this->shouldImplement(UrlPackage::class); - } - - function it_returns_vanilla_url_if_there_are_no_active_themes_and_with_base_url( - VersionStrategyInterface $versionStrategy, - ThemeContextInterface $themeContext, - PathResolverInterface $urlResolver - ): void { - $this->beConstructedWith('https://cdn-url.com/', $versionStrategy, $themeContext, $urlResolver); - - $url = 'bundles/sample/asset.js'; - $versionedPath = 'bundles/sample/asset.js?v=42'; - - $themeContext->getTheme()->shouldBeCalled()->willReturn(null); - $versionStrategy->applyVersion($url)->shouldBeCalled()->willReturn($versionedPath); - - $this->getUrl($url)->shouldReturn('https://cdn-url.com/' . $versionedPath); - } - - function it_returns_modified_url_if_there_is_active_theme_and_with_base_url( - ThemeContextInterface $themeContext, - VersionStrategyInterface $versionStrategy, - PathResolverInterface $urlResolver, - ThemeInterface $theme - ): void { - $url = 'bundles/sample/asset.js'; - $themedPath = 'bundles/theme/foo/bar/sample/asset.js'; - $versionedThemedPath = 'bundles/theme/foo/bar/sample/asset.js?v=42'; - - $themeContext->getTheme()->shouldBeCalled()->willReturn($theme); - $urlResolver->resolve($url, $theme)->shouldBeCalled()->willReturn($themedPath); - $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath); - - $this->getUrl($url)->shouldReturn('https://cdn-url.com/' . $versionedThemedPath); - } - - function it_returns_url_without_changes_if_it_is_absolute(): void - { - $this->getUrl('//localhost/asset.js')->shouldReturn('//localhost/asset.js'); - $this->getUrl('https://localhost/asset.js')->shouldReturn('https://localhost/asset.js'); - } - - function it_does_prepend_it_with_base_url_if_modified_url_is_an_absolute_one( - ThemeContextInterface $themeContext, - VersionStrategyInterface $versionStrategy, - PathResolverInterface $urlResolver, - ThemeInterface $theme - ): void { - $url = 'bundles/sample/asset.js'; - $themedPath = 'bundles/theme/foo/bar/sample/asset.js'; - $versionedThemedPath = 'https://cdn-url.com/bundles/theme/foo/bar/sample/asset.js?v=42'; - - $themeContext->getTheme()->shouldBeCalled()->willReturn($theme); - $urlResolver->resolve($url, $theme)->shouldBeCalled()->willReturn($themedPath); - $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath); - - $this->getUrl($url)->shouldReturn($versionedThemedPath); - } - - function it_does_not_prepend_it_with_base_url_if_modified_url_is_an_absolute_url( - ThemeContextInterface $themeContext, - VersionStrategyInterface $versionStrategy, - PathResolverInterface $urlResolver, - ThemeInterface $theme - ): void { - $url = 'bundles/sample/asset.js'; - $themedPath = 'bundles/theme/foo/bar/sample/asset.js'; - $versionedThemedPath = 'https://bundles/theme/foo/bar/sample/asset.js?v=42'; - - $themeContext->getTheme()->shouldBeCalled()->willReturn($theme); - $urlResolver->resolve($url, $theme)->shouldBeCalled()->willReturn($themedPath); - $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath); - - $this->getUrl($url)->shouldReturn($versionedThemedPath); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Asset/PathResolverSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Asset/PathResolverSpec.php deleted file mode 100644 index 22499ab42e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Asset/PathResolverSpec.php +++ /dev/null @@ -1,40 +0,0 @@ -shouldImplement(PathResolverInterface::class); - } - - function it_returns_modified_path_if_its_referencing_bundle_asset(ThemeInterface $theme): void - { - $theme->getName()->willReturn('theme/name'); - - $this->resolve('bundles/asset.min.js', $theme)->shouldReturn('bundles/_themes/theme/name/asset.min.js'); - } - - function it_does_not_change_path_if_its_not_referencing_bundle_asset(ThemeInterface $theme): void - { - $theme->getName()->willReturn('theme/name'); - - $this->resolve('/long.path/asset.min.js', $theme)->shouldReturn('/long.path/asset.min.js'); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/CompositeConfigurationProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Configuration/CompositeConfigurationProviderSpec.php deleted file mode 100644 index 4ee369ad04..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/CompositeConfigurationProviderSpec.php +++ /dev/null @@ -1,59 +0,0 @@ -beConstructedWith([]); - } - - function it_implements_configuration_provider_interface(): void - { - $this->shouldImplement(ConfigurationProviderInterface::class); - } - - function it_returns_empty_array_if_no_configurations_are_loaded(): void - { - $this->getConfigurations()->shouldReturn([]); - } - - function it_returns_sum_of_configurations_returned_by_nested_configuration_providers( - ConfigurationProviderInterface $firstConfigurationProvider, - ConfigurationProviderInterface $secondConfigurationProvider - ): void { - $this->beConstructedWith([ - $firstConfigurationProvider, - $secondConfigurationProvider, - ]); - - $firstConfigurationProvider->getConfigurations()->willReturn([ - ['name' => 'first/theme'], - ]); - $secondConfigurationProvider->getConfigurations()->willReturn([ - ['name' => 'second/theme'], - ['name' => 'third/theme'], - ]); - - $this->getConfigurations()->shouldReturn([ - ['name' => 'first/theme'], - ['name' => 'second/theme'], - ['name' => 'third/theme'], - ]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/FilesystemConfigurationProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/FilesystemConfigurationProviderSpec.php deleted file mode 100644 index e0607eea79..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/FilesystemConfigurationProviderSpec.php +++ /dev/null @@ -1,55 +0,0 @@ -beConstructedWith($fileLocator, $loader, 'configurationfile.json'); - } - - function it_implements_configuration_provider_interface(): void - { - $this->shouldImplement(ConfigurationProviderInterface::class); - } - - function it_provides_loaded_configuration_files(FileLocatorInterface $fileLocator, ConfigurationLoaderInterface $loader): void - { - $fileLocator->locateFilesNamed('configurationfile.json')->willReturn([ - '/cristopher/configurationfile.json', - '/richard/configurationfile.json', - ]); - - $loader->load('/cristopher/configurationfile.json')->willReturn(['name' => 'cristopher/sylius-theme']); - $loader->load('/richard/configurationfile.json')->willReturn(['name' => 'richard/sylius-theme']); - - $this->getConfigurations()->shouldReturn([ - ['name' => 'cristopher/sylius-theme'], - ['name' => 'richard/sylius-theme'], - ]); - } - - function it_provides_an_empty_array_if_there_were_no_themes_found(FileLocatorInterface $fileLocator): void - { - $fileLocator->locateFilesNamed('configurationfile.json')->willThrow(\InvalidArgumentException::class); - - $this->getConfigurations()->shouldReturn([]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/JsonFileConfigurationLoaderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/JsonFileConfigurationLoaderSpec.php deleted file mode 100644 index f97c88af3a..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/JsonFileConfigurationLoaderSpec.php +++ /dev/null @@ -1,50 +0,0 @@ -beConstructedWith($filesystem); - } - - function it_implements_configuration_loader_interface(): void - { - $this->shouldImplement(ConfigurationLoaderInterface::class); - } - - function it_loads_json_file(FilesystemInterface $filesystem): void - { - $filesystem->exists('/directory/composer.json')->willReturn(true); - - $filesystem->getFileContents('/directory/composer.json')->willReturn('{ "name": "example/sylius-theme" }'); - - $this->load('/directory/composer.json')->shouldReturn([ - 'path' => '/directory', - 'name' => 'example/sylius-theme', - ]); - } - - function it_throws_an_exception_if_file_does_not_exist(FilesystemInterface $filesystem): void - { - $filesystem->exists('composer.json')->willReturn(false); - - $this->shouldThrow(\InvalidArgumentException::class)->during('load', ['composer.json']); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/ProcessingConfigurationLoaderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/ProcessingConfigurationLoaderSpec.php deleted file mode 100644 index 453a8169aa..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Filesystem/ProcessingConfigurationLoaderSpec.php +++ /dev/null @@ -1,75 +0,0 @@ -beConstructedWith($decoratedLoader, $configurationProcessor); - } - - function it_implements_loader_interface(): void - { - $this->shouldImplement(ConfigurationLoaderInterface::class); - } - - function it_processes_the_configuration( - ConfigurationLoaderInterface $decoratedLoader, - ConfigurationProcessorInterface $configurationProcessor - ): void { - $basicConfiguration = ['name' => 'example/sylius-theme']; - - $decoratedLoader->load('theme-configuration-resource')->willReturn($basicConfiguration); - - $configurationProcessor->process([$basicConfiguration])->willReturn([ - 'name' => 'example/sylius-theme', - ]); - - $this->load('theme-configuration-resource')->shouldReturn([ - 'name' => 'example/sylius-theme', - ]); - } - - function it_processes_the_configuration_and_extracts_extra_sylius_theme_key_as_another_configuration( - ConfigurationLoaderInterface $decoratedLoader, - ConfigurationProcessorInterface $configurationProcessor - ): void { - $basicConfiguration = [ - 'name' => 'example/sylius-theme', - 'extra' => [ - 'sylius-theme' => [ - 'name' => 'example/brand-new-sylius-theme', - ], - ], - ]; - - $decoratedLoader->load('theme-configuration-resource')->willReturn($basicConfiguration); - - $configurationProcessor->process([ - $basicConfiguration, - ['name' => 'example/brand-new-sylius-theme'], - ])->willReturn([ - 'name' => 'example/brand-new-sylius-theme', - ]); - - $this->load('theme-configuration-resource')->shouldReturn([ - 'name' => 'example/brand-new-sylius-theme', - ]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/SymfonyConfigurationProcessorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Configuration/SymfonyConfigurationProcessorSpec.php deleted file mode 100644 index b7435b8fbe..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/SymfonyConfigurationProcessorSpec.php +++ /dev/null @@ -1,56 +0,0 @@ -beConstructedWith($configuration, $processor); - } - - function it_implements_configuration_processor_interface(): void - { - $this->shouldImplement(ConfigurationProcessorInterface::class); - } - - function it_proxies_configuration_processing_to_symfony_configuration_processor( - ConfigurationInterface $configuration, - Processor $processor - ): void { - $processor - ->processConfiguration($configuration, [['name' => 'example/theme']]) - ->willReturn(['name' => 'example/theme']) - ; - - $this->process([['name' => 'example/theme']])->shouldReturn(['name' => 'example/theme']); - } - - function it_does_not_catch_any_exception_thrown_by_symfony_configuration_processor( - ConfigurationInterface $configuration, - Processor $processor - ): void { - $processor - ->processConfiguration($configuration, []) - ->willThrow(\Exception::class) - ; - - $this->shouldThrow(\Exception::class)->duringProcess([]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Test/TestConfigurationProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Test/TestConfigurationProviderSpec.php deleted file mode 100644 index a7ffe1763c..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Test/TestConfigurationProviderSpec.php +++ /dev/null @@ -1,42 +0,0 @@ -beConstructedWith($testThemeConfigurationManager); - } - - function it_implements_configuration_provider_interface(): void - { - $this->shouldImplement(ConfigurationProviderInterface::class); - } - - function it_provides_configuration_based_on_test_configuration_manager(TestThemeConfigurationManagerInterface $testThemeConfigurationManager): void - { - $testThemeConfigurationManager->findAll()->willReturn([ - ['name' => 'theme/name'], - ]); - - $this->getConfigurations()->shouldReturn([ - ['name' => 'theme/name'], - ]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Test/TestThemeConfigurationManagerSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Test/TestThemeConfigurationManagerSpec.php deleted file mode 100644 index d72ce0c0bc..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Configuration/Test/TestThemeConfigurationManagerSpec.php +++ /dev/null @@ -1,83 +0,0 @@ -beConstructedWith($configurationProcessor, 'vfs://cache/'); - } - - function letGo(): void - { - VfsStreamWrapper::unregister(); - } - - function it_implements_test_configuration_manager_interface(): void - { - $this->shouldImplement(TestThemeConfigurationManagerInterface::class); - } - - function it_finds_all_saved_configurations(): void - { - $this->findAll()->shouldReturn([]); - } - - function it_stores_theme_configuration(ConfigurationProcessorInterface $configurationProcessor): void - { - $configurationProcessor->process([['name' => 'theme/name']])->willReturn(['name' => 'theme/name']); - - $this->add(['name' => 'theme/name']); - - $this->findAll()->shouldHaveCount(1); - } - - function its_theme_configurations_can_be_removed(ConfigurationProcessorInterface $configurationProcessor): void - { - $configurationProcessor->process([['name' => 'theme/name']])->willReturn(['name' => 'theme/name']); - - $this->add(['name' => 'theme/name']); - $this->remove('theme/name'); - - $this->findAll()->shouldReturn([]); - } - - function it_clears_all_theme_configurations(ConfigurationProcessorInterface $configurationProcessor): void - { - $configurationProcessor->process([['name' => 'theme/name1']])->willReturn(['name' => 'theme/name1']); - $configurationProcessor->process([['name' => 'theme/name2']])->willReturn(['name' => 'theme/name2']); - - $this->add(['name' => 'theme/name1']); - $this->add(['name' => 'theme/name2']); - - $this->clear(); - - $this->findAll()->shouldReturn([]); - } - - function it_does_not_throw_any_exception_if_clearing_unexisting_storage(): void - { - $this->clear(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Context/EmptyThemeContextSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Context/EmptyThemeContextSpec.php deleted file mode 100644 index 9072dfb664..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Context/EmptyThemeContextSpec.php +++ /dev/null @@ -1,30 +0,0 @@ -shouldImplement(ThemeContextInterface::class); - } - - function it_always_returns_null(): void - { - $this->getTheme()->shouldReturn(null); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Context/SettableThemeContextSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Context/SettableThemeContextSpec.php deleted file mode 100644 index 6c31af007d..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Context/SettableThemeContextSpec.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldImplement(ThemeContextInterface::class); - } - - function it_has_theme(ThemeInterface $theme): void - { - $this->getTheme()->shouldReturn(null); - - $this->setTheme($theme); - $this->getTheme()->shouldReturn($theme); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Controller/ThemeScreenshotControllerSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Controller/ThemeScreenshotControllerSpec.php deleted file mode 100644 index e9564fa832..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Controller/ThemeScreenshotControllerSpec.php +++ /dev/null @@ -1,113 +0,0 @@ -beConstructedWith($themeRepository); - - $this->fixturesPath = realpath(__DIR__ . '/../Fixtures'); - } - - function it_streams_screenshot_as_a_response(ThemeRepositoryInterface $themeRepository, ThemeInterface $theme): void - { - $themeRepository->findOneByName('theme/name')->willReturn($theme); - - $theme->getScreenshots()->willReturn([ - new ThemeScreenshot('screenshot/0-amazing.jpg'), // exists - new ThemeScreenshot('screenshot/1-awesome.jpg'), // does not exist - ]); - $theme->getPath()->willReturn($this->fixturesPath); - - $this - ->streamScreenshotAction('theme/name', 0) - ->shouldBeBinaryFileResponseStreamingFile($this->fixturesPath . '/screenshot/0-amazing.jpg') - ; - } - - function it_throws_not_found_http_exception_if_screenshot_cannot_be_found( - ThemeRepositoryInterface $themeRepository, - ThemeInterface $theme - ): void { - $themeRepository->findOneByName('theme/name')->willReturn($theme); - - $theme->getScreenshots()->willReturn([ - new ThemeScreenshot('screenshot/0-amazing.jpg'), // exists - new ThemeScreenshot('screenshot/1-awesome.jpg'), // does not exists - ]); - $theme->getPath()->willReturn($this->fixturesPath); - - $this - ->shouldThrow(new NotFoundHttpException(sprintf( - 'Screenshot "%s/screenshot/1-awesome.jpg" does not exist', - $this->fixturesPath - ))) - ->during('streamScreenshotAction', ['theme/name', 1]) - ; - } - - function it_throws_not_found_http_exception_if_screenshot_number_exceeds_the_number_of_theme_screenshots( - ThemeRepositoryInterface $themeRepository, - ThemeInterface $theme - ): void { - $themeRepository->findOneByName('theme/name')->willReturn($theme); - - $theme->getScreenshots()->willReturn([ - new ThemeScreenshot('screenshot/0-amazing.jpg'), - new ThemeScreenshot('screenshot/1-awesome.jpg'), - ]); - $theme->getTitle()->willReturn('Candy shop'); - - $this - ->shouldThrow(new NotFoundHttpException('Theme "Candy shop" does not have screenshot #4')) - ->during('streamScreenshotAction', ['theme/name', 4]) - ; - } - - function it_throws_not_found_http_exception_if_theme_with_given_id_cannot_be_found(ThemeRepositoryInterface $themeRepository): void - { - $themeRepository->findOneByName('theme/name')->willReturn(null); - - $this - ->shouldThrow(new NotFoundHttpException('Theme with name "theme/name" not found')) - ->during('streamScreenshotAction', ['theme/name', 666]) - ; - } - - /** - * {@inheritdoc} - */ - public function getMatchers(): array - { - return [ - 'beBinaryFileResponseStreamingFile' => function (BinaryFileResponse $response, $file) { - return $response->getFile()->getRealPath() === $file; - }, - ]; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Factory/FinderFactorySpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Factory/FinderFactorySpec.php deleted file mode 100644 index 3e3d649ff8..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Factory/FinderFactorySpec.php +++ /dev/null @@ -1,31 +0,0 @@ -shouldImplement(FinderFactoryInterface::class); - } - - function it_creates_a_brand_new_finder(): void - { - $this->create()->shouldHaveType(Finder::class); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeAuthorFactorySpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeAuthorFactorySpec.php deleted file mode 100644 index 6edde80471..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeAuthorFactorySpec.php +++ /dev/null @@ -1,38 +0,0 @@ -shouldImplement(ThemeAuthorFactoryInterface::class); - } - - function it_creates_an_author_from_an_array(): void - { - $expectedAuthor = new ThemeAuthor(); - $expectedAuthor->setName('Rynkowsky'); - $expectedAuthor->setEmail('richard@rynkowsky.com'); - - $this - ->createFromArray(['name' => 'Rynkowsky', 'email' => 'richard@rynkowsky.com']) - ->shouldBeLike($expectedAuthor) - ; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeFactorySpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeFactorySpec.php deleted file mode 100644 index 9f3d0c229d..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeFactorySpec.php +++ /dev/null @@ -1,40 +0,0 @@ -shouldImplement(ThemeFactoryInterface::class); - } - - function it_creates_a_theme(): void - { - $this->create('example/theme', '/theme/path')->shouldHaveNameAndPath('example/theme', '/theme/path'); - } - - public function getMatchers(): array - { - return [ - 'haveNameAndPath' => function (ThemeInterface $theme, $expectedName, $expectedPath) { - return $expectedName === $theme->getName() && $expectedPath === $theme->getPath(); - }, - ]; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeScreenshotFactorySpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeScreenshotFactorySpec.php deleted file mode 100644 index 4d3805dd09..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Factory/ThemeScreenshotFactorySpec.php +++ /dev/null @@ -1,58 +0,0 @@ -shouldImplement(ThemeScreenshotFactoryInterface::class); - } - - function it_creates_a_screenshot_from_an_array(): void - { - $this - ->createFromArray(['path' => '/screenshot/path.jpg', 'title' => 'Steamboat', 'description' => 'With steamboat into a wonderful cruise']) - ->shouldBeScreenshotWithTheFollowingProperties(['path' => '/screenshot/path.jpg', 'title' => 'Steamboat', 'description' => 'With steamboat into a wonderful cruise']) - ; - } - - /** - * {@inheritdoc} - */ - public function getMatchers(): array - { - return [ - 'beScreenshotWithTheFollowingProperties' => function (ThemeScreenshot $subject, array $properties) { - if (isset($properties['path']) && $subject->getPath() !== $properties['path']) { - return false; - } - - if (isset($properties['title']) && $subject->getTitle() !== $properties['title']) { - return false; - } - - if (isset($properties['description']) && $subject->getDescription() !== $properties['description']) { - return false; - } - - return true; - }, - ]; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Fixtures/screenshot/0-amazing.jpg b/src/Sylius/Bundle/ThemeBundle/spec/Fixtures/screenshot/0-amazing.jpg deleted file mode 100644 index f77da23a24..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Fixtures/screenshot/0-amazing.jpg +++ /dev/null @@ -1,44 +0,0 @@ -Krzysztof Krawczyk - Płatna Miłość (https://www.youtube.com/watch?v=DKxbjMfS6bo) - -Pozoru chłodny, choć w środku płonę -Idąc bez celu, zmierzam do niej -Nie potrzebuję żadnej mapy -Żeby bezbłędnie do niej trafić - -Miłości, bracie, się nie kupi -Ten, kto to śpiewał, nie był głupi -Lecz jest uliczka w moim mieście -Gdzie zawsze można kupić szczęście - -Płatna miłość, innej nie znam -Płatna miłość - poezja - -Czasami, gdy na ciebie patrzę -To chciałbym zostać tu na zawsze -A gdy dotykam twego łona -To gotów byłbym na nim skonać - -A ty żartujesz ze swego ciała -I mówisz "Ale jestem stara" -Te parę zmarszczek, to drobnostka -Skoro do rana mogę zostać - -Płatna miłość, innej nie znam -Płatna miłość - poezja - -Grajcie nam, mandoliny! - -Miłość jest tania, szybka, prosta -Kto się jej oprze, kto jej sprosta -Kochając nie myślimy o tym -że uzależnia, jak narkotyk - -Z pozoru płonę, lecz w środku jestem chłodny -Idąc bez celu, wznoszę modły -Jedno tylko mogę pragnąć -Nie daj im, Panie, kochać darmo - -Płatna miłość, innej nie znam -Płatna miłość - poezja - -Mandoliny, grajcie, grajcie! diff --git a/src/Sylius/Bundle/ThemeBundle/spec/HierarchyProvider/NoopThemeHierarchyProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/HierarchyProvider/NoopThemeHierarchyProviderSpec.php deleted file mode 100644 index 483c2241ed..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/HierarchyProvider/NoopThemeHierarchyProviderSpec.php +++ /dev/null @@ -1,31 +0,0 @@ -shouldImplement(ThemeHierarchyProviderInterface::class); - } - - function it_returns_array_with_given_theme_as_only_element(ThemeInterface $theme): void - { - $this->getThemeHierarchy($theme)->shouldReturn([$theme]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/HierarchyProvider/ThemeHierarchyProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/HierarchyProvider/ThemeHierarchyProviderSpec.php deleted file mode 100644 index 6a71e6a893..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/HierarchyProvider/ThemeHierarchyProviderSpec.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldImplement(ThemeHierarchyProviderInterface::class); - } - - function it_returns_theme_list_in_hierarchized_order(ThemeInterface $firstTheme, ThemeInterface $secondTheme): void - { - $firstTheme->getParents()->willReturn([$secondTheme]); - $secondTheme->getParents()->willReturn([]); - - $this->getThemeHierarchy($firstTheme)->shouldReturn([$firstTheme, $secondTheme]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Loader/CircularDependencyCheckerSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Loader/CircularDependencyCheckerSpec.php deleted file mode 100644 index 48e41dcbd7..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Loader/CircularDependencyCheckerSpec.php +++ /dev/null @@ -1,71 +0,0 @@ -shouldImplement(CircularDependencyCheckerInterface::class); - } - - function it_does_not_find_circular_dependency_if_checking_a_theme_without_any_parents( - ThemeInterface $theme - ): void { - $theme->getParents()->willReturn([]); - - $this->check($theme); - } - - function it_does_not_find_circular_dependency_if_theme_parents_are_not_cycled( - ThemeInterface $firstTheme, - ThemeInterface $secondTheme, - ThemeInterface $thirdTheme, - ThemeInterface $fourthTheme - ): void { - $firstTheme->getParents()->willReturn([$secondTheme, $thirdTheme]); - $secondTheme->getParents()->willReturn([$thirdTheme, $fourthTheme]); - $thirdTheme->getParents()->willReturn([$fourthTheme]); - $fourthTheme->getParents()->willReturn([]); - - $this->check($firstTheme); - } - - function it_finds_circular_dependency_if_theme_parents_are_cycled( - ThemeInterface $firstTheme, - ThemeInterface $secondTheme, - ThemeInterface $thirdTheme, - ThemeInterface $fourthTheme - ): void { - $firstTheme->getParents()->willReturn([$secondTheme, $thirdTheme]); - $secondTheme->getParents()->willReturn([$thirdTheme]); - $thirdTheme->getParents()->willReturn([$fourthTheme]); - $fourthTheme->getParents()->willReturn([$secondTheme]); - - $firstTheme->getName()->willReturn('first/theme'); - $secondTheme->getName()->willReturn('second/theme'); - $thirdTheme->getName()->willReturn('third/theme'); - $fourthTheme->getName()->willReturn('fourth/theme'); - - $this - ->shouldThrow(CircularDependencyFoundException::class) - ->during('check', [$firstTheme]) - ; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Loader/CircularDependencyFoundExceptionSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Loader/CircularDependencyFoundExceptionSpec.php deleted file mode 100644 index b1708dcd4a..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Loader/CircularDependencyFoundExceptionSpec.php +++ /dev/null @@ -1,62 +0,0 @@ -beConstructedWith([]); - } - - function it_is_a_domain_exception(): void - { - $this->shouldHaveType(\DomainException::class); - } - - function it_is_a_logic_exception(): void - { - $this->shouldHaveType(\LogicException::class); - } - - function it_transforms_a_cycle_to_user_friendly_message( - ThemeInterface $firstTheme, - ThemeInterface $secondTheme, - ThemeInterface $thirdTheme, - ThemeInterface $fourthTheme - ): void { - $this->beConstructedWith([$firstTheme, $secondTheme, $thirdTheme, $fourthTheme, $thirdTheme]); - - $firstTheme->getName()->willReturn('first/theme'); - $secondTheme->getName()->willReturn('second/theme'); - $thirdTheme->getName()->willReturn('third/theme'); - $fourthTheme->getName()->willReturn('fourth/theme'); - - $this->getMessage()->shouldReturn('Circular dependency was found while resolving theme "first/theme", caused by cycle "third/theme -> fourth/theme -> third/theme".'); - } - - function it_throws_another_exception_if_there_is_no_cycle_in_given_elements( - ThemeInterface $firstTheme, - ThemeInterface $secondTheme, - ThemeInterface $thirdTheme, - ThemeInterface $fourthTheme - ): void { - $this->beConstructedWith([$firstTheme, $secondTheme, $thirdTheme, $fourthTheme]); - - $this->shouldThrow(new \InvalidArgumentException('There is no cycle within given themes.'))->duringInstantiation(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Loader/ThemeLoaderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Loader/ThemeLoaderSpec.php deleted file mode 100644 index f43803db7e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Loader/ThemeLoaderSpec.php +++ /dev/null @@ -1,284 +0,0 @@ -beConstructedWith( - $configurationProvider, - $themeFactory, - $themeAuthorFactory, - $themeScreenshotFactory, - $themeHydrator, - $circularDependencyChecker - ); - } - - function it_implements_theme_loader_interface(): void - { - $this->shouldImplement(ThemeLoaderInterface::class); - } - - function it_loads_a_single_theme( - ConfigurationProviderInterface $configurationProvider, - ThemeFactoryInterface $themeFactory, - HydrationInterface $themeHydrator, - CircularDependencyCheckerInterface $circularDependencyChecker, - ThemeInterface $theme - ): void { - $configurationProvider->getConfigurations()->willReturn([ - [ - 'name' => 'first/theme', - 'path' => '/theme/path', - 'parents' => [], - 'authors' => [], - 'screenshots' => [], - ], - ]); - - $themeFactory->create('first/theme', '/theme/path')->willReturn($theme); - - $themeHydrator->hydrate([ - 'name' => 'first/theme', - 'path' => '/theme/path', - 'parents' => [], - 'authors' => [], - 'screenshots' => [], - ], $theme)->willReturn($theme); - - $circularDependencyChecker->check($theme)->shouldBeCalled(); - - $this->load()->shouldReturn([$theme]); - } - - function it_loads_a_theme_with_author( - ConfigurationProviderInterface $configurationProvider, - ThemeFactoryInterface $themeFactory, - ThemeAuthorFactoryInterface $themeAuthorFactory, - HydrationInterface $themeHydrator, - CircularDependencyCheckerInterface $circularDependencyChecker, - ThemeInterface $theme - ): void { - $themeAuthor = new ThemeAuthor(); - - $configurationProvider->getConfigurations()->willReturn([ - [ - 'name' => 'first/theme', - 'path' => '/theme/path', - 'parents' => [], - 'authors' => [['name' => 'Richard Rynkowsky']], - 'screenshots' => [], - ], - ]); - - $themeFactory->create('first/theme', '/theme/path')->willReturn($theme); - $themeAuthorFactory->createFromArray(['name' => 'Richard Rynkowsky'])->willReturn($themeAuthor); - - $themeHydrator->hydrate([ - 'name' => 'first/theme', - 'path' => '/theme/path', - 'parents' => [], - 'authors' => [$themeAuthor], - 'screenshots' => [], - ], $theme)->willReturn($theme); - - $circularDependencyChecker->check($theme)->shouldBeCalled(); - - $this->load()->shouldReturn([$theme]); - } - - function it_loads_a_theme_with_screenshot( - ConfigurationProviderInterface $configurationProvider, - ThemeFactoryInterface $themeFactory, - ThemeScreenshotFactoryInterface $themeScreenshotFactory, - HydrationInterface $themeHydrator, - CircularDependencyCheckerInterface $circularDependencyChecker, - ThemeInterface $theme - ): void { - $themeScreenshot = new ThemeScreenshot('screenshot/omg.jpg'); - - $configurationProvider->getConfigurations()->willReturn([ - [ - 'name' => 'first/theme', - 'path' => '/theme/path', - 'parents' => [], - 'authors' => [], - 'screenshots' => [ - ['path' => 'screenshot/omg.jpg', 'title' => 'Title'], - ], - ], - ]); - - $themeFactory->create('first/theme', '/theme/path')->willReturn($theme); - $themeScreenshotFactory->createFromArray(['path' => 'screenshot/omg.jpg', 'title' => 'Title'])->willReturn($themeScreenshot); - - $themeHydrator->hydrate([ - 'name' => 'first/theme', - 'path' => '/theme/path', - 'parents' => [], - 'authors' => [], - 'screenshots' => [$themeScreenshot], - ], $theme)->willReturn($theme); - - $circularDependencyChecker->check($theme)->shouldBeCalled(); - - $this->load()->shouldReturn([$theme]); - } - - function it_loads_a_theme_with_its_dependency( - ConfigurationProviderInterface $configurationProvider, - ThemeFactoryInterface $themeFactory, - HydrationInterface $themeHydrator, - CircularDependencyCheckerInterface $circularDependencyChecker, - ThemeInterface $firstTheme, - ThemeInterface $secondTheme - ): void { - $configurationProvider->getConfigurations()->willReturn([ - [ - 'name' => 'first/theme', - 'path' => '/first/theme/path', - 'parents' => ['second/theme'], - 'authors' => [], - 'screenshots' => [], - ], - [ - 'name' => 'second/theme', - 'path' => '/second/theme/path', - 'parents' => [], - 'authors' => [], - 'screenshots' => [], - ], - ]); - - $themeFactory->create('first/theme', '/first/theme/path')->willReturn($firstTheme); - $themeFactory->create('second/theme', '/second/theme/path')->willReturn($secondTheme); - - $themeHydrator->hydrate([ - 'name' => 'first/theme', - 'path' => '/first/theme/path', - 'parents' => [$secondTheme], - 'authors' => [], - 'screenshots' => [], - ], $firstTheme)->willReturn($firstTheme); - $themeHydrator->hydrate([ - 'name' => 'second/theme', - 'path' => '/second/theme/path', - 'parents' => [], - 'authors' => [], - 'screenshots' => [], - ], $secondTheme)->willReturn($secondTheme); - - $circularDependencyChecker->check($firstTheme)->shouldBeCalled(); - $circularDependencyChecker->check($secondTheme)->shouldBeCalled(); - - $this->load()->shouldReturn([$firstTheme, $secondTheme]); - } - - function it_throws_an_exception_if_requires_not_existing_dependency( - ConfigurationProviderInterface $configurationProvider, - ThemeFactoryInterface $themeFactory, - ThemeInterface $firstTheme - ): void { - $configurationProvider->getConfigurations()->willReturn([ - [ - 'name' => 'first/theme', - 'path' => '/theme/path', - 'parents' => ['second/theme'], - 'authors' => [], - 'screenshots' => [], - ], - ]); - - $themeFactory->create('first/theme', '/theme/path')->willReturn($firstTheme); - - $this - ->shouldThrow(new ThemeLoadingFailedException('Unexisting theme "second/theme" is required by "first/theme".')) - ->during('load') - ; - } - - function it_throws_an_exception_if_there_is_a_circular_dependency_found( - ConfigurationProviderInterface $configurationProvider, - ThemeFactoryInterface $themeFactory, - HydrationInterface $themeHydrator, - CircularDependencyCheckerInterface $circularDependencyChecker, - ThemeInterface $firstTheme, - ThemeInterface $secondTheme - ): void { - $configurationProvider->getConfigurations()->willReturn([ - [ - 'name' => 'first/theme', - 'path' => '/first/theme/path', - 'parents' => ['second/theme'], - 'authors' => [], - 'screenshots' => [], - ], - [ - 'name' => 'second/theme', - 'path' => '/second/theme/path', - 'parents' => ['first/theme'], - 'authors' => [], - 'screenshots' => [], - ], - ]); - - $themeFactory->create('first/theme', '/first/theme/path')->willReturn($firstTheme); - $themeFactory->create('second/theme', '/second/theme/path')->willReturn($secondTheme); - - $themeHydrator->hydrate([ - 'name' => 'first/theme', - 'path' => '/first/theme/path', - 'parents' => [$secondTheme], - 'authors' => [], - 'screenshots' => [], - ], $firstTheme)->willReturn($firstTheme); - $themeHydrator->hydrate([ - 'name' => 'second/theme', - 'path' => '/second/theme/path', - 'parents' => [$firstTheme], - 'authors' => [], - 'screenshots' => [], - ], $secondTheme)->willReturn($secondTheme); - - $circularDependencyChecker->check(Argument::cetera())->willThrow(CircularDependencyFoundException::class); - - $this - ->shouldThrow(new ThemeLoadingFailedException('Circular dependency found.')) - ->during('load') - ; - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Loader/ThemeLoadingFailedExceptionSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Loader/ThemeLoadingFailedExceptionSpec.php deleted file mode 100644 index 128f7fc239..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Loader/ThemeLoadingFailedExceptionSpec.php +++ /dev/null @@ -1,29 +0,0 @@ -shouldHaveType(\DomainException::class); - } - - function it_is_a_logic_exception(): void - { - $this->shouldHaveType(\LogicException::class); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Locator/ApplicationResourceLocatorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Locator/ApplicationResourceLocatorSpec.php deleted file mode 100644 index 54e8329b91..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Locator/ApplicationResourceLocatorSpec.php +++ /dev/null @@ -1,52 +0,0 @@ -beConstructedWith($filesystem); - } - - function it_implements_resource_locator_interface(): void - { - $this->shouldImplement(ResourceLocatorInterface::class); - } - - function it_locates_application_resource(Filesystem $filesystem, ThemeInterface $theme): void - { - $theme->getPath()->willReturn('/theme/path'); - - $filesystem->exists('/theme/path/resource')->willReturn(true); - - $this->locateResource('resource', $theme)->shouldReturn('/theme/path/resource'); - } - - function it_throws_an_exception_if_resource_can_not_be_located(Filesystem $filesystem, ThemeInterface $theme): void - { - $theme->getName()->willReturn('theme/name'); - $theme->getPath()->willReturn('/theme/path'); - - $filesystem->exists('/theme/path/resource')->willReturn(false); - - $this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['resource', $theme]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Locator/BundleResourceLocatorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Locator/BundleResourceLocatorSpec.php deleted file mode 100644 index 5a622e47c2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Locator/BundleResourceLocatorSpec.php +++ /dev/null @@ -1,91 +0,0 @@ -beConstructedWith($filesystem, $kernel); - } - - function it_implements_resource_locator_interface(): void - { - $this->shouldImplement(ResourceLocatorInterface::class); - } - - function it_locates_bundle_resource( - Filesystem $filesystem, - KernelInterface $kernel, - ThemeInterface $theme, - BundleInterface $childBundle, - BundleInterface $parentBundle - ): void { - $kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]); - - $childBundle->getName()->willReturn('ChildBundle'); - $parentBundle->getName()->willReturn('ParentBundle'); - - $theme->getPath()->willReturn('/theme/path'); - - $filesystem->exists('/theme/path/ChildBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false); - $filesystem->exists('/theme/path/ParentBundle/views/index.html.twig')->shouldBeCalled()->willReturn(true); - - $this->locateResource('@ParentBundle/Resources/views/index.html.twig', $theme)->shouldReturn('/theme/path/ParentBundle/views/index.html.twig'); - } - - function it_throws_an_exception_if_resource_can_not_be_located( - Filesystem $filesystem, - KernelInterface $kernel, - ThemeInterface $theme, - BundleInterface $childBundle, - BundleInterface $parentBundle - ): void { - $kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]); - - $childBundle->getName()->willReturn('ChildBundle'); - $parentBundle->getName()->willReturn('ParentBundle'); - - $theme->getName()->willReturn('theme/name'); - $theme->getPath()->willReturn('/theme/path'); - - $filesystem->exists('/theme/path/ChildBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false); - $filesystem->exists('/theme/path/ParentBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false); - - $this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['@ParentBundle/Resources/views/index.html.twig', $theme]); - } - - function it_throws_an_exception_if_resource_path_does_not_start_with_an_asperand(ThemeInterface $theme): void - { - $this->shouldThrow(\InvalidArgumentException::class)->during('locateResource', ['ParentBundle/Resources/views/index.html.twig', $theme]); - } - - function it_throws_an_exception_if_resource_path_contains_two_dots_in_a_row(ThemeInterface $theme): void - { - $this->shouldThrow(\InvalidArgumentException::class)->during('locateResource', ['@ParentBundle/Resources/views/../views/index.html.twig', $theme]); - } - - function it_throws_an_exception_if_resource_path_does_not_contain_resources_dir(ThemeInterface $theme): void - { - $this->shouldThrow(\InvalidArgumentException::class)->during('locateResource', ['@ParentBundle/views/Resources.index.html.twig', $theme]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Locator/RecursiveFileLocatorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Locator/RecursiveFileLocatorSpec.php deleted file mode 100644 index 775ba527c6..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Locator/RecursiveFileLocatorSpec.php +++ /dev/null @@ -1,207 +0,0 @@ -beConstructedWith($finderFactory, ['/search/path/']); - } - - function it_implements_sylius_file_locator_interface(): void - { - $this->shouldImplement(FileLocatorInterface::class); - } - - function it_searches_for_file(FinderFactoryInterface $finderFactory, Finder $finder, SplFileInfo $splFileInfo): void - { - $finderFactory->create()->willReturn($finder); - - $finder->name('readme.md')->shouldBeCalled()->willReturn($finder); - $finder->in('/search/path/')->shouldBeCalled()->willReturn($finder); - $finder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($finder); - $finder->files()->shouldBeCalled()->willReturn($finder); - - $finder->getIterator()->willReturn(new \ArrayIterator([ - $splFileInfo->getWrappedObject(), - ])); - - $splFileInfo->getPathname()->willReturn('/search/path/nested/readme.md'); - - $this->locateFileNamed('readme.md')->shouldReturn('/search/path/nested/readme.md'); - } - - function it_searches_for_files( - FinderFactoryInterface $finderFactory, - Finder $finder, - SplFileInfo $firstSplFileInfo, - SplFileInfo $secondSplFileInfo - ): void { - $finderFactory->create()->willReturn($finder); - - $finder->name('readme.md')->shouldBeCalled()->willReturn($finder); - $finder->in('/search/path/')->shouldBeCalled()->willReturn($finder); - $finder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($finder); - $finder->files()->shouldBeCalled()->willReturn($finder); - - $finder->getIterator()->willReturn(new \ArrayIterator([ - $firstSplFileInfo->getWrappedObject(), - $secondSplFileInfo->getWrappedObject(), - ])); - - $firstSplFileInfo->getPathname()->willReturn('/search/path/nested1/readme.md'); - $secondSplFileInfo->getPathname()->willReturn('/search/path/nested2/readme.md'); - - $this->locateFilesNamed('readme.md')->shouldReturn([ - '/search/path/nested1/readme.md', - '/search/path/nested2/readme.md', - ]); - } - - function it_searches_for_files_at_a_maximum_depth( - FinderFactoryInterface $finderFactory, - Finder $finder, - SplFileInfo $firstSplFileInfo, - SplFileInfo $secondSplFileInfo - ): void { - $this->beConstructedWith($finderFactory, ['/search/path/'], 1); - $finderFactory->create()->willReturn($finder); - - $finder->depth('<= 1')->shouldBeCalled()->willReturn($finder); - $finder->name('readme.md')->shouldBeCalled()->willReturn($finder); - $finder->in('/search/path/')->shouldBeCalled()->willReturn($finder); - $finder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($finder); - $finder->files()->shouldBeCalled()->willReturn($finder); - - $finder->getIterator()->willReturn(new \ArrayIterator([ - $secondSplFileInfo->getWrappedObject(), - ])); - - $firstSplFileInfo->getPathname()->willReturn('/search/path/nested1/leveldeeper/readme.md'); - $secondSplFileInfo->getPathname()->willReturn('/search/path/nested2/readme.md'); - - $this->locateFilesNamed('readme.md')->shouldReturn([ - '/search/path/nested2/readme.md', - ]); - } - - function it_throws_an_exception_if_searching_for_file_with_empty_name(): void - { - $this->shouldThrow(\InvalidArgumentException::class)->during('locateFileNamed', ['']); - } - - function it_throws_an_exception_if_searching_for_files_with_empty_name(): void - { - $this->shouldThrow(\InvalidArgumentException::class)->during('locateFilesNamed', ['']); - } - - function it_throws_an_exception_if_there_is_no_file_that_matches_the_given_name( - FinderFactoryInterface $finderFactory, - Finder $finder - ): void { - $finderFactory->create()->willReturn($finder); - - $finder->name('readme.md')->shouldBeCalled()->willReturn($finder); - $finder->in('/search/path/')->shouldBeCalled()->willReturn($finder); - $finder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($finder); - $finder->files()->shouldBeCalled()->willReturn($finder); - - $finder->getIterator()->willReturn(new \ArrayIterator()); - - $this->shouldThrow(\InvalidArgumentException::class)->during('locateFileNamed', ['readme.md']); - } - - function it_throws_an_exception_if_there_is_there_are_not_any_files_that_matches_the_given_name( - FinderFactoryInterface $finderFactory, - Finder $finder - ): void { - $finderFactory->create()->willReturn($finder); - - $finder->name('readme.md')->shouldBeCalled()->willReturn($finder); - $finder->in('/search/path/')->shouldBeCalled()->willReturn($finder); - $finder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($finder); - $finder->files()->shouldBeCalled()->willReturn($finder); - - $finder->getIterator()->willReturn(new \ArrayIterator()); - - $this->shouldThrow(\InvalidArgumentException::class)->during('locateFilesNamed', ['readme.md']); - } - - function it_isolates_finding_paths_from_multiple_sources( - FinderFactoryInterface $finderFactory, - Finder $firstFinder, - Finder $secondFinder, - SplFileInfo $splFileInfo - ): void { - $this->beConstructedWith($finderFactory, ['/search/path/first/', '/search/path/second/']); - - $finderFactory->create()->willReturn($firstFinder, $secondFinder); - - $firstFinder->name('readme.md')->shouldBeCalled()->willReturn($firstFinder); - $firstFinder->in('/search/path/first/')->shouldBeCalled()->willReturn($firstFinder); - $firstFinder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($firstFinder); - $firstFinder->files()->shouldBeCalled()->willReturn($firstFinder); - - $secondFinder->name('readme.md')->shouldBeCalled()->willReturn($secondFinder); - $secondFinder->in('/search/path/second/')->shouldBeCalled()->willReturn($secondFinder); - $secondFinder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($secondFinder); - $secondFinder->files()->shouldBeCalled()->willReturn($secondFinder); - - $firstFinder->getIterator()->willReturn(new \ArrayIterator([$splFileInfo->getWrappedObject()])); - $secondFinder->getIterator()->willReturn(new \ArrayIterator()); - - $splFileInfo->getPathname()->willReturn('/search/path/first/nested/readme.md'); - - $this->locateFilesNamed('readme.md')->shouldReturn([ - '/search/path/first/nested/readme.md', - ]); - } - - function it_silences_finder_exceptions_even_if_searching_in_multiple_sources( - FinderFactoryInterface $finderFactory, - Finder $firstFinder, - Finder $secondFinder, - SplFileInfo $splFileInfo - ): void { - $this->beConstructedWith($finderFactory, ['/search/path/first/', '/search/path/second/']); - - $finderFactory->create()->willReturn($firstFinder, $secondFinder); - - $firstFinder->name('readme.md')->shouldBeCalled()->willReturn($firstFinder); - $firstFinder->in('/search/path/first/')->shouldBeCalled()->willReturn($firstFinder); - $firstFinder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($firstFinder); - $firstFinder->files()->shouldBeCalled()->willReturn($firstFinder); - - $secondFinder->name('readme.md')->shouldBeCalled()->willReturn($secondFinder); - $secondFinder->in('/search/path/second/')->shouldBeCalled()->willReturn($secondFinder); - $secondFinder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($secondFinder); - $secondFinder->files()->shouldBeCalled()->willReturn($secondFinder); - - $firstFinder->getIterator()->willReturn(new \ArrayIterator([$splFileInfo->getWrappedObject()])); - $secondFinder->getIterator()->willThrow(\InvalidArgumentException::class); - - $splFileInfo->getPathname()->willReturn('/search/path/first/nested/readme.md'); - - $this->locateFilesNamed('readme.md')->shouldReturn([ - '/search/path/first/nested/readme.md', - ]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Locator/ResourceLocatorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Locator/ResourceLocatorSpec.php deleted file mode 100644 index bfd06bfa23..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Locator/ResourceLocatorSpec.php +++ /dev/null @@ -1,58 +0,0 @@ -beConstructedWith($applicationResourceLocator, $bundleResourceLocator); - } - - function it_implements_resource_locator_interface(): void - { - $this->shouldImplement(ResourceLocatorInterface::class); - } - - function it_proxies_locating_resource_to_bundle_resource_locator_if_resource_path_starts_with_an_asperand( - ResourceLocatorInterface $applicationResourceLocator, - ResourceLocatorInterface $bundleResourceLocator, - ThemeInterface $theme - ): void { - $applicationResourceLocator->locateResource(Argument::cetera())->shouldNotBeCalled(); - - $bundleResourceLocator->locateResource('@AcmeBundle/Resources/resource', $theme)->shouldBeCalled(); - - $this->locateResource('@AcmeBundle/Resources/resource', $theme); - } - - function it_proxies_locating_resource_to_application_resource_locator_if_resource_path_does_not_start_with_an_asperand( - ResourceLocatorInterface $applicationResourceLocator, - ResourceLocatorInterface $bundleResourceLocator, - ThemeInterface $theme - ): void { - $bundleResourceLocator->locateResource(Argument::cetera())->shouldNotBeCalled(); - - $applicationResourceLocator->locateResource('AcmeBundle/resource', $theme)->shouldBeCalled(); - - $this->locateResource('AcmeBundle/resource', $theme); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Locator/ResourceNotFoundExceptionSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Locator/ResourceNotFoundExceptionSpec.php deleted file mode 100644 index 3b12729677..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Locator/ResourceNotFoundExceptionSpec.php +++ /dev/null @@ -1,37 +0,0 @@ -getName()->willReturn('theme/name'); - - $this->beConstructedWith('resource name', $theme); - } - - function it_is_a_runtime_exception(): void - { - $this->shouldHaveType(\RuntimeException::class); - } - - function it_has_custom_message(): void - { - $this->getMessage()->shouldReturn('Could not find resource "resource name" using theme "theme/name".'); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeAuthorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeAuthorSpec.php deleted file mode 100644 index 115a367f04..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeAuthorSpec.php +++ /dev/null @@ -1,57 +0,0 @@ -shouldImplement(ThemeAuthor::class); - } - - function it_has_name(): void - { - $this->getName()->shouldReturn(null); - - $this->setName('Krzysztof Krawczyk'); - $this->getName()->shouldReturn('Krzysztof Krawczyk'); - } - - function it_has_email(): void - { - $this->getEmail()->shouldReturn(null); - - $this->setEmail('cristopher@example.com'); - $this->getEmail()->shouldReturn('cristopher@example.com'); - } - - function it_has_homepage(): void - { - $this->getHomepage()->shouldReturn(null); - - $this->setHomepage('http://example.com'); - $this->getHomepage()->shouldReturn('http://example.com'); - } - - function it_has_role(): void - { - $this->getRole()->shouldReturn(null); - - $this->setRole('Developer'); - $this->getRole()->shouldReturn('Developer'); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeScreenshotSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeScreenshotSpec.php deleted file mode 100644 index 1e4aabeac2..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeScreenshotSpec.php +++ /dev/null @@ -1,47 +0,0 @@ -beConstructedWith('/screenshot/path.jpg'); - } - - function it_has_path(): void - { - $this->beConstructedWith('/my/screenshot.jpg'); - - $this->getPath()->shouldReturn('/my/screenshot.jpg'); - } - - function it_has_title(): void - { - $this->getTitle()->shouldReturn(null); - - $this->setTitle('Candy shop'); - $this->getTitle()->shouldReturn('Candy shop'); - } - - function it_has_description(): void - { - $this->getDescription()->shouldReturn(null); - - $this->setDescription('I\'ll take you to the candy shop'); - $this->getDescription()->shouldReturn('I\'ll take you to the candy shop'); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeSpec.php deleted file mode 100644 index 8b8413cc8f..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Model/ThemeSpec.php +++ /dev/null @@ -1,116 +0,0 @@ -beConstructedWith('theme/name', '/theme/path'); - } - - function it_implements_theme_interface(): void - { - $this->shouldImplement(ThemeInterface::class); - } - - function its_name_cannot_have_underscores(): void - { - $this->beConstructedWith('first_theme/name', '/theme/path'); - - $this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation(); - } - - function it_has_immutable_name(): void - { - $this->getName()->shouldReturn('theme/name'); - } - - function its_name_might_contain_numbers(): void - { - $this->beConstructedWith('1e/e7', '/theme/path'); - - $this->getName()->shouldReturn('1e/e7'); - } - - function its_name_might_contain_uppercase_characters(): void - { - $this->beConstructedWith('AbC/DeF', '/theme/path'); - - $this->getName()->shouldReturn('AbC/DeF'); - } - - function it_has_immutable_path(): void - { - $this->getPath()->shouldReturn('/theme/path'); - } - - function it_has_title(): void - { - $this->getTitle()->shouldReturn(null); - - $this->setTitle('Foo Bar'); - $this->getTitle()->shouldReturn('Foo Bar'); - } - - function it_has_description(): void - { - $this->getDescription()->shouldReturn(null); - - $this->setDescription('Lorem ipsum.'); - $this->getDescription()->shouldReturn('Lorem ipsum.'); - } - - function it_has_authors(): void - { - $themeAuthor = new ThemeAuthor(); - - $this->getAuthors()->shouldHaveCount(0); - - $this->addAuthor($themeAuthor); - $this->getAuthors()->shouldHaveCount(1); - - $this->removeAuthor($themeAuthor); - $this->getAuthors()->shouldHaveCount(0); - } - - function it_has_parents(ThemeInterface $theme): void - { - $this->getParents()->shouldHaveCount(0); - - $this->addParent($theme); - $this->getParents()->shouldHaveCount(1); - - $this->removeParent($theme); - $this->getParents()->shouldHaveCount(0); - } - - function it_has_screenshots(): void - { - $themeScreenshot = new ThemeScreenshot('some path'); - - $this->getScreenshots()->shouldHaveCount(0); - - $this->addScreenshot($themeScreenshot); - $this->getScreenshots()->shouldHaveCount(1); - - $this->removeScreenshot($themeScreenshot); - $this->getScreenshots()->shouldHaveCount(0); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Cache/Clearer/TemplatePathsCacheClearerSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Templating/Cache/Clearer/TemplatePathsCacheClearerSpec.php deleted file mode 100644 index 3ea3f259e6..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Cache/Clearer/TemplatePathsCacheClearerSpec.php +++ /dev/null @@ -1,44 +0,0 @@ -beConstructedWith($cache); - } - - function it_implements_cache_clearer_interface(): void - { - $this->shouldImplement(CacheClearerInterface::class); - } - - function it_deletes_all_elements_if_cache_is_clearable(ClearableCache $cache): void - { - $cache->deleteAll()->shouldBeCalled(); - - $this->clear(null); - } - - function it_does_not_throw_any_error_if_cache_is_not_clearable(): void - { - $this->clear(null); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Cache/Warmer/TemplatePathsCacheWarmerSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Templating/Cache/Warmer/TemplatePathsCacheWarmerSpec.php deleted file mode 100644 index a8719a76c8..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Cache/Warmer/TemplatePathsCacheWarmerSpec.php +++ /dev/null @@ -1,67 +0,0 @@ -beConstructedWith($templateFinder, $templateLocator, $themeRepository, $cache); - } - - function it_implements_cache_warmer_interface(): void - { - $this->shouldImplement(CacheWarmerInterface::class); - } - - function it_builds_cache_by_warming_up_every_template_and_every_theme_together( - TemplateFinderInterface $templateFinder, - TemplateLocatorInterface $templateLocator, - ThemeRepositoryInterface $themeRepository, - Cache $cache, - ThemeInterface $theme, - TemplateReferenceInterface $firstTemplate, - TemplateReferenceInterface $secondTemplate - ): void { - $templateFinder->findAllTemplates()->willReturn([$firstTemplate, $secondTemplate]); - - $themeRepository->findAll()->willReturn([$theme]); - - $theme->getName()->willReturn('theme/name'); - $firstTemplate->getLogicalName()->willReturn('Logical:Name:First'); - $secondTemplate->getLogicalName()->willReturn('Logical:Name:Second'); - - $templateLocator->locateTemplate($firstTemplate, $theme)->willReturn('/First/Theme/index.html.twig'); - $templateLocator->locateTemplate($secondTemplate, $theme)->willThrow(ResourceNotFoundException::class); - - $cache->save('Logical:Name:First|theme/name', '/First/Theme/index.html.twig')->shouldBeCalled(); - $cache->save('Logical:Name:Second|theme/name', null)->shouldBeCalled(); - - $this->warmUp(null); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/CachedTemplateLocatorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/CachedTemplateLocatorSpec.php deleted file mode 100644 index bb849bf353..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/CachedTemplateLocatorSpec.php +++ /dev/null @@ -1,87 +0,0 @@ -beConstructedWith($decoratedTemplateLocator, $cache); - } - - function it_implements_template_locator_interface(): void - { - $this->shouldImplement(TemplateLocatorInterface::class); - } - - function it_returns_the_location_found_in_cache( - TemplateLocatorInterface $decoratedTemplateLocator, - Cache $cache, - TemplateReferenceInterface $template, - ThemeInterface $theme - ): void { - $template->getLogicalName()->willReturn('Logical:Name'); - $theme->getName()->willReturn('theme/name'); - - $cache->contains('Logical:Name|theme/name')->willReturn(true); - $cache->fetch('Logical:Name|theme/name')->willReturn('/template.html.twig'); - - $decoratedTemplateLocator->locateTemplate(Argument::cetera())->shouldNotBeCalled(); - - $this->locateTemplate($template, $theme)->shouldReturn('/template.html.twig'); - } - - function it_uses_decorated_template_locator_if_location_can_not_be_found_in_cache( - TemplateLocatorInterface $decoratedTemplateLocator, - Cache $cache, - TemplateReferenceInterface $template, - ThemeInterface $theme - ): void { - $template->getLogicalName()->willReturn('Logical:Name'); - $theme->getName()->willReturn('theme/name'); - - $cache->contains('Logical:Name|theme/name')->willReturn(false); - $cache->fetch(Argument::cetera())->shouldNotBeCalled(); - - $decoratedTemplateLocator->locateTemplate($template, $theme)->willReturn('/template.html.twig'); - - $this->locateTemplate($template, $theme)->shouldReturn('/template.html.twig'); - } - - function it_throws_resource_not_found_exception_if_the_location_found_in_cache_is_null( - TemplateLocatorInterface $decoratedTemplateLocator, - Cache $cache, - TemplateReferenceInterface $template, - ThemeInterface $theme - ): void { - $template->getLogicalName()->willReturn('Logical:Name'); - $template->getPath()->willReturn('@Acme/template.html.twig'); - $theme->getName()->willReturn('theme/name'); - - $cache->contains('Logical:Name|theme/name')->willReturn(true); - $cache->fetch('Logical:Name|theme/name')->willReturn(null); - - $decoratedTemplateLocator->locateTemplate(Argument::cetera())->shouldNotBeCalled(); - - $this->shouldThrow(ResourceNotFoundException::class)->during('locateTemplate', [$template, $theme]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/TemplateFileLocatorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/TemplateFileLocatorSpec.php deleted file mode 100644 index b7d64f346e..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/TemplateFileLocatorSpec.php +++ /dev/null @@ -1,95 +0,0 @@ -beConstructedWith($decoratedFileLocator, $themeContext, $themeHierarchyProvider, $templateLocator); - } - - function it_implements_file_locator_interface(): void - { - $this->shouldImplement(FileLocatorInterface::class); - } - - function it_throws_an_exception_if_located_thing_is_not_an_instance_of_template_reference_interface(): void - { - $this->shouldThrow(\InvalidArgumentException::class)->during('locate', ['not an instance']); - } - - function it_returns_first_possible_theme_resource( - ThemeContextInterface $themeContext, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - TemplateLocatorInterface $templateLocator, - TemplateReferenceInterface $template, - ThemeInterface $firstTheme, - ThemeInterface $secondTheme - ): void { - $themeContext->getTheme()->willReturn($firstTheme); - $themeHierarchyProvider->getThemeHierarchy($firstTheme)->willReturn([$firstTheme, $secondTheme]); - - $templateLocator->locateTemplate($template, $firstTheme)->willThrow(ResourceNotFoundException::class); - $templateLocator->locateTemplate($template, $secondTheme)->willReturn('/second/theme/template/path'); - - $this->locate($template)->shouldReturn('/second/theme/template/path'); - } - - function it_falls_back_to_decorated_template_locator_if_themed_tempaltes_can_not_be_found( - FileLocatorInterface $decoratedFileLocator, - ThemeContextInterface $themeContext, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - TemplateLocatorInterface $templateLocator, - TemplateReferenceInterface $template, - ThemeInterface $theme - ): void { - $themeContext->getTheme()->willReturn($theme); - $themeHierarchyProvider->getThemeHierarchy($theme)->willReturn([$theme]); - - $templateLocator->locateTemplate($template, $theme)->willThrow(ResourceNotFoundException::class); - - $decoratedFileLocator->locate($template, Argument::cetera())->willReturn('/app/template/path'); - - $this->locate($template)->shouldReturn('/app/template/path'); - } - - function it_falls_back_to_decorated_template_locator_if_there_are_no_themes_active( - FileLocatorInterface $decoratedFileLocator, - ThemeContextInterface $themeContext, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - TemplateReferenceInterface $template - ): void { - $themeContext->getTheme()->willReturn(null); - $themeHierarchyProvider->getThemeHierarchy(null)->willReturn([]); - - $decoratedFileLocator->locate($template, Argument::cetera())->willReturn('/app/template/path'); - - $this->locate($template)->shouldReturn('/app/template/path'); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/TemplateLocatorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/TemplateLocatorSpec.php deleted file mode 100644 index 6b37007716..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Templating/Locator/TemplateLocatorSpec.php +++ /dev/null @@ -1,58 +0,0 @@ -beConstructedWith($resourceLocator); - } - - function it_implements_template_locator_interface(): void - { - $this->shouldImplement(TemplateLocatorInterface::class); - } - - function it_proxies_locating_template_to_resource_locator( - ResourceLocatorInterface $resourceLocator, - TemplateReferenceInterface $template, - ThemeInterface $theme - ): void { - $template->getPath()->willReturn('@AcmeBundle/Resources/views/index.html.twig'); - - $resourceLocator->locateResource('@AcmeBundle/Resources/views/index.html.twig', $theme)->willReturn('/acme/index.html.twig'); - - $this->locateTemplate($template, $theme)->shouldReturn('/acme/index.html.twig'); - } - - function it_does_not_catch_exceptions_thrown_while_locating_template_to_resource_locator_even( - ResourceLocatorInterface $resourceLocator, - TemplateReferenceInterface $template, - ThemeInterface $theme - ): void { - $template->getPath()->willReturn('@AcmeBundle/Resources/views/index.html.twig'); - - $resourceLocator->locateResource('@AcmeBundle/Resources/views/index.html.twig', $theme)->willThrow(ResourceNotFoundException::class); - - $this->shouldThrow(ResourceNotFoundException::class)->during('locateTemplate', [$template, $theme]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Templating/TemplateNameParserSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Templating/TemplateNameParserSpec.php deleted file mode 100644 index 556deac386..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Templating/TemplateNameParserSpec.php +++ /dev/null @@ -1,87 +0,0 @@ -beConstructedWith($decoratedParser, $kernel); - } - - function it_is_a_template_name_parser(): void - { - $this->shouldImplement(TemplateNameParserInterface::class); - } - - function it_returns_template_reference_if_passed_as_name(TemplateReferenceInterface $templateReference): void - { - $this->parse($templateReference)->shouldReturn($templateReference); - } - - function it_delegates_logical_paths_to_decorated_parser( - TemplateNameParserInterface $decoratedParser, - TemplateReferenceInterface $templateReference - ): void { - $decoratedParser->parse('Bundle:Not:namespaced.html.twig')->willReturn($templateReference); - - $this->parse('Bundle:Not:namespaced.html.twig')->shouldReturn($templateReference); - } - - function it_delegates_unknown_paths_to_decorated_parser( - TemplateNameParserInterface $decoratedParser, - TemplateReferenceInterface $templateReference - ): void { - $decoratedParser->parse('Bundle/Not/namespaced.html.twig')->willReturn($templateReference); - - $this->parse('Bundle/Not/namespaced.html.twig')->shouldReturn($templateReference); - } - - function it_generates_template_references_from_namespaced_paths(KernelInterface $kernel): void - { - $kernel->getBundle('AcmeBundle')->willReturn(null); // just do not throw an exception - - $this->parse('@Acme/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', '', 'app', 'html', 'twig')); - $this->parse('@Acme/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Directory', 'app', 'html', 'twig')); - $this->parse('@Acme/Directory.WithDot/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Directory.WithDot', 'app', 'html', 'twig')); - $this->parse('@Acme/Directory/app.with.dots.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Directory', 'app.with.dots', 'html', 'twig')); - $this->parse('@Acme/Nested/Directory/app.html.twig')->shouldBeLike(new TemplateReference('AcmeBundle', 'Nested/Directory', 'app', 'html', 'twig')); - } - - function it_delegates_custom_namespace_to_decorated_parser( - KernelInterface $kernel, - TemplateNameParserInterface $decoratedParser, - TemplateReferenceInterface $templateReference - ): void { - $kernel->getBundle('myBundle')->willThrow(\Exception::class); - - $decoratedParser->parse('@my/custom/namespace.html.twig')->willReturn($templateReference); - - $this->parse('@my/custom/namespace.html.twig')->shouldReturn($templateReference); - } - - function it_generates_template_references_from_root_namespaced_paths(): void - { - $this->parse('/app.html.twig')->shouldBeLike(new TemplateReference('', '', 'app', 'html', 'twig')); - $this->parse('/Directory/app.html.twig')->shouldBeLike(new TemplateReference('', 'Directory', 'app', 'html', 'twig')); - $this->parse('/Nested/Directory/app.html.twig')->shouldBeLike(new TemplateReference('', 'Nested/Directory', 'app', 'html', 'twig')); - $this->parse('/Directory.WithDot/app.html.twig')->shouldBeLike(new TemplateReference('', 'Directory.WithDot', 'app', 'html', 'twig')); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Finder/OrderingTranslationFilesFinderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/Finder/OrderingTranslationFilesFinderSpec.php deleted file mode 100644 index a7f877ce48..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Finder/OrderingTranslationFilesFinderSpec.php +++ /dev/null @@ -1,42 +0,0 @@ -beConstructedWith($translationFilesFinder); - } - - function it_implements_Translation_Files_Finder_interface(): void - { - $this->shouldImplement(TranslationFilesFinderInterface::class); - } - - function it_puts_application_translations_files_before_bundle_translations_files( - TranslationFilesFinderInterface $translationFilesFinder - ): void { - $translationFilesFinder->findTranslationFiles('/some/path/to/theme')->willReturn([ - '/some/path/to/theme/AcmeBundle/messages.en.yml', - '/some/path/to/theme/translations/messages.en.yml', - '/some/path/to/theme/YcmeBundle/messages.en.yml', - ]); - - $this->findTranslationFiles('/some/path/to/theme')->shouldStartIteratingAs(['/some/path/to/theme/translations/messages.en.yml']); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Finder/TranslationFilesFinderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/Finder/TranslationFilesFinderSpec.php deleted file mode 100644 index 85a1856028..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Finder/TranslationFilesFinderSpec.php +++ /dev/null @@ -1,55 +0,0 @@ -beConstructedWith($finderFactory); - } - - function it_implements_translation_resource_finder_interface(): void - { - $this->shouldImplement(TranslationFilesFinderInterface::class); - } - - function it_returns_an_array_of_translation_resources_paths( - FinderFactoryInterface $finderFactory, - Finder $finder - ): void { - $finderFactory->create()->willReturn($finder); - - $finder->in('/theme')->shouldBeCalled()->willReturn($finder); - $finder->ignoreUnreadableDirs()->shouldBeCalled()->willReturn($finder); - - $finder->getIterator()->willReturn(new \ArrayIterator([ - '/theme/messages.en.yml', - '/theme/translations/messages.en.yml', - '/theme/translations/messages.en.yml.jpg', - '/theme/translations/messages.yml', - '/theme/AcmeBundle/translations/messages.pl_PL.yml', - ])); - - $this->findTranslationFiles('/theme')->shouldReturn([ - '/theme/translations/messages.en.yml', - '/theme/AcmeBundle/translations/messages.pl_PL.yml', - ]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Loader/TranslatorLoaderProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Loader/TranslatorLoaderProviderSpec.php deleted file mode 100644 index 3ab52f4822..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Loader/TranslatorLoaderProviderSpec.php +++ /dev/null @@ -1,35 +0,0 @@ -shouldImplement(TranslatorLoaderProviderInterface::class); - } - - function it_returns_previously_received_loaders( - LoaderInterface $firstLoader, - LoaderInterface $secondLoader - ): void { - $this->beConstructedWith(['first' => $firstLoader, 'second' => $secondLoader]); - - $this->getLoaders()->shouldReturn(['first' => $firstLoader, 'second' => $secondLoader]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/CompositeTranslatorResourceProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/CompositeTranslatorResourceProviderSpec.php deleted file mode 100644 index 192178752f..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/CompositeTranslatorResourceProviderSpec.php +++ /dev/null @@ -1,64 +0,0 @@ -shouldImplement(TranslatorResourceProviderInterface::class); - } - - function it_aggregates_the_resources( - TranslatorResourceProviderInterface $firstResourceProvider, - TranslatorResourceProviderInterface $secondResourceProvider, - TranslationResourceInterface $firstResource, - TranslationResourceInterface $secondResource - ): void { - $this->beConstructedWith([$firstResourceProvider, $secondResourceProvider]); - - $firstResourceProvider->getResources()->willReturn([$firstResource]); - $secondResourceProvider->getResources()->willReturn([$secondResource, $firstResource]); - - $this->getResources()->shouldReturn([$firstResource, $secondResource, $firstResource]); - } - - function it_aggregates_the_resources_locales( - TranslatorResourceProviderInterface $firstResourceProvider, - TranslatorResourceProviderInterface $secondResourceProvider - ): void { - $this->beConstructedWith([$firstResourceProvider, $secondResourceProvider]); - - $firstResourceProvider->getResourcesLocales()->willReturn(['first-locale']); - $secondResourceProvider->getResourcesLocales()->willReturn(['second-locale']); - - $this->getResourcesLocales()->shouldReturn(['first-locale', 'second-locale']); - } - - function it_aggregates_the_unique_resources_locales( - TranslatorResourceProviderInterface $firstResourceProvider, - TranslatorResourceProviderInterface $secondResourceProvider - ): void { - $this->beConstructedWith([$firstResourceProvider, $secondResourceProvider]); - - $firstResourceProvider->getResourcesLocales()->willReturn(['first-locale']); - $secondResourceProvider->getResourcesLocales()->willReturn(['second-locale', 'first-locale', 'second-locale']); - - $this->getResourcesLocales()->shouldReturn(['first-locale', 'second-locale']); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/ThemeTranslatorResourceProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/ThemeTranslatorResourceProviderSpec.php deleted file mode 100644 index ecebc36709..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/ThemeTranslatorResourceProviderSpec.php +++ /dev/null @@ -1,171 +0,0 @@ -beConstructedWith($translationFilesFinder, $themeRepository, $themeHierarchyProvider); - } - - function it_implements_translator_resource_provider_interface(): void - { - $this->shouldImplement(TranslatorResourceProviderInterface::class); - } - - function it_returns_translation_files_found_in_given_paths( - TranslationFilesFinderInterface $translationFilesFinder, - ThemeRepositoryInterface $themeRepository, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - ThemeInterface $theme - ): void { - $themeRepository->findAll()->willReturn([$theme]); - $themeHierarchyProvider->getThemeHierarchy($theme)->willReturn([$theme]); - - $theme->getPath()->willReturn('/theme/path'); - $theme->getName()->willReturn('theme/name'); - - $translationFilesFinder->findTranslationFiles('/theme/path')->willReturn(['/theme/path/messages.en.yml']); - - $this->getResources()->shouldBeLike([ - new ThemeTranslationResource($theme->getWrappedObject(), '/theme/path/messages.en.yml'), - ]); - } - - function it_returns_inherited_themes_as_the_main_theme_resources( - TranslationFilesFinderInterface $translationFilesFinder, - ThemeRepositoryInterface $themeRepository, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - ThemeInterface $mainTheme, - ThemeInterface $parentTheme - ): void { - $themeRepository->findAll()->willReturn([$mainTheme]); - $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]); - - $mainTheme->getPath()->willReturn('/main/theme/path'); - $mainTheme->getName()->willReturn('main-theme/name'); - - $parentTheme->getPath()->willReturn('/parent/theme/path'); - $parentTheme->getName()->willReturn('parent-theme/name'); - - $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']); - $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']); - - $this->getResources()->shouldBeLike([ - new ThemeTranslationResource($mainTheme->getWrappedObject(), '/parent/theme/path/messages.en.yml'), - new ThemeTranslationResource($mainTheme->getWrappedObject(), '/main/theme/path/messages.en.yml'), - ]); - } - - function it_doubles_resources_if_used_in_more_than_one_theme( - TranslationFilesFinderInterface $translationFilesFinder, - ThemeRepositoryInterface $themeRepository, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - ThemeInterface $mainTheme, - ThemeInterface $parentTheme - ): void { - $themeRepository->findAll()->willReturn([$mainTheme, $parentTheme]); - $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]); - $themeHierarchyProvider->getThemeHierarchy($parentTheme)->willReturn([$parentTheme]); - - $mainTheme->getPath()->willReturn('/main/theme/path'); - $mainTheme->getName()->willReturn('main-theme/name'); - - $parentTheme->getPath()->willReturn('/parent/theme/path'); - $parentTheme->getName()->willReturn('parent-theme/name'); - - $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']); - $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']); - - $this->getResources()->shouldBeLike([ - new ThemeTranslationResource($mainTheme->getWrappedObject(), '/parent/theme/path/messages.en.yml'), - new ThemeTranslationResource($mainTheme->getWrappedObject(), '/main/theme/path/messages.en.yml'), - new ThemeTranslationResource($parentTheme->getWrappedObject(), '/parent/theme/path/messages.en.yml'), - ]); - } - - function it_returns_resources_locales_while_using_just_one_theme( - TranslationFilesFinderInterface $translationFilesFinder, - ThemeRepositoryInterface $themeRepository, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - ThemeInterface $theme - ): void { - $themeRepository->findAll()->willReturn([$theme]); - $themeHierarchyProvider->getThemeHierarchy($theme)->willReturn([$theme]); - - $theme->getPath()->willReturn('/theme/path'); - $theme->getName()->willReturn('theme/name'); - - $translationFilesFinder->findTranslationFiles('/theme/path')->willReturn(['/theme/path/messages.en.yml']); - - $this->getResourcesLocales()->shouldReturn(['en@theme-name']); - } - - function it_returns_resources_locales_while_using_one_nested_theme( - TranslationFilesFinderInterface $translationFilesFinder, - ThemeRepositoryInterface $themeRepository, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - ThemeInterface $mainTheme, - ThemeInterface $parentTheme - ): void { - $themeRepository->findAll()->willReturn([$mainTheme]); - $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]); - - $mainTheme->getPath()->willReturn('/main/theme/path'); - $mainTheme->getName()->willReturn('main-theme/name'); - - $parentTheme->getPath()->willReturn('/parent/theme/path'); - $parentTheme->getName()->willReturn('parent-theme/name'); - - $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']); - $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']); - - $this->getResourcesLocales()->shouldReturn(['en@main-theme-name']); - } - - function it_returns_resources_locales_while_using_more_than_one_theme( - TranslationFilesFinderInterface $translationFilesFinder, - ThemeRepositoryInterface $themeRepository, - ThemeHierarchyProviderInterface $themeHierarchyProvider, - ThemeInterface $mainTheme, - ThemeInterface $parentTheme - ): void { - $themeRepository->findAll()->willReturn([$mainTheme, $parentTheme]); - $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]); - $themeHierarchyProvider->getThemeHierarchy($parentTheme)->willReturn([$parentTheme]); - - $mainTheme->getPath()->willReturn('/main/theme/path'); - $mainTheme->getName()->willReturn('main-theme/name'); - - $parentTheme->getPath()->willReturn('/parent/theme/path'); - $parentTheme->getName()->willReturn('parent-theme/name'); - - $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']); - $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']); - - $this->getResourcesLocales()->shouldReturn(['en@main-theme-name', 'en@parent-theme-name']); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/TranslatorResourceProviderSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/TranslatorResourceProviderSpec.php deleted file mode 100644 index 18d28edc49..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Provider/Resource/TranslatorResourceProviderSpec.php +++ /dev/null @@ -1,53 +0,0 @@ -shouldImplement(TranslatorResourceProviderInterface::class); - } - - function it_transforms_previously_received_paths_into_translation_resources(): void - { - $this->beConstructedWith([ - 'messages.en.yml', - 'domain.en.yml', - ]); - - $this->getResources()->shouldBeLike([ - new TranslationResource('messages.en.yml'), - new TranslationResource('domain.en.yml'), - ]); - } - - function it_extracts_unique_locales_from_received_paths(): void - { - $this->beConstructedWith([ - 'messages.en.yml', - 'domain.en_US.yml', - 'validation.en.yml', - ]); - - $this->getResourcesLocales()->shouldReturn([ - 'en', - 'en_US', - ]); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Resource/ThemeTranslationResourceSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/Resource/ThemeTranslationResourceSpec.php deleted file mode 100644 index d898557fd0..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Resource/ThemeTranslationResourceSpec.php +++ /dev/null @@ -1,50 +0,0 @@ -getName()->willReturn('theme/name'); - - $this->beConstructedWith($theme, 'my-domain.my-locale.my-format'); - } - - function it_implements_translation_resource_interface(): void - { - $this->shouldImplement(TranslationResourceInterface::class); - } - - function it_is_a_translation_resource_value_object(): void - { - $this->getName()->shouldReturn('my-domain.my-locale.my-format'); - $this->getDomain()->shouldReturn('my-domain'); - $this->getLocale()->shouldReturn('my-locale@theme-name'); - $this->getFormat()->shouldReturn('my-format'); - } - - function it_throws_an_invalid_argument_exception_if_failed_to_instantiate_with_given_filepath(ThemeInterface $theme): void - { - $theme->getName()->willReturn('theme/name'); - - $this->beConstructedWith($theme, 'one.dot'); - - $this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Resource/TranslationResourceSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/Resource/TranslationResourceSpec.php deleted file mode 100644 index b347c5c258..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/Resource/TranslationResourceSpec.php +++ /dev/null @@ -1,45 +0,0 @@ -beConstructedWith('my-domain.my-locale.my-format'); - } - - function it_implements_translation_resource_interface(): void - { - $this->shouldImplement(TranslationResourceInterface::class); - } - - function it_is_a_translation_resource_value_object(): void - { - $this->getName()->shouldReturn('my-domain.my-locale.my-format'); - $this->getDomain()->shouldReturn('my-domain'); - $this->getLocale()->shouldReturn('my-locale'); - $this->getFormat()->shouldReturn('my-format'); - } - - function it_throws_an_invalid_argument_exception_if_failed_to_instantiate_with_given_filepath(): void - { - $this->beConstructedWith('one.dot'); - - $this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation(); - } -} diff --git a/src/Sylius/Bundle/ThemeBundle/spec/Translation/ThemeAwareTranslatorSpec.php b/src/Sylius/Bundle/ThemeBundle/spec/Translation/ThemeAwareTranslatorSpec.php deleted file mode 100644 index 3119f98303..0000000000 --- a/src/Sylius/Bundle/ThemeBundle/spec/Translation/ThemeAwareTranslatorSpec.php +++ /dev/null @@ -1,172 +0,0 @@ -implement(TranslatorBagInterface::class); - - $this->beConstructedWith($translator, $themeContext); - } - - function it_implements_translator_interface(): void - { - $this->shouldImplement(TranslatorInterface::class); - } - - function it_implements_translator_bag_interface(): void - { - $this->shouldImplement(TranslatorBagInterface::class); - } - - function it_implements_warmable_interface(): void - { - $this->shouldImplement(WarmableInterface::class); - } - - function it_proxies_getting_the_locale_to_the_decorated_translator(TranslatorInterface $translator): void - { - $translator->getLocale()->willReturn('pl_PL'); - - $this->getLocale()->shouldReturn('pl_PL'); - } - - function it_proxies_setting_the_locale_to_the_decorated_translator(TranslatorInterface $translator): void - { - $translator->setLocale('pl_PL')->shouldBeCalled(); - - $this->setLocale('pl_PL'); - } - - function it_proxies_getting_catalogue_for_given_locale_to_the_decorated_translator( - TranslatorBagInterface $translator, - MessageCatalogueInterface $messageCatalogue - ): void { - $translator->getCatalogue('pl_PL')->willReturn($messageCatalogue); - - $this->getCatalogue('pl_PL')->shouldReturn($messageCatalogue); - } - - function it_just_proxies_translating(TranslatorInterface $translator, ThemeContextInterface $themeContext): void - { - $themeContext->getTheme()->willReturn(null); - - $translator->trans('id', ['param'], 'domain', null)->willReturn('translated string'); - - $this->trans('id', ['param'], 'domain')->shouldReturn('translated string'); - } - - function it_just_proxies_translating_with_custom_locale(TranslatorInterface $translator, ThemeContextInterface $themeContext): void - { - $themeContext->getTheme()->willReturn(null); - - $translator->trans('id', ['param'], 'domain', 'customlocale')->willReturn('translated string'); - - $this->trans('id', ['param'], 'domain', 'customlocale')->shouldReturn('translated string'); - } - - function it_proxies_translating_with_modified_default_locale( - TranslatorInterface $translator, - ThemeContextInterface $themeContext, - ThemeInterface $theme - ): void { - $themeContext->getTheme()->willReturn($theme); - $theme->getName()->willReturn('theme/name'); - - $translator->getLocale()->willReturn('defaultlocale'); - $translator->trans('id', ['param'], 'domain', 'defaultlocale@theme-name')->willReturn('translated string'); - - $this->trans('id', ['param'], 'domain')->shouldReturn('translated string'); - } - - function it_proxies_translating_with_modified_custom_locale( - TranslatorInterface $translator, - ThemeContextInterface $themeContext, - ThemeInterface $theme - ): void { - $themeContext->getTheme()->willReturn($theme); - $theme->getName()->willReturn('theme/name'); - - $translator->trans('id', ['param'], 'domain', 'customlocale@theme-name')->willReturn('translated string'); - - $this->trans('id', ['param'], 'domain', 'customlocale')->shouldReturn('translated string'); - } - - function it_just_proxies_choice_translating(TranslatorInterface $translator, ThemeContextInterface $themeContext): void - { - $themeContext->getTheme()->willReturn(null); - - $translator->transChoice('id', 2, ['param'], 'domain', null)->willReturn('translated string'); - - $this->transChoice('id', 2, ['param'], 'domain')->shouldReturn('translated string'); - } - - function it_just_proxies_choice_translating_with_custom_locale(TranslatorInterface $translator, ThemeContextInterface $themeContext): void - { - $themeContext->getTheme()->willReturn(null); - - $translator->transChoice('id', 2, ['param'], 'domain', 'customlocale')->willReturn('translated string'); - - $this->transChoice('id', 2, ['param'], 'domain', 'customlocale')->shouldReturn('translated string'); - } - - function it_proxies_choice_translating_with_modified_default_locale( - TranslatorInterface $translator, - ThemeContextInterface $themeContext, - ThemeInterface $theme - ): void { - $themeContext->getTheme()->willReturn($theme); - $theme->getName()->willReturn('theme/name'); - - $translator->getLocale()->willReturn('defaultlocale'); - $translator->transChoice('id', 2, ['param'], 'domain', 'defaultlocale@theme-name')->willReturn('translated string'); - - $this->transChoice('id', 2, ['param'], 'domain')->shouldReturn('translated string'); - } - - function it_proxies_choice_translating_with_modified_custom_locale( - TranslatorInterface $translator, - ThemeContextInterface $themeContext, - ThemeInterface $theme - ): void { - $themeContext->getTheme()->willReturn($theme); - $theme->getName()->willReturn('theme/name'); - - $translator->transChoice('id', 2, ['param'], 'domain', 'customlocale@theme-name')->willReturn('translated string'); - - $this->transChoice('id', 2, ['param'], 'domain', 'customlocale')->shouldReturn('translated string'); - } - - function it_does_not_warm_up_if_decorated_translator_is_not_warmable(): void - { - $this->warmUp('cache'); - } - - function it_warms_up_if_decorated_translator_is_warmable(WarmableInterface $translator): void - { - $translator->warmUp('cache')->shouldBeCalled(); - - $this->warmUp('cache'); - } -}