diff --git a/modules/oe_whitelabel_helper/tests/src/Kernel/CorporateLogoBlockTest.php b/modules/oe_whitelabel_helper/tests/src/Kernel/CorporateLogoBlockTest.php deleted file mode 100644 index 287189ab168a1f090c2cdee1a764bc58b3de1eba..0000000000000000000000000000000000000000 --- a/modules/oe_whitelabel_helper/tests/src/Kernel/CorporateLogoBlockTest.php +++ /dev/null @@ -1,157 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\Tests\oe_whitelabel_helper\Kernel; - -use Drupal\KernelTests\KernelTestBase; -use Symfony\Component\DomCrawler\Crawler; -use Drupal\language\Entity\ConfigurableLanguage; - -/** - * Tests the Corporate Logo Block rendering. - */ -class CorporateLogoBlockTest extends KernelTestBase { - - /** - * Languages. - * - * @var array - */ - protected $languages = []; - - /** - * {@inheritdoc} - */ - protected static $modules = [ - 'block', - 'language', - 'oe_bootstrap_theme_helper', - 'oe_whitelabel_helper', - 'system', - 'ui_patterns', - 'ui_patterns_library', - 'user', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - parent::setUp(); - - $this->installConfig(['language']); - $this->installEntitySchema('configurable_language'); - - \Drupal::service('theme_installer')->install(['oe_whitelabel']); - - \Drupal::configFactory() - ->getEditable('system.theme') - ->set('default', 'oe_whitelabel') - ->save(); - $this->container->set('theme.registry', NULL); - } - - /** - * Tests the rendering of blocks. - * - * @param string $lang - * Language code. - * - * @dataProvider providerTestLogoBlockRendering - */ - public function testLogoBlockRendering(string $lang): void { - if ($lang !== 'en') { - $this->setLanguageByCode($lang); - } - // Assert EC logo. - $entity_type_manager = $this->container - ->get('entity_type.manager') - ->getStorage('block'); - $entity = $entity_type_manager->create([ - 'id' => 'sitebranding', - 'theme' => 'oe_whitelabel', - 'plugin' => 'system_branding_block', - 'settings' => [ - 'id' => 'system_branding_block', - 'label' => 'Site Branding', - 'provider' => 'system', - 'label_display' => '0', - ], - ]); - $entity->save(); - $builder = \Drupal::entityTypeManager()->getViewBuilder('block'); - $build = $builder->view($entity, 'block'); - $render = $this->container->get('renderer')->renderRoot($build); - $crawler = new Crawler($render->__toString()); - - $logo = $crawler->filter('img'); - $this->assertCount(1, $logo); - $expected = "/themes/contrib/oe_bootstrap_theme/assets/logos/ec/logo-ec--{$lang}.svg"; - $this->assertSame($expected, $logo->attr('src')); - - // Assert EU logo. - $entity_type_manager = $this->container - ->get('entity_type.manager') - ->getStorage('block'); - $entity = $entity_type_manager->create([ - 'id' => 'sitebranding', - 'theme' => 'oe_whitelabel', - 'plugin' => 'system_branding_block', - 'settings' => [ - 'id' => 'system_branding_block', - 'label' => 'Corporate Logo Block', - 'provider' => 'system', - 'label_display' => '0', - ], - ]); - $entity->save(); - $builder = \Drupal::entityTypeManager()->getViewBuilder('block'); - $build = $builder->view($entity, 'block'); - $render = $this->container->get('renderer')->renderRoot($build); - $crawler = new Crawler($render->__toString()); - - $logo = $crawler->filter('img'); - $this->assertCount(1, $logo); - $expected = "/themes/contrib/oe_bootstrap_theme/assets/logos/eu/logo-eu--{$lang}.svg"; - $this->assertSame($expected, $logo->attr('src')); - $picture = $crawler->filter('picture'); - $this->assertCount(1, $picture); - $source = $crawler->filter('source'); - $expected = "/themes/contrib/oe_bootstrap_theme/assets/logos/eu/mobile/logo-eu--{$lang}.svg"; - $this->assertSame($expected, $source->attr('srcset')); - } - - /** - * Sets language from lang code. - * - * @param string $language_code - * The language code. - */ - protected function setLanguageByCode(string $language_code) :void { - $this->languages[$language_code] = ConfigurableLanguage::createFromLangcode($language_code); - $this->languages[$language_code]->save(); - $this->languageManager = $this->container->get('language_manager'); - $this->languageManager->reset(); - - \Drupal::service('language.default')->set($this->languages[$language_code]); - } - - /** - * Provides test data for ::providerTestLogoBlockRendering(). - * - * @return array[] - * Test data. - */ - public function providerTestLogoBlockRendering(): array { - return [ - 'default' => [ - 'en', - ], - 'german' => [ - 'de', - ], - ]; - } - -} diff --git a/tests/src/Functional/CorporateHeaderLogosTest.php b/tests/src/Functional/CorporateHeaderLogosTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d6d444b86ea7f545f345d89348f5b996f843ad32 --- /dev/null +++ b/tests/src/Functional/CorporateHeaderLogosTest.php @@ -0,0 +1,104 @@ +<?php + +declare(strict_types = 1); + +namespace Drupal\Tests\oe_whitelabel\Functional; + +use Drupal\language\Entity\ConfigurableLanguage; +use Drupal\Tests\BrowserTestBase; + +/** + * Tests that corporate logos are displayed correctly. + */ +class CorporateHeaderLogosTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'language', + 'oe_whitelabel_helper', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + // Enable and set OpenEuropa Theme as default. + \Drupal::service('theme_installer')->install(['oe_whitelabel']); + \Drupal::configFactory() + ->getEditable('system.theme') + ->set('default', 'oe_whitelabel') + ->save(); + + \Drupal::service('module_installer')->install(['language']); + $language = ConfigurableLanguage::createFromLangcode('es'); + $language->save(); + + // Rebuild the ui_pattern definitions to collect the ones provided by + // oe_whitelabel itself. + \Drupal::service('plugin.manager.ui_patterns')->clearCachedDefinitions(); + } + + /** + * Tests that the breadcrumbs are cached correctly. + */ + public function testCorporateHeaderLogos(): void { + // Create a user that does have permission to administer theme settings. + $user = $this->drupalCreateUser(['administer themes']); + $this->drupalLogin($user); + + $this->drupalGet('<front>'); + $page = $this->getSession()->getPage(); + $assert_session = $this->assertSession(); + + $assert_session->elementExists('css', 'header.bcl-header.bcl-header--neutral'); + $assert_session->elementExists('css', 'img[alt="Home logo"]'); + + // Visit theme administration page. + $this->drupalGet('/admin/appearance/settings/oe_whitelabel'); + + // Select EU component library and save configuration. + $page->selectFieldOption('Component library', 'European Union'); + $page->pressButton('Save configuration'); + + $this->drupalGet('<front>'); + + $assert_session->elementExists('css', 'header.bcl-header.bcl-header--eu'); + $assert_session->elementExists('css', 'header > nav > div > div > a[href="https://european-union.europa.eu/index_en"]'); + $assert_session->elementExists('css', 'picture > source[srcset="/build/themes/contrib/oe_bootstrap_theme/assets/logos/eu/mobile/logo-eu--en.svg"]'); + $assert_session->elementExists('css', 'picture > img[src="/build/themes/contrib/oe_bootstrap_theme/assets/logos/eu/logo-eu--en.svg"]'); + + $this->drupalGet('es/'); + + $assert_session->elementExists('css', 'header.bcl-header.bcl-header--eu'); + $assert_session->elementExists('css', 'header > nav > div > div > a[href="https://european-union.europa.eu/index_es"]'); + $assert_session->elementExists('css', 'picture > source[srcset="/build/themes/contrib/oe_bootstrap_theme/assets/logos/eu/mobile/logo-eu--es.svg"]'); + $assert_session->elementExists('css', 'picture > img[src="/build/themes/contrib/oe_bootstrap_theme/assets/logos/eu/logo-eu--es.svg"]'); + + // Visit theme administration page. + $this->drupalGet('/admin/appearance/settings/oe_whitelabel'); + + // Select EC component library and save configuration. + $page->selectFieldOption('Component library', 'European Commission'); + $page->pressButton('Save configuration'); + + $this->drupalGet('<front>'); + $assert_session->elementExists('css', 'header.bcl-header.bcl-header--ec'); + $assert_session->elementExists('css', 'header > nav > div > div > a[href="https://ec.europa.eu/info/index_en"]'); + $assert_session->elementExists('css', 'img[src="/build/themes/contrib/oe_bootstrap_theme/assets/logos/ec/logo-ec--en.svg"]'); + + $this->drupalGet('es/'); + $assert_session->elementExists('css', 'header.bcl-header.bcl-header--ec'); + $assert_session->elementExists('css', 'header > nav > div > div > a[href="https://ec.europa.eu/info/index_es"]'); + $assert_session->elementExists('css', 'img[src="/build/themes/contrib/oe_bootstrap_theme/assets/logos/ec/logo-ec--es.svg"]'); + } + +}