Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OEL-450: Theme the site branding block. #3

Merged
merged 6 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "block.html.twig" %}
{#
/**
* @file
* Theme override for a branding block.
*
* Each branding element variable (logo, name, slogan) is only available if
* enabled in the block configuration.
*
* Available variables:
* - site_logo: Logo for site as defined in Appearance or theme settings.
* - site_name: Name for site as defined in Site information settings.
* - site_slogan: Slogan for site as defined in Site information settings.
*/
#}
{% block content %}
{% if site_logo %}
<a href="{{ path('<front>') }}" rel="home" class="site-logo">
<img src="{{ site_logo }}" alt="{{ 'Home'|t }}" />
</a>
{% endif %}
{% if site_name %}
<div class="site-name h1 text-white text-decoration-none align-bottom">
<a href="{{ path('<front>') }}" rel="home">{{ site_name }}</a>
</div>
{% endif %}
{% if site_slogan %}
<div class="site-slogan">{{ site_slogan }}</div>
{% endif %}
{% endblock %}
68 changes: 68 additions & 0 deletions tests/Functional/SiteBrandingBlockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use a functional test just to check some classes and/or markup.
Please use something similar to https://github.com/openeuropa/oe_theme/blob/2.x/tests/Kernel/RenderingTest.php#L103

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the end that one was incompatible with blocks


declare(strict_types = 1);

namespace Drupal\Tests\oe_whitelabel\Functional;

use Drupal\Tests\BrowserTestBase;

/**
* Tests of Site Branding Block.
*/
class SiteBrandingBlockTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
public static $modules = [
'config',
'system',
'ui_patterns',
'ui_patterns_library',
'ui_patterns_settings',
'components',
'field',
'field_ui',
'toolbar',
'block',
];

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

// Enable and set OpenEuropa Whitelabel Theme as default.
\Drupal::service('theme_installer')->install(['oe_whitelabel']);
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'oe_whitelabel')
->save();

/* Rebuild the ui_pattern definitions to collect the ones provided by
oe_whitelabel itself. */
\Drupal::service('plugin.manager.ui_patterns')->clearCachedDefinitions();

// Ensure that the system branding block is placed as well.
$this->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
]);

}

/**
* Asserts classes contained at site branding block.
*/
public function testClassesSiteName(): void {
$this->drupalGet('<front>');
$assert_session = $this->assertSession();
$assert_session->elementExists('css', 'div.site-name.h1.text-white.text-decoration-none.align-bottom');
}

}