/**
  * @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;
 }
 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]);
 }
 /**
  * @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;
 }
 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]);
 }
 /**
  * {@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;
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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']);
 }
 /**
  * @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_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_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);
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
0
 /**
  * @Then I should not see a homepage from :theme theme
  */
 public function iShouldNotSeeThemedHomepage(ThemeInterface $theme)
 {
     $content = file_get_contents(rtrim($theme->getPath(), '/') . '/SyliusShopBundle/views/Homepage/index.html.twig');
     Assert::notSame($this->homePage->getContents(), $content);
 }
Exemplo n.º 14
0
 /**
  * @Then I should not see a homepage from :theme theme
  */
 public function iShouldNotSeeThemedHomepage(ThemeInterface $theme)
 {
     $content = file_get_contents(rtrim($theme->getPath(), '/') . '/SyliusWebBundle/views/Frontend/Homepage/main.html.twig');
     expect($this->homePage->getContents())->notToBe($content);
 }
Exemplo n.º 15
0
 /**
  * @Given /^(this theme) changes homepage template contents to "([^"]+)"$/
  */
 public function themeChangesHomepageTemplateContents(ThemeInterface $theme, $contents)
 {
     $file = rtrim($theme->getPath(), '/') . '/SyliusShopBundle/views/Homepage/index.html.twig';
     $dir = dirname($file);
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     file_put_contents($file, $contents);
 }
Exemplo n.º 16
0
 /**
  * @param ThemeInterface $theme
  *
  * @return array
  */
 private function getThemeFiles(ThemeInterface $theme)
 {
     $finder = $this->finderFactory->create();
     $finder->ignoreUnreadableDirs()->in($theme->getPath());
     return $finder;
 }
 function it_returns_resources_locales_while_using_one_nested_theme(TranslationFilesFinderInterface $translationFilesFinder, ThemeRepositoryInterface $themeRepository, ThemeHierarchyProviderInterface $themeHierarchyProvider, ThemeInterface $mainTheme, ThemeInterface $parentTheme)
 {
     $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']);
 }