function it_throws_an_exception_if_resource_can_not_be_located(Filesystem $filesystem, ThemeInterface $theme)
 {
     $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]);
 }
Пример #2
0
 function let(LoaderInterface $loader, Collection $resourcesToThemes, ThemeInterface $theme)
 {
     $theme->getLogicalName()->willReturn("sylius/sample-theme");
     $resourcesToThemes->get(realpath($this->getThemeTranslationResourcePath()))->willReturn($theme);
     $resourcesToThemes->get(realpath($this->getVanillaTranslationResourcePath()))->willReturn(null);
     $this->beConstructedWith($loader, $resourcesToThemes);
 }
 function it_throws_an_exception_if_settings_schema_does_not_exist(ThemeInterface $theme)
 {
     $theme->getTitle()->willReturn('Candy shop');
     $theme->getName()->willReturn('candy/shop');
     $theme->getPath()->willReturn($this->vfsStream->url());
     $this->shouldThrow(new \InvalidArgumentException(sprintf('Could not find settings schema of theme "Candy shop" (candy/shop) in file "%s"', $this->vfsStream->url() . '/Settings.php')))->during('getSchema', [$theme]);
 }
Пример #4
0
 /**
  * @param ThemeInterface $theme
  */
 private function updateTheme(ThemeInterface $theme)
 {
     $existingTheme = $this->themeRepository->findOneByName($theme->getName());
     if (null !== $existingTheme) {
         $theme = $this->themeMerger->merge($existingTheme, $theme);
     }
     $this->themeRepository->add($theme);
 }
 /**
  * {@inheritdoc}
  */
 public function locateResource($resourceName, ThemeInterface $theme)
 {
     $path = sprintf('%s/%s', $theme->getPath(), $resourceName);
     if (!$this->filesystem->exists($path)) {
         throw new ResourceNotFoundException($resourceName, $theme);
     }
     return $path;
 }
 public function it_defines_themes_names_choices(OptionsResolver $resolver, ThemeProviderInterface $themeProvider, ThemeInterface $theme)
 {
     $theme->getName()->willReturn('swp/theme-name');
     $themeProvider->getCurrentTenantAvailableThemes()->willReturn([$theme]);
     $resolver->setNormalizer('choices', Argument::type('callable'))->willReturn($resolver);
     $resolver->setDefaults(['invalid_message' => 'The selected theme does not exist'])->shouldBeCalled();
     $this->configureOptions($resolver);
 }
