You are here

public function BlockVisibilityGroupsUITest::testBlockVisibilityCreation in Block Visibility Groups 8

Test for the creation of block visibility groups.

File

src/Tests/BlockVisibilityGroupsUITest.php, line 15

Class

BlockVisibilityGroupsUITest
Tests the block_visibility_groups UI.

Namespace

Drupal\block_visibility_groups\Tests

Code

public function testBlockVisibilityCreation() {

  // Enable action and task blocks.
  $this
    ->drupalPlaceBlock('local_actions_block');
  $this
    ->drupalPlaceBlock('local_tasks_block');

  // Test block visibility tab exists and works.
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->assertLink('Block Visibility Groups');
  $this
    ->clickLink('Block Visibility Groups');
  $this
    ->assertResponse(200);

  // Test add block visibilty button exists and works.
  $this
    ->assertLink('Add Block Visibility Group');
  $this
    ->clickLink('Add Block Visibility Group');
  $this
    ->assertResponse(200);

  // Fill and submit form for block visibilty groups creation.
  $this
    ->assertFieldById('edit-label');
  $edit = [
    'label' => $this
      ->randomMachineName(),
    'id' => 'test_block_visibility_groups',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  // Block visibility created successfully or not.
  $this
    ->assertText(t('Saved the @group Block Visibility Group.', [
    '@group' => $edit['label'],
  ]));
  $this
    ->assertText($edit['label']);
}