Skip to content

Commit

Permalink
JMSITE-340: Do not force the library favicon if the theme is not conf…
Browse files Browse the repository at this point in the history
…igured to do so.
  • Loading branch information
imanoleguskiza authored and 22Alexandra committed Aug 22, 2024
1 parent 6e4db39 commit 26e5d03
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,11 @@ function oe_theme_preprocess_select(&$variables) {
* Implements hook_page_attachments_alter().
*/
function oe_theme_page_attachments_alter(array &$attachments) {
// If the theme is configured to not use the theme favicon, bail out.
if (!theme_get_setting('favicon.use_default')) {
return;
}

// Use different favicon based on theme component library.
$active_theme = \Drupal::theme()->getActiveTheme();
if ($active_theme->getName() === 'oe_theme' || array_key_exists('oe_theme', $active_theme->getBaseThemeExtensions())) {
Expand Down
32 changes: 32 additions & 0 deletions tests/src/Functional/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,38 @@ public function testChangeEclBranding(): void {
}
}

/**
* Test that the correct favicon is used based on theme configuration.
*/
public function testUseEclFavicon(): void {
foreach (['oe_theme', 'oe_theme_subtheme_test'] as $active_theme) {
$this->config('system.theme')->set('default', $active_theme)->save();
$this->container->set('theme.registry', NULL);
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
// Assert that the favicon provided by the theme is being used.
$this->drupalGet('<front>');
$assert_session->responseContains("/$active_theme/images/favicons/ec/favicon.ico");
$assert_session->responseContains("$active_theme/images/favicons/ec/favicon.png");
$assert_session->responseContains("/$active_theme/images/favicons/ec/favicon.svg");

// Configure theme to not use default favicon.
$this->config("$active_theme.settings")->set('favicon', [
'mimetype' => 'image/vnd.microsoft.icon',
'path' => 'https://www.w3schools.com/images/favicon.ico',
'use_default' => FALSE,
])->save();
$this->container->set('theme.registry', NULL);

// Assert that the favicon provided by the theme is not being used.
$this->drupalGet('<front>');
$assert_session->responseNotContains("/$active_theme/images/favicons/ec/favicon.ico");
$assert_session->responseNotContains("$active_theme/images/favicons/ec/favicon.png");
$assert_session->responseNotContains("/$active_theme/images/favicons/ec/favicon.svg");
$assert_session->responseContains("https://www.w3schools.com/images/favicon.ico");
}
}

/**
* Assert that current response contians a link tag with given href.
*
Expand Down

0 comments on commit 26e5d03

Please sign in to comment.