Пример #7
0
 public function it_should_return_global_variables(ThemeInterface $theme, ThemeContextInterface $themeContext)
 {
     $theme->getName()->willReturn('swp/theme-one');
     $theme->getPath()->willReturn('/path/to/theme/');
     $themeContext->getTheme()->shouldBeCalled()->willReturn($theme);
     $globals = ['theme' => $theme];
     $this->getGlobals()->shouldReturn($globals);
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function getThemeHierarchy(ThemeInterface $theme)
 {
     $parents = [];
     $parentsNames = $theme->getParentsNames();
     foreach ($parentsNames as $parentName) {
         $parents = array_merge($parents, $this->getThemeHierarchy($this->getTheme($parentName)));
     }
     return array_merge([$theme], $parents);
 }
 /**
  * @param ThemeInterface $theme
  * @param int $screenshotNumber
  *
  * @return string
  */
 private function getScreenshotPath(ThemeInterface $theme, $screenshotNumber)
 {
     $screenshots = $theme->getScreenshots();
     if (!isset($screenshots[$screenshotNumber])) {
         throw new NotFoundHttpException(sprintf('Theme "%s" does not have screenshot #%d', $theme->getTitle(), $screenshotNumber));
     }
     $screenshotRelativePath = $screenshots[$screenshotNumber];
     return rtrim($theme->getPath(), \DIRECTORY_SEPARATOR) . \DIRECTORY_SEPARATOR . $screenshotRelativePath;
 }
 function it_registers_theme_schema_alias_if_not_exists_during_loading_settings(SettingsManagerInterface $decoratedSettingsManager, ServiceRegistryInterface $schemaRegistry, ThemeSettingsSchemaProviderInterface $themeSettingsSchemaProvider, ThemeInterface $theme, SettingsInterface $settings, SchemaInterface $schema)
 {
     $theme->getName()->willReturn('theme/name');
     $schemaRegistry->has('theme_theme/name')->willReturn(false);
     $themeSettingsSchemaProvider->getSchema($theme)->willReturn($schema);
     $schemaRegistry->register('theme_theme/name', $schema)->shouldBeCalled();
     $decoratedSettingsManager->load('theme_theme/name', null)->willReturn($settings);
     $this->load($theme)->shouldReturn($settings);
 }
 function it_transforms_a_cycle_to_user_friendly_message(ThemeInterface $firstTheme, ThemeInterface $secondTheme, ThemeInterface $thirdTheme, ThemeInterface $fourthTheme)
 {
     $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".');
 }
Пример #12
0
 function it_returns_an_array_of_translation_resources_paths(FinderFactoryInterface $finderFactory, Finder $finder, ThemeInterface $theme)
 {
     $finderFactory->create()->willReturn($finder);
     $theme->getPath()->willReturn('/theme');
     $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']);
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function load(ThemeInterface $theme, $namespace = null)
 {
     $schemaAlias = sprintf('theme_%s', $theme->getName());
     if (!$this->schemaRegistry->has($schemaAlias)) {
         $schema = $this->themeSettingsSchemaProvider->getSchema($theme);
         $this->schemaRegistry->register($schemaAlias, $schema);
     }
     return $this->decoratedSettingsManager->load($schemaAlias, $namespace);
 }
 /**
  * @param string         $resourceName
  * @param ThemeInterface $theme
  *
  * @return array
  */
 protected function getApplicationPaths($resourceName, ThemeInterface $theme)
 {
     $paths = [sprintf('%s/%s', $theme->getPath(), $resourceName)];
     if ($this->deviceDetection->getType() !== null) {
         $paths[] = sprintf('%s/%s/%s', $theme->getPath(), $this->deviceDetection->getType(), $resourceName);
         krsort($paths);
     }
     return $paths;
 }
Пример #15
0
 function it_returns_theme_list_in_hierarchized_order(ThemeRepositoryInterface $themeRepository, ThemeInterface $firstTheme, ThemeInterface $secondTheme)
 {
     $firstTheme->getName()->willReturn('foo/bar1');
     $firstTheme->getParentsNames()->willReturn(['foo/bar2']);
     $secondTheme->getName()->willReturn('foo/bar2');
     $secondTheme->getParentsNames()->willReturn([]);
     $themeRepository->findOneByName('foo/bar1')->willReturn($firstTheme);
     $themeRepository->findOneByName('foo/bar2')->willReturn($secondTheme);
     $this->getThemeHierarchy($firstTheme)->shouldReturn([$firstTheme, $secondTheme]);
 }
 function it_returns_theme_list_in_hierarchized_order(ThemeRepositoryInterface $themeRepository, ThemeInterface $firstTheme, ThemeInterface $secondTheme)
 {
     $firstTheme->getSlug()->willReturn("foo/bar1");
     $firstTheme->getParentsSlugs()->willReturn(["foo/bar2"]);
     $secondTheme->getSlug()->willReturn("foo/bar2");
     $secondTheme->getParentsSlugs()->willReturn([]);
     $themeRepository->findOneBySlug("foo/bar1")->willReturn($firstTheme);
     $themeRepository->findOneBySlug("foo/bar2")->willReturn($secondTheme);
     $this->getThemeHierarchy($firstTheme)->shouldReturn([$firstTheme, $secondTheme]);
 }
 function it_resolves_themes(ThemeRepositoryInterface $themeRepository, ThemeInterface $firstTheme, ThemeInterface $secondTheme)
 {
     $firstTheme->getLogicalName()->willReturn("foo/bar1");
     $firstTheme->getParentsNames()->willReturn(["foo/bar2"]);
     $secondTheme->getLogicalName()->willReturn("foo/bar2");
     $secondTheme->getParentsNames()->willReturn([]);
     $themeRepository->findByLogicalName("foo/bar1")->willReturn($firstTheme);
     $themeRepository->findByLogicalName("foo/bar2")->willReturn($secondTheme);
     $this->getDependencies($firstTheme)->shouldReturn([$secondTheme]);
 }
 function it_throws_resource_not_found_exception_if_the_location_found_in_cache_is_null(TemplateLocatorInterface $decoratedTemplateLocator, Cache $cache, TemplateReferenceInterface $template, ThemeInterface $theme)
 {
     $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]);
 }
