You are here

public function OliveroTest::testPreprocessBlock in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php \Drupal\FunctionalTests\Theme\OliveroTest::testPreprocessBlock()

Tests that olivero_preprocess_block is functioning as expected.

See also

olivero.libraries.yml

File

core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php, line 72

Class

OliveroTest
Tests the Olivero theme.

Namespace

Drupal\FunctionalTests\Theme

Code

public function testPreprocessBlock() {
  $this
    ->drupalGet('');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Confirm that search narrow and search wide libraries haven't yet been
  // added.
  $this
    ->assertSession()
    ->responseNotContains('olivero/css/components/header-search-wide.css');
  $this
    ->assertSession()
    ->responseNotContains('olivero/css/components/header-search-narrow.css');

  // Enable modules that will exercise preprocess block logic.
  \Drupal::service('module_installer')
    ->install([
    'search',
    'menu_link_content',
  ]);

  // Add at least one link to the main menu.
  $parent_menu_link_content = MenuLinkContent::create([
    'title' => 'Home',
    'menu_name' => 'main',
    'link' => [
      'uri' => 'route:<front>',
    ],
  ]);
  $parent_menu_link_content
    ->save();

  // Set branding color.
  $system_theme_config = $this->container
    ->get('config.factory')
    ->getEditable('olivero.settings');
  $system_theme_config
    ->set('site_branding_bg_color', 'gray')
    ->save();
  $this
    ->rebuildAll();
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'search content',
  ]));

  // Confirm that search narrow and search wide libraries were added by
  // preprocess.
  $this
    ->assertSession()
    ->responseContains('olivero/css/components/header-search-wide.css');
  $this
    ->assertSession()
    ->responseContains('olivero/css/components/header-search-narrow.css');

  // Confirm primary-nav class was added to main menu navigation block.
  $this
    ->assertSession()
    ->elementExists('css', '#block-olivero-main-menu.primary-nav');

  // Ensure branding background color class was added.
  $this
    ->assertSession()
    ->elementExists('css', '#block-olivero-site-branding.site-branding--bg-gray');
}