You are here

public function BlockFieldPluginTest::testBlockFieldTitleOverride in Display Suite 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/BlockFieldPluginTest.php \Drupal\Tests\ds\Functional\BlockFieldPluginTest::testBlockFieldTitleOverride()

Test block title override.

File

tests/src/Functional/BlockFieldPluginTest.php, line 54

Class

BlockFieldPluginTest
Tests for managing custom code, and block fields.

Namespace

Drupal\Tests\ds\Functional

Code

public function testBlockFieldTitleOverride() {

  // Block fields.
  $edit = [
    'name' => 'Test block title field',
    'id' => 'test_block_title_field',
    'entities[node]' => '1',
    'block' => 'views_block:ds_testing-block_1',
  ];
  $this
    ->dsCreateBlockField($edit);
  $this
    ->dsSelectLayout();

  // Assert it's found on the Field UI for article.
  $this
    ->drupalGet('admin/structure/types/manage/article/display');
  $this
    ->assertSession()
    ->responseContains('fields[dynamic_block_field:node-test_block_title_field][weight]');
  $fields = [
    'fields[dynamic_block_field:node-test_block_title_field][region]' => 'left',
    'fields[dynamic_block_field:node-test_block_title_field][label]' => 'above',
    'fields[body][region]' => 'right',
  ];
  $this
    ->dsSelectLayout();
  $this
    ->dsConfigureUi($fields);

  // Create a node.
  $settings = [
    'type' => 'article',
    'promote' => 1,
  ];
  $node = $this
    ->drupalCreateNode($settings);

  // Look at node and verify the block title is overridden.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->responseContains('Test block title field');

  // Update testing label.
  $edit = [
    'use_block_title' => '1',
  ];
  $this
    ->drupalGet('admin/structure/ds/fields/manage_block/test_block_title_field');
  $this
    ->submitForm($edit, 'Save');
  $text = t('The field %name has been saved', [
    '%name' => 'Test block title field',
  ]);
  $this
    ->assertSession()
    ->responseContains((string) $text);

  // Look at node and verify the block title is overridden.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->responseContains('Block title from view');
}