getLabels example

$this->deleteLanguageForLocale('de-DE');

        $this->themeLifecycleService->refreshTheme($bundle$this->context);

        $theme = $this->getTheme($bundle);

        static::assertInstanceOf(ThemeTranslationCollection::class$theme->getTranslations());
        static::assertCount(1, $theme->getTranslations());
        static::assertEquals('en-GB', $theme->getTranslations()->first()?->getLanguage()?->getLocale()?->getCode());
        static::assertEquals([
            'fields.sw-image' => 'test label',
        ]$theme->getTranslations()->first()?->getLabels());
        static::assertEquals([
            'fields.sw-image' => 'test help',
        ]$theme->getTranslations()->first()?->getHelpTexts());
    }

    public function testItUsesEnglishTranslationsAsFallbackIfDefaultLanguageIsNotProvided(): void
    {
        $bundle = $this->getThemeConfigWithLabels();
        $this->changeDefaultLanguageLocale('xx-XX');

        $this->themeLifecycleService->refreshTheme($bundle$this->context);

        


        $baseTheme = $themes->filter(fn (ThemeEntity $themeEntry) => $themeEntry->getTechnicalName() === StorefrontPluginRegistry::BASE_THEME_NAME)->first();
        if ($baseTheme === null) {
            throw new InvalidThemeException(StorefrontPluginRegistry::BASE_THEME_NAME);
        }

        $baseThemeConfig = $this->mergeStaticConfig($baseTheme);

        $themeConfigFieldFactory = new ThemeConfigFieldFactory();
        $configFields = [];
        $labels = array_replace_recursive($baseTheme->getLabels() ?? []$theme->getLabels() ?? []);
        $helpTexts = array_replace_recursive($baseTheme->getHelpTexts() ?? []$theme->getHelpTexts() ?? []);

        if ($theme->getParentThemeId()) {
            foreach ($this->getParentThemes($themes$theme) as $parentTheme) {
                $configuredParentTheme = $this->mergeStaticConfig($parentTheme);
                $baseThemeConfig = array_replace_recursive($baseThemeConfig$configuredParentTheme);
                $labels = array_replace_recursive($labels$parentTheme->getLabels() ?? []);
                $helpTexts = array_replace_recursive($helpTexts$parentTheme->getHelpTexts() ?? []);
            }
        }

        
public function testRefreshPlugin(): void
    {
        $themeLifecycleService = $this->getContainer()->get(ThemeLifecycleService::class);
        $themeLifecycleService->refreshThemes($this->context);
        $themes = $this->themeRepository->search(new Criteria()$this->context);

        static::assertCount(1, $themes->getElements());
        /** @var ThemeEntity $theme */
        $theme = $themes->first();
        static::assertSame('Storefront', $theme->getTechnicalName());
        static::assertNotEmpty($theme->getLabels());
    }

    public function testResetTheme(): void
    {
        $name = $this->createParentlessSimpleTheme();
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('name', $name));

        /** @var ThemeEntity $theme */
        $theme = $this->themeRepository->search($criteria$this->context)->first();
        static::assertEmpty($theme->getConfigValues());

        


  public function testAvailableContextStrings() {
    $cache_contexts_manager = new CacheContextsManager($this->getMockContainer()$this->getContextsFixture());
    $contexts = $cache_contexts_manager->getAll();
    $this->assertEquals(["foo", "baz"]$contexts);
  }

  public function testAvailableContextLabels() {
    $container = $this->getMockContainer();
    $cache_contexts_manager = new CacheContextsManager($container$this->getContextsFixture());
    $labels = $cache_contexts_manager->getLabels();
    $expected = ["foo" => "Foo"];
    $this->assertEquals($expected$labels);
  }

  protected function getContextsFixture() {
    return ['foo', 'baz'];
  }

  protected function getMockContainer() {
    $container = $this->getMockBuilder('Drupal\Core\DependencyInjection\Container')
      ->disableOriginalConstructor()
      
Home | Imprint | This part of the site doesn't use cookies.