Пример #19
0
 /**
  * @param ThemeInterface $theme
  * @param string $filepath
  */
 public function __construct(ThemeInterface $theme, $filepath)
 {
     $this->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] . '_' . $theme->getCode();
     $this->format = $parts[2];
 }
 function it_adds_theme_parents_to_context_while_setting_theme(ThemeDependenciesResolverInterface $themeDependenciesResolver, ThemeInterface $firstTheme, ThemeInterface $secondTheme)
 {
     $firstTheme->getLogicalName()->willReturn("foo/bar1");
     $firstTheme->getParentsNames()->willReturn(["foo/bar2"]);
     $secondTheme->getLogicalName()->willReturn("foo/bar2");
     $secondTheme->getParentsNames()->willReturn([]);
     $themeDependenciesResolver->getDependencies($firstTheme)->shouldBeCalled()->willReturn([$secondTheme]);
     $this->setTheme($firstTheme);
     $this->getThemes()->shouldHaveCount(2);
     $this->getThemes()->shouldReturn([$firstTheme, $secondTheme]);
 }
 /**
  * {@inheritdoc}
  */
 public function getThemeHierarchy(ThemeInterface $theme = null)
 {
     if (null === $theme) {
         return [];
     }
     $parents = [];
     foreach ($theme->getParents() as $parent) {
         $parents = array_merge($parents, $this->getThemeHierarchy($parent));
     }
     return array_merge([$theme], $parents);
 }
 function it_throws_an_exception_if_resource_can_not_be_located(Filesystem $filesystem, KernelInterface $kernel, ThemeInterface $theme, BundleInterface $childBundle, BundleInterface $parentBundle)
 {
     $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]);
 }
 /**
  * {@inheritdoc}
  */
 public function getSchema(ThemeInterface $theme)
 {
     $schemaPath = sprintf('%s/Settings.php', $theme->getPath());
     if (!file_exists($schemaPath)) {
         throw new \InvalidArgumentException(sprintf('Could not find settings schema of theme "%s" (%s) in file "%s"', $theme->getTitle(), $theme->getName(), $schemaPath));
     }
     $schema = (require $schemaPath);
     if (!$schema instanceof SchemaInterface) {
         throw new \InvalidArgumentException(sprintf('File "%s" must return an instance of "%s"', $schemaPath, SchemaInterface::class));
     }
     return $schema;
 }
 function it_finds_circular_dependency_if_theme_parents_are_cycled(ThemeInterface $firstTheme, ThemeInterface $secondTheme, ThemeInterface $thirdTheme, ThemeInterface $fourthTheme)
 {
     $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]);
 }
 function it_finds_translation_files_and_adds_them_to_translator(ContainerBuilder $containerBuilder, ThemeRepositoryInterface $themeRepository, ThemeInterface $firstTheme, ThemeInterface $secondTheme, Definition $translatorDefinition)
 {
     $containerBuilder->get("sylius.theme.repository")->shouldBeCalled()->willReturn($themeRepository);
     $themeRepository->findAll()->shouldBeCalled()->willReturn([$firstTheme, $secondTheme]);
     $firstTheme->getPath()->shouldBeCalled()->willReturn($this->getFirstThemePath());
     $secondTheme->getPath()->shouldBeCalled()->willReturn($this->getSecondThemePath());
     $containerBuilder->getParameter('kernel.bundles')->shouldBeCalled()->willReturn(["SampleBundle" => "/Foo/Bar"]);
     $containerBuilder->addResource(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'))->shouldBeCalled();
     $containerBuilder->findDefinition('translator.default')->shouldBeCalled()->willReturn($translatorDefinition);
     $translatorDefinition->getArgument(3)->shouldBeCalled()->willReturn(["resource_files" => ["en" => ["/lorem/ipsum/messages.en.yml"]]]);
     $translatorDefinition->replaceArgument(3, ["resource_files" => ["en" => ["/lorem/ipsum/messages.en.yml", $this->getFirstThemePath() . '/SampleBundle/translations/messages.en.yml', $this->getFirstThemePath() . '/translations/messages.en.yml', $this->getSecondThemePath() . '/translations/messages.en.yml']]])->shouldBeCalled();
     $this->process($containerBuilder);
 }
 /**
  * {@inheritdoc}
  */
 public function check(ThemeInterface $theme, array $previousThemes = [])
 {
     if (0 === count($theme->getParents())) {
         return;
     }
     $previousThemes = array_merge($previousThemes, [$theme]);
     foreach ($theme->getParents() as $parent) {
         if (in_array($parent, $previousThemes, true)) {
             throw new CircularDependencyFoundException(array_merge($previousThemes, [$parent]));
         }
         $this->check($parent, $previousThemes);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getDependencies(ThemeInterface $theme)
 {
     $parents = [];
     $parentsNames = $theme->getParentsNames();
     foreach ($parentsNames as $parentName) {
         $parent = $this->themeRepository->findByLogicalName($parentName);
         if (null === $parent) {
             throw new \InvalidArgumentException(sprintf('Theme "%s" not found (required by theme "%s")!', $parentName, $theme->getLogicalName()), 0);
         }
         $parents = array_merge($parents, [$parent], $this->getDependencies($parent));
     }
     return $parents;
 }
 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)
 {
     $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);
 }
Пример #29
0
 /**
  * {@inheritdoc}
  *
  * @param string $resourcePath Eg. "@AcmeBundle/Resources/views/template.html.twig"
  */
 public function locateResource($resourcePath, ThemeInterface $theme)
 {
     $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
  * @param ThemeInterface $theme
  */
 protected function getBundlePaths($resourcePath, ThemeInterface $theme)
 {
     $bundleName = $this->getBundleNameFromResourcePath($resourcePath);
     $resourceName = $this->getResourceNameFromResourcePath($resourcePath);
     $bundles = $this->kernel->getBundle($bundleName, false);
     $paths = [];
     if (is_array($bundles)) {
         foreach ($bundles as $bundle) {
             if ($this->deviceDetection->getType() !== null) {
                 $paths[] = sprintf('%s/%s/%s/%s', $theme->getPath(), $this->deviceDetection->getType(), $bundle->getName(), $resourceName);
             }
             $paths[] = sprintf('%s/%s/%s', $theme->getPath(), $bundle->getName(), $resourceName);
         }
     }
     return $paths;
 }