You are here

public function SimpleClassTest::testAddClassToBlock in Block Style Plugins 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/SimpleClassTest.php \Drupal\Tests\block_style_plugins\Functional\SimpleClassTest::testAddClassToBlock()

Test that a class name can be added to a block instance in a text field.

File

tests/src/Functional/SimpleClassTest.php, line 50

Class

SimpleClassTest
Test a simple class being added in a text box.

Namespace

Drupal\Tests\block_style_plugins\Functional

Code

public function testAddClassToBlock() {
  $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('Block Styles');
  $assert
    ->responseContains('Add a custom class to this block');
  $assert
    ->fieldExists('third_party_settings[block_style_plugins][simple_class][simple_class]');
  $this
    ->submitForm([
    'third_party_settings[block_style_plugins][simple_class][simple_class]' => 'sample-class',
  ], 'Save block');

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

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

  // 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][simple_class][simple_class]', 'sample-class');
}