You are here

public function BlockTest::testBlock in Display Suite 8.4

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

Test adding a block, modifying output.

File

tests/src/Functional/BlockTest.php, line 59

Class

BlockTest
Tests for the manage display tab in Display Suite.

Namespace

Drupal\Tests\ds\Functional

Code

public function testBlock() {

  // Create basic block type.
  $edit = [
    'label' => 'Basic Block',
    'id' => 'basic',
  ];
  $this
    ->drupalGet('admin/structure/block/block-content/types/add');
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Custom block type Basic Block has been added.');

  // Create a basic block.
  $edit = [];
  $edit['info[0][value]'] = 'Test Block';
  $edit['body[0][value]'] = $this
    ->randomMachineName(16);
  $this
    ->drupalGet('block/add/basic');
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Basic Block Test Block has been created.');

  // Place the block.
  $instance = [
    'id' => 'testblock',
    'settings[label]' => $edit['info[0][value]'],
    'region' => 'sidebar_first',
  ];
  $block = BlockContent::load(1);
  $url = 'admin/structure/block/add/block_content:' . $block
    ->uuid() . '/' . $this
    ->config('system.theme')
    ->get('default');
  $this
    ->drupalGet($url);
  $this
    ->submitForm($instance, 'Save block');

  // Change to a DS layout.
  $url = 'admin/structure/block/block-content/manage/basic/display';
  $edit = [
    'ds_layout' => 'ds_2col',
  ];
  $this
    ->drupalGet($url);
  $this
    ->submitForm($edit, 'Save');
  $fields = [
    'fields[block_description][region]' => 'left',
    'fields[body][region]' => 'right',
  ];
  $this
    ->dsConfigureUi($fields, 'admin/structure/block/block-content/manage/basic/display');

  // View the block.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->pageTextContains('Test Block');
  $xpath = $this
    ->xpath('//div[@class="region region-sidebar-first"]/div/div[@class="block-content block-content--type-basic block-content--view-mode-full ds-2col clearfix"]/div[@class="group-left"]/div[@class="field field--name-block-description field--type-ds field--label-hidden field__item"]/h2');
  $this
    ->assertEquals(count($xpath), 1, 'Description in group-left');
  $xpath = $this
    ->xpath('//div[@class="region region-sidebar-first"]/div/div[@class="block-content block-content--type-basic block-content--view-mode-full ds-2col clearfix"]/div[@class="group-right"]/div[@class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"]/p');
  $this
    ->assertEquals(count($xpath), 1, 'Body in group-right');
}