You are here

DropdownWithIncludeTest.php in Block Style Plugins 8

Same filename and directory in other branches
  1. 8.2 tests/src/Functional/DropdownWithIncludeTest.php

File

tests/src/Functional/DropdownWithIncludeTest.php
View source
<?php

namespace Drupal\Tests\block_style_plugins\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests the DropdownWithInclude plugin.
 *
 * Test a dropdown style selector for only the Powered by Drupal block any
 * "basic" custom block types.
 *
 * @group block_style_plugins
 */
class DropdownWithIncludeTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'block_style_plugins',
    'block_style_plugins_test',
  ];

  /**
   * A user that can edit content types.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;

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

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->adminUser = $this
      ->drupalCreateUser([
      'administer blocks',
      'access administration pages',
    ]);
    $this
      ->drupalLogin($this->adminUser);

    // Place the "Powered By Drupal" block.
    $this
      ->drupalPlaceBlock('system_powered_by_block', [
      'id' => 'poweredbytest',
      'region' => 'content',
    ]);

    // Place the "Breadcrumb" block.
    $this
      ->drupalPlaceBlock('system_breadcrumb_block', [
      'id' => 'breadcrumbtest',
      'region' => 'content',
    ]);
  }

  /**
   * Test that the "Breadcrumb" block does not have style options.
   */
  public function testBreadcrumbBlockUnstyled() {
    $assert = $this
      ->assertSession();

    // Go to the block instance configuration page.
    $this
      ->drupalGet('admin/structure/block/manage/breadcrumbtest');
    $assert
      ->pageTextContains('Block Styles');

    // Check that the style options are NOT available.
    $assert
      ->pageTextNotContains('Choose a style from the dropdown');
    $assert
      ->fieldNotExists('third_party_settings[block_style_plugins][dropdown_with_include][dropdown_class]');
  }

  /**
   * Test the the "Powered by Drupal" block does include style options.
   */
  public function testPoweredByBlockIncluded() {
    $assert = $this
      ->assertSession();

    // Go to the block instance configuration page.
    $this
      ->drupalGet('admin/structure/block/manage/poweredbytest');

    // Check that the style options are available.
    $assert
      ->responseContains('Choose a style from the dropdown');
    $assert
      ->fieldValueEquals('third_party_settings[block_style_plugins][dropdown_with_include][dropdown_class]', 'style-3');

    // Submit the form.
    $this
      ->submitForm([
      'third_party_settings[block_style_plugins][dropdown_with_include][dropdown_class]' => 'style-1',
    ], 'Save block');

    // Go to the home page.
    $this
      ->drupalGet('<front>');

    // Assert that the block was placed and has the custom class.
    $assert
      ->responseContains('style-1');

    // Go back to the block instance configuration page.
    $this
      ->drupalGet('admin/structure/block/manage/poweredbytest');

    // Check that the class is set in the style field.
    $assert
      ->fieldValueEquals('third_party_settings[block_style_plugins][dropdown_with_include][dropdown_class]', 'style-1');
  }

}

Classes

Namesort descending Description
DropdownWithIncludeTest Tests the DropdownWithInclude plugin.