You are here

LayoutBuilderInlineBlockTest.php in Block Style Plugins 8.2

File

tests/src/FunctionalJavascript/LayoutBuilderInlineBlockTest.php
View source
<?php

namespace Drupal\Tests\block_style_plugins\FunctionalJavascript;

use Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockTestBase;

/**
 * Tests that the inline block feature works with styles.
 *
 * @group block_style_plugins
 */
class LayoutBuilderInlineBlockTest extends InlineBlockTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'node',
    'layout_builder',
    'block_style_plugins',
    'block_style_plugins_test',
    'contextual',
  ];

  /**
   * Default Theme.
   */
  protected $defaultTheme = 'classy';

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $user = $this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
      'administer node fields',
      'access contextual links',
      'create and edit custom blocks',
    ]);
    $user
      ->save();
    $this
      ->drupalLogin($user);

    // Enable layout builder.
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
      'layout[allow_custom]' => TRUE,
    ], 'Save');
  }

  /**
   * Tests that styles are correctly included/excluded from inline blocks.
   */
  public function testInlineBlocksVisibility() {
    $assert = $this
      ->assertSession();
    $this
      ->drupalGet('node/1/layout');

    // Add a basic block with the body field set.
    $this
      ->addInlineBlockToLayout('Block title', 'The DEFAULT block body');

    // Force the finicky contextual links to be visible.
    $this
      ->getSession()
      ->executeScript("jQuery('" . static::INLINE_BLOCK_LOCATOR . " .contextual .trigger').each(function () {this.style.setProperty('position', 'relative', 'important')})");

    // Click the contextual link.
    $this
      ->clickContextualLink(static::INLINE_BLOCK_LOCATOR, 'Style settings');
    $assert
      ->assertWaitOnAjaxRequest();

    // There should not be an option for the excluded style.
    $assert
      ->pageTextContains('Simple Class');
    $assert
      ->pageTextContains('Dropdown with Include');
    $assert
      ->pageTextNotContains('Checkbox with Exclude');
    $assert
      ->pageTextNotContains('Styles Created by Yaml');
  }

}

Classes

Namesort descending Description
LayoutBuilderInlineBlockTest Tests that the inline block feature works with styles.