You are here

public function PrintableBlockTest::testPrintableBlock in Printer and PDF versions for Drupal 8+ 2.x

Same name and namespace in other branches
  1. 8 src/Tests/PrintableBlockTest.php \Drupal\printable\Tests\PrintableBlockTest::testPrintableBlock()

Tests the functionality of the Printable block.

File

src/Tests/PrintableBlockTest.php, line 51

Class

PrintableBlockTest
Tests the blocks present in printable module.

Namespace

Drupal\printable\Tests

Code

public function testPrintableBlock() {
  $this
    ->drupalLogin($this->adminUser);
  $edit = [
    'id' => strtolower($this
      ->randomMachineName()),
    'settings[label]' => $this
      ->randomMachineName(8),
    'region' => 'sidebar_first',
    'visibility[node_type][bundles][article]' => 'article',
  ];
  $theme = \Drupal::service('theme_handler')
    ->getDefault();
  $this
    ->drupalPostForm("admin/structure/block/add/printable_links_block%3Anode/{$theme}", $edit, t('Save block'));
  $block = Block::load($edit['id']);
  $visibility = $block
    ->getVisibility();
  $this
    ->assertTrue(isset($visibility['node_type']['bundles']['article']), 'Visibility settings were saved to configuration');

  // Test deleting the block from the edit form.
  $this
    ->drupalGet('admin/structure/block/manage/' . $edit['id']);
  $this
    ->clickLink(t('Delete'));
  $this
    ->assertRaw(t('Are you sure you want to delete the block %name?', [
    '%name' => $edit['settings[label]'],
  ]));
  $this
    ->drupalPostForm(NULL, [], t('Delete'));
  $this
    ->assertRaw(t('The block %name has been deleted.', [
    '%name' => $edit['settings[label]'],
  ]));
}